Skip to content
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

Merged
merged 11 commits into from
Oct 30, 2024
Merged

feat: 공지 CRUD API 구현 #323

merged 11 commits into from
Oct 30, 2024

Conversation

kdkdhoho
Copy link
Collaborator

Description

공지 CRUD API를 구현했습니다.

Relation Issues

@kdkdhoho kdkdhoho self-assigned this Oct 30, 2024
@kdkdhoho kdkdhoho requested a review from pparkjs as a code owner October 30, 2024 07:38
@kdkdhoho kdkdhoho linked an issue Oct 30, 2024 that may be closed by this pull request
9 tasks
Copy link
Collaborator

@pparkjs pparkjs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

생각보다 공지가 구현할게 많았네요!!
고생하셨어요 ㅎㅎ 깔끔하게 잘 구현했네요

제가 코멘트 단부분 한 번 고민하시고 답변 주세용~~~

Comment on lines 87 to 101
@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();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

엇 그럼 이거 그 카톡으로 말했던 문제 이거로 해결이 된건가요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

네엡 해결은 됐습니다만.. 원인은 정확히 모르겠네요 ㅜ

Comment on lines +12 to +26
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));
Copy link
Collaborator

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;

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

개행 제거!

Copy link
Collaborator Author

@kdkdhoho kdkdhoho Oct 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

원래 package 아래는 개행 한 줄이 들어갑니다 😃 (출처)

Comment on lines +40 to +42
public void addContents(List<NoticeContent> contents) {
this.contents.addAll(contents);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아직도 햇갈리는거 contents에 데잍터 바인딩 시켰으면 NoticeContent에서도 Notice 양방향으로 채워줘야하는 거 아니였어요? 이게 아직도 햇갈리네 ㅠ

Copy link
Collaborator Author

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>를 만들 때 객체 참조를 할당해주고 있습니다!

Copy link
Collaborator

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();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

혹시 이게 그 RestFul API 설계 원칙에 HATEOAS 방식을 사용한 건가요? 응답에 uri 넣어주는

Copy link
Collaborator Author

@kdkdhoho kdkdhoho Oct 30, 2024

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) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

평소에 하시던 것 처럼 prevNotice와 nextNotice는 nullable 하니 @nullable 어노테이션으로 명확하게 구분지어 놓는 것도 좋을 거 같아요!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

빠트렸네요! 감사합니다 👍

Comment on lines 16 to 22
@Query("""
select n
from Notice n
join NoticeContent nc on nc.notice = n
where n.id = :noticeId
""")
Notice findOne(Long noticeId);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

요거 fetch join을 통해 사전에 매핑해가지고 와서 n+1 방지하는걸 추천합니다!

Copy link
Collaborator Author

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();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저번에 말했던 분리한 거 👍🏻

Comment on lines 24 to 35
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)
)
);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이거 공지 통합테스트에서 공통으로 많이 쓰이는 거 같은데 번째를 인자로 받는 메서드로 하나 빼는 거 어떨까요!?

Copy link
Collaborator

@pparkjs pparkjs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ㅎㅎ 반영하느라 수고하셨어요 approve 드릴게요!!

Comment on lines +28 to +30
NoticeCreateRequest request1 = createNoticeCreateRequest(1);
NoticeCreateRequest request2 = createNoticeCreateRequest(2);
NoticeCreateRequest request3 = createNoticeCreateRequest(3);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻

@kdkdhoho kdkdhoho merged commit 29fdecd into dev Oct 30, 2024
1 check passed
@kdkdhoho kdkdhoho deleted the feat/312 branch October 30, 2024 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

게시글(공지) 관련 API 구현
2 participants