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 -}