Skip to content

Commit

Permalink
Merge pull request #3 from isd-sgcu/user-init-stamp
Browse files Browse the repository at this point in the history
User init stamp
  • Loading branch information
bookpanda authored Jul 4, 2024
2 parents 0c48e9f + b2a19bb commit 9b98df7
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 4 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ require (
github.com/golang-jwt/jwt/v4 v4.5.0
github.com/golang/mock v1.6.0
github.com/google/uuid v1.6.0
github.com/isd-sgcu/rpkm67-go-proto v0.2.2
github.com/isd-sgcu/rpkm67-model v0.0.4
github.com/isd-sgcu/rpkm67-go-proto v0.2.5
github.com/isd-sgcu/rpkm67-model v0.0.6
github.com/joho/godotenv v1.5.1
github.com/pkg/errors v0.9.1
github.com/redis/go-redis/v9 v9.5.3
Expand Down
10 changes: 10 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,20 @@ github.com/isd-sgcu/rpkm67-go-proto v0.2.0 h1:tPfNgCuqS4g0f+2hzcpY+8hYXSa7DZDPvR
github.com/isd-sgcu/rpkm67-go-proto v0.2.0/go.mod h1:Z5SYz5kEe4W+MdqPouF0zEOiaqvg+s9I1S5d0q6e+Jw=
github.com/isd-sgcu/rpkm67-go-proto v0.2.2 h1:FP2EBqRp+/z2DUSXygOC7SgmS1T3ZRlm4gqRhpU7qbw=
github.com/isd-sgcu/rpkm67-go-proto v0.2.2/go.mod h1:Z5SYz5kEe4W+MdqPouF0zEOiaqvg+s9I1S5d0q6e+Jw=
github.com/isd-sgcu/rpkm67-go-proto v0.2.3 h1:u4ROlwsTmzcXgW3ED2UobPvF1OF+jykHH9AEH8F3XcU=
github.com/isd-sgcu/rpkm67-go-proto v0.2.3/go.mod h1:Z5SYz5kEe4W+MdqPouF0zEOiaqvg+s9I1S5d0q6e+Jw=
github.com/isd-sgcu/rpkm67-go-proto v0.2.4 h1:AmaSn+KFJFMkBf/5pvrnNU/5R/T1SuhO5oH8+9ShWHw=
github.com/isd-sgcu/rpkm67-go-proto v0.2.4/go.mod h1:Z5SYz5kEe4W+MdqPouF0zEOiaqvg+s9I1S5d0q6e+Jw=
github.com/isd-sgcu/rpkm67-go-proto v0.2.5 h1:lNpRUnPr6QiLBnexeCM2MvlNHeUlJ/jbKdrYWj1/qtk=
github.com/isd-sgcu/rpkm67-go-proto v0.2.5/go.mod h1:Z5SYz5kEe4W+MdqPouF0zEOiaqvg+s9I1S5d0q6e+Jw=
github.com/isd-sgcu/rpkm67-model v0.0.3 h1:xvUNozwDIc0e5a68NQPzViH5ICID+5n/0wlMJLXp5Gw=
github.com/isd-sgcu/rpkm67-model v0.0.3/go.mod h1:dxgLSkrFpbQOXsrzqgepZoEOyZUIG2LBGtm5gsuBbVc=
github.com/isd-sgcu/rpkm67-model v0.0.4 h1:tk6z6pXnhWBoG2SaSIoyLxNnwRaXwdbSIEEa/cSi8EY=
github.com/isd-sgcu/rpkm67-model v0.0.4/go.mod h1:dxgLSkrFpbQOXsrzqgepZoEOyZUIG2LBGtm5gsuBbVc=
github.com/isd-sgcu/rpkm67-model v0.0.5 h1:S+uza3ps1CP+JzgGILg6WwqlFJFaBsOIsuNBiJWJug8=
github.com/isd-sgcu/rpkm67-model v0.0.5/go.mod h1:dxgLSkrFpbQOXsrzqgepZoEOyZUIG2LBGtm5gsuBbVc=
github.com/isd-sgcu/rpkm67-model v0.0.6 h1:pYlqOmeXGQIfHdOhyAta4kXkqnoLc4X3KWcAjPrAuds=
github.com/isd-sgcu/rpkm67-model v0.0.6/go.mod h1:dxgLSkrFpbQOXsrzqgepZoEOyZUIG2LBGtm5gsuBbVc=
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk=
Expand Down
9 changes: 7 additions & 2 deletions internal/user/user.repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type Repository interface {
FindOne(id string, user *model.User) error
FindByEmail(email string, user *model.User) error
Create(user *model.User) error
CreateUserStamp(stamp *model.Stamp) error
Update(id string, user *model.User) error
}

Expand All @@ -21,17 +22,21 @@ func NewRepository(db *gorm.DB) Repository {
}

func (r *repositoryImpl) FindOne(id string, user *model.User) error {
return r.Db.First(user, "id = ?", id).Error
return r.Db.Model(user).Preload("Stamp").First(user, "id = ?", id).Error
}

func (r *repositoryImpl) FindByEmail(email string, user *model.User) error {
return r.Db.First(user, "email = ?", email).Error
return r.Db.Model(user).Preload("Stamp").First(user, "email = ?", email).Error
}

func (r *repositoryImpl) Create(user *model.User) error {
return r.Db.Create(user).Error
}

func (r *repositoryImpl) CreateUserStamp(stamp *model.Stamp) error {
return r.Db.Create(stamp).Error
}

func (r *repositoryImpl) Update(id string, user *model.User) error {
return r.Db.Model(user).Where("id = ?", id).Updates(user).Error
}
6 changes: 6 additions & 0 deletions internal/user/user.service.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ func (s *serviceImpl) Create(_ context.Context, req *proto.CreateUserRequest) (r
return nil, err
}

err = s.repo.CreateUserStamp(CreateEmptyStamp(&createUser.ID))
if err != nil {
s.log.Named("Create").Error("CreateUserStamp: ", zap.Error(err))
return nil, status.Error(codes.Internal, err.Error())
}

return &proto.CreateUserResponse{
User: ModelToProto(createUser),
}, nil
Expand Down
19 changes: 19 additions & 0 deletions internal/user/user.utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package user
import (
"github.com/google/uuid"
proto "github.com/isd-sgcu/rpkm67-go-proto/rpkm67/auth/user/v1"
stampProto "github.com/isd-sgcu/rpkm67-go-proto/rpkm67/backend/stamp/v1"
"github.com/isd-sgcu/rpkm67-model/constant"
"github.com/isd-sgcu/rpkm67-model/model"
)
Expand All @@ -28,6 +29,13 @@ func ModelToProto(in *model.User) *proto.User {
PhotoUrl: in.PhotoUrl,
Baan: in.Baan,
ReceiveGift: int32(in.ReceiveGift),
Stamp: &stampProto.Stamp{
PointA: int32(in.Stamp.PointA),
PointB: int32(in.Stamp.PointB),
PointC: int32(in.Stamp.PointC),
PointD: int32(in.Stamp.PointD),
Stamp: in.Stamp.Stamp,
},
}

if in.GroupID != nil {
Expand Down Expand Up @@ -68,3 +76,14 @@ func UpdateRequestToModel(in *proto.UpdateUserRequest) (*model.User, error) {

return user, nil
}

func CreateEmptyStamp(userId *uuid.UUID) *model.Stamp {
return &model.Stamp{
UserID: userId,
PointA: 0,
PointB: 0,
PointC: 0,
PointD: 0,
Stamp: "00000000000",
}
}

0 comments on commit 9b98df7

Please sign in to comment.