Skip to content
This repository has been archived by the owner on Aug 7, 2023. It is now read-only.

Commit

Permalink
feat: update personality game
Browse files Browse the repository at this point in the history
  • Loading branch information
AKKatung159 committed Jul 26, 2023
1 parent 3c6c541 commit ccfdab0
Show file tree
Hide file tree
Showing 6 changed files with 358 additions and 109 deletions.
351 changes: 251 additions & 100 deletions internal/proto/rpkm66/backend/user/v1/user.pb.go

Large diffs are not rendered by default.

55 changes: 46 additions & 9 deletions internal/proto/rpkm66/backend/user/v1/user_grpc.pb.go

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

4 changes: 4 additions & 0 deletions internal/repository/user/user.repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,7 @@ func (r *repositoryImpl) GetUserEstamp(uId string, thisUser *user.User, results
//Get all estamp that this user has
return r.db.Model(thisUser).Where("user_id", uId).Association("Events").Find(&results)
}

func (r *repositoryImpl) UpdatePersonalityGame(id string, result *user.User) error{
return r.db.Where(id, "id = ?", id).Updates(&result).First(&result, "id = ?", id).Error
}
13 changes: 13 additions & 0 deletions internal/service/user/user.service.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,3 +476,16 @@ func GetColumnName(verifyName string) string {
return ""
}
}

func (s *serviceImpl) UpdatePersonalityGame(_ context.Context, req *proto.UpdatePersonalityGameRequest) (res *proto.UpdatePersonalityGameResponse, err error) {
raw := &user.User{
PersonalityGame: req.PersonalityGame,
}

err = s.repo.Update(req.Id, raw)
if err != nil {
return nil, status.Error(codes.NotFound, "user not found")
}

return &proto.UpdatePersonalityGameResponse{User: RawToDto(raw, "")}, nil
}
33 changes: 33 additions & 0 deletions internal/service/user/user.service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -708,3 +708,36 @@ func getBoolPtr() *bool {
value := rand.Intn(2) == 0
return &value
}
func (t *UserServiceTest) TestUpdatePersonalityGameSuccess() {
want := &proto.UpdatePersonalityGameResponse{User: t.UserDto}

repo := &mock.RepositoryMock{}

repo.On("Update", t.User.ID.String(), t.UpdateUser).Return(t.User, nil)

fileSrv := &fMock.ServiceMock{}

eventSrv := &eMock.RepositoryMock{}
srv := NewService(repo, fileSrv, eventSrv)
actual, err := srv.Update(context.Background(), t.UpdateUserReqMock)

assert.Nil(t.T(), err)
assert.Equal(t.T(), want, actual)
}

func (t *UserServiceTest) TestUpdatePersonalityGameNotFound() {
repo := &mock.RepositoryMock{}
repo.On("Update", t.User.ID.String(), t.UpdateUser).Return(nil, errors.New("Not found user"))

fileSrv := &fMock.ServiceMock{}

eventSrv := &eMock.RepositoryMock{}
srv := NewService(repo, fileSrv, eventSrv)
actual, err := srv.Update(context.Background(), t.UpdateUserReqMock)

st, ok := status.FromError(err)

assert.True(t.T(), ok)
assert.Nil(t.T(), actual)
assert.Equal(t.T(), codes.NotFound, st.Code())
}
11 changes: 11 additions & 0 deletions proto/rpkm66/backend/user/v1/user.proto
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ service UserService {
rpc CreateOrUpdate(CreateOrUpdateUserRequest) returns (CreateOrUpdateUserResponse){}
rpc ConfirmEstamp(ConfirmEstampRequest) returns (ConfirmEstampResponse){}
rpc GetUserEstamp(GetUserEstampRequest) returns (GetUserEstampResponse){}
rpc UpdatePersonalityGame (UpdatePersonalityGameRequest) returns (UpdatePersonalityGameResponse){}
}

message User{
Expand Down Expand Up @@ -148,4 +149,14 @@ message GetUserEstampRequest {

message GetUserEstampResponse {
repeated rpkm66.backend.event.v1.Event eventList = 1;
}

// Update Personality Game
message UpdatePersonalityGameRequest{
string id = 1;
string personalityGame = 2;
}

message UpdatePersonalityGameResponse{
User user = 1;
}

0 comments on commit ccfdab0

Please sign in to comment.