feat: move UserDTO logic into single file

This commit is contained in:
2025-06-07 00:11:46 +02:00
parent cc7f7f40c4
commit ae41076673
3 changed files with 24 additions and 27 deletions

View File

@ -13,20 +13,6 @@ import (
"github.com/google/uuid"
)
func NewUserDTO(row *repository.User) types.UserDTO {
return types.UserDTO{
ID: row.ID,
Email: row.Email,
FullName: row.FullName,
IsAdmin: row.IsAdmin,
CreatedAt: row.CreatedAt,
UpdatedAt: row.UpdatedAt,
LastLogin: row.LastLogin,
PhoneNumber: row.PhoneNumber,
ProfilePicture: row.ProfilePicture,
}
}
func (h *AdminHandler) GetUsers(w http.ResponseWriter, r *http.Request) {
userId, ok := util.GetRequestUserId(r.Context())
if !ok {
@ -55,7 +41,7 @@ func (h *AdminHandler) GetUsers(w http.ResponseWriter, r *http.Request) {
var items []types.UserDTO
for _, user := range users {
items = append(items, NewUserDTO(&user))
items = append(items, types.NewUserDTO(&user))
}
encoder := json.NewEncoder(w)
@ -88,7 +74,7 @@ func (h *AdminHandler) GetUser(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
if err := encoder.Encode(NewUserDTO(&user)); err != nil {
if err := encoder.Encode(types.NewUserDTO(&user)); err != nil {
web.Error(w, "failed to encode user dto", http.StatusInternalServerError)
}
}