Skip to content

Commit

Permalink
fix: checkin add timestamp, isDupe
Browse files Browse the repository at this point in the history
  • Loading branch information
bookpanda committed Jul 19, 2024
1 parent fba079f commit 9a33591
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 14 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.21.5
require (
github.com/bxcodec/faker/v4 v4.0.0-beta.3
github.com/golang/mock v1.6.0
github.com/isd-sgcu/rpkm67-go-proto v0.4.6
github.com/isd-sgcu/rpkm67-go-proto v0.5.0
github.com/isd-sgcu/rpkm67-model v0.0.4
github.com/stretchr/testify v1.9.0
go.opentelemetry.io/otel v1.28.0
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 h1:bkypFPDjIYGfCYD5mRBvpqxfYX1
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0/go.mod h1:P+Lt/0by1T8bfcF3z737NnSbmxQAppXMRziHUxPOC8k=
github.com/isd-sgcu/rpkm67-go-proto v0.4.6 h1:yUBzUY3ftBfnI2x/MT+MsynBOlV5pOR143c9OTrVGuU=
github.com/isd-sgcu/rpkm67-go-proto v0.4.6/go.mod h1:w+UCeQnJ3wBuJ7Tyf8LiBiPZVb1KlecjMNCB7kBeL7M=
github.com/isd-sgcu/rpkm67-go-proto v0.4.9 h1:IoTkfugWpcQFhjtLlltonZwQeWhVOO9f2ludMtYZyJw=
github.com/isd-sgcu/rpkm67-go-proto v0.4.9/go.mod h1:w+UCeQnJ3wBuJ7Tyf8LiBiPZVb1KlecjMNCB7kBeL7M=
github.com/isd-sgcu/rpkm67-go-proto v0.5.0 h1:FFYIv/Ejs3fP+AWErtx9ONxbzZLr1y1Ttd7j8xHIJ34=
github.com/isd-sgcu/rpkm67-go-proto v0.5.0/go.mod h1:w+UCeQnJ3wBuJ7Tyf8LiBiPZVb1KlecjMNCB7kBeL7M=
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/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
Expand Down
12 changes: 7 additions & 5 deletions internal/checkin/checkin.service.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@ func (s *serviceImpl) Create(ctx context.Context, req *proto.CreateCheckInReques
}
for _, v := range checkin_userIds {
if v.Event == req.Event && v.UserID == req.UserId {
s.log.Named("Create").Error("Create: User already checkin this event")
s.log.Named("Create").Warn("Create: User already checkin this event")

return nil, status.Error(codes.AlreadyExists, constant.AlreadyCheckinErrorMessage)
return &proto.CreateCheckInResponse{
CheckIn: ModelToProto(v, true),
}, nil
}
}
// span.AddEvent("Verify user checkin not duplicate")
Expand All @@ -74,7 +76,7 @@ func (s *serviceImpl) Create(ctx context.Context, req *proto.CreateCheckInReques
// span.AddEvent("Checkin created")

return &proto.CreateCheckInResponse{
CheckIn: ModelToProto(checkin),
CheckIn: ModelToProto(checkin, false),
}, nil
}

Expand Down Expand Up @@ -106,7 +108,7 @@ func (s *serviceImpl) FindByEmail(ctx context.Context, req *proto.FindByEmailChe
// span.AddEvent("Checkin found")

return &proto.FindByEmailCheckInResponse{
CheckIns: ModelToProtoList(checkins),
CheckIns: ModelToProtoList(checkins, false),
}, nil
}

Expand Down Expand Up @@ -139,6 +141,6 @@ func (s *serviceImpl) FindByUserId(ctx context.Context, req *proto.FindByUserIdC
}

return &proto.FindByUserIdCheckInResponse{
CheckIns: ModelToProtoList(checkins),
CheckIns: ModelToProtoList(checkins, false),
}, nil
}
16 changes: 9 additions & 7 deletions internal/checkin/checkin.utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@ import (
"github.com/isd-sgcu/rpkm67-model/model"
)

func ModelToProto(in *model.CheckIn) *proto.CheckIn {
func ModelToProto(in *model.CheckIn, isDuplicate bool) *proto.CheckIn {
return &proto.CheckIn{
Id: in.ID.String(),
Email: in.Email,
Event: in.Event,
UserId: in.UserID,
Id: in.ID.String(),
Email: in.Email,
Event: in.Event,
UserId: in.UserID,
Timestamp: in.CreatedAt.String(),
IsDuplicate: isDuplicate,
}
}

func ModelToProtoList(in []*model.CheckIn) []*proto.CheckIn {
func ModelToProtoList(in []*model.CheckIn, isDuplicate bool) []*proto.CheckIn {
var out []*proto.CheckIn
for _, v := range in {
out = append(out, ModelToProto(v))
out = append(out, ModelToProto(v, isDuplicate))
}
return out
}
2 changes: 1 addition & 1 deletion internal/checkin/test/checkin.service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (t *CheckinServiceTest) SetupTest() {
t.logger = zap.NewNop()
t.checkinsModel = MockCheckInsModel()
t.checkinModel = t.checkinsModel[0]
t.checkinsProto = checkin.ModelToProtoList(t.checkinsModel)
t.checkinsProto = checkin.ModelToProtoList(t.checkinsModel, false)
t.checkinProto = t.checkinsProto[0]
t.createCheckInProtoRequest = &proto.CreateCheckInRequest{
Email: t.checkinProto.Email,
Expand Down

0 comments on commit 9a33591

Please sign in to comment.