diff --git a/server/backend/cafeteria.go b/server/backend/cafeteria.go index 6a679497..c39c86fc 100644 --- a/server/backend/cafeteria.go +++ b/server/backend/cafeteria.go @@ -58,7 +58,7 @@ func (s *CampusServer) ListCanteenRatings(ctx context.Context, input *pb.ListCan // queryLastCafeteriaRatingsWithLimit // Queries the actual ratings for a cafeteria and attaches the tag ratings which belong to the ratings func queryLastCafeteriaRatingsWithLimit(input *pb.ListCanteenRatingsRequest, cafeteriaID int32, tx *gorm.DB) []*pb.SingleRatingReply { - var ratings []model.CafeteriaRating + var ratings []model.CanteenRating var err error var limit = int(input.Limit) @@ -81,7 +81,8 @@ func queryLastCafeteriaRatingsWithLimit(input *pb.ListCanteenRatingsRequest, caf } else { to = input.To.AsTime() } - err = tx.Order("timestamp desc, cafeteriaRating desc"). + err = tx. + Order("timestamp desc, cafeteriaRating desc"). Limit(limit). Find(&ratings, "cafeteriaID = ? AND timestamp < ? AND timestamp > ?", cafeteriaID, to, from).Error } else { @@ -233,25 +234,25 @@ func queryTags(cafeteriaID int32, dishID int32, ratingType model.ModelType, tx * var results []queryRatingTag var err error if ratingType == model.DISH { - err = tx.Table("dish_rating_tag_option options"). + err = tx.Table("dish_rating_tag_options options"). Joins("JOIN dish_rating_tag_statistics results ON options.dishRatingTagOption = results.tagID"). Select("options.dishRatingTagOption as tagId, results.average as avg, "+ "results.min as min, results.max as max, results.std as std"). Where("results.cafeteriaID = ? AND results.dishID = ?", cafeteriaID, dishID). Scan(&results).Error } else if ratingType == model.CAFETERIA { - err = tx.Table("cafeteria_rating_tag_option options"). + err = tx.Table("cafeteria_rating_tag_options options"). Joins("JOIN cafeteria_rating_tag_statistics results ON options.cafeteriaRatingTagOption = results.tagID"). Select("options.cafeteriaRatingTagOption as tagId, results.average as avg, "+ "results.min as min, results.max as max, results.std as std"). Where("results.cafeteriaID = ?", cafeteriaID). Scan(&results).Error } else { //Query for name tags - err = tx.Table("dish_to_dish_name_tag mapping"). + err = tx.Table("dish_to_dish_name_tags mapping"). Where("mapping.dishID = ?", dishID). Select("mapping.nameTagID as tag"). Joins("JOIN dish_name_tag_statistics results ON mapping.nameTagID = results.tagID"). - Joins("JOIN dish_name_tag_option options ON mapping.nameTagID = options.dishNameTagOption"). + Joins("JOIN dish_name_tag_options options ON mapping.nameTagID = options.dishNameTagOption"). Select("mapping.nameTagID as tagId, results.average as avg, " + "results.min as min, results.max as max, results.std as std"). Scan(&results).Error @@ -282,13 +283,13 @@ func queryTagRatingsOverviewForRating(dishID int64, ratingType model.ModelType, var results []*pb.RatingTagNewRequest var err error if ratingType == model.DISH { - err = tx.Table("dish_rating_tag_option options"). - Joins("JOIN dish_rating_tag rating ON options.dishRatingTagOption = rating.tagID"). + err = tx.Table("dish_rating_tag_options options"). + Joins("JOIN dish_rating_tags rating ON options.dishRatingTagOption = rating.tagID"). Select("dishRatingTagOption as tagId, points, parentRating"). Find(&results, "parentRating = ?", dishID).Error } else { - err = tx.Table("cafeteria_rating_tag_option options"). - Joins("JOIN cafeteria_rating_tag rating ON options.cafeteriaRatingTagOption = rating.tagID"). + err = tx.Table("cafeteria_rating_tag_options options"). + Joins("JOIN cafeteria_rating_tags rating ON options.cafeteriaRatingTagOption = rating.tagID"). Select("cafeteriaRatingTagOption as tagId, points, correspondingRating"). Find(&results, "correspondingRating = ?", dishID).Error } @@ -312,7 +313,7 @@ func (s *CampusServer) CreateCanteenRating(ctx context.Context, input *pb.Create } resPath := imageWrapper(input.Image, "cafeterias", cafeteriaID) - rating := model.CafeteriaRating{ + rating := model.CanteenRating{ Comment: input.Comment, Points: input.Points, CafeteriaID: cafeteriaID, @@ -457,10 +458,10 @@ func inputSanitizationForNewRatingElements(rating int32, comment string, cafeter return -1, status.Error(codes.InvalidArgument, "Comments must not contain @ symbols in order to prevent misuse. Rating has not been saved.") } - var result *model.Cafeteria + var result *model.Canteen if res := tx.First(&result, "name LIKE ?", cafeteriaName); errors.Is(res.Error, gorm.ErrRecordNotFound) || res.RowsAffected == 0 { log.WithError(res.Error).Error("Error while querying the cafeteria id by name: ", cafeteriaName) - return -1, status.Error(codes.InvalidArgument, "Cafeteria does not exist. Rating has not been saved.") + return -1, status.Error(codes.InvalidArgument, "Canteen does not exist. Rating has not been saved.") } return result.Cafeteria, nil @@ -484,7 +485,7 @@ func storeRatingTags(parentRatingID int64, tags []*pb.RatingTag, tagType model.M Where("dishRatingTagOption LIKE ?", currentTag.TagId). Count(&count).Error } else { - err = tx.Model(&model.CafeteriaRatingTagOption{}). + err = tx.Model(&model.CanteenRatingTagOption{}). Where("cafeteriaRatingTagOption LIKE ?", currentTag.TagId). Count(&count).Error } @@ -534,13 +535,13 @@ func getModelStoreTag(tagType model.ModelType, tx *gorm.DB) *gorm.DB { if tagType == model.DISH { return tx.Model(&model.DishRatingTag{}) } else { - return tx.Model(&model.CafeteriaRatingTag{}) + return tx.Model(&model.CanteenRatingTag{}) } } func getIDForCafeteriaName(name string, tx *gorm.DB) int32 { var result int32 = -1 - err := tx.Model(&model.Cafeteria{}). + err := tx.Model(&model.Canteen{}). Where("name LIKE ?", name). Select("cafeteria"). Scan(&result).Error @@ -609,7 +610,7 @@ func (s *CampusServer) GetAvailableCafeteriaTags(ctx context.Context, _ *pb.List var result []*pb.TagsOverview var requestStatus error = nil err := s.db.WithContext(ctx). - Model(&model.CafeteriaRatingTagOption{}). + Model(&model.CanteenRatingTagOption{}). Select("DE as de, EN as en, cafeteriaRatingsTagOption as TagId"). Find(&result).Error if err != nil { @@ -628,7 +629,7 @@ func (s *CampusServer) GetCafeterias(ctx context.Context, _ *pb.ListCanteensRequ var result []*pb.Canteen var requestStatus error = nil if err := s.db.WithContext(ctx). - Model(&model.Cafeteria{}). + Model(&model.Canteen{}). Select("cafeteria as id,address,latitude,longitude"). Scan(&result).Error; err != nil { log.WithError(err).Error("while loading Cafeterias from database.") @@ -657,7 +658,7 @@ func (s *CampusServer) ListDishes(ctx context.Context, req *pb.ListDishesRequest cafeteriaName := strings.ReplaceAll(strings.ToUpper(req.CanteenId), "-", "_") err := s.db.WithContext(ctx). - Table("dishes_of_the_week weekly"). + Table("dishes_of_the_weeks weekly"). Where("weekly.day = ? AND weekly.week = ? and weekly.year = ?", req.Day, req.Week, req.Year). Select("weekly.dishID"). Joins("JOIN dish d ON d.dish = weekly.dishID"). diff --git a/server/backend/cron/dish_name_download.go b/server/backend/cron/dish_name_download.go index c7fb455d..1aa3fe07 100644 --- a/server/backend/cron/dish_name_download.go +++ b/server/backend/cron/dish_name_download.go @@ -51,7 +51,7 @@ func (c *CronService) dishNameDownloadCron() error { } func downloadDailyDishes(c *CronService) { - var results []model.Cafeteria + var results []model.Canteen if err := c.db.Find(&results).Error; err != nil { log.WithError(err).Error("Error while querying all cafeteria names from the database.") return @@ -145,13 +145,13 @@ func downloadCanteenNames(c *CronService) { } for _, cafeteriaName := range cafeteriaNames { - mensa := model.Cafeteria{ + mensa := model.Canteen{ Name: cafeteriaName.Name, Address: cafeteriaName.Location.Address, Latitude: cafeteriaName.Location.Latitude, Longitude: cafeteriaName.Location.Longitude, } - var cafeteriaResult model.Cafeteria + var cafeteriaResult model.Canteen if err := c.db.First(&cafeteriaResult, "name = ?", cafeteriaName.Name).Error; err != nil { if err := c.db.Create(&mensa).Error; err != nil { log.WithError(err).Error("Error while creating the db entry for the cafeteria ", cafeteriaName.Name) @@ -170,7 +170,7 @@ func downloadCanteenNames(c *CronService) { func addDishTagsToMapping(dishID int64, dishName string, db *gorm.DB) { lowercaseDish := strings.ToLower(dishName) var includedTags []int64 - if err := db.Model(&model.DishNameTagOptionIncluded{}). + if err := db.Model(&model.IncludedDishNameTagOption{}). Where("? LIKE CONCAT('%', expression ,'%')", lowercaseDish). Select("nameTagID"). Scan(&includedTags).Error; err != nil { @@ -178,7 +178,7 @@ func addDishTagsToMapping(dishID int64, dishName string, db *gorm.DB) { } var excludedTags []int64 - if err := db.Model(&model.DishNameTagOptionExcluded{}). + if err := db.Model(&model.ExcludedDishNameTagOption{}). Where("? LIKE CONCAT('%', expression ,'%')", lowercaseDish). Select("nameTagID"). Scan(&excludedTags).Error; err != nil { diff --git a/server/backend/cron/movies.go b/server/backend/cron/movies.go index 8c510a92..09e2f6f6 100644 --- a/server/backend/cron/movies.go +++ b/server/backend/cron/movies.go @@ -32,7 +32,7 @@ func (c *CronService) movieCron() error { } log.Trace("parsing upcoming feed") var allMovieLinks []string - if err := c.db.Model(&model.Kino{}). + if err := c.db.Model(&model.Movie{}). Distinct(). Pluck("Link", &allMovieLinks).Error; err != nil { return err @@ -70,7 +70,7 @@ func (c *CronService) movieCron() error { log.WithFields(logFields).WithError(err).Error("error while finding imdb id") continue } - movie := model.Kino{ + movie := model.Movie{ Date: date, Title: item.Title, Location: null.StringFrom(item.Location), diff --git a/server/backend/migration/20240824000000.go b/server/backend/migration/20240824000000.go new file mode 100644 index 00000000..486d57dd --- /dev/null +++ b/server/backend/migration/20240824000000.go @@ -0,0 +1,58 @@ +package migration + +import ( + "github.com/go-gormigrate/gormigrate/v2" + "gorm.io/gorm" +) + +type wrongTableName struct { + Original string + New string +} + +var wrongTableNames = []wrongTableName{ + {"crontab", "crontabs"}, + {"kino", "movies"}, + {"cafeteria", "canteens"}, + {"canteen_head_count", "canteen_head_counts"}, + {"cafeteria_rating", "canteen_ratings"}, + {"cafeteria_rating_tag", "canteen_rating_tags"}, + {"cafeteria_rating_tag_option", "canteen_rating_tag_options"}, + {"dish", "dishes"}, + {"dish_rating", "dish_ratings"}, + {"dish_rating_tag", "dish_rating_tags"}, + {"dish_rating_tag_option", "dish_rating_tag_options"}, + {"dish_name_tag", "dish_name_tags"}, + {"dish_name_tag_option", "dish_name_tag_options"}, + {"dish_name_tag_option_excluded", "excluded_dish_name_tag_options"}, + {"dish_name_tag_option_included", "included_dish_name_tag_option"}, + {"dish_to_dish_name_tag", "dish_to_dish_name_tags"}, + {"dishes_of_the_week", "dishes_of_the_weeks"}, + {"update_note", "update_notes"}, + {"newsSource", "news_sources"}, + {"news_alert", "news_alerts"}, +} + +// migrate20240824000000 +// - replaces all instances of misleadingly named tables with the correct ones +func migrate20240824000000() *gormigrate.Migration { + return &gormigrate.Migration{ + ID: "20240824000000", + Migrate: func(tx *gorm.DB) error { + for _, table := range wrongTableNames { + if err := tx.Migrator().RenameTable(table.Original, table.New); err != nil { + return err + } + } + return nil + }, + Rollback: func(tx *gorm.DB) error { + for _, table := range wrongTableNames { + if err := tx.Migrator().RenameTable(table.New, table.Original); err != nil { + return err + } + } + return nil + }, + } +} diff --git a/server/backend/migration/migration.go b/server/backend/migration/migration.go index 440eec60..c799e00f 100644 --- a/server/backend/migration/migration.go +++ b/server/backend/migration/migration.go @@ -12,18 +12,18 @@ import ( func autoMigrate(db *gorm.DB) error { err := db.AutoMigrate( - &model.Cafeteria{}, - &model.CafeteriaRating{}, - &model.CafeteriaRatingTag{}, - &model.CafeteriaRatingTagOption{}, + &model.Canteen{}, + &model.CanteenRating{}, + &model.CanteenRatingTag{}, + &model.CanteenRatingTagOption{}, &model.CanteenHeadCount{}, &model.Crontab{}, &model.Device{}, &model.Dish{}, &model.DishNameTag{}, &model.DishNameTagOption{}, - &model.DishNameTagOptionExcluded{}, - &model.DishNameTagOptionIncluded{}, + &model.ExcludedDishNameTagOption{}, + &model.IncludedDishNameTagOption{}, &model.DishRating{}, &model.DishRatingTag{}, &model.DishRatingTagOption{}, @@ -31,7 +31,7 @@ func autoMigrate(db *gorm.DB) error { &model.DishesOfTheWeek{}, &model.Feedback{}, &model.File{}, - &model.Kino{}, + &model.Movie{}, &model.NewExamResultsSubscriber{}, &model.News{}, &model.NewsAlert{}, @@ -86,6 +86,7 @@ func manualMigrate(db *gorm.DB) error { migrate20240511000000(), migrate20240512000000(), migrate20240706000000(), + migrate20240824000000(), } return gormigrate.New(db, gormigrateOptions, migrations).Migrate() } diff --git a/server/backend/movie.go b/server/backend/movie.go index b9e7f5e4..b07d8104 100644 --- a/server/backend/movie.go +++ b/server/backend/movie.go @@ -12,7 +12,7 @@ import ( ) func (s *CampusServer) ListMovies(ctx context.Context, req *pb.ListMoviesRequest) (*pb.ListMoviesReply, error) { - var movies []model.Kino + var movies []model.Movie tx := s.db.WithContext(ctx). Joins("File"). Order("date ASC") diff --git a/server/backend/movie_test.go b/server/backend/movie_test.go index f03d2868..68bd96c9 100644 --- a/server/backend/movie_test.go +++ b/server/backend/movie_test.go @@ -78,7 +78,7 @@ var ( } ) -const ListMoviesQuery = "SELECT `kino`.`kino`,`kino`.`date`,`kino`.`created`,`kino`.`title`,`kino`.`year`,`kino`.`runtime`,`kino`.`genre`,`kino`.`director`,`kino`.`actors`,`kino`.`rating`,`kino`.`description`,`kino`.`trailer`,`kino`.`cover`,`kino`.`link`,`kino`.`location`,`File`.`file` AS `File__file`,`File`.`name` AS `File__name`,`File`.`path` AS `File__path`,`File`.`downloads` AS `File__downloads`,`File`.`url` AS `File__url`,`File`.`downloaded` AS `File__downloaded` FROM `kino` LEFT JOIN `files` `File` ON `kino`.`cover` = `File`.`file` WHERE kino > ? ORDER BY date ASC" +const ListMoviesQuery = "SELECT `movies`.`kino`,`movies`.`date`,`movies`.`created`,`movies`.`title`,`movies`.`year`,`movies`.`runtime`,`movies`.`genre`,`movies`.`director`,`movies`.`actors`,`movies`.`rating`,`movies`.`description`,`movies`.`trailer`,`movies`.`cover`,`movies`.`link`,`movies`.`location`,`File`.`file` AS `File__file`,`File`.`name` AS `File__name`,`File`.`path` AS `File__path`,`File`.`downloads` AS `File__downloads`,`File`.`url` AS `File__url`,`File`.`downloaded` AS `File__downloaded` FROM `movies` LEFT JOIN `files` `File` ON `movies`.`cover` = `File`.`file` WHERE kino > ? ORDER BY date ASC" func (s *MovieSuite) Test_ListMoviesAll() { server := CampusServer{db: s.DB} diff --git a/server/backend/news.go b/server/backend/news.go index 4025b8a1..158a14a3 100644 --- a/server/backend/news.go +++ b/server/backend/news.go @@ -25,7 +25,7 @@ func (s *CampusServer) ListNewsSources(ctx context.Context, _ *pb.ListNewsSource if err := s.db.WithContext(ctx). Joins("File"). Find(&sources).Error; err != nil { - log.WithError(err).Error("could not find newsSources") + log.WithError(err).Error("could not find news_sources") return nil, status.Error(codes.Internal, "could not ListNewsSources") } @@ -94,9 +94,9 @@ func (s *CampusServer) ListNewsAlerts(ctx context.Context, req *pb.ListNewsAlert var res []*model.NewsAlert tx := s.db.WithContext(ctx). Joins("File"). - Where("news_alert.to >= NOW()") + Where("news_alerts.to >= NOW()") if req.LastNewsAlertId != 0 { - tx = tx.Where("news_alert.news_alert > ?", req.LastNewsAlertId) + tx = tx.Where("news_alerts.news_alert > ?", req.LastNewsAlertId) } if err := tx.Find(&res).Error; errors.Is(err, gorm.ErrRecordNotFound) { return nil, status.Error(codes.NotFound, "no news alerts") diff --git a/server/backend/news_test.go b/server/backend/news_test.go index 5a03b4e7..11771990 100644 --- a/server/backend/news_test.go +++ b/server/backend/news_test.go @@ -85,7 +85,7 @@ func source2() *model.NewsSource { } } -const ExpectedListNewsSourcesQuery = "SELECT `newsSource`.`source`,`newsSource`.`title`,`newsSource`.`url`,`newsSource`.`icon`,`newsSource`.`hook`,`File`.`file` AS `File__file`,`File`.`name` AS `File__name`,`File`.`path` AS `File__path`,`File`.`downloads` AS `File__downloads`,`File`.`url` AS `File__url`,`File`.`downloaded` AS `File__downloaded` FROM `newsSource` LEFT JOIN `files` `File` ON `newsSource`.`icon` = `File`.`file`" +const ExpectedListNewsSourcesQuery = "SELECT `news_sources`.`source`,`news_sources`.`title`,`news_sources`.`url`,`news_sources`.`icon`,`news_sources`.`hook`,`File`.`file` AS `File__file`,`File`.`name` AS `File__name`,`File`.`path` AS `File__path`,`File`.`downloads` AS `File__downloads`,`File`.`url` AS `File__url`,`File`.`downloaded` AS `File__downloaded` FROM `news_sources` LEFT JOIN `files` `File` ON `news_sources`.`icon` = `File`.`file`" func (s *NewsSuite) Test_ListNewsSourcesMultiple() { s1, s2 := source1(), source2() @@ -141,7 +141,7 @@ func (s *NewsSuite) Test_ListNewsSourcesNone() { require.Equal(s.T(), expectedResp, response) } -const ExpectedListNewsQuery = "SELECT `news`.`news`,`news`.`date`,`news`.`created`,`news`.`title`,`news`.`description`,`news`.`src`,`news`.`link`,`news`.`image`,`news`.`file`,`File`.`file` AS `File__file`,`File`.`name` AS `File__name`,`File`.`path` AS `File__path`,`File`.`downloads` AS `File__downloads`,`File`.`url` AS `File__url`,`File`.`downloaded` AS `File__downloaded`,`NewsSource`.`source` AS `NewsSource__source`,`NewsSource`.`title` AS `NewsSource__title`,`NewsSource`.`url` AS `NewsSource__url`,`NewsSource`.`icon` AS `NewsSource__icon`,`NewsSource`.`hook` AS `NewsSource__hook`,`NewsSource__File`.`file` AS `NewsSource__File__file`,`NewsSource__File`.`name` AS `NewsSource__File__name`,`NewsSource__File`.`path` AS `NewsSource__File__path`,`NewsSource__File`.`downloads` AS `NewsSource__File__downloads`,`NewsSource__File`.`url` AS `NewsSource__File__url`,`NewsSource__File`.`downloaded` AS `NewsSource__File__downloaded` FROM `news` LEFT JOIN `files` `File` ON `news`.`file` = `File`.`file` LEFT JOIN `newsSource` `NewsSource` ON `news`.`src` = `NewsSource`.`source` LEFT JOIN `files` `NewsSource__File` ON `NewsSource`.`icon` = `NewsSource__File`.`file`" +const ExpectedListNewsQuery = "SELECT `news`.`news`,`news`.`date`,`news`.`created`,`news`.`title`,`news`.`description`,`news`.`src`,`news`.`link`,`news`.`image`,`news`.`file`,`File`.`file` AS `File__file`,`File`.`name` AS `File__name`,`File`.`path` AS `File__path`,`File`.`downloads` AS `File__downloads`,`File`.`url` AS `File__url`,`File`.`downloaded` AS `File__downloaded`,`NewsSource`.`source` AS `NewsSource__source`,`NewsSource`.`title` AS `NewsSource__title`,`NewsSource`.`url` AS `NewsSource__url`,`NewsSource`.`icon` AS `NewsSource__icon`,`NewsSource`.`hook` AS `NewsSource__hook`,`NewsSource__File`.`file` AS `NewsSource__File__file`,`NewsSource__File`.`name` AS `NewsSource__File__name`,`NewsSource__File`.`path` AS `NewsSource__File__path`,`NewsSource__File`.`downloads` AS `NewsSource__File__downloads`,`NewsSource__File`.`url` AS `NewsSource__File__url`,`NewsSource__File`.`downloaded` AS `NewsSource__File__downloaded` FROM `news` LEFT JOIN `files` `File` ON `news`.`file` = `File`.`file` LEFT JOIN `news_sources` `NewsSource` ON `news`.`src` = `NewsSource`.`source` LEFT JOIN `files` `NewsSource__File` ON `NewsSource`.`icon` = `NewsSource__File`.`file`" func (s *NewsSuite) Test_ListNewsNone_withFilters() { s.mock.ExpectQuery(regexp.QuoteMeta(ExpectedListNewsQuery+" WHERE src = ? AND news > ?")). @@ -221,7 +221,7 @@ func alert2() *model.NewsAlert { } } -const ExpectedListNewsAlertsQuery = "SELECT `news_alert`.`news_alert`,`news_alert`.`file`,`news_alert`.`name`,`news_alert`.`link`,`news_alert`.`created`,`news_alert`.`from`,`news_alert`.`to`,`File`.`file` AS `File__file`,`File`.`name` AS `File__name`,`File`.`path` AS `File__path`,`File`.`downloads` AS `File__downloads`,`File`.`url` AS `File__url`,`File`.`downloaded` AS `File__downloaded` FROM `news_alert` LEFT JOIN `files` `File` ON `news_alert`.`file` = `File`.`file` WHERE news_alert.to >= NOW()" +const ExpectedListNewsAlertsQuery = "SELECT `news_alerts`.`news_alert`,`news_alerts`.`file`,`news_alerts`.`name`,`news_alerts`.`link`,`news_alerts`.`created`,`news_alerts`.`from`,`news_alerts`.`to`,`File`.`file` AS `File__file`,`File`.`name` AS `File__name`,`File`.`path` AS `File__path`,`File`.`downloads` AS `File__downloads`,`File`.`url` AS `File__url`,`File`.`downloaded` AS `File__downloaded` FROM `news_alerts` LEFT JOIN `files` `File` ON `news_alerts`.`file` = `File`.`file` WHERE news_alerts.to >= NOW()" func (s *NewsSuite) Test_ListNewsAlertsError() { s.mock.ExpectQuery(regexp.QuoteMeta(ExpectedListNewsAlertsQuery)).WillReturnError(gorm.ErrInvalidDB) @@ -241,7 +241,7 @@ func (s *NewsSuite) Test_ListNewsAlertsNone_noFilter() { require.Nil(s.T(), response) } func (s *NewsSuite) Test_ListNewsAlertsNone_Filter() { - s.mock.ExpectQuery(regexp.QuoteMeta(ExpectedListNewsAlertsQuery + " AND news_alert.news_alert > ?")).WithArgs(42).WillReturnError(gorm.ErrRecordNotFound) + s.mock.ExpectQuery(regexp.QuoteMeta(ExpectedListNewsAlertsQuery + " AND news_alerts.news_alert > ?")).WithArgs(42).WillReturnError(gorm.ErrRecordNotFound) server := CampusServer{db: s.DB, deviceBuf: s.deviceBuf} response, err := server.ListNewsAlerts(metadata.NewIncomingContext(context.Background(), metadata.MD{}), &pb.ListNewsAlertsRequest{LastNewsAlertId: 42}) diff --git a/server/backend/update_note_test.go b/server/backend/update_note_test.go index ae74e6b4..008d1854 100644 --- a/server/backend/update_note_test.go +++ b/server/backend/update_note_test.go @@ -46,7 +46,7 @@ func (s *UpdateNoteSuite) SetupSuite() { s.deviceBuf = newDeviceBuffer() } -const ExpectedGetUpdateNoteQuery = "SELECT * FROM `update_note` WHERE `update_note`.`version_code` = ? ORDER BY `update_note`.`version_code` LIMIT ?" +const ExpectedGetUpdateNoteQuery = "SELECT * FROM `update_notes` WHERE `update_notes`.`version_code` = ? ORDER BY `update_notes`.`version_code` LIMIT ?" func (s *UpdateNoteSuite) Test_GetUpdateNoteOne() { s.mock.ExpectQuery(regexp.QuoteMeta(ExpectedGetUpdateNoteQuery)). diff --git a/server/model/cafeteria.go b/server/model/canteen.go similarity index 66% rename from server/model/cafeteria.go rename to server/model/canteen.go index 3b25eb00..1c661980 100644 --- a/server/model/cafeteria.go +++ b/server/model/canteen.go @@ -1,15 +1,10 @@ package model -// Cafeteria stores all Available cafeterias in the format of the eat-api -type Cafeteria struct { +// Canteen stores all Available cafeterias in the format of the eat-api +type Canteen struct { Cafeteria int64 `gorm:"primary_key;AUTO_INCREMENT;column:cafeteria;type:int;not null;" json:"canteen" ` Name string `gorm:"column:name;type:text;not null;" json:"name" ` Address string `gorm:"column:address;type:text;not null;" json:"address" ` Latitude float64 `gorm:"column:latitude;type:double;not null;" json:"latitude" ` Longitude float64 `gorm:"column:longitude;type:double;not null;" json:"longitude"` } - -// TableName sets the insert table name for this struct type -func (n *Cafeteria) TableName() string { - return "cafeteria" -} diff --git a/server/model/canteen_head_count.go b/server/model/canteen_head_count.go index d895130c..ade4144b 100644 --- a/server/model/canteen_head_count.go +++ b/server/model/canteen_head_count.go @@ -12,8 +12,3 @@ type CanteenHeadCount struct { Percent float32 `gorm:"column:percent;type:float;not null;" json:"percent"` Timestamp time.Time `gorm:"column:timestamp;type:timestamp;not null;default:current_timestamp();OnUpdate:current_timestamp();" json:"timestamp" ` } - -// TableName sets the insert table name for this struct type -func (n *CanteenHeadCount) TableName() string { - return "canteen_head_count" -} diff --git a/server/model/cafeteria_rating.go b/server/model/canteen_rating.go similarity index 72% rename from server/model/cafeteria_rating.go rename to server/model/canteen_rating.go index 304f5203..55baad6b 100644 --- a/server/model/cafeteria_rating.go +++ b/server/model/canteen_rating.go @@ -4,8 +4,8 @@ import ( "time" ) -// CafeteriaRating stores all Available cafeterias in the format of the eat-api -type CafeteriaRating struct { +// CanteenRating stores all Available cafeterias in the format of the eat-api +type CanteenRating struct { CafeteriaRating int64 `gorm:"primary_key;AUTO_INCREMENT;column:cafeteriaRating;type:int;not null;" json:"canteenrating"` Points int32 `gorm:"column:points;type:int;not null;" json:"points"` Comment string `gorm:"column:comment;type:text;" json:"comment" ` @@ -13,8 +13,3 @@ type CafeteriaRating struct { Timestamp time.Time `gorm:"column:timestamp;type:timestamp;not null;default:current_timestamp();OnUpdate:current_timestamp();" json:"timestamp" ` Image string `gorm:"column:image;type:text;" json:"image"` } - -// TableName sets the insert table name for this struct type -func (n *CafeteriaRating) TableName() string { - return "cafeteria_rating" -} diff --git a/server/model/cafeteria_rating_statistic.go b/server/model/canteen_rating_statistic.go similarity index 100% rename from server/model/cafeteria_rating_statistic.go rename to server/model/canteen_rating_statistic.go diff --git a/server/model/cafeteria_rating_tag.go b/server/model/canteen_rating_tag.go similarity index 52% rename from server/model/cafeteria_rating_tag.go rename to server/model/canteen_rating_tag.go index 15e964b6..225fe195 100644 --- a/server/model/cafeteria_rating_tag.go +++ b/server/model/canteen_rating_tag.go @@ -1,14 +1,9 @@ package model -// CafeteriaRatingTag struct is a row record of the either the dish_tag_rating-table or the cafeteria_rating_tags-table in the database -type CafeteriaRatingTag struct { - CafeteriaRatingTag int64 `gorm:"primary_key;AUTO_INCREMENT;column:CafeteriaRatingTag;type:int;not null;" json:"CanteenRatingTag" ` +// CanteenRatingTag struct is a row record of the either the dish_tag_ratings-table or the cafeteria_rating_tags-table in the database +type CanteenRatingTag struct { + CafeteriaRatingTag int64 `gorm:"primary_key;AUTO_INCREMENT;column:CanteenRatingTag;type:int;not null;" json:"CanteenRatingTag" ` CorrespondingRating int64 `gorm:"foreignKey:cafeteriaRatingID;column:correspondingRating;type:int;not null;" json:"correspondingRating"` Points int32 `gorm:"column:points;type:int;not null;" json:"points"` TagID int64 `gorm:"foreignKey:cafeteriaRatingTagOption;column:tagID;type:int;not null;" json:"tagID"` } - -// TableName sets the insert table name for this struct type -func (n *CafeteriaRatingTag) TableName() string { - return "cafeteria_rating_tag" -} diff --git a/server/model/cafeteria_rating_tag_option.go b/server/model/canteen_rating_tag_option.go similarity index 53% rename from server/model/cafeteria_rating_tag_option.go rename to server/model/canteen_rating_tag_option.go index e4a9237d..52e97c59 100644 --- a/server/model/cafeteria_rating_tag_option.go +++ b/server/model/canteen_rating_tag_option.go @@ -1,13 +1,8 @@ package model -// CafeteriaRatingTagOption stores all available options for tags which can be used to quickly rate cafeterias -type CafeteriaRatingTagOption struct { +// CanteenRatingTagOption stores all available options for tags which can be used to quickly rate cafeterias +type CanteenRatingTagOption struct { CafeteriaRatingsTagOption int64 `gorm:"primary_key;AUTO_INCREMENT;column:cafeteriaRatingTagOption;type:int;not null;" json:"canteenRatingTagOption"` DE string `gorm:"column:DE;text;default:('de');not null;" json:"DE"` EN string `gorm:"column:EN;text;default:('en');not null;" json:"EN"` } - -// TableName sets the insert table name for this struct type -func (n *CafeteriaRatingTagOption) TableName() string { - return "cafeteria_rating_tag_option" -} diff --git a/server/model/cafeteria_rating_tag_statistic.go b/server/model/canteen_rating_tag_statistic.go similarity index 100% rename from server/model/cafeteria_rating_tag_statistic.go rename to server/model/canteen_rating_tag_statistic.go diff --git a/server/model/cafeteria_model_type.go b/server/model/cantteen_model_type.go similarity index 100% rename from server/model/cafeteria_model_type.go rename to server/model/cantteen_model_type.go diff --git a/server/model/crontab.go b/server/model/crontab.go index aa72a437..37d8cd4d 100644 --- a/server/model/crontab.go +++ b/server/model/crontab.go @@ -4,11 +4,6 @@ import ( "github.com/guregu/null" ) -// TableName overrides the table name used by Crontab to `crontab` (Would otherwise auto-migrate to crontabs) -func (Crontab) TableName() string { - return "crontab" -} - // Crontab struct is a row record of the crontab table in the tca database type Crontab struct { Cron int64 `gorm:"primary_key;AUTO_INCREMENT;column:cron;type:int;" json:"cron"` diff --git a/server/model/dish.go b/server/model/dish.go index 635c8f30..a89e39a7 100644 --- a/server/model/dish.go +++ b/server/model/dish.go @@ -21,5 +21,5 @@ type Dish struct { // TableName sets the insert table name for this struct type func (n *Dish) TableName() string { - return "dish" + return "dishes" } diff --git a/server/model/dish_name_tag.go b/server/model/dish_name_tag.go index 1dc52ab4..7e9d0b13 100644 --- a/server/model/dish_name_tag.go +++ b/server/model/dish_name_tag.go @@ -6,8 +6,3 @@ type DishNameTag struct { Points int32 `gorm:"column:points;type:int;not null;" json:"points"` TagNameID int64 `gorm:"foreignKey:tagRatingID;column:tagNameID;type:int;not null;" json:"tagnameID"` } - -// TableName sets the insert table name for this struct type -func (n *DishNameTag) TableName() string { - return "dish_name_tag" -} diff --git a/server/model/dish_name_tag_option.go b/server/model/dish_name_tag_option.go index 143eb8a4..ff1074e1 100644 --- a/server/model/dish_name_tag_option.go +++ b/server/model/dish_name_tag_option.go @@ -5,8 +5,3 @@ type DishNameTagOption struct { DE string `gorm:"column:DE;type:text;not null;" json:"DE"` EN string `gorm:"column:EN;type:text;not null;" json:"EN"` } - -// TableName sets the insert table name for this struct type -func (n *DishNameTagOption) TableName() string { - return "dish_name_tag_option" -} diff --git a/server/model/dish_rating.go b/server/model/dish_rating.go index df524bf4..f6878d49 100644 --- a/server/model/dish_rating.go +++ b/server/model/dish_rating.go @@ -13,8 +13,3 @@ type DishRating struct { Timestamp time.Time `gorm:"column:timestamp;type:timestamp;not null;default:current_timestamp();OnUpdate:current_timestamp();" json:"timestamp"` Image string `gorm:"column:image;type:text;" json:"image"` } - -// TableName sets the insert table name for this struct type -func (n *DishRating) TableName() string { - return "dish_rating" -} diff --git a/server/model/dish_rating_tag.go b/server/model/dish_rating_tag.go index de2bda74..e0240278 100644 --- a/server/model/dish_rating_tag.go +++ b/server/model/dish_rating_tag.go @@ -6,8 +6,3 @@ type DishRatingTag struct { Points int32 `gorm:"column:points;type:int;not null;" json:"points"` TagID int64 `gorm:"foreignKey:dishRatingTagOption;column:tagID;type:int;not null;" json:"tagID"` } - -// TableName sets the insert table name for this struct type -func (n *DishRatingTag) TableName() string { - return "dish_rating_tag" -} diff --git a/server/model/dish_rating_tag_option.go b/server/model/dish_rating_tag_option.go index 6309b801..e5cb6c21 100644 --- a/server/model/dish_rating_tag_option.go +++ b/server/model/dish_rating_tag_option.go @@ -6,8 +6,3 @@ type DishRatingTagOption struct { DE string `gorm:"column:DE;type:text;default:('de');not null;" json:"DE"` EN string `gorm:"column:EN;type:text;default:('en');not null;" json:"EN"` } - -// TableName sets the insert table name for this struct type -func (n *DishRatingTagOption) TableName() string { - return "dish_rating_tag_option" -} diff --git a/server/model/dish_to_dish_name_tag.go b/server/model/dish_to_dish_name_tag.go index 279ff1c5..079038d1 100644 --- a/server/model/dish_to_dish_name_tag.go +++ b/server/model/dish_to_dish_name_tag.go @@ -5,8 +5,3 @@ type DishToDishNameTag struct { DishID int64 `gorm:"column:dishID;foreignKey:dish;type:int;not null;" json:"dishID"` NameTagID int64 `gorm:"foreignKey:dishNameTagOption;column:nameTagID;type:int;not null;" json:"nameTagID"` } - -// TableName sets the insert table name for this struct type -func (n *DishToDishNameTag) TableName() string { - return "dish_to_dish_name_tag" -} diff --git a/server/model/dishes_of_the_week.go b/server/model/dishes_of_the_week.go index 219c306d..61d33d19 100644 --- a/server/model/dishes_of_the_week.go +++ b/server/model/dishes_of_the_week.go @@ -7,8 +7,3 @@ type DishesOfTheWeek struct { Day int32 `gorm:"column:day;type:int;not null;" json:"day"` DishID int64 `gorm:"column:dishID;foreignKey:dish;type:int;not null;" json:"dishID"` } - -// TableName sets the insert table name for this struct type -func (n *DishesOfTheWeek) TableName() string { - return "dishes_of_the_week" -} diff --git a/server/model/dish_name_tag_option_excluded.go b/server/model/excluded_dish_name_tag_option.go similarity index 65% rename from server/model/dish_name_tag_option_excluded.go rename to server/model/excluded_dish_name_tag_option.go index f957ed11..446c1bdb 100644 --- a/server/model/dish_name_tag_option_excluded.go +++ b/server/model/excluded_dish_name_tag_option.go @@ -1,12 +1,7 @@ package model -type DishNameTagOptionExcluded struct { +type ExcludedDishNameTagOption struct { DishNameTagOptionExcluded int64 `gorm:"primary_key;AUTO_INCREMENT;column:dishNameTagOptionExcluded;type:int;not null;" json:"dishNameTagOptionExcluded"` NameTagID int64 `gorm:"foreignKey:dishNameTagOption;column:nameTagID;type:int;not null;" json:"nameTagID"` Expression string `gorm:"column:expression;type:text;" json:"expression"` } - -// TableName sets the insert table name for this struct type -func (n *DishNameTagOptionExcluded) TableName() string { - return "dish_name_tag_option_excluded" -} diff --git a/server/model/dish_name_tag_option_included.go b/server/model/included_dish_name_tag_option.go similarity index 65% rename from server/model/dish_name_tag_option_included.go rename to server/model/included_dish_name_tag_option.go index ddd7683d..5a44828b 100644 --- a/server/model/dish_name_tag_option_included.go +++ b/server/model/included_dish_name_tag_option.go @@ -1,12 +1,7 @@ package model -type DishNameTagOptionIncluded struct { +type IncludedDishNameTagOption struct { DishNameTagOptionIncluded int64 `gorm:"primary_key;AUTO_INCREMENT;column:dishNameTagOptionIncluded;type:int;not null;" json:"dishNameTagOptionIncluded"` NameTagID int64 `gorm:"foreignKey:dishNameTagOption;column:nameTagID;type:int;not null;" json:"nameTagID"` Expression string `gorm:"column:expression;type:text;" json:"expression"` } - -// TableName sets the insert table name for this struct type -func (n *DishNameTagOptionIncluded) TableName() string { - return "dish_name_tag_option_included" -} diff --git a/server/model/kino.go b/server/model/movie.go similarity index 87% rename from server/model/kino.go rename to server/model/movie.go index ec45063e..565750d2 100644 --- a/server/model/kino.go +++ b/server/model/movie.go @@ -6,8 +6,8 @@ import ( "github.com/guregu/null" ) -// Kino stores all movies -type Kino struct { +// Movie stores all movies +type Movie struct { Id int64 `gorm:"primary_key;AUTO_INCREMENT;column:kino;type:int;not null;"` Date time.Time `gorm:"column:date;type:datetime;not null;"` Created time.Time `gorm:"column:created;type:timestamp;not null;default:current_timestamp()"` @@ -25,8 +25,3 @@ type Kino struct { Link string `gorm:"column:link;type:varchar(190);not null;uniqueIndex:uni_kino_link"` Location null.String `gorm:"column:location;default:null"` } - -// TableName sets the insert table name for this struct type -func (n *Kino) TableName() string { - return "kino" -} diff --git a/server/model/news.go b/server/model/news.go index 3278256a..e837dccb 100755 --- a/server/model/news.go +++ b/server/model/news.go @@ -27,8 +27,3 @@ type News struct { FileID null.Int `gorm:"column:file;type:int;"` File *File `gorm:"foreignKey:FileID;references:file;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"` } - -// TableName sets the insert table name for this struct type -func (n *News) TableName() string { - return "news" -} diff --git a/server/model/news_alert.go b/server/model/news_alert.go index 3541e95c..5da26403 100644 --- a/server/model/news_alert.go +++ b/server/model/news_alert.go @@ -26,8 +26,3 @@ type NewsAlert struct { From time.Time `gorm:"column:from;type:datetime;default:current_timestamp();" json:"from"` To time.Time `gorm:"column:to;type:datetime;default:current_timestamp();" json:"to"` } - -// TableName sets the insert table name for this struct type -func (n *NewsAlert) TableName() string { - return "news_alert" -} diff --git a/server/model/news_source.go b/server/model/news_source.go index 62cc4ca2..e9da6ee3 100644 --- a/server/model/news_source.go +++ b/server/model/news_source.go @@ -15,7 +15,6 @@ var ( _ = uuid.UUID{} ) -// NewsSource struct is a row record of the newsSource table in the tca database type NewsSource struct { Source int64 `gorm:"primary_key;AUTO_INCREMENT;column:source;type:int;"` Title string `gorm:"column:title;type:text;size:16777215;"` @@ -24,8 +23,3 @@ type NewsSource struct { File File `gorm:"foreignKey:FileID;references:file;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"` Hook null.String `gorm:"column:hook;type:char;size:12;"` } - -// TableName sets the insert table name for this struct type -func (n *NewsSource) TableName() string { - return "newsSource" -} diff --git a/server/model/update_note.go b/server/model/update_note.go index ad83708f..8ce7bbc3 100755 --- a/server/model/update_note.go +++ b/server/model/update_note.go @@ -6,8 +6,3 @@ type UpdateNote struct { VersionName string `gorm:"column:version_name;type:text;"` Message string `gorm:"column:message;type:text;"` } - -// TableName sets the insert table name for this struct type -func (n *UpdateNote) TableName() string { - return "update_note" -}