Skip to content

Commit

Permalink
added find by partial title posts and lists and partial username for …
Browse files Browse the repository at this point in the history
…users

updated docs
  • Loading branch information
prymakD committed Jan 10, 2024
1 parent 96fdc24 commit a164ee0
Show file tree
Hide file tree
Showing 14 changed files with 75 additions and 16 deletions.
Binary file added Documentation/Swagger.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ Info about API endpoints, request/response examples, and any required headers ge
by ```{hostname}/swagger-ui.html ```

MVP pattern is used.

![Swagger.png](Documentation%2FSwagger.png)
### Database Schema

MySql is used. DB script can be found in [DbScript](Documentation/DB_and_UI_prototypes/DbScript)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ public ResponseEntity<ParsList> getMovieList(@RequestParam("idMovieList") Long i
return movieListService.getList(idMovieList);
}

@ApiOperation(value = "Get movie list by title", notes = "Returns a list of movies that matches the title if it doesn't match it's empty list")
@ApiOperation(value = "Get movie list by partial title", notes = "Returns a list of movies that matches the title if it doesn't match it's empty list")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Successfully retrieved movie list"),
})
@GetMapping("/get/title")
public ResponseEntity<?> getMovieListByTitle(@RequestParam("idMovieList") String title) {
return movieListService.getAllByTitle(title);
public ResponseEntity<?> getMovieListByPartialTitle(@RequestParam("idMovieList") String title) {
return movieListService.getAllByPartialTitle(title);
}

@ApiOperation(value = "Add or delete movie from list", notes = "Adds or deletes a movie from the specified movie list")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,14 @@ public ResponseEntity<List<ParsPost>> getAllPostByUser() {
}


// @ApiOperation(value = "Get post by title", notes = "Returns a post that matches the title if it doesn't match it's empty post")
// @ApiResponses(value = {
// @ApiResponse(code = 200, message = "Successfully retrieved post"),
// })
// @GetMapping("/getByTitle")
// public ResponseEntity<?> getPostByTitle(@RequestParam("title") String title) {
// return postService.getAllByTitle(title);
// }
@ApiOperation(value = "Get post by title", notes = "Returns a post that matches the title")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Successfully retrieved post"),
})
@GetMapping("/get/title")
public ResponseEntity<?> getPostByPartialTitle(@RequestParam("title") String title) {
return postService.getAllByPartialTitle(title);
}
@ApiOperation(value = "Like or dislike post", notes = "Likes or dislikes the specified post")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Successfully liked or disliked post"),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.moviePocket.controller.user;

import com.moviePocket.controller.dto.UserPostDto;
import com.moviePocket.entities.user.ParsUserPage;
import com.moviePocket.entities.user.User;
import com.moviePocket.service.inter.list.MovieListService;
Expand All @@ -16,6 +17,8 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequiredArgsConstructor
@RestController
@RequestMapping("/user")
Expand Down Expand Up @@ -71,4 +74,9 @@ public ResponseEntity<ParsUserPage> getUserByUsername(@PathVariable String usern
);
return new ResponseEntity<>(parsUserPage, HttpStatus.OK);
}

@GetMapping("/{partialUsername}")
public ResponseEntity<List<UserPostDto>> getUsersByPartialUsername(@PathVariable String username) {
return userService.findByPartialUsername(username);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public interface MovieListRepository extends JpaRepository<ListMovie, Long> {
List<ListMovie> findAllByUser(User user);

@Query("SELECT m FROM ListMovie m WHERE m.title LIKE :title%")
List<ListMovie> findAllByTitle(String title);
List<ListMovie> findAllByPartialTitle(String title);

@Query("SELECT lm FROM ListMovie lm JOIN lm.movies movie WHERE movie.id = :idMovie")
List<ListMovie> findAllByidMovie(@Param("idMovie") Long idMovie);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.moviePocket.entities.user.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;
Expand All @@ -30,4 +31,6 @@ public interface PostRepository extends JpaRepository<Post, Long> {
"ORDER BY likeCount DESC")
List<Post> findTop10LikedPosts();

@Query("SELECT u FROM Post u WHERE u.title LIKE :partialTitle%")
List<Post> findAllByPartialTitle(@Param("partialTitle") String partialTitle);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@

import com.moviePocket.entities.user.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface UserRepository extends JpaRepository<User, Long> {
User findByEmail(String mail);
boolean existsByUsername(String username);
boolean existsByEmail(String email);
User findByUsernameAndAccountActive(String username, boolean isActive);

@Query("SELECT u FROM User u WHERE u.username LIKE :partialUsername%")
List<User> findByPartialUsername(@Param("partialUsername") String partialUsername);
}
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,17 @@ public ResponseEntity<List<ParsList>> getAllByUsernameList(String username) {
}
}

public ResponseEntity<List<ParsList>> getAllByTitle(String title) {
List<ListMovie> movieLists = movieListRepository.findAllByTitle(title);
return ResponseEntity.ok(parsLists(movieLists));
public ResponseEntity<List<ParsList>> getAllByPartialTitle(String title) {
if (title.equals(""))
return ResponseEntity.ok(null);
List<ListMovie> movieLists = movieListRepository.findAllByPartialTitle(title);
List<ParsList> parsLists = new ArrayList<>();
for (ListMovie list : movieLists) {
parsLists.add(parsListWithMovies(list));
}
if (movieLists == null )
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
return ResponseEntity.ok(parsLists);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,16 @@ public ResponseEntity<List<ParsPost>> getAllByTitle(String title) {
return ResponseEntity.ok(parsPost(posts));
}

@Override
public ResponseEntity<List<ParsPost>> getAllByPartialTitle(String title) {
if (title.equals(""))
return ResponseEntity.ok(null);
List<Post> posts = postRepository.findAllByPartialTitle(title);
if (posts == null )
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
return ResponseEntity.ok(parsPost(posts));
}

@Override
public ResponseEntity<ParsPost> getPost(Long idPost) {
if (postRepository.existsById(idPost)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.moviePocket.service.impl.user;

import com.moviePocket.controller.dto.UserPostDto;
import com.moviePocket.controller.dto.UserRegistrationDto;
import com.moviePocket.entities.image.ImageEntity;
import com.moviePocket.entities.user.*;
Expand All @@ -21,6 +22,7 @@
import javax.mail.MessagingException;
import javax.transaction.Transactional;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -248,6 +250,19 @@ public ResponseEntity<Void> resetPassword(String token, String password) {
}
}

@Override
public ResponseEntity<List<UserPostDto>> findByPartialUsername(String username) {
if (username.equals(""))
return ResponseEntity.ok(null);
List<User> users = userRepository.findByPartialUsername(username);
if (users == null)
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
List<UserPostDto> userPostDtos = users.stream()
.map(user -> new UserPostDto(user.getUsername(), user.getAvatar() != null ? user.getAvatar().getId() : null))
.collect(Collectors.toList());
return ResponseEntity.ok(userPostDtos);
}

private void sendEmail(User user, String token) throws MessagingException {
String username = user.getUsername();
String link = "https://moviepocket.projektstudencki.pl/newPassword?token=" + token;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public interface MovieListService {

ResponseEntity<Void> deleteList(String email, Long idMovieList);

ResponseEntity<List<ParsList>> getAllByTitle(String title);
ResponseEntity<List<ParsList>> getAllByPartialTitle(String title);

ResponseEntity<ParsList> getList(Long idMovieList);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,7 @@ public interface PostService {

ResponseEntity<List<ParsPost>> getTop10LikedPosts();

ResponseEntity<List<ParsPost>> getAllByPartialTitle(String title);


}
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.moviePocket.service.inter.user;

import com.moviePocket.controller.dto.UserPostDto;
import com.moviePocket.controller.dto.UserRegistrationDto;
import com.moviePocket.entities.user.User;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.web.multipart.MultipartFile;

import javax.mail.MessagingException;
import java.util.List;

public interface UserService extends UserDetailsService {
void save(UserRegistrationDto registrationDto) throws MessagingException;
Expand Down Expand Up @@ -45,4 +47,6 @@ public interface UserService extends UserDetailsService {

ResponseEntity<Void> resetPassword(String token, String password);

ResponseEntity<List<UserPostDto>> findByPartialUsername(String username);

}

0 comments on commit a164ee0

Please sign in to comment.