Skip to content

Commit

Permalink
feat: user svc delete
Browse files Browse the repository at this point in the history
  • Loading branch information
bookpanda committed Jan 5, 2024
1 parent 59baa48 commit 3ac9671
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/app/dto/user.dto.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ type UpdateUserResponse struct {
Firstname string `json:"firstname"`
Lastname string `json:"lastname"`
}

type DeleteUserResponse struct {
Success bool `json:"success" validate:"required"`
}
31 changes: 29 additions & 2 deletions src/app/service/user/user.service.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ func (s *Service) Update(id string, in *dto.UpdateUserRequest) (*dto.UpdateUserR
Str("module", "update").
Msg(st.Message())
switch st.Code() {
case codes.NotFound:
case codes.AlreadyExists:
return nil, &dto.ResponseErr{
StatusCode: http.StatusNotFound,
Message: constant.UserNotFoundMessage,
Message: constant.DuplicateEmailMessage,
Data: nil,
}

Expand All @@ -114,3 +114,30 @@ func (s *Service) Update(id string, in *dto.UpdateUserRequest) (*dto.UpdateUserR
Email: response.User.Email,
}, nil
}

func (s *Service) Delete(id string) (*dto.DeleteUserResponse, *dto.ResponseErr) {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

response, err := s.client.Delete(ctx, &proto.DeleteUserRequest{
Id: id,
})
if err != nil {
st, _ := status.FromError(err)
log.Error().
Err(err).
Str("service", "user").
Str("module", "delete").
Msg(st.Message())

return nil, &dto.ResponseErr{
StatusCode: http.StatusInternalServerError,
Message: constant.InternalErrorMessage,
Data: nil,
}
}

return &dto.DeleteUserResponse{
Success: response.Success,
}, nil
}
15 changes: 15 additions & 0 deletions src/mocks/service/user/user.mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/pkg/service/user/user.service.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ import (
type Service interface {
FindOne(string) (*dto.FindOneUserResponse, *dto.ResponseErr)
Update(string, *dto.UpdateUserRequest) (*dto.UpdateUserResponse, *dto.ResponseErr)
Delete(string) (*dto.DeleteUserResponse, *dto.ResponseErr)
}

0 comments on commit 3ac9671

Please sign in to comment.