Skip to content

Commit

Permalink
Merge pull request #20 from isd-sgcu/answer-table
Browse files Browse the repository at this point in the history
ans table
  • Loading branch information
bookpanda authored Jul 21, 2024
2 parents be1f5c7 + 017772d commit a96f8e7
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 5 deletions.
2 changes: 1 addition & 1 deletion database/db.connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func InitDatabase(conf *config.DbConfig, isDebug bool) (db *gorm.DB, err error)
return nil, err
}

err = db.AutoMigrate(&model.Group{}, &model.User{}, &model.Selection{}, &model.Stamp{}, &model.CheckIn{}, &model.Count{})
err = db.AutoMigrate(&model.Group{}, &model.User{}, &model.Selection{}, &model.Stamp{}, &model.CheckIn{}, &model.Count{}, &model.Answer{})
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ go 1.22.4
require (
github.com/golang/mock v1.6.0
github.com/google/uuid v1.6.0
github.com/isd-sgcu/rpkm67-go-proto v0.5.3
github.com/isd-sgcu/rpkm67-model v0.2.0
github.com/isd-sgcu/rpkm67-go-proto v0.5.4
github.com/isd-sgcu/rpkm67-model v0.2.1
github.com/joho/godotenv v1.5.1
github.com/redis/go-redis/v9 v9.5.3
github.com/stretchr/testify v1.9.0
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ github.com/isd-sgcu/rpkm67-go-proto v0.5.2 h1:CP9oXIa4MrJZd6ynHkVt18YPGlQU0bkDM1
github.com/isd-sgcu/rpkm67-go-proto v0.5.2/go.mod h1:w+UCeQnJ3wBuJ7Tyf8LiBiPZVb1KlecjMNCB7kBeL7M=
github.com/isd-sgcu/rpkm67-go-proto v0.5.3 h1:DMxo3vu5OB2RaODWQwIIFRTyPEyTNMvwmfDbVmVnmnM=
github.com/isd-sgcu/rpkm67-go-proto v0.5.3/go.mod h1:w+UCeQnJ3wBuJ7Tyf8LiBiPZVb1KlecjMNCB7kBeL7M=
github.com/isd-sgcu/rpkm67-go-proto v0.5.4 h1:XcbTKhQFGHiFf10kxsoK8oyZ2v1b2uQ2gmOmzI5sEYE=
github.com/isd-sgcu/rpkm67-go-proto v0.5.4/go.mod h1:w+UCeQnJ3wBuJ7Tyf8LiBiPZVb1KlecjMNCB7kBeL7M=
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/isd-sgcu/rpkm67-model v0.0.7 h1:3b8gf1Ocg+Ky4xocKtCqVCB3rFDg90IgEXRwNmHt0OE=
Expand All @@ -35,6 +37,8 @@ github.com/isd-sgcu/rpkm67-model v0.1.0 h1:ML4C8cU7L8m53QuAiIkrykzQP9VYlsOWGrQO5
github.com/isd-sgcu/rpkm67-model v0.1.0/go.mod h1:dxgLSkrFpbQOXsrzqgepZoEOyZUIG2LBGtm5gsuBbVc=
github.com/isd-sgcu/rpkm67-model v0.2.0 h1:D2KytmevtV9/3FwfA7FiKo2UKa3jC8knZI97vwRuboA=
github.com/isd-sgcu/rpkm67-model v0.2.0/go.mod h1:dxgLSkrFpbQOXsrzqgepZoEOyZUIG2LBGtm5gsuBbVc=
github.com/isd-sgcu/rpkm67-model v0.2.1 h1:O6mZeZqDjGbiEJa5zzbf6cVwz4uVOtQTuAxnkLj+2oQ=
github.com/isd-sgcu/rpkm67-model v0.2.1/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
5 changes: 5 additions & 0 deletions internal/stamp/stamp.repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
type Repository interface {
FindByUserId(userId string, stamp *model.Stamp) error
StampByUserId(userId string, stamp *model.Stamp) error
CreateAnswer(answer *model.Answer) error
}

type repositoryImpl struct {
Expand All @@ -27,3 +28,7 @@ func (r *repositoryImpl) FindByUserId(userId string, stamp *model.Stamp) error {
func (r *repositoryImpl) StampByUserId(userId string, stamp *model.Stamp) error {
return r.Db.Model(stamp).Where("user_id = ?", userId).Updates(stamp).Error
}

func (r *repositoryImpl) CreateAnswer(answer *model.Answer) error {
return r.Db.Create(answer).Error
}
15 changes: 13 additions & 2 deletions internal/stamp/stamp.service.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,23 @@ func (s *serviceImpl) StampByUserId(_ context.Context, in *proto.StampByUserIdRe

actIdx, ok := s.activityIdToIdx[in.ActivityId]
if !ok {
return nil, status.Error(codes.Internal, errors.New("Invalid Activity ID").Error())
return nil, status.Error(codes.Internal, errors.New("invalid Activity ID").Error())
}

tempStrStamp := []byte(stamp.Stamp)
if tempStrStamp[actIdx] == '1' {
return nil, status.Error(codes.Internal, errors.New("Already stamped").Error())
return nil, status.Error(codes.Internal, errors.New("already stamped").Error())
}

if actIdx >= 9 {
ans := &model.Answer{
ActivityID: in.ActivityId,
Text: in.Answer,
}
if err := s.repo.CreateAnswer(ans); err != nil {
s.log.Named("StampByUserId").Error("CreateAnswer", zap.Error(err))
return nil, status.Error(codes.Internal, err.Error())
}
}

tempStrStamp[actIdx] = '1'
Expand Down

0 comments on commit a96f8e7

Please sign in to comment.