Skip to content
This repository was archived by the owner on Sep 18, 2022. It is now read-only.

Commit 26dc17d

Browse files
Lolymolysamithiwat
authored andcommitted
create event model
add many2many btw user-event finish event CRUD repo, service create event proto gen event-protobuf fix event proto & service add event to automigreate fix bug fix bug complete event crud create event model add many2many btw user-event finish event CRUD repo, service create event proto gen event-protobuf fix event proto & service add event to automigreate fix bug fix bug complete event crud Add event repository almost complete estamp api some bugs in user.service_test Fix build failed fix association bug
1 parent 63676b3 commit 26dc17d

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

src/app/repository/user/user.repository.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ func (r *Repository) Delete(id string) error {
4949

5050
func (r *Repository) ConfirmEstamp(uId string, thisUser *user.User, thisEvent *event.Event) error {
5151
//Add this estamp to user
52-
return r.db.Model(thisUser).Where("id = ?", uId).Omit("Events.*").Association("Events").Append(thisEvent)
52+
return r.db.Model(thisUser).Omit("Events.*").Association("Events").Append(thisEvent)
5353
}
5454

5555
func (r *Repository) GetUserEstamp(uId string, thisUser *user.User, results *[]*event.Event) error {
5656
//Get all estamp that this user has
57-
return r.db.Model(thisUser).Where("user_id", uId).Association("Events").Find(&results)
57+
return r.db.Model(thisUser).Association("Events").Find(&results)
5858
}

src/app/service/user/user.service.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ type IEventRepository interface {
3838
FindAllEvent(result *[]*event.Event) error
3939
}
4040

41+
type IEventRepository interface {
42+
FindEventByID(id string, result *event.Event) error
43+
}
44+
4145
type IFileService interface {
4246
GetSignedUrl(string) (string, error)
4347
}
@@ -213,6 +217,10 @@ func (s *Service) ConfirmEstamp(_ context.Context, req *proto.ConfirmEstampReque
213217
if err != nil {
214218
return nil, err
215219
}
220+
err = s.eventRepo.FindEventByID(req.EId, &event)
221+
if err != nil {
222+
return nil, status.Error(codes.NotFound, "event not found")
223+
}
216224

217225
user := user.User{
218226
Base: model.Base{
@@ -229,6 +237,10 @@ func (s *Service) ConfirmEstamp(_ context.Context, req *proto.ConfirmEstampReque
229237
if err != nil {
230238
return nil, status.Error(codes.NotFound, "something wrong")
231239
}
240+
err = s.eventRepo.FindEventByID(req.EId, &event)
241+
if err != nil {
242+
return nil, status.Error(codes.NotFound, "event not found")
243+
}
232244

233245
return &proto.ConfirmEstampResponse{}, nil
234246
}

src/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import (
1212
grpRepo "github.com/isd-sgcu/rnkm65-backend/src/app/repository/group"
1313
ur "github.com/isd-sgcu/rnkm65-backend/src/app/repository/user"
1414
bSrv "github.com/isd-sgcu/rnkm65-backend/src/app/service/baan"
15+
evtService "github.com/isd-sgcu/rnkm65-backend/src/app/service/event"
16+
bSrv "github.com/isd-sgcu/rnkm65-backend/src/app/service/baan"
1517
csr "github.com/isd-sgcu/rnkm65-backend/src/app/service/checkin"
1618
evtService "github.com/isd-sgcu/rnkm65-backend/src/app/service/event"
1719
fSrv "github.com/isd-sgcu/rnkm65-backend/src/app/service/file"

0 commit comments

Comments
 (0)