Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ans table #20

Merged
merged 1 commit into from
Jul 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading