made usage of first class citizen functions in go
This commit is contained in:
@@ -38,9 +38,9 @@ func (s *UserService) CreateUser(c *gin.Context) {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
userCreate := mappers.MapCreateDTOToUser(userCreateDTO)
|
||||
F.Pipe2(
|
||||
s.repository.Create(c.Request.Context(), userCreate),
|
||||
F.Pipe3(
|
||||
mappers.MapCreateDTOToUser(userCreateDTO),
|
||||
s.repository.Create(c.Request.Context()),
|
||||
E.Map[error](mappers.MapUserToDTO),
|
||||
E.Fold(
|
||||
HandleError(c),
|
||||
@@ -51,9 +51,9 @@ func (s *UserService) CreateUser(c *gin.Context) {
|
||||
|
||||
// GetUserByID handles fetching a user by their ID.
|
||||
func (s *UserService) GetUserByID(c *gin.Context) {
|
||||
id := c.Param("id")
|
||||
F.Pipe2(
|
||||
s.repository.FindByID(c.Request.Context(), id),
|
||||
F.Pipe3(
|
||||
c.Param("id"),
|
||||
s.repository.FindByID(c.Request.Context()),
|
||||
E.Map[error](mappers.MapUserToDTO),
|
||||
E.Fold(
|
||||
HandleError(c),
|
||||
@@ -84,10 +84,9 @@ func (s *UserService) UpdateUser(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
userUpdate := mappers.MapUpdateDTOToUser(userUpdateDTO, id)
|
||||
|
||||
F.Pipe2(
|
||||
s.repository.Update(c.Request.Context(), userUpdate),
|
||||
F.Pipe3(
|
||||
mappers.MapUpdateDTOToUser(userUpdateDTO, id),
|
||||
s.repository.Update(c.Request.Context()),
|
||||
E.Map[error](mappers.MapUserToDTO),
|
||||
E.Fold(
|
||||
HandleError(c),
|
||||
@@ -98,15 +97,13 @@ func (s *UserService) UpdateUser(c *gin.Context) {
|
||||
|
||||
// DeleteUser handles deleting a user by their ID.
|
||||
func (s *UserService) DeleteUser(c *gin.Context) {
|
||||
id := c.Param("id")
|
||||
|
||||
F.Pipe2(
|
||||
s.repository.Delete(c.Request.Context(), id),
|
||||
F.Pipe3(
|
||||
c.Param("id"),
|
||||
s.repository.Delete(c.Request.Context()),
|
||||
E.Map[error](mappers.MapUserToDTO),
|
||||
E.Fold(
|
||||
HandleError(c),
|
||||
HandleSuccess[dto.UserDTO](c, http.StatusOK),
|
||||
),
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user