-
Notifications
You must be signed in to change notification settings - Fork 2
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
feat: 공지 CRUD API 구현 #323
feat: 공지 CRUD API 구현 #323
Conversation
정확한 원인은 파악하지 못했지만, 추측컨데 AcceptanceTest와 IntegrationTest의 테스트 DB가 공유되면서 외래키 제약 조건으로 발생한 것으로 예상 (#312)
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.
생각보다 공지가 구현할게 많았네요!!
고생하셨어요 ㅎㅎ 깔끔하게 잘 구현했네요
제가 코멘트 단부분 한 번 고민하시고 답변 주세용~~~
@Autowired | ||
protected HistoryRepository historyRepository; | ||
@Autowired | ||
protected UserReactionRepository userReactionRepository; | ||
@Autowired | ||
protected ReactionStatsRepository reactionStatsRepository; | ||
|
||
protected User dh, js, ej, sy; | ||
protected ListEntity list; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
historyRepository.deleteAll(); | ||
userReactionRepository.deleteAllInBatch(); | ||
reactionStatsRepository.deleteAllInBatch(); |
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.
엇 그럼 이거 그 카톡으로 말했던 문제 이거로 해결이 된건가요?
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.
네엡 해결은 됐습니다만.. 원인은 정확히 모르겠네요 ㅜ
public enum NoticeType { | ||
|
||
NEWS(1, "소식"), | ||
EVENT(2, "이벤트"), | ||
TIP(3, "팁"), | ||
; | ||
|
||
private final int code; | ||
private final String viewName; | ||
|
||
public static NoticeType codeOf(int code) { | ||
return Arrays.stream(NoticeType.values()) | ||
.filter(noticeType -> noticeType.getCode() == code) | ||
.findFirst() | ||
.orElseThrow(() -> new CustomException(NOT_EXIST_CODE, NOT_EXIST_CODE.getDetail() + " 입력값: " + code)); |
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.
👍🏻
@@ -0,0 +1,20 @@ | |||
package com.listywave.notice.application.converter; | |||
|
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.
개행 제거!
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.
원래 package 아래는 개행 한 줄이 들어갑니다 😃 (출처)
public void addContents(List<NoticeContent> contents) { | ||
this.contents.addAll(contents); | ||
} |
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.
아직도 햇갈리는거 contents에 데잍터 바인딩 시켰으면 NoticeContent에서도 Notice 양방향으로 채워줘야하는 거 아니였어요? 이게 아직도 햇갈리네 ㅠ
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.
연관관계의 주인이 NoticeContent이니까 NoticeContent에도 Notice를 참조하도록 하는 게 맞습니다!
Notice#addContents()
를 호출하는 NoticeService#create()
를 살펴보면,
List<NoticeContent>
를 만들 때 객체 참조를 할당해주고 있습니다!
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.
아아 DTO에서 해주는군요 ㅎㅎ 확인했슴다!
@RequestBody NoticeCreateRequest request | ||
) { | ||
Long id = noticeService.create(request); | ||
return ResponseEntity.created(URI.create("/admin/notices/" + id)).build(); |
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.
혹시 이게 그 RestFul API 설계 원칙에 HATEOAS 방식을 사용한 건가요? 응답에 uri 넣어주는
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.
이는 HTTP - 201 Created 상태 코드의 명세에 따른 것입니다~!
BesideNoticeDto nextNotice | ||
) { | ||
|
||
public static NoticeFindResponse of(Notice notice, Notice prevNotice, Notice nextNotice) { |
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.
평소에 하시던 것 처럼 prevNotice와 nextNotice는 nullable 하니 @nullable 어노테이션으로 명확하게 구분지어 놓는 것도 좋을 거 같아요!
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.
빠트렸네요! 감사합니다 👍
@Query(""" | ||
select n | ||
from Notice n | ||
join NoticeContent nc on nc.notice = n | ||
where n.id = :noticeId | ||
""") | ||
Notice findOne(Long noticeId); |
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.
요거 fetch join을 통해 사전에 매핑해가지고 와서 n+1 방지하는걸 추천합니다!
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.
과거 커밋을 보신 것 같습니다!
fetch 적용했습니다 ㅎㅎ
@PatchMapping("/admin/notices/{noticeId}") | ||
ResponseEntity<Void> updateExposure(@PathVariable Long noticeId) { | ||
noticeService.updateExposure(noticeId); | ||
return ResponseEntity.noContent().build(); |
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.
저번에 말했던 분리한 거 👍🏻
NoticeCreateRequest request1 = new NoticeCreateRequest( | ||
1, | ||
"첫 번째 공지입니다", | ||
"첫 번째 공지에요", | ||
List.of( | ||
new ContentDto(1, "subtitle", "소제목입니다", null, null, null), | ||
new ContentDto(2, "body", "본문입니다", null, null, null), | ||
new ContentDto(3, "image", "이미지입니다", "https://image.com", null, null), | ||
new ContentDto(4, "button", "버튼입니다", null, "버튼 이름", "https://buttonLink.com"), | ||
new ContentDto(5, "note", "유의사항입니다", null, null, null) | ||
) | ||
); |
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.
이거 공지 통합테스트에서 공통으로 많이 쓰이는 거 같은데 번째를 인자로 받는 메서드로 하나 빼는 거 어떨까요!?
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.
ㅎㅎ 반영하느라 수고하셨어요 approve 드릴게요!!
NoticeCreateRequest request1 = createNoticeCreateRequest(1); | ||
NoticeCreateRequest request2 = createNoticeCreateRequest(2); | ||
NoticeCreateRequest request3 = createNoticeCreateRequest(3); |
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.
👍🏻
Description
공지 CRUD API를 구현했습니다.
Relation Issues