Eh jsp j'ai fais des trucs
This commit is contained in:
parent
eb2f3bf151
commit
f41c830970
@ -76,6 +76,12 @@ public class AuthorController {
|
||||
.setPassword("");
|
||||
}
|
||||
|
||||
@GetMapping("/{id}/avatar")
|
||||
public byte[] getProfilePicture(@PathVariable UUID id) {
|
||||
Author author = authorService.findById(id).orElseThrow(() -> new NotFoundException("Author not found"));
|
||||
return author.getProfilePicture();
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public void deleteUser(@PathVariable UUID id, Authentication authentication) {
|
||||
Author authorToDelete = authorService.verifyIfUserIsAuthorized(authentication, id);
|
||||
|
@ -9,6 +9,7 @@ import com.guams.review.service.AuthorService;
|
||||
import com.guams.review.service.CommentService;
|
||||
import com.guams.review.service.PostService;
|
||||
import com.guams.review.service.mapper.Mapper;
|
||||
import com.guams.review.model.dao.PostWithAuthor;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
@ -39,6 +40,11 @@ public class PostController {
|
||||
return postService.list();
|
||||
}
|
||||
|
||||
@GetMapping("authors")
|
||||
public List<PostWithAuthor> listPostsWithAuthor() {
|
||||
return postService.listWithAuthors();
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public Post findPost(@PathVariable Long id) {
|
||||
return postService.findById(id).orElseThrow(() -> new NotFoundException("Post not found"));
|
||||
|
@ -31,7 +31,7 @@ public interface CommentRepository extends CrudRepository<Comment, Long> {
|
||||
" JOIN comment_association ca ON ca.comment_fk = c.id" +
|
||||
" JOIN post p ON p.id = ca.post_fk" +
|
||||
" JOIN author a ON ca.author_fk = a.id" +
|
||||
" WHERE p.id = 3")
|
||||
" WHERE p.id = :postId")
|
||||
List<CommentWithAuthor> getCommentsByPostId(Long postId);
|
||||
|
||||
@Modifying
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.guams.review.model;
|
||||
|
||||
import com.guams.review.model.dao.Post;
|
||||
import com.guams.review.model.dao.PostWithAuthor;
|
||||
import org.springframework.data.jdbc.repository.query.Query;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
@ -15,5 +16,24 @@ public interface PostRepository extends CrudRepository<Post, Long> {
|
||||
"from post join publication on post.id=publication.post_fk where publication.author_fk=:authorId")
|
||||
List<Post> findPostsOfAuthor(UUID authorId);
|
||||
|
||||
|
||||
@Query(value = "SELECT " +
|
||||
" a.id AS author_id, " +
|
||||
" a.name AS author_name, " +
|
||||
" a.profile_picture AS author_profile_picture, " +
|
||||
" a.role AS role, " +
|
||||
" p.id AS post_id, " +
|
||||
" p.description AS post_description, " +
|
||||
" p.illustration AS post_illustration, " +
|
||||
" p.title AS post_title, " +
|
||||
" p.body AS post_body, " +
|
||||
" p.category AS post_category, " +
|
||||
" p.publication_date AS post_publication_date, " +
|
||||
" p.is_updated AS post_is_updated " +
|
||||
"FROM post p " +
|
||||
" JOIN publication pub ON p.id = pub.post_fk " +
|
||||
" JOIN author a ON pub.author_fk = a.id;")
|
||||
List<PostWithAuthor> findPostsWithAuthors();
|
||||
|
||||
List<Post> findAll();
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ public class CommentWithAuthor {
|
||||
private Long id;
|
||||
private UUID authorId;
|
||||
private String authorName;
|
||||
private String profilePicture;
|
||||
private byte[] profilePicture;
|
||||
private String authorRole;
|
||||
private String content;
|
||||
private Timestamp commentDate;
|
||||
|
26
src/main/java/com/guams/review/model/dao/PostWithAuthor.java
Normal file
26
src/main/java/com/guams/review/model/dao/PostWithAuthor.java
Normal file
@ -0,0 +1,26 @@
|
||||
package com.guams.review.model.dao;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.UUID;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Accessors(chain = true)
|
||||
public class PostWithAuthor {
|
||||
private UUID authorId;
|
||||
private String authorName;
|
||||
private byte[] authorProfilePicture;
|
||||
private String role;
|
||||
private Long postId;
|
||||
private String postDescription;
|
||||
private byte[] postIllustration;
|
||||
private String postTitle;
|
||||
private String postBody;
|
||||
private String postCategory;
|
||||
private Timestamp postPublicationDate;
|
||||
private Boolean postIsUpdated;
|
||||
}
|
@ -4,6 +4,7 @@ package com.guams.review.service;
|
||||
import com.guams.review.model.AuthorRepository;
|
||||
import com.guams.review.model.dao.Post;
|
||||
import com.guams.review.model.PostRepository;
|
||||
import com.guams.review.model.dao.PostWithAuthor;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@ -27,6 +28,10 @@ public class PostService
|
||||
return postRepository.findById(id);
|
||||
}
|
||||
|
||||
public List<PostWithAuthor> listWithAuthors() {
|
||||
return postRepository.findPostsWithAuthors();
|
||||
}
|
||||
|
||||
public Post insert(Post post) {
|
||||
return postRepository.save(post);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user