-
Notifications
You must be signed in to change notification settings - Fork 1
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/#144 #147
Open
GayeongKimm
wants to merge
18
commits into
master
Choose a base branch
from
Feat/#144
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Feat/#144 #147
Changes from 16 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
962e7f2
feat: 학부모 회원가입
GayeongKimm 289f676
fix: 병합에러
GayeongKimm 9018cb2
chore: yml
GayeongKimm b2a96f2
fix: merge error
GayeongKimm 63a8622
feat: create
GayeongKimm 1b4b895
feat: add notice division
GayeongKimm d71db24
chore: end point 수정
GayeongKimm a6df004
feat: 전체불러오기
GayeongKimm 53ec259
feat: 카테고리별 공지 불러오기
GayeongKimm 9c5973b
chore: security
GayeongKimm 66f4787
chore: api url
GayeongKimm 006595d
chore: security
GayeongKimm 2355832
chore: 리뷰 반영
GayeongKimm 7727561
chore: transactional 추가
GayeongKimm 75266ee
chore: 리뷰 반영
GayeongKimm f08a3e4
chore: 필요없는 null 체크 제거
GayeongKimm f200b99
chore: req의division크기만큼 query실행 -> 한번에 query실행
GayeongKimm 12ba084
chore: 필요없는 애노테이션 삭제
GayeongKimm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...-rest-api/src/main/java/b1nd/dodam/restapi/member/application/data/req/JoinParentReq.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package b1nd.dodam.restapi.member.application.data.req; | ||
|
||
import b1nd.dodam.domain.rds.member.entity.Member; | ||
import b1nd.dodam.domain.rds.member.entity.Parent; | ||
import b1nd.dodam.domain.rds.member.entity.Teacher; | ||
import b1nd.dodam.domain.rds.member.enumeration.ActiveStatus; | ||
import b1nd.dodam.domain.rds.member.enumeration.MemberRole; | ||
import jakarta.validation.constraints.Email; | ||
import jakarta.validation.constraints.NotEmpty; | ||
|
||
public record JoinParentReq(@NotEmpty String id, @NotEmpty String pw, @NotEmpty String name, @NotEmpty @Email String email, | ||
@NotEmpty String relation, @NotEmpty String phone) { | ||
public Parent mapToParent(Member member) { | ||
return Parent.builder() | ||
.member(member) | ||
.relation(relation) | ||
.build(); | ||
} | ||
|
||
public Member mapToMember(String encodedPw) { | ||
return Member.builder() | ||
.id(id) | ||
.pw(encodedPw) | ||
.email(email) | ||
.name(name) | ||
.role(MemberRole.PARENT) | ||
.phone(phone) | ||
.status(ActiveStatus.PENDING) | ||
.build(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
...ion/dodam-rest-api/src/main/java/b1nd/dodam/restapi/notice/application/NoticeUseCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package b1nd.dodam.restapi.notice.application; | ||
|
||
import b1nd.dodam.domain.rds.division.entity.Division; | ||
import b1nd.dodam.domain.rds.division.entity.DivisionMember; | ||
import b1nd.dodam.domain.rds.division.service.DivisionMemberService; | ||
import b1nd.dodam.domain.rds.division.service.DivisionService; | ||
import b1nd.dodam.domain.rds.member.entity.Member; | ||
import b1nd.dodam.domain.rds.notice.entity.Notice; | ||
import b1nd.dodam.domain.rds.notice.entity.NoticeDivision; | ||
import b1nd.dodam.domain.rds.notice.enumration.NoticeStatus; | ||
import b1nd.dodam.domain.rds.notice.service.NoticeDivisionService; | ||
import b1nd.dodam.domain.rds.notice.service.NoticeService; | ||
import b1nd.dodam.restapi.auth.infrastructure.security.support.MemberAuthenticationHolder; | ||
import b1nd.dodam.restapi.notice.application.data.req.GenerateNoticeReq; | ||
import b1nd.dodam.restapi.notice.application.data.res.NoticeRes; | ||
import b1nd.dodam.restapi.support.data.ResponseData; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.List; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
@Transactional(rollbackFor = Exception.class) | ||
public class NoticeUseCase { | ||
|
||
private final NoticeService noticeService; | ||
private final NoticeDivisionService noticeDivisionService; | ||
private final DivisionService divisionService; | ||
private final DivisionMemberService divisionMemberService; | ||
private final MemberAuthenticationHolder memberAuthenticationHolder; | ||
|
||
public ResponseData<Long> register(GenerateNoticeReq generateNoticeReq){ | ||
Member member = memberAuthenticationHolder.current(); | ||
Notice notice = noticeService.save(generateNoticeReq.toEntity(member)); | ||
|
||
List<Division> divisions = generateNoticeReq.divisions().stream() | ||
.map(divisionService::getById) | ||
.toList(); | ||
|
||
List<NoticeDivision> noticeDivisions = generateNoticeReq.toEntity(notice, divisions); | ||
|
||
noticeService.changeStatus(notice.getId(), NoticeStatus.CREATED); | ||
noticeDivisionService.saveAll(noticeDivisions); | ||
|
||
return ResponseData.of(HttpStatus.OK, "공지 생성 성공", notice.getId()); | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
public ResponseData<List<NoticeRes>> getNotices(Long lastId, int limit, NoticeStatus status) { | ||
Member member = memberAuthenticationHolder.current(); | ||
List<DivisionMember> divisionMembers = divisionMemberService.getByMember(member); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. divisionMemberService.getByMember가 호출될 때 마다 getDivision으로 조직을 가져오는데 그냥 DivisionService에서 쿼리로 해결하는게 좋을 듯합니다 |
||
|
||
List<Long> divisionIds = divisionMembers.stream() | ||
.map(divisionMember -> divisionMember.getDivision().getId()) | ||
.toList(); | ||
|
||
List<Notice> notices = noticeService.getAllByStatus(divisionIds, status, lastId, limit); | ||
|
||
return ResponseData.of(HttpStatus.OK, "전체 공지 불러오기 성공", NoticeRes.of(notices, member)); | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
public ResponseData<List<NoticeRes>> getNoticesByDivision(Long divisionId, Long lastId, int limit){ | ||
Member member = memberAuthenticationHolder.current(); | ||
Division division = divisionService.getById(divisionId); | ||
|
||
List<Notice> notices = noticeService.getAllByDivision(member.getId(), division.getId(), lastId, limit) | ||
.stream() | ||
.toList(); | ||
|
||
return ResponseData.of(HttpStatus.OK, "카테고리별 공지 불러오기 성공", NoticeRes.of(notices, member)); | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
...ication/dodam-rest-api/src/main/java/b1nd/dodam/restapi/notice/application/data/File.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package b1nd.dodam.restapi.notice.application.data; | ||
|
||
import b1nd.dodam.domain.rds.notice.entity.NoticeFile; | ||
import b1nd.dodam.domain.rds.support.enumeration.FileType; | ||
import jakarta.validation.constraints.NotEmpty; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public record File(@NotEmpty String url, @NotEmpty String name, @NotEmpty FileType fileType) { | ||
public static List<File> of(List<NoticeFile> noticeFiles){ | ||
return noticeFiles.stream().map( | ||
noticeFile -> | ||
new File(noticeFile.getFileUrl(), | ||
noticeFile.getFileName(), | ||
noticeFile.getFileType()) | ||
).collect(Collectors.toList()); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...pi/src/main/java/b1nd/dodam/restapi/notice/application/data/req/AddNoticeDivisionReq.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package b1nd.dodam.restapi.notice.application.data.req; | ||
|
||
import b1nd.dodam.domain.rds.division.entity.Division; | ||
import b1nd.dodam.domain.rds.notice.entity.Notice; | ||
import b1nd.dodam.domain.rds.notice.entity.NoticeDivision; | ||
|
||
public record AddNoticeDivisionReq( | ||
Long divisionId | ||
) { | ||
public NoticeDivision toEntity(Notice notice, Division division){ | ||
return NoticeDivision.builder() | ||
.notice(notice) | ||
.division(division) | ||
.build(); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
...t-api/src/main/java/b1nd/dodam/restapi/notice/application/data/req/GenerateNoticeReq.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package b1nd.dodam.restapi.notice.application.data.req; | ||
|
||
import b1nd.dodam.domain.rds.division.entity.Division; | ||
import b1nd.dodam.domain.rds.member.entity.Member; | ||
import b1nd.dodam.domain.rds.notice.entity.Notice; | ||
import b1nd.dodam.domain.rds.notice.entity.NoticeDivision; | ||
import b1nd.dodam.domain.rds.notice.entity.NoticeFile; | ||
import b1nd.dodam.domain.rds.notice.enumration.NoticeStatus; | ||
import b1nd.dodam.restapi.notice.application.data.File; | ||
import jakarta.validation.constraints.NotEmpty; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import static b1nd.dodam.domain.rds.notice.enumration.NoticeStatus.DRAFT; | ||
|
||
public record GenerateNoticeReq (@NotEmpty String title, @NotEmpty String content, List<File> files, | ||
List<Long> divisions){ | ||
|
||
public Notice toEntity(Member member) { | ||
Notice notice = Notice.builder() | ||
.title(title) | ||
.content(content) | ||
.noticeStatus(NoticeStatus.DRAFT) | ||
.member(member) | ||
.build(); | ||
|
||
if (files != null && !files.isEmpty()) { | ||
files.forEach(file -> notice.addNoticeFiles( | ||
NoticeFile.builder() | ||
.fileUrl(file.url()) | ||
.fileName(file.name()) | ||
.fileType(file.fileType()) | ||
.build() | ||
)); | ||
} | ||
|
||
return notice; | ||
} | ||
|
||
public List<NoticeDivision> toEntity(Notice notice, List<Division> divisions) { | ||
return divisions.stream() | ||
.map(division -> { | ||
NoticeDivision noticeDivision = GenerateNoticeReq.toEntity(notice, division); | ||
notice.addNoticeDivision(noticeDivision); | ||
return noticeDivision; | ||
}) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
public static NoticeDivision toEntity(Notice notice, Division division){ | ||
return NoticeDivision.builder() | ||
.notice(notice) | ||
.division(division) | ||
.build(); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...odam-rest-api/src/main/java/b1nd/dodam/restapi/notice/application/data/res/NoticeRes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package b1nd.dodam.restapi.notice.application.data.res; | ||
|
||
import b1nd.dodam.domain.rds.member.entity.Member; | ||
import b1nd.dodam.domain.rds.notice.entity.Notice; | ||
import b1nd.dodam.domain.rds.notice.enumration.NoticeStatus; | ||
import b1nd.dodam.domain.rds.support.enumeration.FileType; | ||
import b1nd.dodam.restapi.member.application.data.res.MemberInfoRes; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public record NoticeRes( | ||
Long id, | ||
String title, | ||
String content, | ||
String fileUrl, | ||
FileType fileType, | ||
NoticeStatus noticeStatus, | ||
MemberInfoRes memberInfoRes, | ||
LocalDateTime createdAt, LocalDateTime modifiedAt | ||
) { | ||
public static List<NoticeRes> of(List<Notice> notices, Member member) { | ||
return notices.parallelStream() | ||
.map(notice -> NoticeRes.of(notice, member)) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
public static NoticeRes of(Notice notice, Member member) { | ||
return new NoticeRes( | ||
notice.getId(), | ||
notice.getTitle(), | ||
notice.getContent(), | ||
notice.getFileUrl(), | ||
notice.getFileType(), | ||
notice.getNoticeStatus(), | ||
MemberInfoRes.of(member, null, null), | ||
notice.getCreatedAt(), | ||
notice.getModifiedAt() | ||
); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...dodam-rest-api/src/main/java/b1nd/dodam/restapi/notice/presentation/NoticeController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package b1nd.dodam.restapi.notice.presentation; | ||
|
||
import b1nd.dodam.domain.rds.notice.enumration.NoticeStatus; | ||
import b1nd.dodam.restapi.notice.application.NoticeUseCase; | ||
import b1nd.dodam.restapi.notice.application.data.req.GenerateNoticeReq; | ||
import b1nd.dodam.restapi.notice.application.data.res.NoticeRes; | ||
import b1nd.dodam.restapi.support.data.ResponseData; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequestMapping("/notice") | ||
@RequiredArgsConstructor | ||
public class NoticeController { | ||
|
||
private final NoticeUseCase noticeUseCase; | ||
|
||
@PostMapping | ||
public ResponseData<Long> generate(@RequestBody GenerateNoticeReq generateNoticeReq){ | ||
return noticeUseCase.register(generateNoticeReq); | ||
} | ||
|
||
@GetMapping | ||
public ResponseData<List<NoticeRes>> getByStatus( | ||
@RequestParam Long lastId, | ||
@RequestParam int limit, | ||
@RequestParam NoticeStatus status | ||
|
||
){ | ||
return noticeUseCase.getNotices(lastId, limit, status); | ||
} | ||
|
||
@GetMapping("/{id}/division") | ||
public ResponseData<List<NoticeRes>> getBy( | ||
@PathVariable Long id, | ||
@RequestParam Long lastId, | ||
@RequestParam int limit | ||
){ | ||
return noticeUseCase.getNoticesByDivision(id, lastId, limit); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
division 개수만큼 SQL 조회하는 거 아닌가요?
SQL 한번만 쓸 수 있지 않나여?