-
Notifications
You must be signed in to change notification settings - Fork 1
Yg 176 refactor post #49
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
base: develop
Are you sure you want to change the base?
Changes from all commits
5b37e93
c5ea3bf
8216f0d
956e7a2
08e2313
8ebb8b3
69ce683
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| package com.example.yeogiserver.common.application; | ||
|
|
||
| import com.example.yeogiserver.common.exception.CustomException; | ||
| import com.example.yeogiserver.common.exception.ErrorCode; | ||
| import com.example.yeogiserver.member.domain.Member; | ||
| import com.example.yeogiserver.member.domain.MemberRepository; | ||
| import com.example.yeogiserver.member.repository.DefaultMemberRepository; | ||
| import com.example.yeogiserver.security.domain.CustomUserDetails; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| import java.time.LocalDateTime; | ||
| import java.time.ZoneId; | ||
| import java.time.ZonedDateTime; | ||
| import java.time.format.DateTimeFormatter; | ||
| import java.util.Optional; | ||
|
|
||
| @Component | ||
| @RequiredArgsConstructor | ||
| public class CommonService { | ||
|
|
||
| private final DefaultMemberRepository memberRepository; | ||
|
|
||
| public String getTime() { | ||
|
|
||
| ZonedDateTime dateTime = ZonedDateTime.now(ZoneId.of("Asia/Seoul")); | ||
|
|
||
| return dateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); | ||
| } | ||
|
|
||
| public String getName(CustomUserDetails customUserDetails) { | ||
| Member member = memberRepository.findById(customUserDetails.getId()).orElseThrow(() -> new CustomException(ErrorCode.MEMBER_NOT_FOUND)); | ||
| return member.getNickname(); | ||
| } | ||
|
Comment on lines
+31
to
+34
Contributor
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. 요거는 어디에쓰는걸까요?? |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,8 +23,13 @@ public enum ErrorCode { | |
| HEADER_REFRESH_TOKEN_NOT_EXISTS(404 , "헤더에 Refresh 토큰이 존재하지 않습니다."), | ||
|
|
||
| //OAuth | ||
| ILLEGAL_REGISTRATION_ID(400 , "올바르지 않은 registrationId 입니다."); | ||
| ILLEGAL_REGISTRATION_ID(400 , "올바르지 않은 registrationId 입니다."), | ||
|
|
||
| //POST | ||
| POST_NOT_FOUND(500 , "포스트를 찾을 수 없습니다."), | ||
| NOT_MY_POST(501 , "사용자가 작성한 포스트가 아닙니다."), | ||
| MEMBER_ALREADY_LIKE_POST(502 , "사용자가 이미 좋아요를 누른 포스트입니다."), | ||
| MEMBER_ALREADY_DISLIKE_POST(503 , "사용자가 이미 싫어요를 누른 포스트입니다."); | ||
|
|
||
|
Comment on lines
+28
to
33
Contributor
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. 죠습니다 |
||
|
|
||
| private int status; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| package com.example.yeogiserver.post.presentation; | ||
|
|
||
| import com.example.yeogiserver.common.application.CommonService; | ||
| import com.example.yeogiserver.post.application.PostService; | ||
| import com.example.yeogiserver.post.application.dto.request.PostRequestDto; | ||
| import com.example.yeogiserver.post.application.dto.request.PostUpdateRequest; | ||
|
|
@@ -8,6 +9,7 @@ | |
| import io.swagger.v3.oas.annotations.security.SecurityRequirement; | ||
| import io.swagger.v3.oas.annotations.tags.Tag; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
| import org.springframework.web.bind.annotation.DeleteMapping; | ||
|
|
@@ -24,9 +26,11 @@ | |
| @RequiredArgsConstructor | ||
| @SecurityRequirement(name = "Bearer Authentication") | ||
| @Tag(name = "게시글 쓰기(C,U,D) 컨트롤러") | ||
| @Slf4j | ||
| public class PostController { | ||
|
|
||
| private final PostService postService; | ||
| private final CommonService commonService; | ||
|
|
||
| @PostMapping("/posts") | ||
| @Operation(description = "게시글을 생성한다.") | ||
|
|
@@ -45,7 +49,7 @@ public ResponseEntity<Void> createPost(@RequestBody PostRequestDto postRequestDt | |
|
|
||
| @PostMapping("/posts/{postId}/views") | ||
| @Operation(description = "postId 에 해당하는 게시글의 조회수를 추가 한다.") | ||
| public void addViewCount(@PathVariable Long postId){ | ||
| public void addViewCount(@PathVariable Long postId , @AuthenticationPrincipal CustomUserDetails userDetails){ | ||
|
Contributor
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. 조회수 추가하는데에 인증정보는 필요 없을 것으로 보입니다 |
||
| postService.addViewCount(postId); | ||
| } | ||
|
|
||
|
|
@@ -57,8 +61,8 @@ public void updatePost(@PathVariable Long postId, @RequestBody PostUpdateRequest | |
|
|
||
| @DeleteMapping("/posts/{postId}") | ||
| @Operation(description = "postId 에 해당하는 게시글을 삭제한다.") | ||
| public void deletePost(@PathVariable Long postId) { | ||
| postService.delete(postId); | ||
| public void deletePost(@PathVariable Long postId , @AuthenticationPrincipal CustomUserDetails userDetails) { | ||
| postService.delete(postId , userDetails.getId()); | ||
| } | ||
|
|
||
| @PostMapping("/posts/{postId}/likes") | ||
|
|
||
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.
이 컴포넌트는 어디에서 쓰이고있을까요?