diff --git a/schema.js b/schema.js index 39e6510..1c42c5d 100644 --- a/schema.js +++ b/schema.js @@ -42,7 +42,7 @@ var video3 = db.videos.insertOne({ "publishDate": "2010-07-16", "category": category1, "views": 150, - "favoritedBy": [user1, user2] + "favoritedBy": null }).insertedId; var video4 = db.videos.insertOne({ @@ -58,5 +58,5 @@ var video4 = db.videos.insertOne({ // Update the users documents with the _id fields of the videos documents -db.users.updateOne({ "_id": user1 }, { "$set": { "favorites": [video1] } }); -db.users.updateOne({ "_id": user2 }, { "$set": { "favorites": [video2] } }); \ No newline at end of file +db.users.updateOne({ "_id": user1 }, { "$set": { "favorites": [video1, video4] } }); +db.users.updateOne({ "_id": user2 }, { "$set": { "favorites": [video2, video4] } }); \ No newline at end of file diff --git a/src/main/java/com/postech30/movies/controller/VideoController.java b/src/main/java/com/postech30/movies/controller/VideoController.java index 66b9d4d..8f222e5 100644 --- a/src/main/java/com/postech30/movies/controller/VideoController.java +++ b/src/main/java/com/postech30/movies/controller/VideoController.java @@ -73,7 +73,7 @@ public Flux getVideoByPublishDate(@PathVariable("publishDate") LocalDa @ApiResponse(responseCode = "422", description = "Parâmetro não pode ser nulo")}) @GetMapping(value = "category/{category}") public Flux getVideoByCategory(@PathVariable("category") String category) { - return videoService.getVideoByCategory(category); + return videoService.getVideosByCategory(category); } @Operation(summary = "Salva um vídeo", description = "Salva um vídeo na base de dados do sistema.") diff --git a/src/main/java/com/postech30/movies/dto/VideoDTO.java b/src/main/java/com/postech30/movies/dto/VideoDTO.java index 08f8443..599358f 100644 --- a/src/main/java/com/postech30/movies/dto/VideoDTO.java +++ b/src/main/java/com/postech30/movies/dto/VideoDTO.java @@ -45,10 +45,4 @@ public class VideoDTO { @JsonProperty private String category; - @JsonProperty - private String categoryName; - - @JsonProperty - private String categoryDescription; - } diff --git a/src/main/java/com/postech30/movies/entity/Video.java b/src/main/java/com/postech30/movies/entity/Video.java index f0eae45..24e2440 100644 --- a/src/main/java/com/postech30/movies/entity/Video.java +++ b/src/main/java/com/postech30/movies/entity/Video.java @@ -25,8 +25,6 @@ public class Video { private String url; private LocalDate publishDate; private Integer views; - private String category; private List favoritedBy; - private String categoryName; - private String categoryDescription; + private ObjectId category; } diff --git a/src/main/java/com/postech30/movies/mapper/VideoMapper.java b/src/main/java/com/postech30/movies/mapper/VideoMapper.java index 2313927..b914b04 100644 --- a/src/main/java/com/postech30/movies/mapper/VideoMapper.java +++ b/src/main/java/com/postech30/movies/mapper/VideoMapper.java @@ -21,8 +21,7 @@ public static VideoDTO mapToVideoDTO(Video video) { video.getFavoritedBy().stream() .map(ObjectId::toHexString) .collect(Collectors.toList()) : null) - .categoryName(video.getCategoryName()) - .categoryDescription(video.getCategoryDescription()) + .category(video.getCategory() != null ? video.getCategory().toHexString() : null) .build(); } @@ -34,13 +33,11 @@ public static Video mapToVideo(VideoDTO videoDTO) { videoDTO.getUrl(), videoDTO.getPublishDate(), videoDTO.getViews(), - videoDTO.getCategory(), videoDTO.getFavoritedBy() != null ? videoDTO.getFavoritedBy().stream() .map(ObjectId::new) .collect(Collectors.toList()) : null, - videoDTO.getCategoryName(), - videoDTO.getCategoryDescription() + videoDTO.getCategory() != null ? new ObjectId(videoDTO.getCategory()) : null ); } } diff --git a/src/main/java/com/postech30/movies/repository/VideoRepository.java b/src/main/java/com/postech30/movies/repository/VideoRepository.java index 82e82e8..11d9bf5 100644 --- a/src/main/java/com/postech30/movies/repository/VideoRepository.java +++ b/src/main/java/com/postech30/movies/repository/VideoRepository.java @@ -20,7 +20,7 @@ public interface VideoRepository extends ReactiveMongoRepository Flux