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

[Refactor, Test] Notice 도메인 작업 #113 #116

Merged
merged 12 commits into from
Dec 7, 2023

Conversation

seunghyun333
Copy link
Collaborator

작업 PR
#113

작업내역
Notice Controller 및 Service Refactoring
Notice기능의 TestCase제작


다음 차례는 ,,, 두근두근

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.

이번엔 리뷰다라봤슴미담.

수정할지 말지는 승현님 마음이기떄문에, 일단 Approve는 해놓는걸로... :)

Comment on lines -69 to -81
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);
}
}
}
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 66 to 67
List<Notice> notices = noticeService.findNoticesByStatus(NoticeStatus.Y);
return notices;
Copy link
Member

@donsonioc2010 donsonioc2010 Dec 3, 2023

Choose a reason for hiding this comment

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

동일한 코드가 되지않나 싶습니다 ㅋㅋ

Suggested change
List<Notice> notices = noticeService.findNoticesByStatus(NoticeStatus.Y);
return notices;
return noticeService.findNoticesByStatus(NoticeStatus.Y);

}


// 삭제
@PostMapping("/api/notice/delete/{noticeNo}")
@DeleteMapping("/{noticeNo}")
Copy link
Member

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

Choose a reason for hiding this comment

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

Optional을 사용하는 안좋은 예라고 말씀드릴수 있을 것 같습니다 ㅎㅎ;;

Comment on lines 31 to 51
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();

}
Copy link
Member

Choose a reason for hiding this comment

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

동일한 기능인데 전 이렇게 할 것 같아요.

if문을 계속 타고 들어가면 가독성이 떨어지다 보니 최대한 제거하는 방향으로 작성을 하려고 전 지향합니다 ㅎㅎ :)

번외로 스트림 익혀보는것도 권장합니다 ㅋㅋ

Suggested change
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();
}

Comment on lines 72 to 82
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());
}
}
}
}
Copy link
Member

Choose a reason for hiding this comment

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

요기도 요론식으로, If문을 제거해볼 수 있을 것 같아요.

Suggested change
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) {
Copy link
Member

Choose a reason for hiding this comment

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

요기도 흐흐흐

@seunghyun333 seunghyun333 merged commit 0918ead into dev Dec 7, 2023
@seunghyun333 seunghyun333 deleted the feat/113_NoticeRefactor branch December 7, 2023 04:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants