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"`
|
Email string `json:"email"`
|
||||||
PhotoUrl string `json:"photo_url"`
|
PhotoUrl string `json:"photo_url"`
|
||||||
Roles []UserRolesResponse `json:"roles,omitempty"`
|
Roles []UserRolesResponse `json:"roles,omitempty"`
|
||||||
|
Client dto.IdNameResponse `json:"client"`
|
||||||
}
|
}
|
||||||
|
|
||||||
UserRolesResponse struct {
|
UserRolesResponse struct {
|
||||||
|
|
|
||||||
|
|
@ -144,6 +144,7 @@ func (r *userRepository) GetUserById(ctx context.Context, tx *gorm.DB, userId st
|
||||||
|
|
||||||
var user entities.M_User
|
var user entities.M_User
|
||||||
if err := tx.WithContext(ctx).
|
if err := tx.WithContext(ctx).
|
||||||
|
Preload("Client").
|
||||||
Preload("Roles").
|
Preload("Roles").
|
||||||
Where("id = ?", userId).
|
Where("id = ?", userId).
|
||||||
Take(&user).Error; err != nil {
|
Take(&user).Error; err != nil {
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ import (
|
||||||
authService "github.com/Caknoooo/go-gin-clean-starter/modules/auth/service"
|
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/dto"
|
||||||
"github.com/Caknoooo/go-gin-clean-starter/modules/user/repository"
|
"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/Caknoooo/go-gin-clean-starter/pkg/utils"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"gorm.io/gorm"
|
"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{
|
return dto.UserResponse{
|
||||||
ID: user.ID.String(),
|
ID: user.ID.String(),
|
||||||
Name: user.Name,
|
Name: user.Name,
|
||||||
|
|
@ -121,6 +128,7 @@ func (s *userService) GetUserById(ctx context.Context, userId string) (dto.UserR
|
||||||
Phone: user.Phone,
|
Phone: user.Phone,
|
||||||
PhotoUrl: user.PhotoUrl,
|
PhotoUrl: user.PhotoUrl,
|
||||||
Roles: roles,
|
Roles: roles,
|
||||||
|
Client: client,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue