From ea68230645d02c1f6f8fe10e9d34959a3a213fcb Mon Sep 17 00:00:00 2001 From: Tobias Jungmann <32565407+tobiasjungmann@users.noreply.github.com> Date: Fri, 6 Oct 2023 20:37:14 +0200 Subject: [PATCH] Canteen Batch Logging Silencing (#254) * move head count to canteen service * silence logging for batch db operations * renamed cafeteria service to cafeteria * Update server/backend/cafeteria_rating_db_initializer.go Co-authored-by: Frank Elsinga * Update server/backend/cafeteria_rating_db_initializer.go Co-authored-by: Frank Elsinga * code review feedback --------- Co-authored-by: Frank Elsinga --- .../{cafeteria_service.go => cafeteria.go} | 17 +++++++++++ server/backend/canteen_head_count.go | 29 ------------------- 2 files changed, 17 insertions(+), 29 deletions(-) rename server/backend/{cafeteria_service.go => cafeteria.go} (97%) delete mode 100644 server/backend/canteen_head_count.go diff --git a/server/backend/cafeteria_service.go b/server/backend/cafeteria.go similarity index 97% rename from server/backend/cafeteria_service.go rename to server/backend/cafeteria.go index 85a5c69f..57593161 100644 --- a/server/backend/cafeteria_service.go +++ b/server/backend/cafeteria.go @@ -729,3 +729,20 @@ func (s *CampusServer) ListDishes(ctx context.Context, request *pb.ListDishesReq Dish: results, }, requestStatus } + +// GetCanteenHeadCount RPC Endpoint +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.WithContext(ctx).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, status.Error(codes.Internal, "failed to query head count") + } + + return &pb.GetCanteenHeadCountReply{ + Count: data.Count, + MaxCount: data.MaxCount, + Percent: data.Percent, + Timestamp: timestamppb.New(data.Timestamp), + }, nil +} diff --git a/server/backend/canteen_head_count.go b/server/backend/canteen_head_count.go deleted file mode 100644 index 5aa1c8fc..00000000 --- a/server/backend/canteen_head_count.go +++ /dev/null @@ -1,29 +0,0 @@ -package backend - -import ( - "context" - "errors" - - pb "github.com/TUM-Dev/Campus-Backend/server/api/tumdev" - "github.com/TUM-Dev/Campus-Backend/server/model" - log "github.com/sirupsen/logrus" - "google.golang.org/protobuf/types/known/timestamppb" - "gorm.io/gorm" -) - -// GetCanteenHeadCount RPC Endpoint -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.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") - } - - return &pb.GetCanteenHeadCountReply{ - Count: data.Count, - MaxCount: data.MaxCount, - Percent: data.Percent, - Timestamp: timestamppb.New(data.Timestamp), - }, nil -}