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

chore:context-utilisation #235

Merged
merged 6 commits into from
Sep 19, 2023
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 client/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/TUM-Dev/Campus-Backend/client
go 1.21

require (
github.com/TUM-Dev/Campus-Backend/server v0.0.0-20230919151227-4e173519f39f
github.com/TUM-Dev/Campus-Backend/server v0.0.0-20230919155641-f895a75987e0
github.com/sirupsen/logrus v1.9.3
google.golang.org/grpc v1.58.1
)
Expand Down
4 changes: 2 additions & 2 deletions client/go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/TUM-Dev/Campus-Backend/server v0.0.0-20230919151227-4e173519f39f h1:+SvWYtUOg+L0DiuFvxwmdo4B48Dllk5M1oRG0Zsfyuw=
github.com/TUM-Dev/Campus-Backend/server v0.0.0-20230919151227-4e173519f39f/go.mod h1:fjoLL3rbdY6wTRJIksekT2p3OUp5ocFfXjB/avV/TVI=
github.com/TUM-Dev/Campus-Backend/server v0.0.0-20230919155641-f895a75987e0 h1:rZqUJmywWU9aV9Bk/IYKIYN76+nYcATD2q+pFVBYQN4=
github.com/TUM-Dev/Campus-Backend/server v0.0.0-20230919155641-f895a75987e0/go.mod h1:fjoLL3rbdY6wTRJIksekT2p3OUp5ocFfXjB/avV/TVI=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
134 changes: 68 additions & 66 deletions server/backend/cafeteriaService.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions server/backend/canteenHeadCount.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import (
)

// GetCanteenHeadCount RPC Endpoint
func (s *CampusServer) GetCanteenHeadCount(_ context.Context, input *pb.GetCanteenHeadCountRequest) (*pb.GetCanteenHeadCountReply, error) {
func (s *CampusServer) GetCanteenHeadCount(ctx context.Context, input *pb.GetCanteenHeadCountRequest) (*pb.GetCanteenHeadCountReply, error) {
data := model.CanteenHeadCount{Count: 0, MaxCount: 0, Percent: -1} // Initialize with an empty (not found) value
err := s.db.Model(&model.CanteenHeadCount{}).Where(model.CanteenHeadCount{CanteenId: input.CanteenId}).FirstOrInit(&data).Error
err := s.db.WithContext(ctx).Model(&model.CanteenHeadCount{}).Where(model.CanteenHeadCount{CanteenId: input.CanteenId}).FirstOrInit(&data).Error
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
log.WithError(err).Error("while querying the canteen head count for: ", input.CanteenId)
return nil, errors.New("failed to query head count")
Expand Down
4 changes: 2 additions & 2 deletions server/backend/news.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func (s *CampusServer) GetNewsSources(ctx context.Context, _ *pb.GetNewsSourcesR
}

var sources []model.NewsSource
if err := s.db.Joins("Files").Find(&sources).Error; err != nil {
if err := s.db.WithContext(ctx).Joins("Files").Find(&sources).Error; err != nil {
log.WithError(err).Error("could not find newsSources")
return nil, status.Error(codes.Internal, "could not GetNewsSources")
}
Expand All @@ -42,7 +42,7 @@ func (s *CampusServer) GetNews(ctx context.Context, req *pb.GetNewsRequest) (*pb
}

var newsEntries []model.News
tx := s.db.Joins("Files")
tx := s.db.WithContext(ctx).Joins("Files")
if req.NewsSource != 0 {
tx = tx.Where("src = ?", req.NewsSource)
}
Expand Down
2 changes: 1 addition & 1 deletion server/backend/newsAlerts.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func (s *CampusServer) GetTopNews(ctx context.Context, _ *pb.GetTopNewsRequest)
}

var res *model.NewsAlert
err := s.db.Joins("Files").Where("NOW() between `from` and `to`").First(&res).Error
err := s.db.WithContext(ctx).Joins("Files").Where("NOW() between `from` and `to`").First(&res).Error
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, status.Error(codes.NotFound, "no current active top news")
} else if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion server/backend/rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (s *CampusServer) SearchRooms(ctx context.Context, req *pb.SearchRoomsReque
Campus string
Name string
}
err := s.db.Raw("SELECT r.*, a.campus, a.name "+
err := s.db.WithContext(ctx).Raw("SELECT r.*, a.campus, a.name "+
"FROM roomfinder_rooms r "+
"LEFT JOIN roomfinder_building2area a ON a.building_nr = r.building_nr "+
"WHERE MATCH(room_code, info, address) AGAINST(?)", req.Query).Scan(&res).Error
Expand Down
2 changes: 1 addition & 1 deletion server/backend/updateNote.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func (s *CampusServer) GetUpdateNote(ctx context.Context, req *pb.GetUpdateNoteR
}

res := model.UpdateNote{VersionCode: req.Version}
if err := s.db.First(&res).Error; errors.Is(err, gorm.ErrRecordNotFound) {
if err := s.db.WithContext(ctx).First(&res).Error; errors.Is(err, gorm.ErrRecordNotFound) {
return nil, status.Error(codes.NotFound, "No update note found")
} else if err != nil {
log.WithField("VersionCode", req.Version).WithError(err).Error("Failed to get update note")
Expand Down
Loading