-
Notifications
You must be signed in to change notification settings - Fork 3
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
[Refactor, Test] Notice 도메인 작업 #113 #116
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.
이번엔 리뷰다라봤슴미담.
수정할지 말지는 승현님 마음이기떄문에, 일단 Approve는 해놓는걸로... :)
src/main/java/bleuauction/bleuauction_be/server/notice/controller/NoticeController.java
Outdated
Show resolved
Hide resolved
if(loginUser.get().getMemberCategory() == A) { | ||
notice.setMemberNo(loginUser.get()); | ||
|
||
if (multipartFiles != null && multipartFiles.size() > 0) { | ||
ArrayList<Attach> attaches = new ArrayList<>(); | ||
for (MultipartFile multipartFile : multipartFiles) { | ||
if (multipartFile.getSize() > 0) { | ||
Attach attach = ncpObjectStorageService.uploadFile(new Attach(), | ||
"bleuauction-bucket", "notice/", multipartFile); | ||
notice.addNoticeAttach(attach); | ||
} | ||
} | ||
} |
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.
👍
List<Notice> notices = noticeService.findNoticesByStatus(NoticeStatus.Y); | ||
return notices; |
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.
동일한 코드가 되지않나 싶습니다 ㅋㅋ
List<Notice> notices = noticeService.findNoticesByStatus(NoticeStatus.Y); | |
return notices; | |
return noticeService.findNoticesByStatus(NoticeStatus.Y); |
} | ||
|
||
|
||
// 삭제 | ||
@PostMapping("/api/notice/delete/{noticeNo}") | ||
@DeleteMapping("/{noticeNo}") |
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.
👍
} else { | ||
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body("관리자 권한이 필요합니다"); | ||
} | ||
noticeService.deleteNotice(noticeNo,loginUser.get()); |
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.
Optional을 사용하는 안좋은 예라고 말씀드릴수 있을 것 같습니다 ㅎㅎ;;
src/main/java/bleuauction/bleuauction_be/server/notice/service/NoticeService.java
Outdated
Show resolved
Hide resolved
src/main/java/bleuauction/bleuauction_be/server/notice/controller/NoticeController.java
Outdated
Show resolved
Hide resolved
public Long enroll(Notice notice, List<MultipartFile> multipartFiles, Member member) { | ||
|
||
if(member.getMemberCategory() == MemberCategory.A) { | ||
notice.setMemberNo(member); | ||
noticeRepository.save(notice); | ||
|
||
if (multipartFiles != null && multipartFiles.size() > 0) { | ||
ArrayList<Attach> attaches = new ArrayList<>(); | ||
for (MultipartFile multipartFile : multipartFiles) { | ||
if (multipartFile.getSize() > 0) { | ||
Attach attach = ncpObjectStorageService.uploadFile(new Attach(), | ||
"bleuauction-bucket", "notice/", multipartFile); | ||
notice.addNoticeAttach(attach); | ||
} | ||
} | ||
} | ||
|
||
} | ||
return notice.getNoticeNo(); | ||
|
||
} |
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.
동일한 기능인데 전 이렇게 할 것 같아요.
if문을 계속 타고 들어가면 가독성이 떨어지다 보니 최대한 제거하는 방향으로 작성을 하려고 전 지향합니다 ㅎㅎ :)
번외로 스트림 익혀보는것도 권장합니다 ㅋㅋ
public Long enroll(Notice notice, List<MultipartFile> multipartFiles, Member member) { | |
if(member.getMemberCategory() == MemberCategory.A) { | |
notice.setMemberNo(member); | |
noticeRepository.save(notice); | |
if (multipartFiles != null && multipartFiles.size() > 0) { | |
ArrayList<Attach> attaches = new ArrayList<>(); | |
for (MultipartFile multipartFile : multipartFiles) { | |
if (multipartFile.getSize() > 0) { | |
Attach attach = ncpObjectStorageService.uploadFile(new Attach(), | |
"bleuauction-bucket", "notice/", multipartFile); | |
notice.addNoticeAttach(attach); | |
} | |
} | |
} | |
} | |
return notice.getNoticeNo(); | |
} | |
public Long enroll(Notice notice, List<MultipartFile> multipartFiles, Member member) { | |
if (!MemberCategory.A.equals(member.getMemberCategory())) { | |
// 관리자가 아니기 떄문에 예외처리 로직 | |
} | |
notice.setMemberNo(member); | |
if (multipartFiles != null && !multipartFiles.isEmpty()) { | |
multipartFiles.stream() | |
.filter(file -> file.getSize() > 0) | |
.forEach(multipartFile -> | |
notice.addNoticeAttach(ncpObjectStorageService.uploadFile(new Attach(), | |
"bleuauction-bucket", "notice/", multipartFile)) | |
); | |
} | |
return noticeRepository.save(notice).getNoticeNo(); | |
} |
public void deleteNotice(Long noticeNo, Member member) { | ||
if (member.getMemberCategory()==MemberCategory.A) { | ||
Notice notice = noticeRepository.findByNoticeNo(noticeNo); | ||
notice.delete(); | ||
if (notice.getNoticeAttaches() != null && !notice.getNoticeAttaches().isEmpty()) { | ||
for (Attach attach : notice.getNoticeAttaches()) { | ||
attachService.changeFileStatusToDeleteByFileNo(attach.getFileNo()); | ||
} | ||
} | ||
} | ||
} |
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.
요기도 요론식으로, If문을 제거해볼 수 있을 것 같아요.
public void deleteNotice(Long noticeNo, Member member) { | |
if (member.getMemberCategory()==MemberCategory.A) { | |
Notice notice = noticeRepository.findByNoticeNo(noticeNo); | |
notice.delete(); | |
if (notice.getNoticeAttaches() != null && !notice.getNoticeAttaches().isEmpty()) { | |
for (Attach attach : notice.getNoticeAttaches()) { | |
attachService.changeFileStatusToDeleteByFileNo(attach.getFileNo()); | |
} | |
} | |
} | |
} | |
@Transactional | |
public void deleteNotice(Long noticeNo, Member member) { | |
if(!MemberCategory.A.equals(member.getMemberCategory())) { | |
// 관리자가 아니기 떄문에, 예외처리 | |
} | |
Notice notice = noticeRepository.findByNoticeNo(noticeNo); | |
notice.delete(); | |
if (notice.getNoticeAttaches() != null && !notice.getNoticeAttaches().isEmpty()) { | |
for (Attach attach : notice.getNoticeAttaches()) { | |
attachService.changeFileStatusToDeleteByFileNo(attach.getFileNo()); | |
} | |
} | |
} |
|
||
Notice existingnotice = noticeRepository.findByNoticeNo(updatedNotice.getNoticeNo()); | ||
|
||
if(member.getMemberCategory() == A) { |
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.
요기도 흐흐흐
작업 PR
#113
작업내역
Notice Controller 및 Service Refactoring
Notice기능의 TestCase제작
다음 차례는 ,,, 두근두근