Skip to content

Commit

Permalink
chore:fixed us unnessesarily truncating our id fields (#234)
Browse files Browse the repository at this point in the history
* fixed us unnessesarily truncating our id fields

* fixed compilation errors
  • Loading branch information
CommanderStorm authored Sep 19, 2023
1 parent 4e17351 commit f65d4ec
Show file tree
Hide file tree
Showing 47 changed files with 136 additions and 136 deletions.
24 changes: 12 additions & 12 deletions server/api/tumdev/campus_backend.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions server/api/tumdev/campus_backend.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions server/api/tumdev/campus_backend.proto
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ message SearchRoomsReply {
}

message Room {
int32 room_id = 1;
int64 room_id = 1;
string room_code = 2;
string building_nr = 3;
string arch_id = 4;
Expand All @@ -231,7 +231,7 @@ message Room {
}

message NewsItem {
int32 id = 1;
int64 id = 1;
string title = 2;
string text = 3;
string link = 4;
Expand Down Expand Up @@ -377,7 +377,7 @@ message TagsOverview {
}

message RatingTag {
int32 tag_id = 1;
int64 tag_id = 1;
double points = 2;
}

Expand Down Expand Up @@ -478,7 +478,7 @@ message OpeningTimesMsgElement {
}

message GetUpdateNoteRequest {
int32 version = 1;
int64 version = 1;
}

message GetUpdateNoteReply {
Expand Down
16 changes: 8 additions & 8 deletions server/api/tumdev/campus_backend.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -966,8 +966,8 @@
"name": "version",
"in": "path",
"required": true,
"type": "integer",
"format": "int32"
"type": "string",
"format": "int64"
}
],
"tags": [
Expand Down Expand Up @@ -1565,8 +1565,8 @@
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int32"
"type": "string",
"format": "int64"
},
"title": {
"type": "string"
Expand Down Expand Up @@ -1647,8 +1647,8 @@
"type": "object",
"properties": {
"tagId": {
"type": "integer",
"format": "int32"
"type": "string",
"format": "int64"
},
"points": {
"type": "number",
Expand Down Expand Up @@ -1748,8 +1748,8 @@
"type": "object",
"properties": {
"roomId": {
"type": "integer",
"format": "int32"
"type": "string",
"format": "int64"
},
"roomCode": {
"type": "string"
Expand Down
6 changes: 3 additions & 3 deletions server/backend/cafeteriaRatingDBInitializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Old tags won't be removed to prevent problems with foreign keys.
func updateNameTagOptions(db *gorm.DB) {
tagsNames := generateNameTagListFromFile("static_data/dishNameTags.json")
for _, v := range tagsNames.MultiLanguageNameTags {
var parentId int32
var parentId int64
res := db.Model(&model.DishNameTagOption{}).
Where("EN LIKE ? AND DE LIKE ?", v.TagNameEnglish, v.TagNameGerman).
Select("DishNameTagOption").
Expand All @@ -99,7 +99,7 @@ func updateNameTagOptions(db *gorm.DB) {
}
}

func addNotIncluded(parentId int32, db *gorm.DB, v nameTag) {
func addNotIncluded(parentId int64, db *gorm.DB, v nameTag) {
var count int64
for _, expression := range v.NotIncluded {
fields := log.Fields{"expression": expression, "parentId": parentId}
Expand All @@ -123,7 +123,7 @@ func addNotIncluded(parentId int32, db *gorm.DB, v nameTag) {
}
}

func addCanBeIncluded(parentId int32, db *gorm.DB, v nameTag) {
func addCanBeIncluded(parentId int64, db *gorm.DB, v nameTag) {
var count int64
for _, expression := range v.CanBeIncluded {
fields := log.Fields{"expression": expression, "parentId": parentId}
Expand Down
30 changes: 15 additions & 15 deletions server/backend/cafeteriaService.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ func (s *CampusServer) GetCafeteriaRatings(_ context.Context, input *pb.GetCante
cafeteriaTags := queryTags(s.db, cafeteriaId, -1, CAFETERIA)

return &pb.GetCanteenRatingsReply{
Avg: float64(result.Average),
Std: float64(result.Std),
Min: int32(result.Min),
Max: int32(result.Max),
Avg: result.Average,
Std: result.Std,
Min: result.Min,
Max: result.Max,
Rating: ratings,
RatingTags: cafeteriaTags,
}, nil
Expand Down Expand Up @@ -166,10 +166,10 @@ func (s *CampusServer) GetDishRatings(_ context.Context, input *pb.GetDishRating
nameTags := queryTags(s.db, cafeteriaID, dishID, NAME)

return &pb.GetDishRatingsReply{
Avg: float64(result.Average),
Std: float64(result.Std),
Min: int32(result.Min),
Max: int32(result.Max),
Avg: result.Average,
Std: result.Std,
Min: result.Min,
Max: result.Max,
Rating: ratings,
RatingTags: dishTags,
NameTags: nameTags,
Expand Down Expand Up @@ -331,7 +331,7 @@ func queryTags(db *gorm.DB, cafeteriaID int32, dishID int32, ratingType modelTyp

// queryTagRatingOverviewForRating
// Query all rating tags which belong to a specific rating given with an ID and return it as TagRatingOverviews
func queryTagRatingsOverviewForRating(s *CampusServer, dishID int32, ratingType modelType) []*pb.RatingTagNewRequest {
func queryTagRatingsOverviewForRating(s *CampusServer, dishID int64, ratingType modelType) []*pb.RatingTagNewRequest {
var results []*pb.RatingTagNewRequest
var err error
if ratingType == DISH {
Expand Down Expand Up @@ -383,7 +383,7 @@ func (s *CampusServer) NewCanteenRating(_ context.Context, input *pb.NewCanteenR
return &pb.NewCanteenRatingReply{}, nil
}

func imageWrapper(image []byte, path string, id int32) string {
func imageWrapper(image []byte, path string, id int64) string {
var resPath = ""
if len(image) > 0 {
var resError error
Expand Down Expand Up @@ -484,8 +484,8 @@ func (s *CampusServer) NewDishRating(_ context.Context, input *pb.NewDishRatingR

// assignDishNameTag
// Query all name tags for this specific dish and generate the DishNameTag Ratings ffor each name tag
func assignDishNameTag(s *CampusServer, rating model.DishRating, dishID int32) {
var result []int
func assignDishNameTag(s *CampusServer, rating model.DishRating, dishID int64) {
var result []int64
err := s.db.Model(&model.DishToDishNameTag{}).
Where("dishID = ? ", dishID).
Select("nameTagID").
Expand All @@ -508,7 +508,7 @@ func assignDishNameTag(s *CampusServer, rating model.DishRating, dishID int32) {

// inputSanitizationForNewRatingElements Checks parameters of the new rating for all cafeteria and dish ratings.
// Additionally, queries the cafeteria ID, since it checks whether the cafeteria actually exists.
func inputSanitizationForNewRatingElements(rating int32, comment string, cafeteriaName string, s *CampusServer) (int32, error) {
func inputSanitizationForNewRatingElements(rating int32, comment string, cafeteriaName string, s *CampusServer) (int64, error) {
if rating > 5 || rating < 0 {
return -1, status.Error(codes.InvalidArgument, "Rating must be a positive number not larger than 10. Rating has not been saved.")
}
Expand Down Expand Up @@ -536,7 +536,7 @@ func inputSanitizationForNewRatingElements(rating int32, comment string, cafeter
// storeRatingTags
// Checks whether the rating-tag name is a valid option and if so,
// it will be saved with a reference to the rating
func storeRatingTags(s *CampusServer, parentRatingID int32, tags []*pb.RatingTag, tagType modelType) error {
func storeRatingTags(s *CampusServer, parentRatingID int64, tags []*pb.RatingTag, tagType modelType) error {
var errorOccurred = ""
var warningOccurred = ""
if len(tags) > 0 {
Expand Down Expand Up @@ -569,7 +569,7 @@ func storeRatingTags(s *CampusServer, parentRatingID int32, tags []*pb.RatingTag
Create(&model.DishRatingTag{
CorrespondingRating: parentRatingID,
Points: int32(currentTag.Points),
TagID: int(currentTag.TagId),
TagID: currentTag.TagId,
}).Error
if err != nil {
log.WithError(err).Error("while Creating a currentTag rating for a new rating.")
Expand Down
2 changes: 1 addition & 1 deletion server/backend/cron/canteenHeadCount.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func sumApCounts(aps []AccessPoint) uint32 {
log.WithError(err).Error("Canteen HeadCount getting the count failed for access point: ", ap.Target)
continue
}
total += uint32(count)
total += count
}
return total
}
Expand Down
14 changes: 7 additions & 7 deletions server/backend/cron/dishNameDownload.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type cafeteriaName struct {

type cafeteriaWithID struct {
Name string `json:"name"`
Cafeteria int32 `json:"cafeteria"`
Cafeteria int64 `json:"cafeteria"`
}

type location struct {
Expand Down Expand Up @@ -98,7 +98,7 @@ func downloadDailyDishes(c *CronService) {
}

var count int64
var dishId int32
var dishId int64
errCount := c.db.Model(&model.Dish{}).
Where("name = ? AND cafeteriaID = ?", dish.Name, dish.CafeteriaID).
Select("dish").First(&dishId).
Expand Down Expand Up @@ -176,9 +176,9 @@ func downloadCanteenNames(c *CronService) {
// addDishTagsToMapping
// Checks whether the dish name includes one of the expressions for the excluded tags as well as the included tags.
// The corresponding tags for all identified DishNames will be saved in the table DishNameTags.
func addDishTagsToMapping(dishID int32, dishName string, db *gorm.DB) {
func addDishTagsToMapping(dishID int64, dishName string, db *gorm.DB) {
lowercaseDish := strings.ToLower(dishName)
var includedTags []int32
var includedTags []int64
errIncluded := db.Model(&model.DishNameTagOptionIncluded{}).
Where("? LIKE CONCAT('%', expression ,'%')", lowercaseDish).
Select("nameTagID").
Expand All @@ -187,7 +187,7 @@ func addDishTagsToMapping(dishID int32, dishName string, db *gorm.DB) {
log.WithError(errIncluded).Error("Error while querying all included expressions for the dish: ", lowercaseDish)
}

var excludedTags []int32
var excludedTags []int64
errExcluded := db.Model(&model.DishNameTagOptionExcluded{}).
Where("? LIKE CONCAT('%', expression ,'%')", lowercaseDish).
Select("nameTagID").
Expand Down Expand Up @@ -219,10 +219,10 @@ func addDishTagsToMapping(dishID int32, dishName string, db *gorm.DB) {
}
}
}
func contains(s []int32, e int32) int32 {
func contains(s []int64, e int64) int64 {
for i, a := range s {
if a == e {
return int32(i)
return int64(i)
}
}
return -1
Expand Down
4 changes: 2 additions & 2 deletions server/backend/cron/news.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (c *CronService) parseNewsFeed(source model.NewsSource) error {
Src: source.Source,
Link: item.Link,
Image: enclosureUrl,
FilesID: null.IntFrom(int64(file.File)),
FilesID: null.IntFrom(file.File),
Files: file,
}
newNews = append(newNews, newsItem)
Expand Down Expand Up @@ -177,7 +177,7 @@ func skipNews(existingLinks []string, link string) bool {
return false
}

func (c *CronService) cleanOldNewsForSource(source int32) error {
func (c *CronService) cleanOldNewsForSource(source int64) error {
log.WithField("source", source).Trace("Truncating old entries")
if res := c.db.Delete(&model.News{}, "`src` = ? AND `created` < ?", source, time.Now().Add(time.Hour*24*365*-1)); res.Error == nil {
log.WithField("RowsAffected", res.RowsAffected).Info("cleaned up old news")
Expand Down
Loading

0 comments on commit f65d4ec

Please sign in to comment.