diff --git a/server/backend/movie.go b/server/backend/movie.go index e692b0c6..2e6f7df4 100644 --- a/server/backend/movie.go +++ b/server/backend/movie.go @@ -13,7 +13,7 @@ import ( func (s *CampusServer) ListMovies(ctx context.Context, req *pb.ListMoviesRequest) (*pb.ListMoviesReply, error) { var movies []model.Kino - tx := s.db.WithContext(ctx).Joins("File") + tx := s.db.WithContext(ctx).Joins("File").Order("date DESC") if req.OldestDateAt.GetSeconds() != 0 || req.OldestDateAt.GetNanos() != 0 { tx = tx.Where("date > ?", req.OldestDateAt.AsTime()) } diff --git a/server/backend/movie_test.go b/server/backend/movie_test.go index 5144a6cb..04f9b00d 100644 --- a/server/backend/movie_test.go +++ b/server/backend/movie_test.go @@ -3,6 +3,7 @@ package backend import ( "context" "database/sql" + "regexp" "testing" "time" @@ -77,11 +78,11 @@ var ( } ) -const ListMoviesQuery = "SELECT `kino`.`kino`,`kino`.`date`,`kino`.`created`,`kino`.`title`,`kino`.`year`,`kino`.`runtime`,`kino`.`genre`,`kino`.`director`,`kino`.`actors`,`kino`.`rating`,`kino`.`description`,`kino`.`trailer`,`kino`.`cover`,`kino`.`link`,`kino`.`location`,`File`.`file` AS `File__file`,`File`.`name` AS `File__name`,`File`.`path` AS `File__path`,`File`.`downloads` AS `File__downloads`,`File`.`url` AS `File__url`,`File`.`downloaded` AS `File__downloaded` FROM `kino` LEFT JOIN `files` `File` ON `kino`.`cover` = `File`.`file` WHERE kino > ?" +const ListMoviesQuery = "SELECT `kino`.`kino`,`kino`.`date`,`kino`.`created`,`kino`.`title`,`kino`.`year`,`kino`.`runtime`,`kino`.`genre`,`kino`.`director`,`kino`.`actors`,`kino`.`rating`,`kino`.`description`,`kino`.`trailer`,`kino`.`cover`,`kino`.`link`,`kino`.`location`,`File`.`file` AS `File__file`,`File`.`name` AS `File__name`,`File`.`path` AS `File__path`,`File`.`downloads` AS `File__downloads`,`File`.`url` AS `File__url`,`File`.`downloaded` AS `File__downloaded` FROM `kino` LEFT JOIN `files` `File` ON `kino`.`cover` = `File`.`file` WHERE kino > ? ORDER BY date DESC" func (s *MovieSuite) Test_ListMoviesAll() { server := CampusServer{db: s.DB} - s.mock.ExpectQuery(ListMoviesQuery). + s.mock.ExpectQuery(regexp.QuoteMeta(ListMoviesQuery)). WithArgs(-1). WillReturnRows(sqlmock.NewRows([]string{"kino", "date", "created", "title", "year", "runtime", "genre", "director", "actors", "rating", "description", "trailer", "cover", "link", "location", "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.AdditionalInformationUrl, movie2.Location, movie2.CoverId, "mission_impossible_5.jpg", "movie/", 1, "", 1). @@ -93,7 +94,7 @@ func (s *MovieSuite) Test_ListMoviesAll() { func (s *MovieSuite) Test_ListMoviesOne() { server := CampusServer{db: s.DB} - s.mock.ExpectQuery(ListMoviesQuery). + s.mock.ExpectQuery(regexp.QuoteMeta(ListMoviesQuery)). WithArgs(1). WillReturnRows(sqlmock.NewRows([]string{"kino", "date", "created", "title", "year", "runtime", "genre", "director", "actors", "rating", "description", "trailer", "cover", "link", "location", "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.AdditionalInformationUrl, movie1.Location, movie1.CoverId, "mission_impossible_4.jpg", "movie/", 1, "", 1)) @@ -104,7 +105,7 @@ func (s *MovieSuite) Test_ListMoviesOne() { func (s *MovieSuite) Test_ListMoviesNone() { server := CampusServer{db: s.DB} - s.mock.ExpectQuery(ListMoviesQuery). + s.mock.ExpectQuery(regexp.QuoteMeta(ListMoviesQuery)). WithArgs(42). WillReturnRows(sqlmock.NewRows([]string{"kino", "date", "created", "title", "year", "runtime", "genre", "director", "actors", "rating", "description", "trailer", "cover", "link", "location", "File__file", "File__name", "File__path", "File__downloads", "File__url", "File__downloaded"})) response, err := server.ListMovies(context.Background(), &pb.ListMoviesRequest{LastId: 42})