-
Notifications
You must be signed in to change notification settings - Fork 13
Feat/week3 #29
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
zwo-n
wants to merge
5
commits into
ApptiveDev:강지원
Choose a base branch
from
zwo-n:feat/week-3
base: 강지원
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/week3 #29
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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
Binary file not shown.
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 |
|---|---|---|
|
|
@@ -35,3 +35,5 @@ out/ | |
|
|
||
| ### VS Code ### | ||
| .vscode/ | ||
|
|
||
| .env | ||
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 |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| # backend-study-sns | ||
| 강지원 |
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
31 changes: 31 additions & 0 deletions
31
src/main/java/com/example/devSns/controller/CommentActionController.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,31 @@ | ||
| package com.example.devSns.controller; | ||
|
|
||
| import com.example.devSns.dto.CommentResponse; | ||
| import com.example.devSns.dto.CommentUpdateRequest; | ||
| import com.example.devSns.entity.Comment; | ||
| import com.example.devSns.service.CommentService; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.*; | ||
|
|
||
| @RestController | ||
| @RequestMapping("/comments") | ||
| public class CommentActionController { | ||
| private final CommentService commentService; | ||
|
|
||
| public CommentActionController(CommentService commentService){ | ||
| this.commentService = commentService; | ||
| } | ||
| @DeleteMapping("/{commentId}") | ||
| public void deleteComment(@PathVariable Long commentId) { | ||
| commentService.deleteComment(commentId); | ||
| } | ||
|
|
||
| @PatchMapping("/{commentId}") | ||
| public ResponseEntity<CommentResponse> updateComment( | ||
| @PathVariable Long commentId, | ||
| @RequestBody CommentUpdateRequest request | ||
| ) { | ||
| Comment updated = commentService.updateComment(commentId, request.getContent()); | ||
| return ResponseEntity.ok(new CommentResponse(updated)); | ||
| } | ||
| } |
36 changes: 36 additions & 0 deletions
36
src/main/java/com/example/devSns/controller/CommentController.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,36 @@ | ||
| package com.example.devSns.controller; | ||
|
|
||
| import com.example.devSns.dto.CommentCreateRequest; | ||
| import com.example.devSns.dto.CommentResponse; | ||
| import com.example.devSns.dto.CommentUpdateRequest; | ||
| import com.example.devSns.entity.Comment; | ||
| import com.example.devSns.service.CommentService; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.*; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| @RestController | ||
| @RequestMapping("/posts/{postId}/comments") | ||
| public class CommentController { | ||
| private final CommentService commentService; | ||
|
|
||
| public CommentController(CommentService commentService) { | ||
| this.commentService = commentService; | ||
| } | ||
|
|
||
| @GetMapping | ||
| public List<CommentResponse> getComments(@PathVariable Long postId) { | ||
| return commentService.getCommentByPost(postId).stream() | ||
| .map(CommentResponse::new) | ||
| .toList(); | ||
| } | ||
|
|
||
| @PostMapping | ||
| public CommentResponse createComment(@PathVariable Long postId, @RequestBody CommentCreateRequest request) { | ||
| Comment created = commentService.addComment(postId, request); | ||
| return new CommentResponse(created); | ||
| } | ||
|
|
||
|
|
||
| } |
29 changes: 29 additions & 0 deletions
29
src/main/java/com/example/devSns/controller/LikeController.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,29 @@ | ||
| package com.example.devSns.controller; | ||
|
|
||
| import com.example.devSns.dto.LikeResponse; | ||
| import com.example.devSns.dto.LikeToggleRequest; | ||
| import com.example.devSns.service.LikeService; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.*; | ||
|
|
||
| @RestController | ||
| @RequiredArgsConstructor | ||
| @RequestMapping("/likes") | ||
| public class LikeController { | ||
| private final LikeService likeService; | ||
|
|
||
| @PostMapping("/toggle") | ||
| public ResponseEntity<LikeResponse> toggleLike(@RequestBody LikeToggleRequest request){ | ||
| likeService.toggleLike(request.getMemberId(), request.getPostId()); | ||
| long count = likeService.getLikeCount(request.getPostId()); | ||
| return ResponseEntity.ok(new LikeResponse(request.getPostId(),count,true)); | ||
| } | ||
|
|
||
| @GetMapping("/count/{postId}") | ||
| public ResponseEntity<Long> getLikeCount(@PathVariable Long postId){ | ||
| long count = likeService.getLikeCount(postId); | ||
| return ResponseEntity.ok(count); | ||
| } | ||
|
|
||
| } |
52 changes: 52 additions & 0 deletions
52
src/main/java/com/example/devSns/controller/MemberController.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,52 @@ | ||
| package com.example.devSns.controller; | ||
|
|
||
| import com.example.devSns.dto.CommentResponse; | ||
| import com.example.devSns.dto.MemberJoinRequest; | ||
| import com.example.devSns.dto.MemberResponse; | ||
| import com.example.devSns.dto.PostResponse; | ||
| import com.example.devSns.entity.Member; | ||
| import com.example.devSns.service.MemberService; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.web.bind.annotation.*; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @RestController | ||
| @RequiredArgsConstructor | ||
| @RequestMapping("/members") | ||
| public class MemberController { | ||
| private final MemberService memberService; | ||
|
|
||
| @GetMapping("/{id}") | ||
| public MemberResponse getMember(@PathVariable Long id) { | ||
| Member member = memberService.findMemberById(id); | ||
| return new MemberResponse(member); | ||
| } | ||
|
|
||
| @GetMapping("/search") | ||
| public List<MemberResponse> search(@RequestParam String keyword) { | ||
| return memberService.searchMembers(keyword).stream().map(MemberResponse::new).toList(); | ||
| } | ||
|
|
||
| @GetMapping("/{id}/posts") | ||
| public List<PostResponse> getMemberPosts(@PathVariable Long id) { | ||
| return memberService.getPostsByMember(id); | ||
| } | ||
|
|
||
| @GetMapping("/{id}/comments") | ||
| public List<CommentResponse> getMemberComments(@PathVariable Long id) { | ||
| return memberService.getCommentsByMember(id); | ||
| } | ||
|
|
||
| @GetMapping("/{id}/likes") | ||
| public List<PostResponse> getMemberLikes(@PathVariable Long id) { | ||
| return memberService.getLikedPosts(id); | ||
| } | ||
|
|
||
| @PostMapping | ||
| public MemberResponse createMember(@RequestBody MemberJoinRequest request){ | ||
| Member member = memberService.join(request.toEntity()); | ||
| return new MemberResponse(member); | ||
| } | ||
|
|
||
| } |
52 changes: 52 additions & 0 deletions
52
src/main/java/com/example/devSns/controller/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,52 @@ | ||
| package com.example.devSns.controller; | ||
|
|
||
| import com.example.devSns.dto.PostCreateRequest; | ||
| import com.example.devSns.dto.PostResponse; | ||
| import com.example.devSns.dto.PostUpdateRequest; | ||
| import com.example.devSns.entity.Post; | ||
| import com.example.devSns.service.PostService; | ||
| import jakarta.persistence.PostUpdate; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.*; | ||
|
|
||
| import java.time.LocalDateTime; | ||
| import java.util.List; | ||
| import java.util.Optional; | ||
|
|
||
| @RestController | ||
| @RequestMapping("/post") | ||
| public class PostController { | ||
| private final PostService postService; | ||
|
|
||
| public PostController(PostService postService) { | ||
| this.postService = postService; | ||
| } | ||
|
|
||
| @GetMapping | ||
| public List<PostResponse> getAllPosts(){ | ||
| return postService.findAll().stream().map(PostResponse::new).toList(); | ||
| } | ||
|
|
||
| @GetMapping("/{id}") | ||
| public ResponseEntity<PostResponse> getPostById(@PathVariable Long id){ | ||
| Post post = postService.findById(id); | ||
| return ResponseEntity.ok(new PostResponse(post)); | ||
| } | ||
|
|
||
| @PostMapping | ||
| public PostResponse createPost(@RequestBody PostCreateRequest request){ | ||
| Post created = postService.createPost(request); | ||
| return new PostResponse(created); | ||
| } | ||
|
|
||
| @PatchMapping("/{id}") | ||
| public PostResponse updatePost(@PathVariable Long id, @RequestBody PostUpdateRequest request){ | ||
| Post updated = postService.updatePost(id, request); | ||
| return new PostResponse(updated); | ||
| } | ||
|
|
||
| @DeleteMapping("/{id}") | ||
| public void deletePost(@PathVariable Long id){ | ||
| postService.delete(id); | ||
| } | ||
| } | ||
12 changes: 12 additions & 0 deletions
12
src/main/java/com/example/devSns/dto/CommentCreateRequest.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.dto; | ||
|
|
||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @Getter | ||
| @NoArgsConstructor | ||
| public class CommentCreateRequest { | ||
| private String content; | ||
| private String username; | ||
| private Long memberId; | ||
|
Comment on lines
+9
to
+11
Member
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. DTO 내에 Validation을 적용해보는 것도 좋을 거 같습니다 음수나 빈 제목 등을 사전에 검증해 입력되는 걸 방지할 수 있습니다..! |
||
| } | ||
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.entity.Comment; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| public record CommentResponse( | ||
| Long id, | ||
| String content, | ||
| String username, | ||
| LocalDateTime createdAt | ||
| ){ | ||
| public CommentResponse(Comment comment){ | ||
| this( | ||
| comment.getId(), | ||
| comment.getContent(), | ||
| comment.getUsername(), | ||
| comment.getCreatedAt() | ||
| ); | ||
| } | ||
| } |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/example/devSns/dto/CommentUpdateRequest.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,10 @@ | ||
| package com.example.devSns.dto; | ||
|
|
||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @Getter | ||
| @NoArgsConstructor | ||
| public class CommentUpdateRequest { | ||
| private String content; | ||
| } |
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.dto; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| @AllArgsConstructor | ||
| public class LikeResponse { | ||
| private Long PostId; | ||
| private long likeCount; | ||
| private boolean liked; | ||
| } |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/example/devSns/dto/LikeToggleRequest.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,11 @@ | ||
| package com.example.devSns.dto; | ||
|
|
||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @Getter | ||
| @NoArgsConstructor | ||
| public class LikeToggleRequest { | ||
| private Long memberId; | ||
| private Long postId; | ||
| } |
17 changes: 17 additions & 0 deletions
17
src/main/java/com/example/devSns/dto/MemberJoinRequest.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,17 @@ | ||
| package com.example.devSns.dto; | ||
|
|
||
| import com.example.devSns.entity.Member; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @Getter | ||
| @NoArgsConstructor | ||
| public class MemberJoinRequest { | ||
| private String username; | ||
| private String email; | ||
| private String password; | ||
|
|
||
| public Member toEntity(){ | ||
| return Member.create(username, email, password); | ||
| } | ||
| } |
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,17 @@ | ||
| package com.example.devSns.dto; | ||
|
|
||
| import com.example.devSns.entity.Member; | ||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| public class MemberResponse { | ||
| private Long id; | ||
| private String username; | ||
| private String email; | ||
|
|
||
| public MemberResponse(Member member){ | ||
| this.id = member.getId(); | ||
| this.username = member.getUsername(); | ||
| this.email = member.getEmail(); | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/example/devSns/dto/PostCreateRequest.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,11 @@ | ||
| package com.example.devSns.dto; | ||
|
|
||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @Getter | ||
| @NoArgsConstructor | ||
| public class PostCreateRequest { | ||
| private String content; | ||
| private Long memberId; | ||
| } |
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.
posts로 복수형으로 변경해서 통일시키는게 나을 거 같습니다!