From ea50bfe05ce657ce58cb9e3a26ede85bb5514c37 Mon Sep 17 00:00:00 2001 From: Danila Date: Wed, 10 Jan 2024 00:08:31 +0100 Subject: [PATCH 1/2] added get by username posts --- .../controller/post/PostController.java | 58 +++++++++++-------- .../repository/user/UserRepository.java | 6 ++ 2 files changed, 40 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/moviePocket/controller/post/PostController.java b/src/main/java/com/moviePocket/controller/post/PostController.java index c706f57..258ca5a 100644 --- a/src/main/java/com/moviePocket/controller/post/PostController.java +++ b/src/main/java/com/moviePocket/controller/post/PostController.java @@ -98,22 +98,22 @@ public ResponseEntity getPost(@RequestParam("idPost") Long idPost) { } @GetMapping("/movie") - public ResponseEntity> getAllPostByIdMovie(@RequestParam("idMovie") Long idMovie) { + public ResponseEntity> getAllPostsByIdMovie(@RequestParam("idMovie") Long idMovie) { return postService.getAllByIdMovie(idMovie); } @GetMapping("/list") - public ResponseEntity> getAllPostByIdList(@RequestParam("idList") Long idList) { + public ResponseEntity> getAllPostsByIdList(@RequestParam("idList") Long idList) { return postService.getAllByIdList(idList); } @GetMapping("/person") - public ResponseEntity> getAllPostByIdPerson(@RequestParam("idPerson") Long idPerson) { + public ResponseEntity> getAllPostsByIdPerson(@RequestParam("idPerson") Long idPerson) { return postService.getAllByIdPerson(idPerson); } @GetMapping("/user") - public ResponseEntity> getAllPostByUser() { + public ResponseEntity> getAllMyPosts() { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); return postService.getAllByUser(authentication.getName()); } @@ -162,17 +162,17 @@ public ResponseEntity getAuthorshipByIdPost(@RequestParam("idPost") Lon // return postService.getAllMyPosts(authentication.getName()); // } // -// @ApiOperation(value = "Get all posts of user", notes = "Returns a list of all posts for the specified username") -// @ApiResponses(value = { -// @ApiResponse(code = 200, message = "Successfully retrieved all posts for specified username"), -// @ApiResponse(code = 400, message = "Invalid username"), -// @ApiResponse(code = 404, message = "User not found") -// }) -// @GetMapping("/getAllUserPosts") -// public ResponseEntity> getAllUsername(@RequestParam("username") String username) { -// return postService.getAllByUsernamePosts(username); -// } -// +@ApiOperation(value = "Get all posts of user", notes = "Returns a list of all posts for the specified username") +@ApiResponses(value = { + @ApiResponse(code = 200, message = "Successfully retrieved all posts for specified username"), + @ApiResponse(code = 401, message = "Invalid username") +}) +@GetMapping("/someUser") +public ResponseEntity> getAllByUsername(@RequestParam("username") String username) { + return postService.getAllByUsernamePosts(username); +} + + // // @ApiOperation(value = "Get the most recent posts", notes = "Returns a sorted list of posts from newest to oldest") // @ApiResponses(value = { // @ApiResponse(code = 200, message = "Successfully retrieved all posts "), @@ -224,13 +224,23 @@ public ResponseEntity getAllLikePostsByIdMovie(@RequestParam("idPost") // return likePostService.getLeastLikedPosts(); // } - @GetMapping("/get/last") - public ResponseEntity> getLast() { - return postService.getTop10LatestPosts(); - } - - @GetMapping("/get/top") - public ResponseEntity> getTop() { - return postService.getTop10LikedPosts(); - } +// @ApiOperation(value = "Get the least liked(popular) posts", notes = "Returns a sorted list of posts from most least to liked") +// @ApiResponses(value = { +// @ApiResponse(code = 200, message = "Successfully retrieved all posts "), +// @ApiResponse(code = 404, message = "Not found") +// }) +// @GetMapping("/getLeastLikedPosts") +// public ResponseEntity> getLeastLikedPosts() { +// return likePostService.getLeastLikedPosts(); +// } +// +// @GetMapping("/get/latest3Posts") +// public ResponseEntity> getLatest3Posts() { +// return postService.getTop10LatestPosts(); +// } +// +// @GetMapping("/get/top3Liked") +// public ResponseEntity> getTop3LikedPosts() { +// return postService.getTop3LikedPosts(); +// } } diff --git a/src/main/java/com/moviePocket/repository/user/UserRepository.java b/src/main/java/com/moviePocket/repository/user/UserRepository.java index 2d15dcc..7a51bbb 100644 --- a/src/main/java/com/moviePocket/repository/user/UserRepository.java +++ b/src/main/java/com/moviePocket/repository/user/UserRepository.java @@ -6,8 +6,14 @@ @Repository public interface UserRepository extends JpaRepository { + User findByEmail(String mail); + boolean existsByUsername(String username); + boolean existsByEmail(String email); + User findByUsernameAndAccountActive(String username, boolean isActive); + + User findByUsername(String username); } From fb49df4aa743de8c10c9356c9d76e7d54fb7084b Mon Sep 17 00:00:00 2001 From: Danila Date: Wed, 10 Jan 2024 09:17:27 +0100 Subject: [PATCH 2/2] minor fix --- .../controller/post/PostController.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/moviePocket/controller/post/PostController.java b/src/main/java/com/moviePocket/controller/post/PostController.java index 258ca5a..4110c5b 100644 --- a/src/main/java/com/moviePocket/controller/post/PostController.java +++ b/src/main/java/com/moviePocket/controller/post/PostController.java @@ -234,13 +234,13 @@ public ResponseEntity getAllLikePostsByIdMovie(@RequestParam("idPost") // return likePostService.getLeastLikedPosts(); // } // -// @GetMapping("/get/latest3Posts") -// public ResponseEntity> getLatest3Posts() { -// return postService.getTop10LatestPosts(); -// } -// -// @GetMapping("/get/top3Liked") -// public ResponseEntity> getTop3LikedPosts() { -// return postService.getTop3LikedPosts(); -// } +@GetMapping("/get/last") +public ResponseEntity> getLast() { + return postService.getTop10LatestPosts(); +} + + @GetMapping("/get/top") + public ResponseEntity> getTop() { + return postService.getTop10LikedPosts(); + } }