feat: customer list

This commit is contained in:
fernanda-one
2024-08-15 22:37:57 +07:00
parent f2029ab5b4
commit b39b791c0e
5 changed files with 38 additions and 2 deletions
+32
View File
@@ -28,6 +28,7 @@ func (h *Handler) Route(group *gin.RouterGroup, jwt gin.HandlerFunc) {
route.GET("/customer/list", jwt, h.GetAllCustomer)
route.GET("/:id", jwt, h.GetByID)
route.PUT("/:id", jwt, h.Update)
route.PUT("/customer/:id", jwt, h.UpdateCustomer)
route.DELETE("/:id", jwt, h.Delete)
}
@@ -146,6 +147,35 @@ func (h *Handler) Update(c *gin.Context) {
Data: h.toUserResponse(updatedUser),
})
}
func (h *Handler) UpdateCustomer(c *gin.Context) {
ctx := request.GetMyContext(c)
id := c.Param("id")
userID, err := strconv.ParseInt(id, 10, 64)
if err != nil {
response.ErrorWrapper(c, errors.ErrorBadRequest)
return
}
var req request.User
if err := c.ShouldBindJSON(&req); err != nil {
response.ErrorWrapper(c, errors.ErrorBadRequest)
return
}
updatedUser, err := h.service.Update(ctx, userID, req.ToEntity())
if err != nil {
response.ErrorWrapper(c, err)
return
}
c.JSON(http.StatusOK, response.BaseResponse{
Success: true,
Status: http.StatusOK,
Data: h.toUserResponse(updatedUser),
})
}
// GetAll retrieves a list of users.
// @Summary Get a list of users
@@ -289,6 +319,8 @@ func (h *Handler) toUserResponse(resp *entity.User) response.User {
ID: resp.ID,
Name: resp.Name,
Email: resp.Email,
PhoneNumber: resp.PhoneNumber,
NIK: resp.NIK,
Status: string(resp.Status),
RoleID: int64(resp.RoleID),
RoleName: resp.RoleName,
+2
View File
@@ -6,6 +6,8 @@ type User struct {
ID int64 `json:"id"`
Name string `json:"name"`
Email string `json:"email"`
PhoneNumber string `json:"phone_number"`
NIK string `json:"nik"`
Status string `json:"status"`
RoleID int64 `json:"role_id"`
RoleName string `json:"role_name"`