diff --git a/internal/handlers/http/user/user.go b/internal/handlers/http/user/user.go index cdaf440..e6b8267 100644 --- a/internal/handlers/http/user/user.go +++ b/internal/handlers/http/user/user.go @@ -166,12 +166,7 @@ func (h *Handler) GetAll(c *gin.Context) { } - if !ctx.IsSuperAdmin() { - response.ErrorWrapper(c, errors.ErrorUnauthorized) - return - } - - users, total, err := h.service.GetAll(ctx, req.ToEntity()) + users, total, err := h.service.GetAll(ctx, req.ToEntity(ctx)) if err != nil { response.ErrorWrapper(c, err) return diff --git a/internal/handlers/request/user.go b/internal/handlers/request/user.go index 1170347..d08676e 100644 --- a/internal/handlers/request/user.go +++ b/internal/handlers/request/user.go @@ -1,6 +1,7 @@ package request import ( + "furtuna-be/internal/common/mycontext" "furtuna-be/internal/constants/role" "furtuna-be/internal/entity" @@ -48,12 +49,18 @@ type UserParam struct { Offset int `form:"offset,default=0" json:"offset" example:"0"` } -func (p *UserParam) ToEntity() entity.UserSearch { +func (p *UserParam) ToEntity(ctx mycontext.Context) entity.UserSearch { + partnerID := p.PartnerID + + if !ctx.IsAdmin() { + partnerID = *ctx.GetPartnerID() + } + return entity.UserSearch{ Search: p.Search, Name: p.Name, RoleID: p.RoleID, - PartnerID: p.PartnerID, + PartnerID: partnerID, Limit: p.Limit, Offset: p.Offset, }