diff --git a/database/db.connection.go b/database/db.connection.go index 52f3705..89dd172 100644 --- a/database/db.connection.go +++ b/database/db.connection.go @@ -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 } diff --git a/go.mod b/go.mod index 1bfaf28..0c4ec78 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index b3da297..3833e07 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -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= diff --git a/internal/stamp/stamp.repository.go b/internal/stamp/stamp.repository.go index 228ea54..d00f162 100644 --- a/internal/stamp/stamp.repository.go +++ b/internal/stamp/stamp.repository.go @@ -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 { @@ -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 +} diff --git a/internal/stamp/stamp.service.go b/internal/stamp/stamp.service.go index 2606790..3412e89 100644 --- a/internal/stamp/stamp.service.go +++ b/internal/stamp/stamp.service.go @@ -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'