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: controller, service 수정 #14 #19

Merged
merged 21 commits into from
Oct 13, 2023
Merged

feat: controller, service 수정 #14 #19

merged 21 commits into from
Oct 13, 2023

Conversation

kwchoi11
Copy link
Collaborator

controller, service 수정했습니다.
NoticeService 파일에서 saveNotice 부분의 빌더는 리뷰 받고 채워서 다시 올리겠습니다.

@kwchoi11 kwchoi11 self-assigned this Oct 10, 2023
@kwchoi11 kwchoi11 added the enhancement New feature or request label Oct 10, 2023
Copy link
Member

@bongsh0112 bongsh0112 left a comment

Choose a reason for hiding this comment

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

고생하셨습니다
수정사항 확인해주세요

* @return
*/
@GetMapping("{/noticeArticleId}")
public NoticeArticleDto getNoticeArticle(@PathVariable Long noticeArticleId, HttpServletRequest request, LanguageType languageType) {
Copy link
Member

Choose a reason for hiding this comment

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

Controller에서 LanguageType을 받을 수 있을 지가 확실하지않네요
아마 requestHeader에 넣어주고 받을 것 같습니다
이미 밑에서 해준 것 같으니 LanguageType을 빼도 될 것 같아요
requestHeader를 사용하기 위해서는 @RequestHeader 어노테이션에 대해서도 알아보시면 좋을 것 같네요

* @return
*/
@GetMapping
public List<NoticeArticleDto> getNoticeArticleList(HttpServletRequest request, LanguageType languageType, NoticeArticleDto requestData) {
Copy link
Member

Choose a reason for hiding this comment

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

마찬가지로 LanguageTyperequestHeader에서 뽑아올 수 있도록 구성할 것이므로 빼도 될 것 같습니다

* 공지사항 등록
*/
@PostMapping
public void addNotice(@RequestBody @Valid NoticeArticleDto articleRequest, NoticeContentDto contentRequest) {
Copy link
Member

Choose a reason for hiding this comment

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

@Valid를 사용하려면 DTO 내에서 작업이 필요합니다
참고해보세요

Comment on lines 67 to 68
public void updateNotice(@PathVariable Long id,
@RequestBody @Valid NoticeArticleDto articleDto, NoticeContentDto contentDto) {
Copy link
Member

Choose a reason for hiding this comment

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

마찬가지로 @Valid를 사용하기 위해서는 따로 작업이 필요합니다
@RequestBody를 사용할 때는
@RequestBody @Valid UpdateNoticeRequest body와 같이 구성하고
request dto를 하나 만들어보시는게 나을 수도 있겠네요

Comment on lines +76 to +79
@DeleteMapping("/{noticeArticleId}")
public void deleteNotice(@PathVariable Long noticeArticleId) {
noticeService.deleteNotice(noticeArticleId);
}
Copy link
Member

Choose a reason for hiding this comment

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

@DeleteMapping에 대해서는 추가적으로 찾아보셔야 할 것 같네요

noticeContentRepository.save(noticeContent);
}

@Transactional(readOnly = true)
Copy link
Member

Choose a reason for hiding this comment

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

readonly 좋습니다

Comment on lines 44 to 55
for (NoticeArticle noticeArticle : all) {
NoticeArticleDto articleDto = NoticeArticleDto.builder()
.id(noticeArticle.getId())
.language(noticeArticle.getLanguage())
.status(noticeArticle.getStatus())
.createdAt(noticeArticle.getCreatedAt())
.createdUser(noticeArticle.getCreatedUser())
.updatedAt(noticeArticle.getUpdatedAt())
.updatedUser(noticeArticle.getUpdatedUser())
.build();
noticeArticleDtoList.add(articleDto);
}
Copy link
Member

Choose a reason for hiding this comment

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

stream을 써보는 것은 어떨까요

Comment on lines 60 to 69
public NoticeContentDto getNotice(Long id) {
NoticeContent noticeContent = noticeContentRepository.findById(id).orElseThrow(() -> NoticeArticleNotFoundException.EXCEPTION);

return NoticeContentDto.builder()
.id(noticeContent.getId())
.language(noticeContent.getLanguage())
.title(noticeContent.getTitle())
.content(noticeContent.getContent())
.build();
}
Copy link
Member

Choose a reason for hiding this comment

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

이 코드는 나중에 또 쓸 수 있으니
NoticeContentDtofrom 메소드를 만들어보는 것은 어떨까요?

Suggested change
public NoticeContentDto getNotice(Long id) {
NoticeContent noticeContent = noticeContentRepository.findById(id).orElseThrow(() -> NoticeArticleNotFoundException.EXCEPTION);
return NoticeContentDto.builder()
.id(noticeContent.getId())
.language(noticeContent.getLanguage())
.title(noticeContent.getTitle())
.content(noticeContent.getContent())
.build();
}
public NoticeContentDto getNotice(Long id) {
NoticeContent noticeContent = noticeContentRepository.findById(id).orElseThrow(() -> NoticeArticleNotFoundException.EXCEPTION);
return NoticeContentDto.from(noticeContent);
}

처럼 나오도록 한번 만들어보세요!

Comment on lines 77 to 80
public void update(Long id, NoticeArticleDto articleDto) {
Optional<NoticeArticle> byId = noticeArticleRepository.findById(id);
// TODO : 수정 받고 다시 작업 예정
}
Copy link
Member

Choose a reason for hiding this comment

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

JPA에서 update는 어떻게 하는지 리서치해보시는것도 추천드립니다

Comment on lines 82 to 88
public NoticeArticleDto getNoticeArticleByArticleId(Long noticeArticleId, LanguageType languageType) {
return null;
}

public List<NoticeArticleDto> getNoticeArticleList(Long noticeArticleId, LanguageType languageType) {
return null;
}
Copy link
Member

Choose a reason for hiding this comment

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

이런 것들을 서비스에서 따로 정의하는것도 괜찮지만,
JPA repository에서 바로 가져올 수도 있을 것 같네요.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

그러면 서비스에서 이것들은 지워버리고 컨트롤러에서 바로 가져오도록 하면 되나요?

@@ -43,7 +43,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
.authorizeHttpRequests(authorization -> authorization
.requestMatchers(
"/login",
"/register", "/health").permitAll()
"/register", "/health", "/notice/**").permitAll()
Copy link
Member

Choose a reason for hiding this comment

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

해당 코드는 테스트케이스에서만 사용해주시고, 롤백해주시기 바랍니다.

Comment on lines 13 to 22
public static LanguageType findType(String value) {
if (value == null || value.isEmpty()) {
return KO;
// throw IllegalArgumentException.EXCEPTION;
}
return Arrays.stream(LanguageType.values())
.filter(type -> type.name().equals(value.toUpperCase()))
.findFirst()
.orElseThrow(() -> IllegalArgumentException.EXCEPTION);
}
Copy link
Member

Choose a reason for hiding this comment

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

Default로 KO를 주기를 의도한 것 같은데, 실제 Value가 들어온 경우 (ex: "abc")에는 Exception이 발생하나요 아니면 KO가 반환되나요?

}

public static LanguageType findTypeByRequest(HttpServletRequest request) {
if(request == null)
Copy link
Member

Choose a reason for hiding this comment

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

위에서 Default로 KO를 주기로 생각한것 같은데 request가 null인 경우에는 return을 EXCEPTION으로 할 예정인 건가요???

@kwchoi11
Copy link
Collaborator Author

공지사항에 페이지네이션과 파파고 적용하면 완료될 것 같습니다.

- 공지사항 리스트 조회 (페이징)
- Exception추가
- 공지사항 게시물의 추가
  - 관리자 검증
  - 게시물 번역
  - 실패시 롤백
- 공지사항 게시물의 수정
  - 관리자 검증
  - 게시물 상태 검증
  - 번역실패시 롤백
- 공지사항 게시물 삭제

- 동일 명칭 Repository
Copy link
Member

@donsonioc2010 donsonioc2010 left a comment

Choose a reason for hiding this comment

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

@donsonioc2010 donsonioc2010 merged commit effeb80 into dev Oct 13, 2023
1 check passed
@donsonioc2010 donsonioc2010 deleted the feat/14-admin-page branch October 13, 2023 09:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants