-
Notifications
You must be signed in to change notification settings - Fork 0
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
Conversation
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.
고생하셨습니다
수정사항 확인해주세요
* @return | ||
*/ | ||
@GetMapping("{/noticeArticleId}") | ||
public NoticeArticleDto getNoticeArticle(@PathVariable Long noticeArticleId, HttpServletRequest request, LanguageType languageType) { |
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.
Controller에서 LanguageType을 받을 수 있을 지가 확실하지않네요
아마 requestHeader
에 넣어주고 받을 것 같습니다
이미 밑에서 해준 것 같으니 LanguageType
을 빼도 될 것 같아요
또 requestHeader
를 사용하기 위해서는 @RequestHeader
어노테이션에 대해서도 알아보시면 좋을 것 같네요
* @return | ||
*/ | ||
@GetMapping | ||
public List<NoticeArticleDto> getNoticeArticleList(HttpServletRequest request, LanguageType languageType, NoticeArticleDto requestData) { |
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.
마찬가지로 LanguageType
은 requestHeader
에서 뽑아올 수 있도록 구성할 것이므로 빼도 될 것 같습니다
* 공지사항 등록 | ||
*/ | ||
@PostMapping | ||
public void addNotice(@RequestBody @Valid NoticeArticleDto articleRequest, NoticeContentDto contentRequest) { |
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.
@Valid
를 사용하려면 DTO 내에서 작업이 필요합니다
참고해보세요
public void updateNotice(@PathVariable Long id, | ||
@RequestBody @Valid NoticeArticleDto articleDto, NoticeContentDto contentDto) { |
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.
마찬가지로 @Valid
를 사용하기 위해서는 따로 작업이 필요합니다
@RequestBody
를 사용할 때는
@RequestBody @Valid UpdateNoticeRequest body
와 같이 구성하고
request dto를 하나 만들어보시는게 나을 수도 있겠네요
@DeleteMapping("/{noticeArticleId}") | ||
public void deleteNotice(@PathVariable Long noticeArticleId) { | ||
noticeService.deleteNotice(noticeArticleId); | ||
} |
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.
@DeleteMapping
에 대해서는 추가적으로 찾아보셔야 할 것 같네요
noticeContentRepository.save(noticeContent); | ||
} | ||
|
||
@Transactional(readOnly = true) |
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.
readonly 좋습니다
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); | ||
} |
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.
stream
을 써보는 것은 어떨까요
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(); | ||
} |
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.
이 코드는 나중에 또 쓸 수 있으니
NoticeContentDto
에 from
메소드를 만들어보는 것은 어떨까요?
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); | |
} |
처럼 나오도록 한번 만들어보세요!
public void update(Long id, NoticeArticleDto articleDto) { | ||
Optional<NoticeArticle> byId = noticeArticleRepository.findById(id); | ||
// TODO : 수정 받고 다시 작업 예정 | ||
} |
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.
JPA에서 update
는 어떻게 하는지 리서치해보시는것도 추천드립니다
public NoticeArticleDto getNoticeArticleByArticleId(Long noticeArticleId, LanguageType languageType) { | ||
return null; | ||
} | ||
|
||
public List<NoticeArticleDto> getNoticeArticleList(Long noticeArticleId, LanguageType languageType) { | ||
return 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.
이런 것들을 서비스에서 따로 정의하는것도 괜찮지만,
JPA repository에서 바로 가져올 수도 있을 것 같네요.
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.
그러면 서비스에서 이것들은 지워버리고 컨트롤러에서 바로 가져오도록 하면 되나요?
@@ -43,7 +43,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti | |||
.authorizeHttpRequests(authorization -> authorization | |||
.requestMatchers( | |||
"/login", | |||
"/register", "/health").permitAll() | |||
"/register", "/health", "/notice/**").permitAll() |
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 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); | ||
} |
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.
Default로 KO를 주기를 의도한 것 같은데, 실제 Value가 들어온 경우 (ex: "abc")에는 Exception이 발생하나요 아니면 KO가 반환되나요?
} | ||
|
||
public static LanguageType findTypeByRequest(HttpServletRequest request) { | ||
if(request == 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.
위에서 Default로 KO를 주기로 생각한것 같은데 request가 null인 경우에는 return을 EXCEPTION으로 할 예정인 건가요???
공지사항에 페이지네이션과 파파고 적용하면 완료될 것 같습니다. |
- 공지사항 리스트 조회 (페이징) - Exception추가 - 공지사항 게시물의 추가 - 관리자 검증 - 게시물 번역 - 실패시 롤백 - 공지사항 게시물의 수정 - 관리자 검증 - 게시물 상태 검증 - 번역실패시 롤백 - 공지사항 게시물 삭제 - 동일 명칭 Repository
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.
넴
controller, service 수정했습니다.
NoticeService 파일에서 saveNotice 부분의 빌더는 리뷰 받고 채워서 다시 올리겠습니다.