Skip to content

Commit

Permalink
Merge pull request #53 from olmangjolmang/#52-post-api-separation
Browse files Browse the repository at this point in the history
#52 post api separation
  • Loading branch information
chaeyeonKong authored Jul 24, 2024
2 parents 0956a90 + 9852363 commit fe80c2c
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.ticle.server.post.domain.type.PostSort;
import com.ticle.server.post.dto.PostResponse;
import com.ticle.server.post.dto.QuizResponse;
import com.ticle.server.post.dto.ReadRecommendPost;
import com.ticle.server.post.service.PostService;
import com.ticle.server.scrapped.domain.Scrapped;
import com.ticle.server.scrapped.dto.ScrappedDto;
Expand Down Expand Up @@ -49,7 +50,6 @@ public ResponseEntity<ResponseTemplate<Object>> getArticle(
return ResponseEntity
.status(HttpStatus.OK)
.body(ResponseTemplate.from(postPage));

}

//특정 아티클 조회
Expand All @@ -60,8 +60,19 @@ public ResponseEntity<ResponseTemplate<Object>> getArticleDetail(@PathVariable l

return ResponseEntity
.status(HttpStatus.OK)
.body(ResponseTemplate.from(PostResponse.from((Post) post)));
.body(ResponseTemplate.from(PostResponse.from(post)));
}


//함께 읽으면 좋을 아티클 추천
@Operation(summary = "함께 읽으면 좋을 아티클 추천", description = "함께 읽으면 좋을 아티클 추천")
@GetMapping("/recommend/{id}")
public ResponseEntity<ResponseTemplate<Object>> ReadRecommendPost(@PathVariable long id) {
Post post = postService.ArticleReadRecommend(id);

return ResponseEntity
.status(HttpStatus.OK)
.body(ResponseTemplate.from(ReadRecommendPost.from(post)));
}

@Operation(summary = "아티클 스크랩", description = "새로운 아티클 스크랩, 스크랩 취소")
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/ticle/server/post/dto/PostResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class PostResponse {
private Date createdDate;
private Category postCategory;
private S3Info image;
private List recommendPost;
// private List recommendPost;

public static PostResponse from(Post post) {
return new PostResponse(
Expand All @@ -34,8 +34,8 @@ public static PostResponse from(Post post) {
post.getAuthor(),
post.getCreatedDate(),
post.getCategory(),
post.getImage(),
post.getRecommendPost()
post.getImage()
// post.getRecommendPost()
);
}
}
21 changes: 21 additions & 0 deletions src/main/java/com/ticle/server/post/dto/ReadRecommendPost.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.ticle.server.post.dto;

import com.ticle.server.post.domain.Post;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.List;

@Getter
@AllArgsConstructor
@NoArgsConstructor
public class ReadRecommendPost {
private List recommendPost;

public static ReadRecommendPost from(Post post) {
return new ReadRecommendPost(
post.getRecommendPost());
}

}
10 changes: 10 additions & 0 deletions src/main/java/com/ticle/server/post/service/PostService.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ public Post findArticleById(Long id) {
Optional<Post> optionalPost = postRepository.findById(id);
Post post = optionalPost.orElseThrow(() -> new IllegalArgumentException("Post not found with ID: " + id));

return post;
}

//post id별 함께 읽으면 좋을 아티클 추천
public Post ArticleReadRecommend(Long id) {

Optional<Post> optionalPost = postRepository.findById(id);
Post post = optionalPost.orElseThrow(() -> new IllegalArgumentException("Post not found with ID: " + id));

String now_post_title = post.getTitle();
List<PostIdTitleDto> alltitle = postRepository.findAllPostSummaries();

Expand Down Expand Up @@ -101,6 +110,7 @@ public Post findArticleById(Long id) {
return post;
}


public Object scrappedById(long id, CustomUserDetails customUserDetails) {

// 게시물 조회
Expand Down

0 comments on commit fe80c2c

Please sign in to comment.