-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feature: 메모 추가하기 (#39) * feat: 메모 수정하기 대응(#39) * feat: 메모 삭제하기 (#39) * refactor: postReader 메소드 명 수정 (#39) * refactor: swagger yml 분리 (#22)
- Loading branch information
Showing
10 changed files
with
169 additions
and
27 deletions.
There are no files selected for viewing
This file contains 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
30 changes: 30 additions & 0 deletions
30
src/main/java/project/backend/business/memo/MemoService.java
This file contains 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,30 @@ | ||
package project.backend.business.memo; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import project.backend.business.memo.implement.MemoManager; | ||
import project.backend.business.memo.request.CreateUpdateMemoServiceRequest; | ||
import project.backend.business.post.implement.PostReader; | ||
import project.backend.entity.post.Post; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class MemoService { | ||
|
||
private final PostReader postReader; | ||
private final MemoManager memoManager; | ||
|
||
@Transactional | ||
public void createUpdateMemo(Long userId, CreateUpdateMemoServiceRequest memoServiceRequest) { | ||
Post post = postReader.readActivatedPublishedPost(userId, memoServiceRequest.getPostId()); | ||
memoManager.createUpdateMemo(post, memoServiceRequest.getContent()); | ||
} | ||
|
||
@Transactional | ||
public void deleteMemo(Long userId, Long postId) { | ||
Post post = postReader.readActivatedPublishedPost(userId, postId); | ||
memoManager.deleteMemo(post); | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/project/backend/business/memo/implement/MemoManager.java
This file contains 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,28 @@ | ||
package project.backend.business.memo.implement; | ||
|
||
import java.time.LocalDateTime; | ||
import lombok.AllArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Component; | ||
import project.backend.entity.post.Post; | ||
import project.backend.repository.post.PostRepository; | ||
|
||
@Slf4j | ||
@Component | ||
@AllArgsConstructor | ||
public class MemoManager { | ||
|
||
private final PostRepository postRepository; | ||
|
||
public void createUpdateMemo(Post post, String content) { | ||
post.setMemo(content); | ||
post.setMemoCreatedAt(LocalDateTime.now()); | ||
postRepository.save(post); | ||
} | ||
|
||
public void deleteMemo(Post post) { | ||
post.setMemo(null); | ||
post.setMemoCreatedAt(null); | ||
postRepository.save(post); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/project/backend/business/memo/request/CreateUpdateMemoServiceRequest.java
This file contains 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,13 @@ | ||
package project.backend.business.memo.request; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@Builder | ||
public class CreateUpdateMemoServiceRequest { | ||
|
||
private Long postId; | ||
private String content; | ||
|
||
} |
This file contains 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 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
39 changes: 39 additions & 0 deletions
39
src/main/java/project/backend/presentation/memo/controller/MemoController.java
This file contains 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,39 @@ | ||
package project.backend.presentation.memo.controller; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import project.backend.business.memo.MemoService; | ||
import project.backend.presentation.memo.request.CreateUpdateMemoRequest; | ||
import project.backend.security.aop.AssignCurrentUserInfo; | ||
import project.backend.security.aop.CurrentUserInfo; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/memo") | ||
public class MemoController implements MemoControllerDocs { | ||
|
||
private final MemoService memoService; | ||
|
||
@AssignCurrentUserInfo | ||
@PostMapping | ||
public ResponseEntity<Void> createUpdateMemo(CurrentUserInfo userInfo, @RequestParam Long postId, | ||
@RequestBody CreateUpdateMemoRequest memoRequest) { | ||
memoService.createUpdateMemo(userInfo.getUserId(), memoRequest.toServiceRequest(postId)); | ||
return new ResponseEntity<>(HttpStatus.OK); | ||
} | ||
|
||
@AssignCurrentUserInfo | ||
@DeleteMapping | ||
public ResponseEntity<Void> deleteMemo(CurrentUserInfo userInfo, @RequestParam Long postId) { | ||
memoService.deleteMemo(userInfo.getUserId(), postId); | ||
return new ResponseEntity<>(HttpStatus.OK); | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/project/backend/presentation/memo/controller/MemoControllerDocs.java
This file contains 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,24 @@ | ||
package project.backend.presentation.memo.controller; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import project.backend.presentation.memo.request.CreateUpdateMemoRequest; | ||
import project.backend.security.aop.CurrentUserInfo; | ||
|
||
@Tag(name = "메모 API") | ||
public interface MemoControllerDocs { | ||
|
||
@Operation(summary = "메모 추가/수정 API", description = "게시글에 메모를 추가 및 수정합니다.") | ||
@Parameter(name = "userInfo", hidden = true) | ||
@Parameter(name = "postId", description = "메모 추가/수정할 게시글 id") | ||
ResponseEntity<Void> createUpdateMemo(CurrentUserInfo userInfo, Long postId, | ||
CreateUpdateMemoRequest memoRequest); | ||
|
||
@Operation(summary = "메모 삭제 API", description = "게시글의 메모를 삭제 합니다.") | ||
@Parameter(name = "userInfo", hidden = true) | ||
@Parameter(name = "postId", description = "메모 삭제할 게시글 id") | ||
ResponseEntity<Void> deleteMemo(CurrentUserInfo userInfo, @RequestParam Long postId); | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/project/backend/presentation/memo/request/CreateUpdateMemoRequest.java
This file contains 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 project.backend.presentation.memo.request; | ||
|
||
import lombok.Getter; | ||
import project.backend.business.memo.request.CreateUpdateMemoServiceRequest; | ||
|
||
@Getter | ||
public class CreateUpdateMemoRequest { | ||
|
||
private String content; | ||
|
||
public CreateUpdateMemoServiceRequest toServiceRequest(Long postId) { | ||
return CreateUpdateMemoServiceRequest.builder() | ||
.postId(postId) | ||
.content(content) | ||
.build(); | ||
} | ||
} |
This file contains 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