feat(user): Add client information to UserResponse and preload client in GetUserById
Deploy Application / deploy (push) Successful in 24s Details

This commit is contained in:
Habib Fatkhul Rohman 2025-11-03 13:41:49 +07:00
parent 6b608a86a9
commit f1a5395d68
3 changed files with 10 additions and 0 deletions

View File

@ -74,6 +74,7 @@ type (
Email string `json:"email"`
PhotoUrl string `json:"photo_url"`
Roles []UserRolesResponse `json:"roles,omitempty"`
Client dto.IdNameResponse `json:"client"`
}
UserRolesResponse struct {

View File

@ -144,6 +144,7 @@ func (r *userRepository) GetUserById(ctx context.Context, tx *gorm.DB, userId st
var user entities.M_User
if err := tx.WithContext(ctx).
Preload("Client").
Preload("Roles").
Where("id = ?", userId).
Take(&user).Error; err != nil {

View File

@ -12,6 +12,7 @@ import (
authService "github.com/Caknoooo/go-gin-clean-starter/modules/auth/service"
"github.com/Caknoooo/go-gin-clean-starter/modules/user/dto"
"github.com/Caknoooo/go-gin-clean-starter/modules/user/repository"
pkgdto "github.com/Caknoooo/go-gin-clean-starter/pkg/dto"
"github.com/Caknoooo/go-gin-clean-starter/pkg/utils"
"github.com/google/uuid"
"gorm.io/gorm"
@ -111,6 +112,12 @@ func (s *userService) GetUserById(ctx context.Context, userId string) (dto.UserR
})
}
var client pkgdto.IdNameResponse
client = pkgdto.IdNameResponse{
ID: user.Client.ID.String(),
Name: user.Client.Name,
}
return dto.UserResponse{
ID: user.ID.String(),
Name: user.Name,
@ -121,6 +128,7 @@ func (s *userService) GetUserById(ctx context.Context, userId string) (dto.UserR
Phone: user.Phone,
PhotoUrl: user.PhotoUrl,
Roles: roles,
Client: client,
}, nil
}