feat: enhance user response to include associated warehouses in GetUserById

This commit is contained in:
Habib Fatkhul Rohman 2025-11-21 10:24:26 +07:00
parent ff8cd07e9c
commit 51a6f291e0
2 changed files with 19 additions and 12 deletions

View File

@ -15,7 +15,6 @@ import (
"github.com/gin-gonic/gin"
"github.com/google/uuid"
"github.com/samber/do"
"github.com/sirupsen/logrus"
"gorm.io/gorm"
)
@ -106,7 +105,6 @@ func (c *userController) AddUserWarehouse(ctx *gin.Context) {
// GetUserWarehouses implements UserController.
func (c *userController) GetUserWarehouses(ctx *gin.Context) {
userId := ctx.Param("id")
logrus.Infof("Getting warehouses for user ID: %s", userId)
result, err := c.userService.GetUserWarehouses(ctx.Request.Context(), userId)
if err != nil {
res := utils.BuildResponseFailed(dto.MESSAGE_FAILED_GET_USER, err.Error(), nil)

View File

@ -442,6 +442,14 @@ func (s *userService) GetUserById(ctx context.Context, userId string) (dto.UserR
Name: user.Client.Name,
}
var warehouses []pkgdto.IdNameResponse
for _, uw := range user.Warehouses {
warehouses = append(warehouses, pkgdto.IdNameResponse{
ID: uw.ID.String(),
Name: uw.Name,
})
}
return dto.UserResponse{
ID: user.ID.String(),
Name: user.Name,
@ -453,6 +461,7 @@ func (s *userService) GetUserById(ctx context.Context, userId string) (dto.UserR
PhotoUrl: user.PhotoUrl,
Roles: roles,
Client: client,
Warehouses: warehouses,
}, nil
}