Skip to content

Commit

Permalink
PostTestAPI
Browse files Browse the repository at this point in the history
  • Loading branch information
sleeg00 committed Jul 15, 2023
1 parent 6d7210f commit 5265b10
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,15 @@ public ResponseEntity<Post> createPost(Authentication authentication,
return postService.createPost(authentication, postsDTO, file);
}

@PostMapping(value = "/post/test/posts")
@Operation(summary = "글 작성 Test API", description = "api/post/posts랑 같지만 File을 안 넘겨도 글을 쓸수 있습니다!\n"+"" +
"즉 Readme없어도 됨 내가 테스트 할려고 만듬..")
public ResponseEntity<Post> createPost(Authentication authentication,
@ModelAttribute PostsDTO postsDTO) throws IOException, TranscoderException {

// Post 작성 서비스 호출
return postService.createPostTest(authentication, postsDTO);
}


@Operation(summary = "모든 사용자의 전체 글을 조회하는 API")
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/com/example/Pick_Read_Me/Service/PostService.java
Original file line number Diff line number Diff line change
Expand Up @@ -391,4 +391,30 @@ public String extractImageUrlsFromHtml(String html, String repoName) {
}


public ResponseEntity<Post> createPostTest(Authentication authentication, PostsDTO postsDTO) {
log.info(String.valueOf(authentication));
Long github_id = Long.valueOf(authentication.getName());
Member member = memberRepository.findById(Long.valueOf(github_id))
.orElseThrow(() -> new MemberNotFoundException("Member not found with id: " + github_id));


if (postsDTO.getTitle() == null || postsDTO.getTitle().isEmpty())
return ResponseEntity.badRequest().body(null);

Post post = new Post();
post.setContent(postsDTO.getContent());
post.setTitle(postsDTO.getTitle());
post.setPostCreatedAt(new Date());
post.setPostUpdatedAt(new Date());
post.setRepo(postsDTO.getRepo());
post.setPost_like(0L);
post.setMember(member);

member.getPosts().add(post);

postRepository.save(post);
memberRepository.save(member);

return ResponseEntity.ok().body(post);
}
}

0 comments on commit 5265b10

Please sign in to comment.