From 7fef4c330937374968f15aec3de2723bac165f08 Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Fri, 22 Sep 2023 12:56:37 +0200 Subject: [PATCH 1/6] removed the roomfinder-cronjob stub --- client/go.mod | 2 +- client/go.sum | 4 ++-- server/backend/cron/cronjobs.go | 3 --- server/backend/cron/roomfinder.go | 7 ------- 4 files changed, 3 insertions(+), 13 deletions(-) delete mode 100644 server/backend/cron/roomfinder.go diff --git a/client/go.mod b/client/go.mod index b52b76d1..f6eea579 100644 --- a/client/go.mod +++ b/client/go.mod @@ -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-20230921201035-301a0c7bab98 + github.com/TUM-Dev/Campus-Backend/server v0.0.0-20230922013215-91e5d7e9f078 github.com/sirupsen/logrus v1.9.3 google.golang.org/grpc v1.58.1 ) diff --git a/client/go.sum b/client/go.sum index 5a226406..761db78e 100644 --- a/client/go.sum +++ b/client/go.sum @@ -1,5 +1,5 @@ -github.com/TUM-Dev/Campus-Backend/server v0.0.0-20230921201035-301a0c7bab98 h1:cifzCP3eUZgN+iqfhfGPTL1JFz4g/qjBNpwhcjlKOWk= -github.com/TUM-Dev/Campus-Backend/server v0.0.0-20230921201035-301a0c7bab98/go.mod h1:fjoLL3rbdY6wTRJIksekT2p3OUp5ocFfXjB/avV/TVI= +github.com/TUM-Dev/Campus-Backend/server v0.0.0-20230922013215-91e5d7e9f078 h1:c+OiShZ5m9FXg6bjjjFkVs3g3mxNjvUqegf5TKdZxLU= +github.com/TUM-Dev/Campus-Backend/server v0.0.0-20230922013215-91e5d7e9f078/go.mod h1:FIIdW5aglREN0ULXZXDQtvuBdbTMa/fCrKSTS8FYP7k= 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= diff --git a/server/backend/cron/cronjobs.go b/server/backend/cron/cronjobs.go index 663715e9..6925b2eb 100644 --- a/server/backend/cron/cronjobs.go +++ b/server/backend/cron/cronjobs.go @@ -34,7 +34,6 @@ const ( MovieType = "movie" /* MensaType = "mensa" - RoomfinderType = "roomfinder" AlarmType = "alarm" */ ) @@ -117,8 +116,6 @@ func (c *CronService) Run() error { g.Go(func() error { return c.mensaCron() }) case KinoType: g.Go(func() error { return c.kinoCron() }) - case RoomfinderType: - g.Go(func() error { return c.roomFinderCron() }) case AlarmType: g.Go(func() error { return c.alarmCron() }) */ diff --git a/server/backend/cron/roomfinder.go b/server/backend/cron/roomfinder.go deleted file mode 100644 index af68f7e4..00000000 --- a/server/backend/cron/roomfinder.go +++ /dev/null @@ -1,7 +0,0 @@ -package cron - -//lint:ignore U1000 stub -func (c *CronService) roomFinderCron() error { - // TODO: implement - return nil -} From a75a33f336e489ca6343f8fe605446b72acf9b59 Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Fri, 22 Sep 2023 13:02:19 +0200 Subject: [PATCH 2/6] renamed `Files` -> `File` to be consistent with other models --- server/backend/cron/fileDownload.go | 6 +- server/backend/cron/movies.go | 6 +- server/backend/cron/news.go | 12 ++-- server/backend/migration/20230904100000.go | 10 +-- server/backend/migration/migration.go | 2 +- server/backend/movie.go | 8 +-- server/backend/movie_test.go | 12 ++-- server/backend/news.go | 6 +- server/backend/newsAlerts.go | 4 +- server/backend/newsAlerts_test.go | 12 ++-- server/backend/news_test.go | 72 +++++++++++----------- server/model/files.go | 9 +-- server/model/kino.go | 4 +- server/model/news.go | 4 +- server/model/news_alert.go | 4 +- server/model/news_source.go | 12 ++-- 16 files changed, 89 insertions(+), 94 deletions(-) diff --git a/server/backend/cron/fileDownload.go b/server/backend/cron/fileDownload.go index 3e16f5a0..8b2706a0 100644 --- a/server/backend/cron/fileDownload.go +++ b/server/backend/cron/fileDownload.go @@ -18,7 +18,7 @@ import ( // fileDownloadCron downloads all files that are not marked as finished in the database func (c *CronService) fileDownloadCron() error { return c.db.Transaction(func(tx *gorm.DB) error { - var files []model.Files + var files []model.File err := tx.Find(&files, "downloaded = 0 AND url IS NOT NULL").Error if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { log.WithError(err).Error("Could not get files from database") @@ -30,7 +30,7 @@ func (c *CronService) fileDownloadCron() error { fields := log.Fields{"url": file.URL.String, "dstPath": dstPath} log.WithFields(fields).Info("downloading file") - if err = tx.Model(&model.Files{File: file.File}).Update("downloads", file.Downloads+1).Error; err != nil { + if err = tx.Model(&model.File{File: file.File}).Update("downloads", file.Downloads+1).Error; err != nil { log.WithError(err).WithFields(fields).Error("Could not set update the download-count") continue } @@ -48,7 +48,7 @@ func (c *CronService) fileDownloadCron() error { continue } // everything went well => we can mark the file as downloaded - if err = tx.Model(&model.Files{URL: file.URL}).Update("downloaded", true).Error; err != nil { + if err = tx.Model(&model.File{URL: file.URL}).Update("downloaded", true).Error; err != nil { log.WithError(err).WithFields(fields).Error("Could not set image to downloaded.") continue } diff --git a/server/backend/cron/movies.go b/server/backend/cron/movies.go index ebba1075..9c89ced7 100644 --- a/server/backend/cron/movies.go +++ b/server/backend/cron/movies.go @@ -78,7 +78,7 @@ func (c *CronService) movieCron() error { } // add a file to preview (downloaded in another cronjob) - file := model.Files{ + file := model.File{ Name: item.Title, Path: MovieImageDirectory, URL: null.StringFrom(item.Enclosure.Url), @@ -99,8 +99,8 @@ func (c *CronService) movieCron() error { Actors: omdbMovie.Actors, ImdbRating: omdbMovie.ImdbRating, Description: omdbMovie.Plot, // we get this from imdb as tu-fim does truncate their plot - FilesID: file.File, - Files: file, + FileID: file.File, + File: file, Link: item.Link, } if err := c.db.Create(&movie).Error; err != nil { diff --git a/server/backend/cron/news.go b/server/backend/cron/news.go index 43ed0f4b..640754e2 100644 --- a/server/backend/cron/news.go +++ b/server/backend/cron/news.go @@ -100,7 +100,7 @@ func (c *CronService) parseNewsFeed(source model.NewsSource) error { } } var enclosureUrl = null.StringFrom("") - var file *model.Files + var file *model.File if pickedEnclosure != nil { file, err = c.saveImage(pickedEnclosure.URL) if err != nil { @@ -119,8 +119,8 @@ func (c *CronService) parseNewsFeed(source model.NewsSource) error { Src: source.Source, Link: item.Link, Image: enclosureUrl, - FilesID: null.IntFrom(file.File), - Files: file, + FileID: null.IntFrom(file.File), + File: file, } newNews = append(newNews, newsItem) } @@ -138,9 +138,9 @@ func (c *CronService) parseNewsFeed(source model.NewsSource) error { } // saveImage saves an image to the database, so it can be downloaded by another cronjob and returns its id -func (c *CronService) saveImage(url string) (*model.Files, error) { +func (c *CronService) saveImage(url string) (*model.File, error) { targetFileName := fmt.Sprintf("%x.jpg", md5.Sum([]byte(url))) - file := model.Files{ + file := model.File{ Name: targetFileName, // path intentionally omitted } if err := c.db.First(&file).Error; err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { @@ -151,7 +151,7 @@ func (c *CronService) saveImage(url string) (*model.Files, error) { } // does not exist, store in database - file = model.Files{ + file = model.File{ Name: targetFileName, Path: NewsImageDirectory, URL: null.StringFrom(url), diff --git a/server/backend/migration/20230904100000.go b/server/backend/migration/20230904100000.go index e439ddfb..0af99f79 100644 --- a/server/backend/migration/20230904100000.go +++ b/server/backend/migration/20230904100000.go @@ -45,11 +45,11 @@ func (m TumDBMigrator) migrate20230904100000() *gormigrate.Migration { return err } if err := tx.Create(&model.NewsSource{ - Source: 2, - Title: "TU Film", - URL: null.StringFrom("http://www.tu-film.de/programm/index/upcoming.rss"), - FilesID: 2, - Hook: null.String{}, + Source: 2, + Title: "TU Film", + URL: null.StringFrom("http://www.tu-film.de/programm/index/upcoming.rss"), + FileID: 2, + Hook: null.String{}, }).Error; err != nil { return err } diff --git a/server/backend/migration/migration.go b/server/backend/migration/migration.go index 2b34e95f..b5dcbcf5 100644 --- a/server/backend/migration/migration.go +++ b/server/backend/migration/migration.go @@ -26,7 +26,7 @@ func (m TumDBMigrator) Migrate() error { err := m.database.AutoMigrate( &model.TopNews{}, &model.Crontab{}, - &model.Files{}, + &model.File{}, &model.NewsSource{}, &model.NewsAlert{}, &model.News{}, diff --git a/server/backend/movie.go b/server/backend/movie.go index 71be0023..ff5b177e 100644 --- a/server/backend/movie.go +++ b/server/backend/movie.go @@ -13,7 +13,7 @@ import ( func (s *CampusServer) GetMovies(ctx context.Context, req *pb.GetMoviesRequest) (*pb.GetMoviesReply, error) { var movies []model.Kino - if err := s.db.WithContext(ctx).Joins("Files").Find(&movies, "kino > ?", req.LastId).Error; err != nil { + if err := s.db.WithContext(ctx).Joins("File").Find(&movies, "kino > ?", req.LastId).Error; err != nil { log.WithError(err).Error("Error while fetching movies from database") return nil, status.Error(codes.Internal, "Error while fetching movies from database") } @@ -31,9 +31,9 @@ func (s *CampusServer) GetMovies(ctx context.Context, req *pb.GetMoviesRequest) Actors: movie.Actors, ImdbRating: movie.ImdbRating, Description: movie.Description, - CoverName: movie.Files.Name, - CoverPath: movie.Files.Path, - CoverId: movie.Files.File, + CoverName: movie.File.Name, + CoverPath: movie.File.Path, + CoverId: movie.File.File, Link: movie.Link, }) } diff --git a/server/backend/movie_test.go b/server/backend/movie_test.go index 0cab874e..0c2dd31d 100644 --- a/server/backend/movie_test.go +++ b/server/backend/movie_test.go @@ -79,9 +79,9 @@ var ( func (s *MovieSuite) Test_GetMoviesAll() { server := CampusServer{db: s.DB} - s.mock.ExpectQuery("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`,`Files`.`file` AS `Files__file`,`Files`.`name` AS `Files__name`,`Files`.`path` AS `Files__path`,`Files`.`downloads` AS `Files__downloads`,`Files`.`url` AS `Files__url`,`Files`.`downloaded` AS `Files__downloaded` FROM `kino` LEFT JOIN `files` `Files` ON `kino`.`cover` = `Files`.`file` WHERE kino > ?"). + s.mock.ExpectQuery("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`,`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 > ?"). WithArgs(-1). - WillReturnRows(sqlmock.NewRows([]string{"kino", "date", "created", "title", "year", "runtime", "genre", "director", "actors", "rating", "description", "trailer", "cover", "link", "Files__file", "Files__name", "Files__path", "Files__downloads", "Files__url", "Files__downloaded"}). + WillReturnRows(sqlmock.NewRows([]string{"kino", "date", "created", "title", "year", "runtime", "genre", "director", "actors", "rating", "description", "trailer", "cover", "link", "File__file", "File__name", "File__path", "File__downloads", "File__url", "File__downloaded"}). AddRow(movie2.MovieId, movie2.Date.AsTime(), movie2.Created.AsTime(), movie2.Title, movie2.ReleaseYear, movie2.Runtime, movie2.Genre, movie2.Director, movie2.Actors, movie2.ImdbRating, movie2.Description, nil, movie2.CoverId, movie2.Link, movie2.CoverId, movie2.CoverName, movie2.CoverPath, 1, "", 1). AddRow(movie1.MovieId, movie1.Date.AsTime(), movie1.Created.AsTime(), movie1.Title, movie1.ReleaseYear, movie1.Runtime, movie1.Genre, movie1.Director, movie1.Actors, movie1.ImdbRating, movie1.Description, nil, movie1.CoverId, movie1.Link, movie1.CoverId, movie1.CoverName, movie1.CoverPath, 1, "", 1)) response, err := server.GetMovies(context.Background(), &pb.GetMoviesRequest{LastId: -1}) @@ -91,9 +91,9 @@ func (s *MovieSuite) Test_GetMoviesAll() { func (s *MovieSuite) Test_GetMoviesOne() { server := CampusServer{db: s.DB} - s.mock.ExpectQuery("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`,`Files`.`file` AS `Files__file`,`Files`.`name` AS `Files__name`,`Files`.`path` AS `Files__path`,`Files`.`downloads` AS `Files__downloads`,`Files`.`url` AS `Files__url`,`Files`.`downloaded` AS `Files__downloaded` FROM `kino` LEFT JOIN `files` `Files` ON `kino`.`cover` = `Files`.`file` WHERE kino > ?"). + s.mock.ExpectQuery("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`,`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 > ?"). WithArgs(1). - WillReturnRows(sqlmock.NewRows([]string{"kino", "date", "created", "title", "year", "runtime", "genre", "director", "actors", "rating", "description", "trailer", "cover", "link", "Files__file", "Files__name", "Files__path", "Files__downloads", "Files__url", "Files__downloaded"}). + WillReturnRows(sqlmock.NewRows([]string{"kino", "date", "created", "title", "year", "runtime", "genre", "director", "actors", "rating", "description", "trailer", "cover", "link", "File__file", "File__name", "File__path", "File__downloads", "File__url", "File__downloaded"}). AddRow(movie1.MovieId, movie1.Date.AsTime(), movie1.Created.AsTime(), movie1.Title, movie1.ReleaseYear, movie1.Runtime, movie1.Genre, movie1.Director, movie1.Actors, movie1.ImdbRating, movie1.Description, nil, movie1.CoverId, movie1.Link, movie1.CoverId, movie1.CoverName, movie1.CoverPath, 1, "", 1)) response, err := server.GetMovies(context.Background(), &pb.GetMoviesRequest{LastId: 1}) require.NoError(s.T(), err) @@ -102,9 +102,9 @@ func (s *MovieSuite) Test_GetMoviesOne() { func (s *MovieSuite) Test_GetMoviesNone() { server := CampusServer{db: s.DB} - s.mock.ExpectQuery("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`,`Files`.`file` AS `Files__file`,`Files`.`name` AS `Files__name`,`Files`.`path` AS `Files__path`,`Files`.`downloads` AS `Files__downloads`,`Files`.`url` AS `Files__url`,`Files`.`downloaded` AS `Files__downloaded` FROM `kino` LEFT JOIN `files` `Files` ON `kino`.`cover` = `Files`.`file` WHERE kino > ?"). + s.mock.ExpectQuery("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`,`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 > ?"). WithArgs(42). - WillReturnRows(sqlmock.NewRows([]string{"kino", "date", "created", "title", "year", "runtime", "genre", "director", "actors", "rating", "description", "trailer", "cover", "link", "Files__file", "Files__name", "Files__path", "Files__downloads", "Files__url", "Files__downloaded"})) + WillReturnRows(sqlmock.NewRows([]string{"kino", "date", "created", "title", "year", "runtime", "genre", "director", "actors", "rating", "description", "trailer", "cover", "link", "File__file", "File__name", "File__path", "File__downloads", "File__url", "File__downloaded"})) response, err := server.GetMovies(context.Background(), &pb.GetMoviesRequest{LastId: 42}) require.NoError(s.T(), err) require.Equal(s.T(), &pb.GetMoviesReply{Movies: []*pb.Movie(nil)}, response) diff --git a/server/backend/news.go b/server/backend/news.go index f2e3a58a..23acd183 100644 --- a/server/backend/news.go +++ b/server/backend/news.go @@ -19,7 +19,7 @@ func (s *CampusServer) GetNewsSources(ctx context.Context, _ *pb.GetNewsSourcesR } var sources []model.NewsSource - if err := s.db.WithContext(ctx).Joins("Files").Find(&sources).Error; err != nil { + if err := s.db.WithContext(ctx).Joins("File").Find(&sources).Error; err != nil { log.WithError(err).Error("could not find newsSources") return nil, status.Error(codes.Internal, "could not GetNewsSources") } @@ -30,7 +30,7 @@ func (s *CampusServer) GetNewsSources(ctx context.Context, _ *pb.GetNewsSourcesR resp = append(resp, &pb.NewsSource{ Source: fmt.Sprintf("%d", source.Source), Title: source.Title, - Icon: source.Files.URL.String, + Icon: source.File.URL.String, }) } return &pb.GetNewsSourcesReply{Sources: resp}, nil @@ -42,7 +42,7 @@ func (s *CampusServer) GetNews(ctx context.Context, req *pb.GetNewsRequest) (*pb } var newsEntries []model.News - tx := s.db.WithContext(ctx).Joins("Files") + tx := s.db.WithContext(ctx).Joins("File") if req.NewsSource != 0 { tx = tx.Where("src = ?", req.NewsSource) } diff --git a/server/backend/newsAlerts.go b/server/backend/newsAlerts.go index 6189b256..2501ab21 100644 --- a/server/backend/newsAlerts.go +++ b/server/backend/newsAlerts.go @@ -19,7 +19,7 @@ func (s *CampusServer) GetTopNews(ctx context.Context, _ *pb.GetTopNewsRequest) } var res *model.NewsAlert - err := s.db.WithContext(ctx).Joins("Files").Where("NOW() between `from` and `to`").First(&res).Error + err := s.db.WithContext(ctx).Joins("File").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 { @@ -28,7 +28,7 @@ func (s *CampusServer) GetTopNews(ctx context.Context, _ *pb.GetTopNewsRequest) } return &pb.GetTopNewsReply{ - ImageUrl: res.Files.URL.String, + ImageUrl: res.File.URL.String, Link: res.Link.String, Created: timestamppb.New(res.Created), From: timestamppb.New(res.From), diff --git a/server/backend/newsAlerts_test.go b/server/backend/newsAlerts_test.go index ffbb0579..36e24196 100644 --- a/server/backend/newsAlerts_test.go +++ b/server/backend/newsAlerts_test.go @@ -49,13 +49,13 @@ func (s *NewsAlertSuite) SetupSuite() { s.deviceBuf = newDeviceBuffer() } -const ExpectedGetTopNewsQuery = "SELECT `news_alert`.`news_alert`,`news_alert`.`file`,`news_alert`.`name`,`news_alert`.`link`,`news_alert`.`created`,`news_alert`.`from`,`news_alert`.`to`,`Files`.`file` AS `Files__file`,`Files`.`name` AS `Files__name`,`Files`.`path` AS `Files__path`,`Files`.`downloads` AS `Files__downloads`,`Files`.`url` AS `Files__url`,`Files`.`downloaded` AS `Files__downloaded` FROM `news_alert` LEFT JOIN `files` `Files` ON `news_alert`.`file` = `Files`.`file` WHERE NOW() between `from` and `to` ORDER BY `news_alert`.`news_alert` LIMIT 1" +const ExpectedGetTopNewsQuery = "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 NOW() between `from` and `to` ORDER BY `news_alert`.`news_alert` LIMIT 1" func (s *NewsAlertSuite) Test_GetTopNewsOne() { expectedAlert := model.NewsAlert{ NewsAlert: 1, - FilesID: 3001, - Files: model.Files{ + FileID: 3001, + File: model.File{ File: 3001, Name: "Tournament_app_02-02.png", Path: "newsalerts/", @@ -70,15 +70,15 @@ func (s *NewsAlertSuite) Test_GetTopNewsOne() { To: time.Time.Add(time.Now(), time.Hour*2), } s.mock.ExpectQuery(regexp.QuoteMeta(ExpectedGetTopNewsQuery)). - WillReturnRows(sqlmock.NewRows([]string{"news_alert", "file", "name", "link", "created", "from", "to", "Files__file", "Files__name", "Files__path", "Files__downloads", "Files__url", "Files__downloaded"}). - AddRow(expectedAlert.NewsAlert, expectedAlert.FilesID, expectedAlert.Name, expectedAlert.Link, expectedAlert.Created, expectedAlert.From, expectedAlert.To, expectedAlert.Files.File, expectedAlert.Files.Name, expectedAlert.Files.Path, expectedAlert.Files.Downloads, expectedAlert.Files.URL, expectedAlert.Files.Downloaded)) + WillReturnRows(sqlmock.NewRows([]string{"news_alert", "file", "name", "link", "created", "from", "to", "File__file", "File__name", "File__path", "File__downloads", "File__url", "File__downloaded"}). + AddRow(expectedAlert.NewsAlert, expectedAlert.FileID, expectedAlert.Name, expectedAlert.Link, expectedAlert.Created, expectedAlert.From, expectedAlert.To, expectedAlert.File.File, expectedAlert.File.Name, expectedAlert.File.Path, expectedAlert.File.Downloads, expectedAlert.File.URL, expectedAlert.File.Downloaded)) meta := metadata.MD{} server := CampusServer{db: s.DB, deviceBuf: s.deviceBuf} response, err := server.GetTopNews(metadata.NewIncomingContext(context.Background(), meta), nil) require.NoError(s.T(), err) require.Equal(s.T(), &pb.GetTopNewsReply{ - ImageUrl: expectedAlert.Files.URL.String, + ImageUrl: expectedAlert.File.URL.String, Link: expectedAlert.Link.String, Created: timestamppb.New(expectedAlert.Created), From: timestamppb.New(expectedAlert.From), diff --git a/server/backend/news_test.go b/server/backend/news_test.go index 2bbafbf6..37ef4be3 100644 --- a/server/backend/news_test.go +++ b/server/backend/news_test.go @@ -48,8 +48,8 @@ func (s *NewsSuite) SetupSuite() { s.deviceBuf = newDeviceBuffer() } -func file(id int64) *model.Files { - return &model.Files{ +func file(id int64) *model.File { + return &model.File{ File: id, Name: fmt.Sprintf("src_%d.png", id), Path: "news/sources", @@ -61,33 +61,33 @@ func file(id int64) *model.Files { func source1() *model.NewsSource { return &model.NewsSource{ - Source: 1, - Title: "Amazing News 1", - URL: null.StringFrom("https://example.com/amazing1"), - FilesID: file(2).File, - Files: *file(2), - Hook: null.StringFrom(""), + Source: 1, + Title: "Amazing News 1", + URL: null.StringFrom("https://example.com/amazing1"), + FileID: file(2).File, + File: *file(2), + Hook: null.StringFrom(""), } } func source2() *model.NewsSource { return &model.NewsSource{ - Source: 2, - Title: "Amazing News 2", - URL: null.StringFrom("https://example.com/amazing2"), - FilesID: file(2).File, - Files: *file(2), - Hook: null.StringFrom("hook"), + Source: 2, + Title: "Amazing News 2", + URL: null.StringFrom("https://example.com/amazing2"), + FileID: file(2).File, + File: *file(2), + Hook: null.StringFrom("hook"), } } -const ExpectedGetSourceQuery = "SELECT `newsSource`.`source`,`newsSource`.`title`,`newsSource`.`url`,`newsSource`.`icon`,`newsSource`.`hook`,`Files`.`file` AS `Files__file`,`Files`.`name` AS `Files__name`,`Files`.`path` AS `Files__path`,`Files`.`downloads` AS `Files__downloads`,`Files`.`url` AS `Files__url`,`Files`.`downloaded` AS `Files__downloaded` FROM `newsSource` LEFT JOIN `files` `Files` ON `newsSource`.`icon` = `Files`.`file`" +const ExpectedGetSourceQuery = "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`" func (s *NewsSuite) Test_GetNewsSourcesMultiple() { s.mock.ExpectQuery(regexp.QuoteMeta(ExpectedGetSourceQuery)). - WillReturnRows(sqlmock.NewRows([]string{"source", "title", "url", "icon", "hook", "Files__file", "Files__name", "Files__path", "Files__downloads", "Files__url", "Files__downloaded"}). - AddRow(source1().Source, source1().Title, source1().URL, source1().FilesID, source1().Hook, source1().Files.File, source1().Files.Name, source1().Files.Path, source1().Files.Downloads, source1().Files.URL, source1().Files.Downloaded). - AddRow(source2().Source, source2().Title, source2().URL, source2().FilesID, source2().Hook, source2().Files.File, source2().Files.Name, source2().Files.Path, source2().Files.Downloads, source2().Files.URL, source2().Files.Downloaded)) + WillReturnRows(sqlmock.NewRows([]string{"source", "title", "url", "icon", "hook", "File__file", "File__name", "File__path", "File__downloads", "File__url", "File__downloaded"}). + AddRow(source1().Source, source1().Title, source1().URL, source1().FileID, source1().Hook, source1().File.File, source1().File.Name, source1().File.Path, source1().File.Downloads, source1().File.URL, source1().File.Downloaded). + AddRow(source2().Source, source2().Title, source2().URL, source2().FileID, source2().Hook, source2().File.File, source2().File.Name, source2().File.Path, source2().File.Downloads, source2().File.URL, source2().File.Downloaded)) meta := metadata.MD{} server := CampusServer{db: s.DB, deviceBuf: s.deviceBuf} @@ -95,8 +95,8 @@ func (s *NewsSuite) Test_GetNewsSourcesMultiple() { require.NoError(s.T(), err) expectedResp := &pb.GetNewsSourcesReply{ Sources: []*pb.NewsSource{ - {Source: fmt.Sprintf("%d", source1().Source), Title: source1().Title, Icon: source1().Files.URL.String}, - {Source: fmt.Sprintf("%d", source2().Source), Title: source2().Title, Icon: source2().Files.URL.String}, + {Source: fmt.Sprintf("%d", source1().Source), Title: source1().Title, Icon: source1().File.URL.String}, + {Source: fmt.Sprintf("%d", source2().Source), Title: source2().Title, Icon: source2().File.URL.String}, }, } require.Equal(s.T(), expectedResp, response) @@ -104,27 +104,27 @@ func (s *NewsSuite) Test_GetNewsSourcesMultiple() { func news1() *model.News { return &model.News{ - News: 1, - Title: "Amazing News 1", - Link: "https://example.com/amazing2", - FilesID: null.IntFrom(file(1).File), - Files: file(1), + News: 1, + Title: "Amazing News 1", + Link: "https://example.com/amazing2", + FileID: null.IntFrom(file(1).File), + File: file(1), } } func news2() *model.News { return &model.News{ - News: 2, - Title: "Amazing News 2", - Link: "https://example.com/amazing2", - FilesID: null.Int{}, - Files: nil, + News: 2, + Title: "Amazing News 2", + Link: "https://example.com/amazing2", + FileID: null.Int{}, + File: nil, } } func (s *NewsSuite) Test_GetNewsSourcesNone() { s.mock.ExpectQuery(regexp.QuoteMeta(ExpectedGetSourceQuery)). - WillReturnRows(sqlmock.NewRows([]string{"source", "title", "url", "icon", "hook", "Files__file", "Files__name", "Files__path", "Files__downloads", "Files__url", "Files__downloaded"})) + WillReturnRows(sqlmock.NewRows([]string{"source", "title", "url", "icon", "hook", "File__file", "File__name", "File__path", "File__downloads", "File__url", "File__downloaded"})) meta := metadata.MD{} server := CampusServer{db: s.DB, deviceBuf: s.deviceBuf} @@ -136,12 +136,12 @@ func (s *NewsSuite) Test_GetNewsSourcesNone() { require.Equal(s.T(), expectedResp, response) } -const ExpectedGetNewsQuery = "SELECT `news`.`news`,`news`.`date`,`news`.`created`,`news`.`title`,`news`.`description`,`news`.`src`,`news`.`link`,`news`.`image`,`news`.`file`,`Files`.`file` AS `Files__file`,`Files`.`name` AS `Files__name`,`Files`.`path` AS `Files__path`,`Files`.`downloads` AS `Files__downloads`,`Files`.`url` AS `Files__url`,`Files`.`downloaded` AS `Files__downloaded` FROM `news` LEFT JOIN `files` `Files` ON `news`.`file` = `Files`.`file`" +const ExpectedGetNewsQuery = "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` FROM `news` LEFT JOIN `files` `File` ON `news`.`file` = `File`.`file`" func (s *NewsSuite) Test_GetNewsNone_withFilters() { s.mock.ExpectQuery(regexp.QuoteMeta(ExpectedGetNewsQuery+" WHERE src = ? AND news > ?")). WithArgs(1, 2). - WillReturnRows(sqlmock.NewRows([]string{"news", "date", "created", "title", "description", "src", "link", "image", "file", "Files__file", "Files__name", "Files__path", "Files__downloads", "Files__url", "Files__downloaded"})) + WillReturnRows(sqlmock.NewRows([]string{"news", "date", "created", "title", "description", "src", "link", "image", "file", "File__file", "File__name", "File__path", "File__downloads", "File__url", "File__downloaded"})) meta := metadata.NewIncomingContext(context.Background(), metadata.MD{}) server := CampusServer{db: s.DB, deviceBuf: s.deviceBuf} @@ -154,7 +154,7 @@ func (s *NewsSuite) Test_GetNewsNone_withFilters() { } func (s *NewsSuite) Test_GetNewsNone() { s.mock.ExpectQuery(regexp.QuoteMeta(ExpectedGetNewsQuery)). - WillReturnRows(sqlmock.NewRows([]string{"news", "date", "created", "title", "description", "src", "link", "image", "file", "Files__file", "Files__name", "Files__path", "Files__downloads", "Files__url", "Files__downloaded"})) + WillReturnRows(sqlmock.NewRows([]string{"news", "date", "created", "title", "description", "src", "link", "image", "file", "File__file", "File__name", "File__path", "File__downloads", "File__url", "File__downloaded"})) meta := metadata.NewIncomingContext(context.Background(), metadata.MD{}) server := CampusServer{db: s.DB, deviceBuf: s.deviceBuf} @@ -169,8 +169,8 @@ func (s *NewsSuite) Test_GetNewsMultiple() { n1 := news1() n2 := news2() s.mock.ExpectQuery(regexp.QuoteMeta(" ")). - WillReturnRows(sqlmock.NewRows([]string{"news", "date", "created", "title", "description", "src", "link", "image", "file", "Files__file", "Files__name", "Files__path", "Files__downloads", "Files__url", "Files__downloaded"}). - AddRow(n1.News, n1.Date, n1.Created, n1.Title, n1.Description, n1.Src, n1.Link, n1.Image, n1.FilesID, n1.Files.File, n1.Files.Name, n1.Files.Path, n1.Files.Downloads, n1.Files.URL, n1.Files.Downloaded). + WillReturnRows(sqlmock.NewRows([]string{"news", "date", "created", "title", "description", "src", "link", "image", "file", "File__file", "File__name", "File__path", "File__downloads", "File__url", "File__downloaded"}). + AddRow(n1.News, n1.Date, n1.Created, n1.Title, n1.Description, n1.Src, n1.Link, n1.Image, n1.FileID, n1.File.File, n1.File.Name, n1.File.Path, n1.File.Downloads, n1.File.URL, n1.File.Downloaded). AddRow(n2.News, n2.Date, n2.Created, n2.Title, n2.Description, n2.Src, n2.Link, n2.Image, nil, nil, nil, nil, nil, nil, nil)) meta := metadata.NewIncomingContext(context.Background(), metadata.MD{}) diff --git a/server/model/files.go b/server/model/files.go index 430bb247..f9d27ddd 100644 --- a/server/model/files.go +++ b/server/model/files.go @@ -15,8 +15,8 @@ var ( _ = uuid.UUID{} ) -// Files struct is a row record of the files table in the tca database -type Files struct { +// File struct is a row record of the files table in the tca database +type File struct { File int64 `gorm:"primary_key;AUTO_INCREMENT;column:file;type:int;" json:"file"` Name string `gorm:"column:name;type:text;size:16777215;" json:"name"` Path string `gorm:"column:path;type:text;size:16777215;" json:"path"` @@ -24,8 +24,3 @@ type Files struct { URL null.String `gorm:"column:url;default:null;" json:"url"` // URL of the files source (if any) Downloaded null.Bool `gorm:"column:downloaded;type:boolean;default:1;" json:"downloaded"` // true when file is ready to be served, false when still being downloaded } - -// TableName sets the insert table name for this struct type -func (f *Files) TableName() string { - return "files" -} diff --git a/server/model/kino.go b/server/model/kino.go index a4b6f645..f8eec7a0 100644 --- a/server/model/kino.go +++ b/server/model/kino.go @@ -20,8 +20,8 @@ type Kino struct { ImdbRating string `gorm:"column:rating;type:varchar(4);not null;"` Description string `gorm:"column:description;type:text;not null;"` Trailer null.String `gorm:"column:trailer"` - FilesID int64 `gorm:"column:cover"` - Files Files `gorm:"foreignKey:FilesID;references:file"` + FileID int64 `gorm:"column:cover"` + File File `gorm:"foreignKey:FileID;references:file"` Link string `gorm:"column:link;type:varchar(190);not null;unique;"` } diff --git a/server/model/news.go b/server/model/news.go index 4cabb46c..4fa2158f 100755 --- a/server/model/news.go +++ b/server/model/news.go @@ -23,8 +23,8 @@ type News struct { Src int64 `gorm:"column:src;type:int;"` Link string `gorm:"column:link;type:varchar(190);"` Image null.String `gorm:"column:image;type:text;size:65535;"` - FilesID null.Int `gorm:"column:file;type:int;"` - Files *Files `gorm:"foreignKey:FilesID;references:file;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"` + 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 diff --git a/server/model/news_alert.go b/server/model/news_alert.go index 55a2a65f..076c1ae1 100644 --- a/server/model/news_alert.go +++ b/server/model/news_alert.go @@ -18,8 +18,8 @@ var ( // NewsAlert struct is a row record of the news_alert table in the tca database type NewsAlert struct { NewsAlert int64 `gorm:"primary_key;AUTO_INCREMENT;column:news_alert;type:int;" json:"news_alert"` - FilesID int64 `gorm:"column:file;not null"` - Files Files `gorm:"foreignKey:FilesID;references:file;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"` + FileID int64 `gorm:"column:file;not null"` + File File `gorm:"foreignKey:FileID;references:file;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"` Name null.String `gorm:"column:name;type:varchar(100);" json:"name"` Link null.String `gorm:"column:link;type:text;size:65535;" json:"link"` Created time.Time `gorm:"column:created;type:timestamp;default:CURRENT_TIMESTAMP;" json:"created"` diff --git a/server/model/news_source.go b/server/model/news_source.go index 94d06a2b..79d05e0e 100644 --- a/server/model/news_source.go +++ b/server/model/news_source.go @@ -17,12 +17,12 @@ var ( // 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;"` - URL null.String `gorm:"column:url;type:text;size:16777215;"` - FilesID int64 `gorm:"column:icon;not null"` - Files Files `gorm:"foreignKey:FilesID;references:file;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"` - Hook null.String `gorm:"column:hook;type:char;size:12;"` + Source int64 `gorm:"primary_key;AUTO_INCREMENT;column:source;type:int;"` + Title string `gorm:"column:title;type:text;size:16777215;"` + URL null.String `gorm:"column:url;type:text;size:16777215;"` + FileID int64 `gorm:"column:icon;not null"` + 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 From 5fea25488c85feeeb71e001133f69292c08ec7ea Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Fri, 22 Sep 2023 13:32:59 +0200 Subject: [PATCH 3/6] introduced a file-name linter and renamed all files accoridngly --- .github/workflows/lint.yml | 3 +++ .ls-lint.yaml | 6 ++++++ ...gDBInitializer.go => cafeteria_rating_db_initializer.go} | 0 .../backend/{cafeteriaService.go => cafeteria_service.go} | 0 server/backend/campus_api/{campusApi.go => campus_api.go} | 0 .../backend/{canteenHeadCount.go => canteen_head_count.go} | 0 ...geRatingComputation.go => average_rating_computation.go} | 0 .../cron/{canteenHeadCount.go => canteen_head_count.go} | 0 .../cron/{dishNameDownload.go => dish_name_download.go} | 0 server/backend/cron/{fileDownload.go => file_download.go} | 0 .../cron/{fileDownload_test.go => file_download_test.go} | 0 .../cron/{iosNotifications.go => ios_notifications.go} | 0 server/backend/cron/{movie_test.go => movies_test.go} | 0 .../{newExamResultsHook.go => new_exam_results_hook.go} | 0 .../backend/{iosNotifications.go => ios_notifications.go} | 0 .../ios_apns_jwt/{iosAPNsToken.go => ios_apns_token.go} | 0 .../{iosAPNsRepository.go => ios_apns_repository.go} | 0 .../ios_apns/{iosAPNsService.go => ios_apns_service.go} | 0 .../ios_crypto/{encryptedString.go => encrypted_string.go} | 0 .../{iosDeviceRepository.go => ios_device_repository.go} | 0 .../{iosDeviceService.go => ios_device_service.go} | 0 ...pository.go => ios_devices_activity_reset_repository.go} | 0 ...esetService.go => ios_devices_activity_reset_service.go} | 0 ...onseRepository.go => ios_request_response_repository.go} | 0 ...stResponseService.go => ios_request_response_service.go} | 0 ...Repository.go => ios_scheduled_update_log_repository.go} | 0 ...SchedulingRepository.go => ios_scheduling_repository.go} | 0 .../{iosSchedulingService.go => ios_scheduling_service.go} | 0 .../migration/{safeEnumMigrate.go => safe_enum_migrate.go} | 0 .../{safeEnumMigrate_test.go => safe_enum_migrate_test.go} | 0 ...ository.go => new_exam_results_scheduling_repository.go} | 0 ...ingService.go => new_exam_results_scheduling_service.go} | 0 ...ository.go => new_exam_results_subscriber_repository.go} | 0 ...berService.go => new_exam_results_subscriber_service.go} | 0 server/backend/{newsAlerts.go => news_alerts.go} | 0 server/backend/{newsAlerts_test.go => news_alerts_test.go} | 0 server/backend/{updateNote.go => update_note.go} | 0 server/backend/{updateNews_test.go => update_note_test.go} | 0 server/model/{cafeteriaRating.go => cafeteria_rating.go} | 0 ...afeteriaRatingAverage.go => cafeteria_rating_average.go} | 0 .../{cafeteriaRatingTag.go => cafeteria_rating_tag.go} | 0 ...aRatingTagAverage.go => cafeteria_rating_tag_average.go} | 0 ...aRatingTagOptions.go => cafeteria_rating_tag_options.go} | 0 server/model/{canteenHeadCount.go => canteen_head_count.go} | 0 server/model/{dishNameTag.go => dish_name_tag.go} | 0 .../{dishNameTagAverage.go => dish_name_tag_average.go} | 0 .../model/{dishNameTagOption.go => dish_name_tag_option.go} | 0 ...agOptionExcluded.go => dish_name_tag_option_excluded.go} | 0 ...agOptionIncluded.go => dish_name_tag_option_included.go} | 0 server/model/{dishRating.go => dish_rating.go} | 0 .../model/{dishRatingAverage.go => dish_rating_average.go} | 0 server/model/{dishRatingTag.go => dish_rating_tag.go} | 0 .../{dishRatingTagAverage.go => dish_rating_tag_average.go} | 0 .../{dishRatingTagOption.go => dish_rating_tag_option.go} | 0 .../{dishToDishNameTags.go => dish_to_dish_name_tag.go} | 0 server/model/{dishesOfTheWeek.go => dishes_of_the_week.go} | 0 .../{examResultPublished.go => exam_result_published.go} | 0 server/model/{files.go => file.go} | 0 server/model/{iosDevice.go => ios_device.go} | 0 .../{iosDeviceLastUpdated.go => ios_device_last_updated.go} | 0 .../{iosDeviceRequestLog.go => ios_device_request_log.go} | 0 ...evicesActivityReset.go => ios_devices_activity_reset.go} | 0 ...{iosRemoteNotification.go => ios_remote_notification.go} | 0 ...iosScheduledUpdateLog.go => ios_scheduled_update_log.go} | 0 ...{iosSchedulingPriority.go => ios_scheduling_priority.go} | 0 ...mResultsSubscriber.go => new_exam_results_subscriber.go} | 0 server/model/{updateNote.go => update_note.go} | 0 67 files changed, 9 insertions(+) create mode 100644 .ls-lint.yaml rename server/backend/{cafeteriaRatingDBInitializer.go => cafeteria_rating_db_initializer.go} (100%) rename server/backend/{cafeteriaService.go => cafeteria_service.go} (100%) rename server/backend/campus_api/{campusApi.go => campus_api.go} (100%) rename server/backend/{canteenHeadCount.go => canteen_head_count.go} (100%) rename server/backend/cron/{averageRatingComputation.go => average_rating_computation.go} (100%) rename server/backend/cron/{canteenHeadCount.go => canteen_head_count.go} (100%) rename server/backend/cron/{dishNameDownload.go => dish_name_download.go} (100%) rename server/backend/cron/{fileDownload.go => file_download.go} (100%) rename server/backend/cron/{fileDownload_test.go => file_download_test.go} (100%) rename server/backend/cron/{iosNotifications.go => ios_notifications.go} (100%) rename server/backend/cron/{movie_test.go => movies_test.go} (100%) rename server/backend/cron/{newExamResultsHook.go => new_exam_results_hook.go} (100%) rename server/backend/{iosNotifications.go => ios_notifications.go} (100%) rename server/backend/ios_notifications/ios_apns/ios_apns_jwt/{iosAPNsToken.go => ios_apns_token.go} (100%) rename server/backend/ios_notifications/ios_apns/{iosAPNsRepository.go => ios_apns_repository.go} (100%) rename server/backend/ios_notifications/ios_apns/{iosAPNsService.go => ios_apns_service.go} (100%) rename server/backend/ios_notifications/ios_crypto/{encryptedString.go => encrypted_string.go} (100%) rename server/backend/ios_notifications/ios_device/{iosDeviceRepository.go => ios_device_repository.go} (100%) rename server/backend/ios_notifications/ios_device/{iosDeviceService.go => ios_device_service.go} (100%) rename server/backend/ios_notifications/ios_devices_activity_reset/{iosDevicesActivityResetRepository.go => ios_devices_activity_reset_repository.go} (100%) rename server/backend/ios_notifications/ios_devices_activity_reset/{iosDevicesActivityResetService.go => ios_devices_activity_reset_service.go} (100%) rename server/backend/ios_notifications/ios_request_response/{iosRequestResponseRepository.go => ios_request_response_repository.go} (100%) rename server/backend/ios_notifications/ios_request_response/{iosRequestResponseService.go => ios_request_response_service.go} (100%) rename server/backend/ios_notifications/ios_scheduled_update_log/{iosScheduledUpdateLogRepository.go => ios_scheduled_update_log_repository.go} (100%) rename server/backend/ios_notifications/ios_scheduling/{iosSchedulingRepository.go => ios_scheduling_repository.go} (100%) rename server/backend/ios_notifications/ios_scheduling/{iosSchedulingService.go => ios_scheduling_service.go} (100%) rename server/backend/migration/{safeEnumMigrate.go => safe_enum_migrate.go} (100%) rename server/backend/migration/{safeEnumMigrate_test.go => safe_enum_migrate_test.go} (100%) rename server/backend/new_exam_results_hook/new_exam_results_scheduling/{newExamResultsSchedulingRepository.go => new_exam_results_scheduling_repository.go} (100%) rename server/backend/new_exam_results_hook/new_exam_results_scheduling/{newExamResultsSchedulingService.go => new_exam_results_scheduling_service.go} (100%) rename server/backend/new_exam_results_hook/new_exam_results_subscriber/{newExamResultsSubscriberRepository.go => new_exam_results_subscriber_repository.go} (100%) rename server/backend/new_exam_results_hook/new_exam_results_subscriber/{newExamResultsSubscriberService.go => new_exam_results_subscriber_service.go} (100%) rename server/backend/{newsAlerts.go => news_alerts.go} (100%) rename server/backend/{newsAlerts_test.go => news_alerts_test.go} (100%) rename server/backend/{updateNote.go => update_note.go} (100%) rename server/backend/{updateNews_test.go => update_note_test.go} (100%) rename server/model/{cafeteriaRating.go => cafeteria_rating.go} (100%) rename server/model/{cafeteriaRatingAverage.go => cafeteria_rating_average.go} (100%) rename server/model/{cafeteriaRatingTag.go => cafeteria_rating_tag.go} (100%) rename server/model/{cafeteriaRatingTagAverage.go => cafeteria_rating_tag_average.go} (100%) rename server/model/{cafeteriaRatingTagOptions.go => cafeteria_rating_tag_options.go} (100%) rename server/model/{canteenHeadCount.go => canteen_head_count.go} (100%) rename server/model/{dishNameTag.go => dish_name_tag.go} (100%) rename server/model/{dishNameTagAverage.go => dish_name_tag_average.go} (100%) rename server/model/{dishNameTagOption.go => dish_name_tag_option.go} (100%) rename server/model/{dishNameTagOptionExcluded.go => dish_name_tag_option_excluded.go} (100%) rename server/model/{dishNameTagOptionIncluded.go => dish_name_tag_option_included.go} (100%) rename server/model/{dishRating.go => dish_rating.go} (100%) rename server/model/{dishRatingAverage.go => dish_rating_average.go} (100%) rename server/model/{dishRatingTag.go => dish_rating_tag.go} (100%) rename server/model/{dishRatingTagAverage.go => dish_rating_tag_average.go} (100%) rename server/model/{dishRatingTagOption.go => dish_rating_tag_option.go} (100%) rename server/model/{dishToDishNameTags.go => dish_to_dish_name_tag.go} (100%) rename server/model/{dishesOfTheWeek.go => dishes_of_the_week.go} (100%) rename server/model/{examResultPublished.go => exam_result_published.go} (100%) rename server/model/{files.go => file.go} (100%) rename server/model/{iosDevice.go => ios_device.go} (100%) rename server/model/{iosDeviceLastUpdated.go => ios_device_last_updated.go} (100%) rename server/model/{iosDeviceRequestLog.go => ios_device_request_log.go} (100%) rename server/model/{iosDevicesActivityReset.go => ios_devices_activity_reset.go} (100%) rename server/model/{iosRemoteNotification.go => ios_remote_notification.go} (100%) rename server/model/{iosScheduledUpdateLog.go => ios_scheduled_update_log.go} (100%) rename server/model/{iosSchedulingPriority.go => ios_scheduling_priority.go} (100%) rename server/model/{newExamResultsSubscriber.go => new_exam_results_subscriber.go} (100%) rename server/model/{updateNote.go => update_note.go} (100%) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 1689fa86..fd79261f 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -31,3 +31,6 @@ jobs: - run: bash server/api/installBuf.bash - name: pre-commit uses: pre-commit/action@v3.0.0 + - uses: ls-lint/action@v2.0.1 + with: + config: .ls-lint.yaml diff --git a/.ls-lint.yaml b/.ls-lint.yaml new file mode 100644 index 00000000..fa0301ae --- /dev/null +++ b/.ls-lint.yaml @@ -0,0 +1,6 @@ +ls: + .pb.gw.go: snake_case + .pb.go: snake_case + .go: snake_case + +ignore: [] diff --git a/server/backend/cafeteriaRatingDBInitializer.go b/server/backend/cafeteria_rating_db_initializer.go similarity index 100% rename from server/backend/cafeteriaRatingDBInitializer.go rename to server/backend/cafeteria_rating_db_initializer.go diff --git a/server/backend/cafeteriaService.go b/server/backend/cafeteria_service.go similarity index 100% rename from server/backend/cafeteriaService.go rename to server/backend/cafeteria_service.go diff --git a/server/backend/campus_api/campusApi.go b/server/backend/campus_api/campus_api.go similarity index 100% rename from server/backend/campus_api/campusApi.go rename to server/backend/campus_api/campus_api.go diff --git a/server/backend/canteenHeadCount.go b/server/backend/canteen_head_count.go similarity index 100% rename from server/backend/canteenHeadCount.go rename to server/backend/canteen_head_count.go diff --git a/server/backend/cron/averageRatingComputation.go b/server/backend/cron/average_rating_computation.go similarity index 100% rename from server/backend/cron/averageRatingComputation.go rename to server/backend/cron/average_rating_computation.go diff --git a/server/backend/cron/canteenHeadCount.go b/server/backend/cron/canteen_head_count.go similarity index 100% rename from server/backend/cron/canteenHeadCount.go rename to server/backend/cron/canteen_head_count.go diff --git a/server/backend/cron/dishNameDownload.go b/server/backend/cron/dish_name_download.go similarity index 100% rename from server/backend/cron/dishNameDownload.go rename to server/backend/cron/dish_name_download.go diff --git a/server/backend/cron/fileDownload.go b/server/backend/cron/file_download.go similarity index 100% rename from server/backend/cron/fileDownload.go rename to server/backend/cron/file_download.go diff --git a/server/backend/cron/fileDownload_test.go b/server/backend/cron/file_download_test.go similarity index 100% rename from server/backend/cron/fileDownload_test.go rename to server/backend/cron/file_download_test.go diff --git a/server/backend/cron/iosNotifications.go b/server/backend/cron/ios_notifications.go similarity index 100% rename from server/backend/cron/iosNotifications.go rename to server/backend/cron/ios_notifications.go diff --git a/server/backend/cron/movie_test.go b/server/backend/cron/movies_test.go similarity index 100% rename from server/backend/cron/movie_test.go rename to server/backend/cron/movies_test.go diff --git a/server/backend/cron/newExamResultsHook.go b/server/backend/cron/new_exam_results_hook.go similarity index 100% rename from server/backend/cron/newExamResultsHook.go rename to server/backend/cron/new_exam_results_hook.go diff --git a/server/backend/iosNotifications.go b/server/backend/ios_notifications.go similarity index 100% rename from server/backend/iosNotifications.go rename to server/backend/ios_notifications.go diff --git a/server/backend/ios_notifications/ios_apns/ios_apns_jwt/iosAPNsToken.go b/server/backend/ios_notifications/ios_apns/ios_apns_jwt/ios_apns_token.go similarity index 100% rename from server/backend/ios_notifications/ios_apns/ios_apns_jwt/iosAPNsToken.go rename to server/backend/ios_notifications/ios_apns/ios_apns_jwt/ios_apns_token.go diff --git a/server/backend/ios_notifications/ios_apns/iosAPNsRepository.go b/server/backend/ios_notifications/ios_apns/ios_apns_repository.go similarity index 100% rename from server/backend/ios_notifications/ios_apns/iosAPNsRepository.go rename to server/backend/ios_notifications/ios_apns/ios_apns_repository.go diff --git a/server/backend/ios_notifications/ios_apns/iosAPNsService.go b/server/backend/ios_notifications/ios_apns/ios_apns_service.go similarity index 100% rename from server/backend/ios_notifications/ios_apns/iosAPNsService.go rename to server/backend/ios_notifications/ios_apns/ios_apns_service.go diff --git a/server/backend/ios_notifications/ios_crypto/encryptedString.go b/server/backend/ios_notifications/ios_crypto/encrypted_string.go similarity index 100% rename from server/backend/ios_notifications/ios_crypto/encryptedString.go rename to server/backend/ios_notifications/ios_crypto/encrypted_string.go diff --git a/server/backend/ios_notifications/ios_device/iosDeviceRepository.go b/server/backend/ios_notifications/ios_device/ios_device_repository.go similarity index 100% rename from server/backend/ios_notifications/ios_device/iosDeviceRepository.go rename to server/backend/ios_notifications/ios_device/ios_device_repository.go diff --git a/server/backend/ios_notifications/ios_device/iosDeviceService.go b/server/backend/ios_notifications/ios_device/ios_device_service.go similarity index 100% rename from server/backend/ios_notifications/ios_device/iosDeviceService.go rename to server/backend/ios_notifications/ios_device/ios_device_service.go diff --git a/server/backend/ios_notifications/ios_devices_activity_reset/iosDevicesActivityResetRepository.go b/server/backend/ios_notifications/ios_devices_activity_reset/ios_devices_activity_reset_repository.go similarity index 100% rename from server/backend/ios_notifications/ios_devices_activity_reset/iosDevicesActivityResetRepository.go rename to server/backend/ios_notifications/ios_devices_activity_reset/ios_devices_activity_reset_repository.go diff --git a/server/backend/ios_notifications/ios_devices_activity_reset/iosDevicesActivityResetService.go b/server/backend/ios_notifications/ios_devices_activity_reset/ios_devices_activity_reset_service.go similarity index 100% rename from server/backend/ios_notifications/ios_devices_activity_reset/iosDevicesActivityResetService.go rename to server/backend/ios_notifications/ios_devices_activity_reset/ios_devices_activity_reset_service.go diff --git a/server/backend/ios_notifications/ios_request_response/iosRequestResponseRepository.go b/server/backend/ios_notifications/ios_request_response/ios_request_response_repository.go similarity index 100% rename from server/backend/ios_notifications/ios_request_response/iosRequestResponseRepository.go rename to server/backend/ios_notifications/ios_request_response/ios_request_response_repository.go diff --git a/server/backend/ios_notifications/ios_request_response/iosRequestResponseService.go b/server/backend/ios_notifications/ios_request_response/ios_request_response_service.go similarity index 100% rename from server/backend/ios_notifications/ios_request_response/iosRequestResponseService.go rename to server/backend/ios_notifications/ios_request_response/ios_request_response_service.go diff --git a/server/backend/ios_notifications/ios_scheduled_update_log/iosScheduledUpdateLogRepository.go b/server/backend/ios_notifications/ios_scheduled_update_log/ios_scheduled_update_log_repository.go similarity index 100% rename from server/backend/ios_notifications/ios_scheduled_update_log/iosScheduledUpdateLogRepository.go rename to server/backend/ios_notifications/ios_scheduled_update_log/ios_scheduled_update_log_repository.go diff --git a/server/backend/ios_notifications/ios_scheduling/iosSchedulingRepository.go b/server/backend/ios_notifications/ios_scheduling/ios_scheduling_repository.go similarity index 100% rename from server/backend/ios_notifications/ios_scheduling/iosSchedulingRepository.go rename to server/backend/ios_notifications/ios_scheduling/ios_scheduling_repository.go diff --git a/server/backend/ios_notifications/ios_scheduling/iosSchedulingService.go b/server/backend/ios_notifications/ios_scheduling/ios_scheduling_service.go similarity index 100% rename from server/backend/ios_notifications/ios_scheduling/iosSchedulingService.go rename to server/backend/ios_notifications/ios_scheduling/ios_scheduling_service.go diff --git a/server/backend/migration/safeEnumMigrate.go b/server/backend/migration/safe_enum_migrate.go similarity index 100% rename from server/backend/migration/safeEnumMigrate.go rename to server/backend/migration/safe_enum_migrate.go diff --git a/server/backend/migration/safeEnumMigrate_test.go b/server/backend/migration/safe_enum_migrate_test.go similarity index 100% rename from server/backend/migration/safeEnumMigrate_test.go rename to server/backend/migration/safe_enum_migrate_test.go diff --git a/server/backend/new_exam_results_hook/new_exam_results_scheduling/newExamResultsSchedulingRepository.go b/server/backend/new_exam_results_hook/new_exam_results_scheduling/new_exam_results_scheduling_repository.go similarity index 100% rename from server/backend/new_exam_results_hook/new_exam_results_scheduling/newExamResultsSchedulingRepository.go rename to server/backend/new_exam_results_hook/new_exam_results_scheduling/new_exam_results_scheduling_repository.go diff --git a/server/backend/new_exam_results_hook/new_exam_results_scheduling/newExamResultsSchedulingService.go b/server/backend/new_exam_results_hook/new_exam_results_scheduling/new_exam_results_scheduling_service.go similarity index 100% rename from server/backend/new_exam_results_hook/new_exam_results_scheduling/newExamResultsSchedulingService.go rename to server/backend/new_exam_results_hook/new_exam_results_scheduling/new_exam_results_scheduling_service.go diff --git a/server/backend/new_exam_results_hook/new_exam_results_subscriber/newExamResultsSubscriberRepository.go b/server/backend/new_exam_results_hook/new_exam_results_subscriber/new_exam_results_subscriber_repository.go similarity index 100% rename from server/backend/new_exam_results_hook/new_exam_results_subscriber/newExamResultsSubscriberRepository.go rename to server/backend/new_exam_results_hook/new_exam_results_subscriber/new_exam_results_subscriber_repository.go diff --git a/server/backend/new_exam_results_hook/new_exam_results_subscriber/newExamResultsSubscriberService.go b/server/backend/new_exam_results_hook/new_exam_results_subscriber/new_exam_results_subscriber_service.go similarity index 100% rename from server/backend/new_exam_results_hook/new_exam_results_subscriber/newExamResultsSubscriberService.go rename to server/backend/new_exam_results_hook/new_exam_results_subscriber/new_exam_results_subscriber_service.go diff --git a/server/backend/newsAlerts.go b/server/backend/news_alerts.go similarity index 100% rename from server/backend/newsAlerts.go rename to server/backend/news_alerts.go diff --git a/server/backend/newsAlerts_test.go b/server/backend/news_alerts_test.go similarity index 100% rename from server/backend/newsAlerts_test.go rename to server/backend/news_alerts_test.go diff --git a/server/backend/updateNote.go b/server/backend/update_note.go similarity index 100% rename from server/backend/updateNote.go rename to server/backend/update_note.go diff --git a/server/backend/updateNews_test.go b/server/backend/update_note_test.go similarity index 100% rename from server/backend/updateNews_test.go rename to server/backend/update_note_test.go diff --git a/server/model/cafeteriaRating.go b/server/model/cafeteria_rating.go similarity index 100% rename from server/model/cafeteriaRating.go rename to server/model/cafeteria_rating.go diff --git a/server/model/cafeteriaRatingAverage.go b/server/model/cafeteria_rating_average.go similarity index 100% rename from server/model/cafeteriaRatingAverage.go rename to server/model/cafeteria_rating_average.go diff --git a/server/model/cafeteriaRatingTag.go b/server/model/cafeteria_rating_tag.go similarity index 100% rename from server/model/cafeteriaRatingTag.go rename to server/model/cafeteria_rating_tag.go diff --git a/server/model/cafeteriaRatingTagAverage.go b/server/model/cafeteria_rating_tag_average.go similarity index 100% rename from server/model/cafeteriaRatingTagAverage.go rename to server/model/cafeteria_rating_tag_average.go diff --git a/server/model/cafeteriaRatingTagOptions.go b/server/model/cafeteria_rating_tag_options.go similarity index 100% rename from server/model/cafeteriaRatingTagOptions.go rename to server/model/cafeteria_rating_tag_options.go diff --git a/server/model/canteenHeadCount.go b/server/model/canteen_head_count.go similarity index 100% rename from server/model/canteenHeadCount.go rename to server/model/canteen_head_count.go diff --git a/server/model/dishNameTag.go b/server/model/dish_name_tag.go similarity index 100% rename from server/model/dishNameTag.go rename to server/model/dish_name_tag.go diff --git a/server/model/dishNameTagAverage.go b/server/model/dish_name_tag_average.go similarity index 100% rename from server/model/dishNameTagAverage.go rename to server/model/dish_name_tag_average.go diff --git a/server/model/dishNameTagOption.go b/server/model/dish_name_tag_option.go similarity index 100% rename from server/model/dishNameTagOption.go rename to server/model/dish_name_tag_option.go diff --git a/server/model/dishNameTagOptionExcluded.go b/server/model/dish_name_tag_option_excluded.go similarity index 100% rename from server/model/dishNameTagOptionExcluded.go rename to server/model/dish_name_tag_option_excluded.go diff --git a/server/model/dishNameTagOptionIncluded.go b/server/model/dish_name_tag_option_included.go similarity index 100% rename from server/model/dishNameTagOptionIncluded.go rename to server/model/dish_name_tag_option_included.go diff --git a/server/model/dishRating.go b/server/model/dish_rating.go similarity index 100% rename from server/model/dishRating.go rename to server/model/dish_rating.go diff --git a/server/model/dishRatingAverage.go b/server/model/dish_rating_average.go similarity index 100% rename from server/model/dishRatingAverage.go rename to server/model/dish_rating_average.go diff --git a/server/model/dishRatingTag.go b/server/model/dish_rating_tag.go similarity index 100% rename from server/model/dishRatingTag.go rename to server/model/dish_rating_tag.go diff --git a/server/model/dishRatingTagAverage.go b/server/model/dish_rating_tag_average.go similarity index 100% rename from server/model/dishRatingTagAverage.go rename to server/model/dish_rating_tag_average.go diff --git a/server/model/dishRatingTagOption.go b/server/model/dish_rating_tag_option.go similarity index 100% rename from server/model/dishRatingTagOption.go rename to server/model/dish_rating_tag_option.go diff --git a/server/model/dishToDishNameTags.go b/server/model/dish_to_dish_name_tag.go similarity index 100% rename from server/model/dishToDishNameTags.go rename to server/model/dish_to_dish_name_tag.go diff --git a/server/model/dishesOfTheWeek.go b/server/model/dishes_of_the_week.go similarity index 100% rename from server/model/dishesOfTheWeek.go rename to server/model/dishes_of_the_week.go diff --git a/server/model/examResultPublished.go b/server/model/exam_result_published.go similarity index 100% rename from server/model/examResultPublished.go rename to server/model/exam_result_published.go diff --git a/server/model/files.go b/server/model/file.go similarity index 100% rename from server/model/files.go rename to server/model/file.go diff --git a/server/model/iosDevice.go b/server/model/ios_device.go similarity index 100% rename from server/model/iosDevice.go rename to server/model/ios_device.go diff --git a/server/model/iosDeviceLastUpdated.go b/server/model/ios_device_last_updated.go similarity index 100% rename from server/model/iosDeviceLastUpdated.go rename to server/model/ios_device_last_updated.go diff --git a/server/model/iosDeviceRequestLog.go b/server/model/ios_device_request_log.go similarity index 100% rename from server/model/iosDeviceRequestLog.go rename to server/model/ios_device_request_log.go diff --git a/server/model/iosDevicesActivityReset.go b/server/model/ios_devices_activity_reset.go similarity index 100% rename from server/model/iosDevicesActivityReset.go rename to server/model/ios_devices_activity_reset.go diff --git a/server/model/iosRemoteNotification.go b/server/model/ios_remote_notification.go similarity index 100% rename from server/model/iosRemoteNotification.go rename to server/model/ios_remote_notification.go diff --git a/server/model/iosScheduledUpdateLog.go b/server/model/ios_scheduled_update_log.go similarity index 100% rename from server/model/iosScheduledUpdateLog.go rename to server/model/ios_scheduled_update_log.go diff --git a/server/model/iosSchedulingPriority.go b/server/model/ios_scheduling_priority.go similarity index 100% rename from server/model/iosSchedulingPriority.go rename to server/model/ios_scheduling_priority.go diff --git a/server/model/newExamResultsSubscriber.go b/server/model/new_exam_results_subscriber.go similarity index 100% rename from server/model/newExamResultsSubscriber.go rename to server/model/new_exam_results_subscriber.go diff --git a/server/model/updateNote.go b/server/model/update_note.go similarity index 100% rename from server/model/updateNote.go rename to server/model/update_note.go From 283f9d8c5aa44404f6c03bd574069b46229c2a44 Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Fri, 22 Sep 2023 13:35:56 +0200 Subject: [PATCH 4/6] reconfigured to also lint directory names --- .ls-lint.yaml | 10 +++++++++- client/{localServer => local}/client.go | 2 +- .../{localServer => local}/images/sampleimage.jpeg | Bin client/{publicServer => public}/client.go | 0 4 files changed, 10 insertions(+), 2 deletions(-) rename client/{localServer => local}/client.go (99%) rename client/{localServer => local}/images/sampleimage.jpeg (100%) rename client/{publicServer => public}/client.go (100%) diff --git a/.ls-lint.yaml b/.ls-lint.yaml index fa0301ae..d43a775f 100644 --- a/.ls-lint.yaml +++ b/.ls-lint.yaml @@ -1,6 +1,14 @@ ls: + .dir: snake_case .pb.gw.go: snake_case .pb.go: snake_case .go: snake_case -ignore: [] +ignore: + - venv + - server/swagger/node_modules + - .idea + - .git + - .github + - .vscode + - apns_auth_key.p8 diff --git a/client/localServer/client.go b/client/local/client.go similarity index 99% rename from client/localServer/client.go rename to client/local/client.go index eb6e03d6..281e76b8 100644 --- a/client/localServer/client.go +++ b/client/local/client.go @@ -19,7 +19,7 @@ import ( const ( localAddress = "127.0.0.1:50051" - testImage = "./localServer/images/sampleimage.jpeg" + testImage = "./local/images/sampleimage.jpeg" ) // main connects to a seperatly started local server and creates ratings for both, canteens and dishes. diff --git a/client/localServer/images/sampleimage.jpeg b/client/local/images/sampleimage.jpeg similarity index 100% rename from client/localServer/images/sampleimage.jpeg rename to client/local/images/sampleimage.jpeg diff --git a/client/publicServer/client.go b/client/public/client.go similarity index 100% rename from client/publicServer/client.go rename to client/public/client.go From c7a69563364d969ceda42b4b083fe71edc944e84 Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Fri, 22 Sep 2023 13:48:58 +0200 Subject: [PATCH 5/6] removed the redundant ios prefixes from the ios notifications directory --- .ls-lint.yaml | 10 ++----- server/backend/cron/cronjobs.go | 6 ++--- server/backend/cron/ios_notifications.go | 20 +++++++------- server/backend/cron/new_exam_results_hook.go | 4 +-- server/backend/ios_notifications.go | 27 +++++++++---------- .../{ios_apns => apns}/ios_apns_repository.go | 9 +++---- .../{ios_apns => apns}/ios_apns_service.go | 13 +++++---- .../ios_apns_token.go => apns/jwt_token.go} | 16 +++++------ .../encrypted_string.go | 4 +-- .../device_repository.go} | 2 +- .../device_service.go} | 4 +-- .../devices_activity_reset_repository.go} | 2 +- .../devices_activity_reset_service.go} | 6 ++--- .../request_response_repository.go} | 8 +++--- .../request_response_service.go} | 14 +++++----- .../scheduled_update_log_repository.go} | 4 +-- .../scheduling_repository.go} | 2 +- .../scheduling_service.go} | 22 +++++++-------- .../new_exam_results_scheduling_service.go | 12 ++++----- server/backend/rpcserver.go | 7 +++-- server/model/ios_grade.go | 10 +++---- server/model/ios_remote_notification.go | 8 +++--- 22 files changed, 100 insertions(+), 110 deletions(-) rename server/backend/ios_notifications/{ios_apns => apns}/ios_apns_repository.go (94%) rename server/backend/ios_notifications/{ios_apns => apns}/ios_apns_service.go (83%) rename server/backend/ios_notifications/{ios_apns/ios_apns_jwt/ios_apns_token.go => apns/jwt_token.go} (89%) rename server/backend/ios_notifications/{ios_crypto => crypto}/encrypted_string.go (95%) rename server/backend/ios_notifications/{ios_device/ios_device_repository.go => device/device_repository.go} (99%) rename server/backend/ios_notifications/{ios_device/ios_device_service.go => device/device_service.go} (94%) rename server/backend/ios_notifications/{ios_devices_activity_reset/ios_devices_activity_reset_repository.go => devices_activity_reset/devices_activity_reset_repository.go} (98%) rename server/backend/ios_notifications/{ios_devices_activity_reset/ios_devices_activity_reset_service.go => devices_activity_reset/devices_activity_reset_service.go} (94%) rename server/backend/ios_notifications/{ios_request_response/ios_request_response_repository.go => request_response/request_response_repository.go} (91%) rename server/backend/ios_notifications/{ios_request_response/ios_request_response_service.go => request_response/request_response_service.go} (95%) rename server/backend/ios_notifications/{ios_scheduled_update_log/ios_scheduled_update_log_repository.go => scheduled_update_log/scheduled_update_log_repository.go} (83%) rename server/backend/ios_notifications/{ios_scheduling/ios_scheduling_repository.go => scheduling/scheduling_repository.go} (94%) rename server/backend/ios_notifications/{ios_scheduling/ios_scheduling_service.go => scheduling/scheduling_service.go} (91%) diff --git a/.ls-lint.yaml b/.ls-lint.yaml index d43a775f..24d29197 100644 --- a/.ls-lint.yaml +++ b/.ls-lint.yaml @@ -1,14 +1,8 @@ ls: - .dir: snake_case + .dir: lowercase .pb.gw.go: snake_case .pb.go: snake_case .go: snake_case ignore: - - venv - - server/swagger/node_modules - - .idea - - .git - - .github - - .vscode - - apns_auth_key.p8 + - swagger diff --git a/server/backend/cron/cronjobs.go b/server/backend/cron/cronjobs.go index 6925b2eb..396ca328 100644 --- a/server/backend/cron/cronjobs.go +++ b/server/backend/cron/cronjobs.go @@ -3,7 +3,7 @@ package cron import ( "time" - "github.com/TUM-Dev/Campus-Backend/server/backend/ios_notifications/ios_apns" + "github.com/TUM-Dev/Campus-Backend/server/backend/ios_notifications/apns" "github.com/TUM-Dev/Campus-Backend/server/env" "github.com/TUM-Dev/Campus-Backend/server/model" @@ -16,7 +16,7 @@ import ( type CronService struct { db *gorm.DB gf *gofeed.Parser - APNs *ios_apns.Service + APNs *apns.Service } const StorageDir = "/Storage/" // target location of files @@ -41,7 +41,7 @@ func New(db *gorm.DB) *CronService { return &CronService{ db: db, gf: gofeed.NewParser(), - APNs: ios_apns.NewCronService(db), + APNs: apns.NewCronService(db), } } diff --git a/server/backend/cron/ios_notifications.go b/server/backend/cron/ios_notifications.go index ce9b8c96..99c51161 100644 --- a/server/backend/cron/ios_notifications.go +++ b/server/backend/cron/ios_notifications.go @@ -1,31 +1,31 @@ package cron import ( - "github.com/TUM-Dev/Campus-Backend/server/backend/ios_notifications/ios_device" - "github.com/TUM-Dev/Campus-Backend/server/backend/ios_notifications/ios_devices_activity_reset" - "github.com/TUM-Dev/Campus-Backend/server/backend/ios_notifications/ios_scheduled_update_log" - "github.com/TUM-Dev/Campus-Backend/server/backend/ios_notifications/ios_scheduling" + "github.com/TUM-Dev/Campus-Backend/server/backend/ios_notifications/device" + "github.com/TUM-Dev/Campus-Backend/server/backend/ios_notifications/devices_activity_reset" + "github.com/TUM-Dev/Campus-Backend/server/backend/ios_notifications/scheduled_update_log" + "github.com/TUM-Dev/Campus-Backend/server/backend/ios_notifications/scheduling" ) // Starts the cron job for sending iOS notifications reuses -// the APNs client (ios_apns.Service) stored in CronService +// the APNs client (apns.Service) stored in CronService func (c *CronService) iosNotificationsCron() error { if !c.APNs.IsActive { return nil } - repo := ios_scheduling.NewRepository(c.db) - devicesRepo := ios_device.NewRepository(c.db) - schedulerRepo := ios_scheduled_update_log.NewRepository(c.db) + repo := scheduling.NewRepository(c.db) + devicesRepo := device.NewRepository(c.db) + schedulerRepo := scheduled_update_log.NewRepository(c.db) - service := ios_scheduling.NewService(repo, devicesRepo, schedulerRepo, c.APNs) + service := scheduling.NewService(repo, devicesRepo, schedulerRepo, c.APNs) return service.HandleScheduledCron() } // Resets the activity of all devices to 0 every day, week, month or year func (c *CronService) iosActivityReset() error { - service := ios_devices_activity_reset.NewService(c.db) + service := devices_activity_reset.NewService(c.db) return service.HandleScheduledActivityReset() } diff --git a/server/backend/cron/new_exam_results_hook.go b/server/backend/cron/new_exam_results_hook.go index 122d636c..5779f1af 100644 --- a/server/backend/cron/new_exam_results_hook.go +++ b/server/backend/cron/new_exam_results_hook.go @@ -1,13 +1,13 @@ package cron import ( - "github.com/TUM-Dev/Campus-Backend/server/backend/ios_notifications/ios_device" + "github.com/TUM-Dev/Campus-Backend/server/backend/ios_notifications/device" "github.com/TUM-Dev/Campus-Backend/server/backend/new_exam_results_hook/new_exam_results_scheduling" ) func (c *CronService) newExamResultsHookCron() error { repo := new_exam_results_scheduling.NewRepository(c.db) - devicesRepo := ios_device.NewRepository(c.db) + devicesRepo := device.NewRepository(c.db) service := new_exam_results_scheduling.NewService(repo, devicesRepo, c.APNs) diff --git a/server/backend/ios_notifications.go b/server/backend/ios_notifications.go index bc759e92..392997fd 100644 --- a/server/backend/ios_notifications.go +++ b/server/backend/ios_notifications.go @@ -4,35 +4,34 @@ import ( "context" pb "github.com/TUM-Dev/Campus-Backend/server/api/tumdev" - "github.com/TUM-Dev/Campus-Backend/server/backend/ios_notifications/ios_apns" - "github.com/TUM-Dev/Campus-Backend/server/backend/ios_notifications/ios_apns/ios_apns_jwt" - "github.com/TUM-Dev/Campus-Backend/server/backend/ios_notifications/ios_device" - "github.com/TUM-Dev/Campus-Backend/server/backend/ios_notifications/ios_request_response" + "github.com/TUM-Dev/Campus-Backend/server/backend/ios_notifications/apns" + "github.com/TUM-Dev/Campus-Backend/server/backend/ios_notifications/device" + "github.com/TUM-Dev/Campus-Backend/server/backend/ios_notifications/request_response" "gorm.io/gorm" ) type IOSNotificationsService struct { DB *gorm.DB - APNSToken *ios_apns_jwt.Token + APNSToken *apns.JWTToken IsActive bool } -func (s *CampusServer) GetIOSDeviceService() *ios_device.Service { - repository := ios_device.NewRepository(s.db) +func (s *CampusServer) GetIOSDeviceService() *device.Service { + repository := device.NewRepository(s.db) - return ios_device.NewService(repository) + return device.NewService(repository) } -func (s *CampusServer) GetIOSAPNsService() *ios_apns.Service { - repository := ios_apns.NewRepository(s.db, s.GetIOSNotificationsService().APNSToken) +func (s *CampusServer) GetIOSAPNsService() *apns.Service { + repository := apns.NewRepository(s.db, s.GetIOSNotificationsService().APNSToken) - return ios_apns.NewService(repository) + return apns.NewService(repository) } -func (s *CampusServer) GetIOSRequestResponseService() *ios_request_response.Service { - repository := ios_request_response.NewRepository(s.db, s.GetIOSNotificationsService().APNSToken) +func (s *CampusServer) GetIOSRequestResponseService() *request_response.Service { + repository := request_response.NewRepository(s.db, s.GetIOSNotificationsService().APNSToken) - return ios_request_response.NewService(repository) + return request_response.NewService(repository) } func (s *CampusServer) IOSDeviceRequestResponse(_ context.Context, req *pb.IOSDeviceRequestResponseRequest) (*pb.IOSDeviceRequestResponseReply, error) { diff --git a/server/backend/ios_notifications/ios_apns/ios_apns_repository.go b/server/backend/ios_notifications/apns/ios_apns_repository.go similarity index 94% rename from server/backend/ios_notifications/ios_apns/ios_apns_repository.go rename to server/backend/ios_notifications/apns/ios_apns_repository.go index 339c4019..41d905d6 100644 --- a/server/backend/ios_notifications/ios_apns/ios_apns_repository.go +++ b/server/backend/ios_notifications/apns/ios_apns_repository.go @@ -1,4 +1,4 @@ -package ios_apns +package apns import ( "bytes" @@ -9,7 +9,6 @@ import ( "strconv" "time" - "github.com/TUM-Dev/Campus-Backend/server/backend/ios_notifications/ios_apns/ios_apns_jwt" "github.com/TUM-Dev/Campus-Backend/server/env" "github.com/TUM-Dev/Campus-Backend/server/model" log "github.com/sirupsen/logrus" @@ -38,7 +37,7 @@ var ( type Repository struct { DB gorm.DB - Token *ios_apns_jwt.Token + Token *JWTToken httpClient *http.Client } @@ -117,7 +116,7 @@ func (r *Repository) SendNotification(notification *model.IOSNotificationPayload return &response, nil } -func NewRepository(db *gorm.DB, token *ios_apns_jwt.Token) *Repository { +func NewRepository(db *gorm.DB, token *JWTToken) *Repository { transport := &http2.Transport{ ReadIdleTimeout: ReadIdleTimeout, } @@ -138,7 +137,7 @@ func NewCronRepository(db *gorm.DB) (*Repository, error) { return nil, err } - token, err := ios_apns_jwt.NewToken() + token, err := NewToken() if err != nil { log.WithError(err).Error("Could not create APNs token") } diff --git a/server/backend/ios_notifications/ios_apns/ios_apns_service.go b/server/backend/ios_notifications/apns/ios_apns_service.go similarity index 83% rename from server/backend/ios_notifications/ios_apns/ios_apns_service.go rename to server/backend/ios_notifications/apns/ios_apns_service.go index 42b4d02c..8e3f8c65 100644 --- a/server/backend/ios_notifications/ios_apns/ios_apns_service.go +++ b/server/backend/ios_notifications/apns/ios_apns_service.go @@ -1,11 +1,10 @@ -// Package ios_apns contains the logic for sending push notifications to iOS devices. +// Package apns contains the logic for sending push notifications to iOS devices. // and communicating with the Apple Push Notification Service (APNs). -package ios_apns +package apns import ( "errors" - "github.com/TUM-Dev/Campus-Backend/server/backend/ios_notifications/ios_apns/ios_apns_jwt" "github.com/TUM-Dev/Campus-Backend/server/model" log "github.com/sirupsen/logrus" "gorm.io/gorm" @@ -41,19 +40,19 @@ func (s *Service) RequestGradeUpdateForDevice(deviceID string) error { } func ValidateRequirementsForIOSNotificationsService() error { - if ios_apns_jwt.ApnsKeyId == "" { + if ApnsKeyId == "" { return errors.New("APNS_KEY_ID env variable is not set") } - if ios_apns_jwt.ApnsTeamId == "" { + if ApnsTeamId == "" { return errors.New("APNS_TEAM_ID env variable is not set") } - if ios_apns_jwt.ApnsP8FilePath == "" { + if ApnsP8FilePath == "" { return errors.New("APNS_P8_FILE_PATH env variable is not set") } - if _, err := ios_apns_jwt.APNsEncryptionKeyFromFile(); err != nil { + if _, err := APNsEncryptionKeyFromFile(); err != nil { return errors.New("APNS P8 token is not valid or not set") } diff --git a/server/backend/ios_notifications/ios_apns/ios_apns_jwt/ios_apns_token.go b/server/backend/ios_notifications/apns/jwt_token.go similarity index 89% rename from server/backend/ios_notifications/ios_apns/ios_apns_jwt/ios_apns_token.go rename to server/backend/ios_notifications/apns/jwt_token.go index cb9cecd3..45d0dfc0 100644 --- a/server/backend/ios_notifications/ios_apns/ios_apns_jwt/ios_apns_token.go +++ b/server/backend/ios_notifications/apns/jwt_token.go @@ -1,5 +1,5 @@ -// Package ios_apns_jwt handles the generation and validation of the JWT token for the APNs service -package ios_apns_jwt +// Package apns handles the generation and validation of the JWT token for the APNs service +package apns import ( "crypto/ecdsa" @@ -29,7 +29,7 @@ var ( ApnsP8FilePath = os.Getenv("APNS_P8_FILE_PATH") ) -type Token struct { +type JWTToken struct { sync.Mutex EncryptionKey *ecdsa.PrivateKey KeyId string @@ -38,13 +38,13 @@ type Token struct { Bearer string } -func NewToken() (*Token, error) { +func NewToken() (*JWTToken, error) { encryptionKey, err := APNsEncryptionKeyFromFile() if err != nil { return nil, err } - token := Token{ + token := JWTToken{ EncryptionKey: encryptionKey, KeyId: ApnsKeyId, TeamId: ApnsTeamId, @@ -99,7 +99,7 @@ func APNsEncryptionKeyFromFile() (*ecdsa.PrivateKey, error) { return nil, ErrorAuthKeyNotEcdsa } -func (t *Token) GenerateNewTokenIfExpired() (bearer string) { +func (t *JWTToken) GenerateNewTokenIfExpired() (bearer string) { t.Lock() defer t.Unlock() @@ -113,11 +113,11 @@ func (t *Token) GenerateNewTokenIfExpired() (bearer string) { return t.Bearer } -func (t *Token) IsExpired() bool { +func (t *JWTToken) IsExpired() bool { return currentTimestamp() >= (t.IssuedAt + TokenTimeout) } -func (t *Token) Generate() error { +func (t *JWTToken) Generate() error { if t.EncryptionKey == nil { return ErrorAuthKeyNil } diff --git a/server/backend/ios_notifications/ios_crypto/encrypted_string.go b/server/backend/ios_notifications/crypto/encrypted_string.go similarity index 95% rename from server/backend/ios_notifications/ios_crypto/encrypted_string.go rename to server/backend/ios_notifications/crypto/encrypted_string.go index 24a7aac4..3ee6fd7c 100644 --- a/server/backend/ios_notifications/ios_crypto/encrypted_string.go +++ b/server/backend/ios_notifications/crypto/encrypted_string.go @@ -1,5 +1,5 @@ -// Package ios_crypto provides functions for encrypting and decrypting strings using AES-256-GCM. -package ios_crypto +// Package crypto provides functions for encrypting and decrypting strings using AES-256-GCM. +package crypto import ( "crypto/aes" diff --git a/server/backend/ios_notifications/ios_device/ios_device_repository.go b/server/backend/ios_notifications/device/device_repository.go similarity index 99% rename from server/backend/ios_notifications/ios_device/ios_device_repository.go rename to server/backend/ios_notifications/device/device_repository.go index 969256c0..e3ebe045 100644 --- a/server/backend/ios_notifications/ios_device/ios_device_repository.go +++ b/server/backend/ios_notifications/device/device_repository.go @@ -1,4 +1,4 @@ -package ios_device +package device import ( "errors" diff --git a/server/backend/ios_notifications/ios_device/ios_device_service.go b/server/backend/ios_notifications/device/device_service.go similarity index 94% rename from server/backend/ios_notifications/ios_device/ios_device_service.go rename to server/backend/ios_notifications/device/device_service.go index 8a92db49..8ff9132c 100644 --- a/server/backend/ios_notifications/ios_device/ios_device_service.go +++ b/server/backend/ios_notifications/device/device_service.go @@ -1,5 +1,5 @@ -// Package ios_device provides functions to register and remove ios devices -package ios_device +// Package device provides functions to register and remove ios devices +package device import ( pb "github.com/TUM-Dev/Campus-Backend/server/api/tumdev" diff --git a/server/backend/ios_notifications/ios_devices_activity_reset/ios_devices_activity_reset_repository.go b/server/backend/ios_notifications/devices_activity_reset/devices_activity_reset_repository.go similarity index 98% rename from server/backend/ios_notifications/ios_devices_activity_reset/ios_devices_activity_reset_repository.go rename to server/backend/ios_notifications/devices_activity_reset/devices_activity_reset_repository.go index e2c02b0d..251187c6 100644 --- a/server/backend/ios_notifications/ios_devices_activity_reset/ios_devices_activity_reset_repository.go +++ b/server/backend/ios_notifications/devices_activity_reset/devices_activity_reset_repository.go @@ -1,4 +1,4 @@ -package ios_devices_activity_reset +package devices_activity_reset import ( "time" diff --git a/server/backend/ios_notifications/ios_devices_activity_reset/ios_devices_activity_reset_service.go b/server/backend/ios_notifications/devices_activity_reset/devices_activity_reset_service.go similarity index 94% rename from server/backend/ios_notifications/ios_devices_activity_reset/ios_devices_activity_reset_service.go rename to server/backend/ios_notifications/devices_activity_reset/devices_activity_reset_service.go index 764c590e..f808a983 100644 --- a/server/backend/ios_notifications/ios_devices_activity_reset/ios_devices_activity_reset_service.go +++ b/server/backend/ios_notifications/devices_activity_reset/devices_activity_reset_service.go @@ -1,9 +1,9 @@ -package ios_devices_activity_reset +package devices_activity_reset import ( "time" - "github.com/TUM-Dev/Campus-Backend/server/backend/ios_notifications/ios_device" + "github.com/TUM-Dev/Campus-Backend/server/backend/ios_notifications/device" log "github.com/sirupsen/logrus" "gorm.io/gorm" ) @@ -41,7 +41,7 @@ func (service *Service) HandleScheduledActivityReset() error { now := time.Now() - devicesRepo := ios_device.NewRepository(service.Repository.DB) + devicesRepo := device.NewRepository(service.Repository.DB) if now.Sub(daily.LastReset).Hours() > 24 { if err := service.Repository.ResettedDevicesDaily(); err != nil { diff --git a/server/backend/ios_notifications/ios_request_response/ios_request_response_repository.go b/server/backend/ios_notifications/request_response/request_response_repository.go similarity index 91% rename from server/backend/ios_notifications/ios_request_response/ios_request_response_repository.go rename to server/backend/ios_notifications/request_response/request_response_repository.go index b1fab13b..9e2b39cc 100644 --- a/server/backend/ios_notifications/ios_request_response/ios_request_response_repository.go +++ b/server/backend/ios_notifications/request_response/request_response_repository.go @@ -1,14 +1,14 @@ -package ios_request_response +package request_response import ( - "github.com/TUM-Dev/Campus-Backend/server/backend/ios_notifications/ios_apns/ios_apns_jwt" + "github.com/TUM-Dev/Campus-Backend/server/backend/ios_notifications/apns" "github.com/TUM-Dev/Campus-Backend/server/model" "gorm.io/gorm" ) type Repository struct { DB *gorm.DB - Token *ios_apns_jwt.Token + Token *apns.JWTToken } func (r *Repository) SaveEncryptedGrade(grade *model.IOSEncryptedGrade) error { @@ -70,7 +70,7 @@ func (r *Repository) DeleteAllRequestLogsForThisDeviceWithType(requestLog *model return nil } -func NewRepository(db *gorm.DB, token *ios_apns_jwt.Token) *Repository { +func NewRepository(db *gorm.DB, token *apns.JWTToken) *Repository { return &Repository{ DB: db, Token: token, diff --git a/server/backend/ios_notifications/ios_request_response/ios_request_response_service.go b/server/backend/ios_notifications/request_response/request_response_service.go similarity index 95% rename from server/backend/ios_notifications/ios_request_response/ios_request_response_service.go rename to server/backend/ios_notifications/request_response/request_response_service.go index 798ab588..85f58a72 100644 --- a/server/backend/ios_notifications/ios_request_response/ios_request_response_service.go +++ b/server/backend/ios_notifications/request_response/request_response_service.go @@ -1,7 +1,7 @@ -// Package ios_request_response provides functionality to handle device requests. +// Package request_response provides functionality to handle device requests. // Device Requests are requests that are sent from the device to the server when the // device received a background push notification from the backend. -package ios_request_response +package request_response import ( "fmt" @@ -11,8 +11,8 @@ import ( pb "github.com/TUM-Dev/Campus-Backend/server/api/tumdev" "github.com/TUM-Dev/Campus-Backend/server/backend/campus_api" - "github.com/TUM-Dev/Campus-Backend/server/backend/ios_notifications/ios_apns" - "github.com/TUM-Dev/Campus-Backend/server/backend/ios_notifications/ios_device" + "github.com/TUM-Dev/Campus-Backend/server/backend/ios_notifications/apns" + "github.com/TUM-Dev/Campus-Backend/server/backend/ios_notifications/device" "github.com/TUM-Dev/Campus-Backend/server/model" log "github.com/sirupsen/logrus" "google.golang.org/grpc/codes" @@ -72,7 +72,7 @@ func (service *Service) HandleDeviceRequestResponse(request *pb.IOSDeviceRequest func (service *Service) handleDeviceCampusTokenRequest(requestLog *model.IOSDeviceRequestLog, campusToken string) (*pb.IOSDeviceRequestResponseReply, error) { log.WithField("DeviceID", requestLog.DeviceID).Info("Handling campus token request") - userRepo := ios_device.NewRepository(service.Repository.DB) + userRepo := device.NewRepository(service.Repository.DB) device, err := userRepo.GetDevice(requestLog.DeviceID) @@ -121,7 +121,7 @@ func (service *Service) handleDeviceCampusTokenRequest(requestLog *model.IOSDevi log.WithFields(log.Fields{"old": len(oldGrades), "new": len(newGrades)}).Info("Found grades") if len(newGrades) > 0 && len(oldGrades) > 0 { - apnsRepository := ios_apns.NewRepository(service.Repository.DB, service.Repository.Token) + apnsRepository := apns.NewRepository(service.Repository.DB, service.Repository.Token) sendGradesToDevice(device, newGrades, apnsRepository) } @@ -195,7 +195,7 @@ func (service *Service) encryptGradesAndStoreInDatabase(grades []model.IOSGrade, } } -func sendGradesToDevice(device *model.IOSDevice, grades []model.IOSGrade, apns *ios_apns.Repository) { +func sendGradesToDevice(device *model.IOSDevice, grades []model.IOSGrade, apns *apns.Repository) { alertTitle := fmt.Sprintf("%d New Grades Available", len(grades)) if len(grades) == 1 { diff --git a/server/backend/ios_notifications/ios_scheduled_update_log/ios_scheduled_update_log_repository.go b/server/backend/ios_notifications/scheduled_update_log/scheduled_update_log_repository.go similarity index 83% rename from server/backend/ios_notifications/ios_scheduled_update_log/ios_scheduled_update_log_repository.go rename to server/backend/ios_notifications/scheduled_update_log/scheduled_update_log_repository.go index 116c338d..e85ae0af 100644 --- a/server/backend/ios_notifications/ios_scheduled_update_log/ios_scheduled_update_log_repository.go +++ b/server/backend/ios_notifications/scheduled_update_log/scheduled_update_log_repository.go @@ -1,6 +1,6 @@ -// Package ios_scheduled_update_log provides functionality for logging scheduler updates +// Package scheduled_update_log provides functionality for logging scheduler updates // E.g. when a device updated its grades, the scheduler will log the update -package ios_scheduled_update_log +package scheduled_update_log import ( "github.com/TUM-Dev/Campus-Backend/server/model" diff --git a/server/backend/ios_notifications/ios_scheduling/ios_scheduling_repository.go b/server/backend/ios_notifications/scheduling/scheduling_repository.go similarity index 94% rename from server/backend/ios_notifications/ios_scheduling/ios_scheduling_repository.go rename to server/backend/ios_notifications/scheduling/scheduling_repository.go index d1a11d51..01c9ac2d 100644 --- a/server/backend/ios_notifications/ios_scheduling/ios_scheduling_repository.go +++ b/server/backend/ios_notifications/scheduling/scheduling_repository.go @@ -1,4 +1,4 @@ -package ios_scheduling +package scheduling import ( "github.com/TUM-Dev/Campus-Backend/server/model" diff --git a/server/backend/ios_notifications/ios_scheduling/ios_scheduling_service.go b/server/backend/ios_notifications/scheduling/scheduling_service.go similarity index 91% rename from server/backend/ios_notifications/ios_scheduling/ios_scheduling_service.go rename to server/backend/ios_notifications/scheduling/scheduling_service.go index 517c8351..00cc7d79 100644 --- a/server/backend/ios_notifications/ios_scheduling/ios_scheduling_service.go +++ b/server/backend/ios_notifications/scheduling/scheduling_service.go @@ -1,6 +1,6 @@ -// Package ios_scheduling provides functionality for updating user information +// Package scheduling provides functionality for updating user information // and optionally sending notifications to iOS devices. -package ios_scheduling +package scheduling import ( "sync" @@ -8,9 +8,9 @@ import ( "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" - "github.com/TUM-Dev/Campus-Backend/server/backend/ios_notifications/ios_apns" - "github.com/TUM-Dev/Campus-Backend/server/backend/ios_notifications/ios_device" - "github.com/TUM-Dev/Campus-Backend/server/backend/ios_notifications/ios_scheduled_update_log" + "github.com/TUM-Dev/Campus-Backend/server/backend/ios_notifications/apns" + "github.com/TUM-Dev/Campus-Backend/server/backend/ios_notifications/device" + "github.com/TUM-Dev/Campus-Backend/server/backend/ios_notifications/scheduled_update_log" "github.com/TUM-Dev/Campus-Backend/server/model" log "github.com/sirupsen/logrus" ) @@ -27,10 +27,10 @@ var devicesToUpdate = promauto.NewGauge(prometheus.GaugeOpts{ type Service struct { Repository *Repository - DevicesRepository *ios_device.Repository - SchedulerLogRepository *ios_scheduled_update_log.Repository + DevicesRepository *device.Repository + SchedulerLogRepository *scheduled_update_log.Repository Priority *model.IOSSchedulingPriority - APNs *ios_apns.Service + APNs *apns.Service } func (service *Service) HandleScheduledCron() error { @@ -175,9 +175,9 @@ func mergeIOSSchedulingPriorities(priorities []model.IOSSchedulingPriority) *mod } func NewService(repository *Repository, - devicesRepository *ios_device.Repository, - schedulerRepository *ios_scheduled_update_log.Repository, - apnsService *ios_apns.Service, + devicesRepository *device.Repository, + schedulerRepository *scheduled_update_log.Repository, + apnsService *apns.Service, ) *Service { return &Service{ Repository: repository, diff --git a/server/backend/new_exam_results_hook/new_exam_results_scheduling/new_exam_results_scheduling_service.go b/server/backend/new_exam_results_hook/new_exam_results_scheduling/new_exam_results_scheduling_service.go index 30c266f4..ba37c996 100644 --- a/server/backend/new_exam_results_hook/new_exam_results_scheduling/new_exam_results_scheduling_service.go +++ b/server/backend/new_exam_results_hook/new_exam_results_scheduling/new_exam_results_scheduling_service.go @@ -4,8 +4,8 @@ import ( "os" "github.com/TUM-Dev/Campus-Backend/server/backend/campus_api" - "github.com/TUM-Dev/Campus-Backend/server/backend/ios_notifications/ios_apns" - "github.com/TUM-Dev/Campus-Backend/server/backend/ios_notifications/ios_device" + "github.com/TUM-Dev/Campus-Backend/server/backend/ios_notifications/apns" + "github.com/TUM-Dev/Campus-Backend/server/backend/ios_notifications/device" "github.com/TUM-Dev/Campus-Backend/server/backend/new_exam_results_hook/new_exam_results_subscriber" "github.com/TUM-Dev/Campus-Backend/server/model" log "github.com/sirupsen/logrus" @@ -17,9 +17,9 @@ var ( type Service struct { Repository *Repository - DevicesRepository *ios_device.Repository + DevicesRepository *device.Repository Priority *model.IOSSchedulingPriority - APNs *ios_apns.Service + APNs *apns.Service } func (service *Service) HandleScheduledCron() error { @@ -87,8 +87,8 @@ func (service *Service) notifySubscribers(newPublishedExamResults *[]model.Publi } func NewService(repository *Repository, - devicesRepository *ios_device.Repository, - apnsService *ios_apns.Service, + devicesRepository *device.Repository, + apnsService *apns.Service, ) *Service { return &Service{ Repository: repository, diff --git a/server/backend/rpcserver.go b/server/backend/rpcserver.go index 3544fef1..944511e0 100644 --- a/server/backend/rpcserver.go +++ b/server/backend/rpcserver.go @@ -8,8 +8,7 @@ import ( "github.com/TUM-Dev/Campus-Backend/server/env" pb "github.com/TUM-Dev/Campus-Backend/server/api/tumdev" - "github.com/TUM-Dev/Campus-Backend/server/backend/ios_notifications/ios_apns" - "github.com/TUM-Dev/Campus-Backend/server/backend/ios_notifications/ios_apns/ios_apns_jwt" + "github.com/TUM-Dev/Campus-Backend/server/backend/ios_notifications/apns" "github.com/TUM-Dev/Campus-Backend/server/model" log "github.com/sirupsen/logrus" "google.golang.org/grpc" @@ -51,7 +50,7 @@ func New(db *gorm.DB) *CampusServer { } func NewIOSNotificationsService() *IOSNotificationsService { - if err := ios_apns.ValidateRequirementsForIOSNotificationsService(); err != nil { + if err := apns.ValidateRequirementsForIOSNotificationsService(); err != nil { log.WithError(err).Warn("failed to validate requirements for ios notifications service") return &IOSNotificationsService{ @@ -60,7 +59,7 @@ func NewIOSNotificationsService() *IOSNotificationsService { } } - token, err := ios_apns_jwt.NewToken() + token, err := apns.NewToken() if err != nil { log.WithError(err).Error("failed to create new token") } diff --git a/server/model/ios_grade.go b/server/model/ios_grade.go index a4fdb061..48a3cc83 100644 --- a/server/model/ios_grade.go +++ b/server/model/ios_grade.go @@ -4,7 +4,7 @@ import ( "encoding/xml" "time" - "github.com/TUM-Dev/Campus-Backend/server/backend/ios_notifications/ios_crypto" + "github.com/TUM-Dev/Campus-Backend/server/backend/ios_notifications/crypto" ) // IOSGrades is a wrapper for a list of grades => XML stuff @@ -64,12 +64,12 @@ type IOSEncryptedGrade struct { } func (e *IOSEncryptedGrade) Encrypt(key string) error { - encryptedTitle, err := ios_crypto.SymmetricEncrypt(e.LectureTitle, key) + encryptedTitle, err := crypto.SymmetricEncrypt(e.LectureTitle, key) if err != nil { return err } - encryptedGrade, err := ios_crypto.SymmetricEncrypt(e.Grade, key) + encryptedGrade, err := crypto.SymmetricEncrypt(e.Grade, key) if err != nil { return err } @@ -82,12 +82,12 @@ func (e *IOSEncryptedGrade) Encrypt(key string) error { } func (e *IOSEncryptedGrade) Decrypt(key string) error { - decryptedTitle, err := ios_crypto.SymmetricDecrypt(ios_crypto.EncryptedString(e.LectureTitle), key) + decryptedTitle, err := crypto.SymmetricDecrypt(crypto.EncryptedString(e.LectureTitle), key) if err != nil { return err } - decryptedGrade, err := ios_crypto.SymmetricDecrypt(ios_crypto.EncryptedString(e.Grade), key) + decryptedGrade, err := crypto.SymmetricDecrypt(crypto.EncryptedString(e.Grade), key) if err != nil { return err } diff --git a/server/model/ios_remote_notification.go b/server/model/ios_remote_notification.go index 4c7464c9..ee174c50 100644 --- a/server/model/ios_remote_notification.go +++ b/server/model/ios_remote_notification.go @@ -5,7 +5,7 @@ package model import ( "encoding/json" - "github.com/TUM-Dev/Campus-Backend/server/backend/ios_notifications/ios_crypto" + "github.com/TUM-Dev/Campus-Backend/server/backend/ios_notifications/crypto" ) type IOSNotificationPayload struct { @@ -122,7 +122,7 @@ func (np *IOSNotificationPayload) Encrypt(publicKey string) *IOSNotificationPayl np.aps().MutableContent = 1 if alert.Title != "" { - res, err := ios_crypto.AsymmetricEncrypt(alert.Title, publicKey) + res, err := crypto.AsymmetricEncrypt(alert.Title, publicKey) if err != nil { alert.Title = "You have a new notification" @@ -132,7 +132,7 @@ func (np *IOSNotificationPayload) Encrypt(publicKey string) *IOSNotificationPayl } if alert.Body != "" { - res, err := ios_crypto.AsymmetricEncrypt(alert.Body, publicKey) + res, err := crypto.AsymmetricEncrypt(alert.Body, publicKey) if err != nil { alert.Body = "" @@ -142,7 +142,7 @@ func (np *IOSNotificationPayload) Encrypt(publicKey string) *IOSNotificationPayl } if alert.Subtitle != "" { - res, err := ios_crypto.AsymmetricEncrypt(alert.Subtitle, publicKey) + res, err := crypto.AsymmetricEncrypt(alert.Subtitle, publicKey) if err != nil { alert.Subtitle = "" From cb7544912185a6cf51d75362eac2ced7095112f1 Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Fri, 22 Sep 2023 15:53:41 +0200 Subject: [PATCH 6/6] simplified the ios naming more --- .../apns/{ios_apns_repository.go => repository.go} | 0 .../ios_notifications/apns/{ios_apns_service.go => service.go} | 0 .../device/{device_repository.go => repository.go} | 0 .../ios_notifications/device/{device_service.go => service.go} | 0 .../{devices_activity_reset_repository.go => repository.go} | 0 .../{devices_activity_reset_service.go => service.go} | 0 .../{request_response_repository.go => repository.go} | 0 .../request_response/{request_response_service.go => service.go} | 0 .../{scheduled_update_log_repository.go => repository.go} | 0 .../scheduling/{scheduling_repository.go => repository.go} | 0 .../scheduling/{scheduling_service.go => service.go} | 0 11 files changed, 0 insertions(+), 0 deletions(-) rename server/backend/ios_notifications/apns/{ios_apns_repository.go => repository.go} (100%) rename server/backend/ios_notifications/apns/{ios_apns_service.go => service.go} (100%) rename server/backend/ios_notifications/device/{device_repository.go => repository.go} (100%) rename server/backend/ios_notifications/device/{device_service.go => service.go} (100%) rename server/backend/ios_notifications/devices_activity_reset/{devices_activity_reset_repository.go => repository.go} (100%) rename server/backend/ios_notifications/devices_activity_reset/{devices_activity_reset_service.go => service.go} (100%) rename server/backend/ios_notifications/request_response/{request_response_repository.go => repository.go} (100%) rename server/backend/ios_notifications/request_response/{request_response_service.go => service.go} (100%) rename server/backend/ios_notifications/scheduled_update_log/{scheduled_update_log_repository.go => repository.go} (100%) rename server/backend/ios_notifications/scheduling/{scheduling_repository.go => repository.go} (100%) rename server/backend/ios_notifications/scheduling/{scheduling_service.go => service.go} (100%) diff --git a/server/backend/ios_notifications/apns/ios_apns_repository.go b/server/backend/ios_notifications/apns/repository.go similarity index 100% rename from server/backend/ios_notifications/apns/ios_apns_repository.go rename to server/backend/ios_notifications/apns/repository.go diff --git a/server/backend/ios_notifications/apns/ios_apns_service.go b/server/backend/ios_notifications/apns/service.go similarity index 100% rename from server/backend/ios_notifications/apns/ios_apns_service.go rename to server/backend/ios_notifications/apns/service.go diff --git a/server/backend/ios_notifications/device/device_repository.go b/server/backend/ios_notifications/device/repository.go similarity index 100% rename from server/backend/ios_notifications/device/device_repository.go rename to server/backend/ios_notifications/device/repository.go diff --git a/server/backend/ios_notifications/device/device_service.go b/server/backend/ios_notifications/device/service.go similarity index 100% rename from server/backend/ios_notifications/device/device_service.go rename to server/backend/ios_notifications/device/service.go diff --git a/server/backend/ios_notifications/devices_activity_reset/devices_activity_reset_repository.go b/server/backend/ios_notifications/devices_activity_reset/repository.go similarity index 100% rename from server/backend/ios_notifications/devices_activity_reset/devices_activity_reset_repository.go rename to server/backend/ios_notifications/devices_activity_reset/repository.go diff --git a/server/backend/ios_notifications/devices_activity_reset/devices_activity_reset_service.go b/server/backend/ios_notifications/devices_activity_reset/service.go similarity index 100% rename from server/backend/ios_notifications/devices_activity_reset/devices_activity_reset_service.go rename to server/backend/ios_notifications/devices_activity_reset/service.go diff --git a/server/backend/ios_notifications/request_response/request_response_repository.go b/server/backend/ios_notifications/request_response/repository.go similarity index 100% rename from server/backend/ios_notifications/request_response/request_response_repository.go rename to server/backend/ios_notifications/request_response/repository.go diff --git a/server/backend/ios_notifications/request_response/request_response_service.go b/server/backend/ios_notifications/request_response/service.go similarity index 100% rename from server/backend/ios_notifications/request_response/request_response_service.go rename to server/backend/ios_notifications/request_response/service.go diff --git a/server/backend/ios_notifications/scheduled_update_log/scheduled_update_log_repository.go b/server/backend/ios_notifications/scheduled_update_log/repository.go similarity index 100% rename from server/backend/ios_notifications/scheduled_update_log/scheduled_update_log_repository.go rename to server/backend/ios_notifications/scheduled_update_log/repository.go diff --git a/server/backend/ios_notifications/scheduling/scheduling_repository.go b/server/backend/ios_notifications/scheduling/repository.go similarity index 100% rename from server/backend/ios_notifications/scheduling/scheduling_repository.go rename to server/backend/ios_notifications/scheduling/repository.go diff --git a/server/backend/ios_notifications/scheduling/scheduling_service.go b/server/backend/ios_notifications/scheduling/service.go similarity index 100% rename from server/backend/ios_notifications/scheduling/scheduling_service.go rename to server/backend/ios_notifications/scheduling/service.go