-
Notifications
You must be signed in to change notification settings - Fork 13
Feat/week 3 #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
scholar-star
wants to merge
20
commits into
ApptiveDev:main
Choose a base branch
from
scholar-star:feat/week-3
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Feat/week 3 #26
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
b1dbd49
Controller, Service, Repository 기초 작업 완료
scholar-star 1e63d38
CRUD 기능 구현 완료
scholar-star 43cb730
EntityNotFoundException handler 추가, findByName 수정
scholar-star 299dc06
DataAccessException(SQL) 관련 handler 추가
scholar-star ac326f8
update/delete의 Postbody로 id를 포함하여 보내던 부분을 @PathVariable로 리팩토링
scholar-star a24b3aa
기존 수정사항 반영, Entity와 Controller, Service 토대 만들기
scholar-star 676e68d
Controller와 Service get, create 진행, Entity에 Join 연결
scholar-star 7b94fda
Controller와 Service get, create 진행, Entity에 Join 연결
scholar-star 7b53c52
User Entity 추가, Reply에 Post와 User의 의존 관계 연결
scholar-star 90ce723
service, controller 토대 만들기
scholar-star 3df566e
GlobalExceptionHandler로 예외 처리 옮기기, Controller 기본 채워넣기
scholar-star 7fe66e9
ReplyRepository findby 형태 변경(postId->Posts), 오류 해결
scholar-star 5f6e179
Post 리팩토링
scholar-star bb8aaf7
Post, Reply Like 추가
scholar-star 0ba9159
좋아요 기능 추가 Test 완료
scholar-star 6bb6db2
좋아요 기능 추가 Test
scholar-star 39a61b6
Revert "좋아요 기능 추가 Test"
scholar-star e52f1a2
수정사항 반영 첫 번째
scholar-star b759e4b
수정사항 반영 두 번째
scholar-star 3042d2a
Post 검색 기능 추가
scholar-star File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
src/main/java/com/example/devSns/controllers/PostController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| package com.example.devSns.controllers; | ||
|
|
||
| import com.example.devSns.dto.PostDTO; | ||
| import com.example.devSns.dto.PostResponse; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.http.HttpStatus; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.*; | ||
| import com.example.devSns.services.PostService; | ||
| import java.util.List; | ||
|
|
||
| @RestController | ||
| @RequestMapping("/sns") | ||
| @RequiredArgsConstructor | ||
| public class PostController { | ||
| private final PostService postService; | ||
|
|
||
| @GetMapping("/show") | ||
| public ResponseEntity<List<PostResponse>> showPosts() { | ||
| List<PostResponse> posts = postService.findAll(); | ||
| return new ResponseEntity<>(posts, HttpStatus.OK); | ||
| } | ||
|
|
||
| @GetMapping("/show/{userID}") | ||
| public ResponseEntity<List<PostResponse>> showPost(@PathVariable Long userID) { | ||
| List<PostResponse> post = postService.findByUserID(userID); | ||
| return new ResponseEntity<>(post, HttpStatus.OK); | ||
| } | ||
|
|
||
| @GetMapping("/show/{content}") | ||
| public ResponseEntity<List<PostResponse>> showPost(@PathVariable String content) { | ||
| List<PostResponse> post = postService.findByContent(content); | ||
| return new ResponseEntity<>(post, HttpStatus.OK); | ||
| } | ||
|
|
||
| @PostMapping("/add") | ||
| public ResponseEntity<PostResponse> addPost(@RequestBody PostDTO postDTO) { | ||
| PostResponse postResponse = postService.save(postDTO); | ||
| return new ResponseEntity<>(postResponse, HttpStatus.CREATED); | ||
| } | ||
|
|
||
| @PutMapping("/{id}") | ||
| public ResponseEntity<PostResponse> updatePost(@PathVariable Long id, @RequestBody PostDTO postDTO) { | ||
| PostResponse postResponse = postService.update(id, postDTO); | ||
| return new ResponseEntity<>(postResponse, HttpStatus.OK); | ||
| } | ||
|
|
||
| @PatchMapping("/{id}/likeit") | ||
| public ResponseEntity<PostResponse> likePost(@PathVariable Long id) { | ||
| PostResponse postResponse = postService.likePost(id); | ||
| return new ResponseEntity<>(postResponse, HttpStatus.OK); | ||
| } | ||
|
|
||
| @DeleteMapping("/{id}") | ||
| public ResponseEntity<String> deletePost(@PathVariable Long id) { | ||
| postService.delete(id); | ||
| return new ResponseEntity<>("Post deleted", HttpStatus.OK); | ||
| } | ||
| } | ||
53 changes: 53 additions & 0 deletions
53
src/main/java/com/example/devSns/controllers/ReplyController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| package com.example.devSns.controllers; | ||
|
|
||
| import com.example.devSns.dto.ReplyDTO; | ||
| import com.example.devSns.dto.ReplyResponse; | ||
| import com.example.devSns.services.ReplyService; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.http.HttpStatus; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.*; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @RestController | ||
| @RequestMapping("/sns/reply") | ||
| @RequiredArgsConstructor | ||
| public class ReplyController { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reply라면 답글을 의미하는 것 같다고 생각했는데, 그렇다면 댓글과 답글을 따로 관리하는 방식인가요? |
||
| private final ReplyService replyService; | ||
|
|
||
| @GetMapping("/{postId}/replies") | ||
| public ResponseEntity<List<ReplyResponse>> getReplies(@PathVariable long postId) { | ||
| List<ReplyResponse> replies = replyService.replyGetAll(postId); | ||
| ResponseEntity<List<ReplyResponse>> responseEntity = new ResponseEntity<>(replies, HttpStatus.OK); | ||
| return responseEntity; | ||
| } | ||
|
|
||
| @PostMapping("/{postId}/add") | ||
| public ResponseEntity<ReplyResponse> writeReply(@PathVariable long postId, @RequestBody ReplyDTO reply) { | ||
| ReplyResponse replyResponse = replyService.writeReply(postId, reply); | ||
| ResponseEntity<ReplyResponse> responseEntity = new ResponseEntity<>(replyResponse, HttpStatus.OK); | ||
| return responseEntity; | ||
| } | ||
|
|
||
| @PutMapping("/{replyId}") | ||
| public ResponseEntity<ReplyResponse> updateReply(@PathVariable long replyId, @RequestBody ReplyDTO reply) { | ||
| ReplyResponse replyResponse = replyService.updateReply(replyId, reply); | ||
| ResponseEntity<ReplyResponse> responseEntity = new ResponseEntity<>(replyResponse, HttpStatus.OK); | ||
| return responseEntity; | ||
| } | ||
|
|
||
| @PatchMapping("/{id}") | ||
| public ResponseEntity<ReplyResponse> likeReply(@PathVariable long id) { | ||
| ReplyResponse replyResponse = replyService.likeReply(id); | ||
| ResponseEntity<ReplyResponse> responseEntity = new ResponseEntity<>(replyResponse, HttpStatus.OK); | ||
| return responseEntity; | ||
| } | ||
|
|
||
| @DeleteMapping("/{replyId}") | ||
| public ResponseEntity<String> deleteReply(@PathVariable long replyId) { | ||
| String deleteCheck = replyService.deleteReply(replyId); | ||
| ResponseEntity<String> responseEntity = new ResponseEntity<>(deleteCheck, HttpStatus.OK); | ||
| return responseEntity; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| package com.example.devSns.dto; | ||
|
|
||
| import com.example.devSns.entities.Posts; | ||
| import com.example.devSns.entities.Users; | ||
| import jakarta.validation.constraints.NotBlank; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| public record PostDTO( | ||
| @NotBlank Long userId, | ||
| @NotBlank String username, | ||
| String content | ||
| ) { | ||
| public static Posts dtoToEntity(PostDTO postDTO, Users user) { | ||
| Posts postEntity = Posts.builder() | ||
| .users(user) | ||
| .content(postDTO.content()) | ||
| .createat(LocalDateTime.now()) | ||
| .build(); | ||
| return postEntity; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| package com.example.devSns.dto; | ||
|
|
||
| import com.example.devSns.entities.Posts; | ||
| import lombok.*; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| @Builder | ||
| public record PostResponse( | ||
| Long id, | ||
| String username, | ||
| String content, | ||
| Integer like, | ||
| LocalDateTime createAt, | ||
| LocalDateTime updateAt | ||
| ) { | ||
| public static PostResponse entityToDto(Posts post) { | ||
| return PostResponse.builder() | ||
| .id(post.getId()) | ||
| .username(post.getUsers().getUsername()) | ||
| .content(post.getContent()) | ||
| .like(post.getLikeit()) | ||
| .createAt(post.getCreateat()) | ||
| .updateAt(post.getUpdateat()) | ||
| .build(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package com.example.devSns.dto; | ||
|
|
||
| import com.example.devSns.entities.Posts; | ||
| import com.example.devSns.entities.Replies; | ||
| import com.example.devSns.entities.Users; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| public record ReplyDTO( | ||
| Long userID, | ||
| String comment | ||
| ) { | ||
| public static Replies dtoToEntity(Posts post, Users user, ReplyDTO replyDTO) { | ||
| return Replies.builder() | ||
| .posts(post) | ||
| .users(user) | ||
| .createAt(LocalDateTime.now()) | ||
| .reply(replyDTO.comment()) | ||
| .build(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package com.example.devSns.dto; | ||
|
|
||
| import com.example.devSns.entities.Replies; | ||
| import lombok.Builder; | ||
|
|
||
| @Builder | ||
| public record ReplyResponse( | ||
| long replyId, | ||
| String username, | ||
| String comment, | ||
| Integer like | ||
| ) { | ||
| public static ReplyResponse entityToDTO(Replies replies) { | ||
| return ReplyResponse.builder() | ||
| .replyId(replies.getId()) | ||
| .username(replies.getUsers().getUsername()) | ||
| .comment(replies.getReply()) | ||
| .like(replies.getLikeit()) | ||
| .build(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| package com.example.devSns.entities; | ||
|
|
||
| import jakarta.persistence.*; | ||
| import jakarta.validation.constraints.NotNull; | ||
| import lombok.*; | ||
| import org.hibernate.annotations.ColumnDefault; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| @Entity | ||
| @Getter | ||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
| @Builder | ||
| public class Posts { | ||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.AUTO) | ||
| private Long id; | ||
|
|
||
| @NotNull | ||
| @Column | ||
| private String content; | ||
|
|
||
| @JoinColumn(name = "users_id") | ||
| @ManyToOne | ||
| @NotNull | ||
| private Users users; | ||
|
|
||
| @ColumnDefault("0") | ||
| private int likeit; | ||
|
|
||
| @Column | ||
| private LocalDateTime createat; | ||
|
|
||
| @Column | ||
| private LocalDateTime updateat; | ||
|
|
||
| public void setUpdateat(LocalDateTime updateat) { | ||
| this.updateat = updateat; | ||
| } | ||
|
|
||
| public void setContent(String content) { | ||
| this.content = content; | ||
| } | ||
|
|
||
| public void setLikeit(int likeit) { | ||
| this.likeit = likeit; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| package com.example.devSns.entities; | ||
|
|
||
| import jakarta.persistence.*; | ||
| import jakarta.validation.constraints.NotNull; | ||
| import lombok.*; | ||
| import org.hibernate.annotations.ColumnDefault; | ||
| import java.time.LocalDateTime; | ||
|
|
||
| @Entity | ||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
| @Getter | ||
| @Builder | ||
| public class Replies { | ||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.AUTO) | ||
| private long id; | ||
|
|
||
| @JoinColumn(name = "posts_id") | ||
| @ManyToOne | ||
| @NotNull | ||
| private Posts posts; | ||
|
|
||
| @JoinColumn(name = "users_id") | ||
| @ManyToOne | ||
| @NotNull | ||
| private Users users; | ||
|
|
||
| @Column | ||
| @ColumnDefault("0") // Table 생성 시점 기본값 | ||
| private int likeit; | ||
|
|
||
| @NotNull | ||
| private String reply; | ||
|
|
||
| @NotNull | ||
| private LocalDateTime createAt; | ||
|
|
||
| private LocalDateTime updateAt; | ||
|
|
||
| public void setReply(String reply) { | ||
| this.reply = reply; | ||
| } | ||
|
|
||
| public void setUpdateAt(LocalDateTime updateAt) { | ||
| this.updateAt = updateAt; | ||
| } | ||
|
|
||
| public void setLikeit(int likeit) { | ||
| this.likeit = likeit; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| package com.example.devSns.entities; | ||
|
|
||
| import jakarta.persistence.*; | ||
| import jakarta.validation.constraints.NotNull; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| import java.time.LocalDate; | ||
|
|
||
| @Entity | ||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
| @Getter | ||
| @Builder | ||
| public class Users { | ||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.AUTO) | ||
| private long id; | ||
|
|
||
| @NotNull | ||
| private String username; | ||
|
|
||
| @NotNull | ||
| private Integer age; | ||
|
|
||
| private LocalDate birthday; | ||
| } |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/example/devSns/repositories/PostRepository.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package com.example.devSns.repositories; | ||
|
|
||
| import com.example.devSns.entities.Posts; | ||
| import com.example.devSns.entities.Users; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Optional; | ||
|
|
||
| public interface PostRepository extends JpaRepository<Posts, Long> { | ||
| public List<Posts> findAll(); | ||
| public Optional<Posts> findById(Integer id); | ||
| public List<Posts> findByUsers(Users user); | ||
| public List<Posts> findByContentContaining(String partialContent); | ||
| } |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/example/devSns/repositories/ReplyRepository.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package com.example.devSns.repositories; | ||
|
|
||
| import com.example.devSns.entities.Posts; | ||
| import com.example.devSns.entities.Replies; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public interface ReplyRepository extends JpaRepository<Replies, Long> { | ||
| public List<Replies> findByPosts(Posts posts); | ||
| public Replies findById(long id); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
메소드의 이름을 searchPostByKeyword 와같이 명확하게 한다면, 추후에 코드를 수정해야하는 경우에 메소드명만 보고도 기능을 유추할 수 있어 더 좋을 것 같아요! (service쪽도 마찬가지!!)