Skip to content

Commit

Permalink
Merge pull request #62 from isd-sgcu/dev
Browse files Browse the repository at this point in the history
update main
  • Loading branch information
bookpanda authored Aug 3, 2024
2 parents 4772318 + 45387a8 commit 2b7239b
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
12 changes: 12 additions & 0 deletions internal/checkin/checkin.handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,18 @@ func (h *handlerImpl) Create(c context.Ctx) {
return
}

if body.StudentID != "" {
req := &dto.FindByEmailUserRequest{Email: body.StudentID + "@student.chula.ac.th"}
res, appErr := h.userSvc.FindByEmail(req)
if appErr != nil {
h.log.Named("Create").Error("FindOne: ", zap.Error(appErr))
c.ResponseError(appErr)
return
}

body.UserID = res.User.Id
}

req := &dto.CreateCheckInRequest{
Email: body.Email,
UserID: body.UserID,
Expand Down
7 changes: 4 additions & 3 deletions internal/dto/checkin.dto.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ type CheckIn struct {
}

type CreateCheckInRequest struct {
UserID string `json:"user_id"`
Email string `json:"email"`
Event string `json:"event"`
UserID string `json:"user_id"`
StudentID string `json:"student_id"`
Email string `json:"email"`
Event string `json:"event"`
}

type CreateCheckInResponse struct {
Expand Down
8 changes: 8 additions & 0 deletions internal/dto/user.dto.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ type FindOneUserResponse struct {
User *User `json:"user"`
}

type FindByEmailUserRequest struct {
Email string `json:"email" validate:"required,email"`
}

type FindByEmailUserResponse struct {
User *User `json:"user"`
}

type UpdateUserProfileBody struct {
Nickname string `json:"nickname"`
Title string `json:"title"`
Expand Down
18 changes: 18 additions & 0 deletions internal/user/user.service.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

type Service interface {
FindOne(req *dto.FindOneUserRequest) (*dto.FindOneUserResponse, *apperror.AppError)
FindByEmail(req *dto.FindByEmailUserRequest) (*dto.FindByEmailUserResponse, *apperror.AppError)
UpdateProfile(req *dto.UpdateUserProfileRequest) (*dto.UpdateUserProfileResponse, *apperror.AppError)
UpdatePicture(req *dto.UpdateUserPictureRequest) (*dto.UpdateUserPictureResponse, *apperror.AppError)
}
Expand Down Expand Up @@ -48,6 +49,23 @@ func (s *serviceImpl) FindOne(req *dto.FindOneUserRequest) (*dto.FindOneUserResp
}, nil
}

func (s *serviceImpl) FindByEmail(req *dto.FindByEmailUserRequest) (*dto.FindByEmailUserResponse, *apperror.AppError) {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

res, err := s.client.FindByEmail(ctx, &userProto.FindByEmailRequest{
Email: req.Email,
})
if err != nil {
s.log.Named("FindByEmail").Error("FindByEmail: ", zap.Error(err))
return nil, apperror.HandleServiceError(err)
}

return &dto.FindByEmailUserResponse{
User: ProtoToDto(res.User),
}, nil
}

func (s *serviceImpl) UpdateProfile(req *dto.UpdateUserProfileRequest) (*dto.UpdateUserProfileResponse, *apperror.AppError) {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
Expand Down

0 comments on commit 2b7239b

Please sign in to comment.