feat(user): Add client information to UserResponse and preload client in GetUserById
Deploy Application / deploy (push) Successful in 24s
Details
Deploy Application / deploy (push) Successful in 24s
Details
This commit is contained in:
parent
6b608a86a9
commit
f1a5395d68
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue