diff --git a/.github/ISSUE_TEMPLATE/bug-report.md b/.github/ISSUE_TEMPLATE/bug-report.md new file mode 100644 index 00000000..b89a6cbd --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug-report.md @@ -0,0 +1,17 @@ +--- +name: Bug report(버그 수정 템플릿) +about: 버그 제보 관련 템플릿 +title: '' +labels: '' +assignees: '' +--- + +## 버그 사항 +버그 내용을 상세하게 적어주세요! + + +## 기대했던 상황 +원했던 상황을 자세하게 적어주세요 😊 + + +## **Screenshots** \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/default-issue.md b/.github/ISSUE_TEMPLATE/default-issue.md new file mode 100644 index 00000000..03059483 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/default-issue.md @@ -0,0 +1,15 @@ +--- +name: Default Issue +about: 기본 양식 +title: '' +labels: '' +assignees: '' +--- + +## ❓ 어떤 이슈인가요? + + +## ✅ 투두리스트 + +- [ ] item +- [ ] item \ No newline at end of file diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 00000000..3f794489 --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,11 @@ +## 🔥 연관 이슈 + +- close #이슈번호 + +## 🚀 작업 내용 + + +## 🤔 고민했던 내용 + + +## 💬 리뷰 중점사항 \ No newline at end of file diff --git a/.platform/nginx/nginx.conf b/.platform/nginx/nginx.conf index f6514fb9..ac67b7b1 100644 --- a/.platform/nginx/nginx.conf +++ b/.platform/nginx/nginx.conf @@ -29,7 +29,7 @@ http { } server { - listen 80 default_server; + listen 80 default_server; location / { proxy_pass http://springboot; diff --git a/src/main/java/ddingdong/ddingdongBE/domain/club/controller/dto/request/RegisterClubRequest.java b/src/main/java/ddingdong/ddingdongBE/domain/club/controller/dto/request/RegisterClubRequest.java index bdc967b3..89c0d7cd 100644 --- a/src/main/java/ddingdong/ddingdongBE/domain/club/controller/dto/request/RegisterClubRequest.java +++ b/src/main/java/ddingdong/ddingdongBE/domain/club/controller/dto/request/RegisterClubRequest.java @@ -3,7 +3,7 @@ import ddingdong.ddingdongBE.domain.club.entity.Club; import ddingdong.ddingdongBE.domain.club.entity.Location; import ddingdong.ddingdongBE.domain.club.entity.PhoneNumber; -import ddingdong.ddingdongBE.domain.club.entity.Score; +import ddingdong.ddingdongBE.domain.scorehistory.entity.Score; import ddingdong.ddingdongBE.domain.user.entity.User; import lombok.Getter; diff --git a/src/main/java/ddingdong/ddingdongBE/domain/club/controller/dto/request/UpdateClubRequest.java b/src/main/java/ddingdong/ddingdongBE/domain/club/controller/dto/request/UpdateClubRequest.java index b108b91f..42b304ea 100644 --- a/src/main/java/ddingdong/ddingdongBE/domain/club/controller/dto/request/UpdateClubRequest.java +++ b/src/main/java/ddingdong/ddingdongBE/domain/club/controller/dto/request/UpdateClubRequest.java @@ -1,12 +1,8 @@ package ddingdong.ddingdongBE.domain.club.controller.dto.request; -import com.fasterxml.jackson.annotation.JsonFormat; -import java.time.LocalDateTime; import java.util.List; - import lombok.AllArgsConstructor; import lombok.Getter; -import org.springframework.format.annotation.DateTimeFormat; @Getter @AllArgsConstructor @@ -26,11 +22,9 @@ public class UpdateClubRequest { private String location; - @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm") - private LocalDateTime startRecruitPeriod; + private String startRecruitPeriod; - @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm") - private LocalDateTime endRecruitPeriod; + private String endRecruitPeriod; private String regularMeeting; diff --git a/src/main/java/ddingdong/ddingdongBE/domain/club/controller/dto/response/AdminClubResponse.java b/src/main/java/ddingdong/ddingdongBE/domain/club/controller/dto/response/AdminClubResponse.java index f9a29fb2..eeca23be 100644 --- a/src/main/java/ddingdong/ddingdongBE/domain/club/controller/dto/response/AdminClubResponse.java +++ b/src/main/java/ddingdong/ddingdongBE/domain/club/controller/dto/response/AdminClubResponse.java @@ -15,12 +15,12 @@ public class AdminClubResponse { private String category; - private int score; + private float score; private List profileImageUrls; @Builder - private AdminClubResponse(Long id, String name, String category, int score, List profileImageUrls) { + private AdminClubResponse(Long id, String name, String category, float score, List profileImageUrls) { this.id = id; this.name = name; this.category = category; diff --git a/src/main/java/ddingdong/ddingdongBE/domain/club/controller/dto/response/ClubResponse.java b/src/main/java/ddingdong/ddingdongBE/domain/club/controller/dto/response/ClubResponse.java index bff91351..10de23cb 100644 --- a/src/main/java/ddingdong/ddingdongBE/domain/club/controller/dto/response/ClubResponse.java +++ b/src/main/java/ddingdong/ddingdongBE/domain/club/controller/dto/response/ClubResponse.java @@ -15,24 +15,24 @@ public class ClubResponse { private String tag; - private boolean isRecruit; + private String recruitStatus; @Builder - public ClubResponse(Long id, String name, String category, String tag, boolean isRecruit) { + public ClubResponse(Long id, String name, String category, String tag, String recruitStatus) { this.id = id; this.name = name; this.category = category; this.tag = tag; - this.isRecruit = isRecruit; + this.recruitStatus = recruitStatus; } - public static ClubResponse of(Club club, boolean isRecruit) { + public static ClubResponse of(Club club, String recruitStatus) { return ClubResponse.builder() .id(club.getId()) .name(club.getName()) .category(club.getCategory()) .tag(club.getTag()) - .isRecruit(isRecruit).build(); + .recruitStatus(recruitStatus).build(); } } diff --git a/src/main/java/ddingdong/ddingdongBE/domain/club/entity/Club.java b/src/main/java/ddingdong/ddingdongBE/domain/club/entity/Club.java index 12f7d717..16a14a86 100644 --- a/src/main/java/ddingdong/ddingdongBE/domain/club/entity/Club.java +++ b/src/main/java/ddingdong/ddingdongBE/domain/club/entity/Club.java @@ -2,9 +2,11 @@ import ddingdong.ddingdongBE.common.BaseEntity; import ddingdong.ddingdongBE.domain.club.controller.dto.request.UpdateClubRequest; +import ddingdong.ddingdongBE.domain.scorehistory.entity.Score; import ddingdong.ddingdongBE.domain.user.entity.User; import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.List; import javax.persistence.Embedded; @@ -94,9 +96,9 @@ public void updateClubInfo(UpdateClubRequest request) { request.getPhoneNumber() != null ? PhoneNumber.of(request.getPhoneNumber()) : this.phoneNumber; this.location = request.getLocation() != null ? Location.of(request.getLocation()) : this.location; this.startRecruitPeriod = - request.getStartRecruitPeriod() != null ? request.getStartRecruitPeriod() : this.startRecruitPeriod; + request.getStartRecruitPeriod().isBlank() ? null : parseLocalDateTime(request.getStartRecruitPeriod()); this.endRecruitPeriod = - request.getEndRecruitPeriod() != null ? request.getEndRecruitPeriod() : this.endRecruitPeriod; + request.getEndRecruitPeriod().isBlank() ? null : parseLocalDateTime(request.getEndRecruitPeriod()); this.regularMeeting = request.getRegularMeeting() != null ? request.getRegularMeeting() : this.regularMeeting; this.introduction = request.getIntroduction() != null ? request.getIntroduction() : this.introduction; this.activity = request.getActivity() != null ? request.getActivity() : this.activity; @@ -104,7 +106,12 @@ public void updateClubInfo(UpdateClubRequest request) { this.formUrl = request.getFormUrl() != null ? request.getFormUrl() : this.formUrl; } - public int editScore(Score score) { + private static LocalDateTime parseLocalDateTime(String inputLocalDateTimeFormat) { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); + return LocalDateTime.parse(inputLocalDateTimeFormat, formatter); + } + + public float editScore(Score score) { this.score = score; return this.score.getValue(); diff --git a/src/main/java/ddingdong/ddingdongBE/domain/club/entity/RecruitmentStatus.java b/src/main/java/ddingdong/ddingdongBE/domain/club/entity/RecruitmentStatus.java new file mode 100644 index 00000000..a268db2d --- /dev/null +++ b/src/main/java/ddingdong/ddingdongBE/domain/club/entity/RecruitmentStatus.java @@ -0,0 +1,15 @@ +package ddingdong.ddingdongBE.domain.club.entity; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +public enum RecruitmentStatus { + + BEFORE_RECRUIT("모집 예정"), + RECRUITING("모집 중"), + END_RECRUIT("모집 마감"); + + private final String text; +} diff --git a/src/main/java/ddingdong/ddingdongBE/domain/club/repository/ClubMemberRepository.java b/src/main/java/ddingdong/ddingdongBE/domain/club/repository/ClubMemberRepository.java index 922370b9..e2163656 100644 --- a/src/main/java/ddingdong/ddingdongBE/domain/club/repository/ClubMemberRepository.java +++ b/src/main/java/ddingdong/ddingdongBE/domain/club/repository/ClubMemberRepository.java @@ -1,8 +1,19 @@ package ddingdong.ddingdongBE.domain.club.repository; import ddingdong.ddingdongBE.domain.club.entity.ClubMember; + +import java.util.List; + import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; +import org.springframework.transaction.annotation.Transactional; public interface ClubMemberRepository extends JpaRepository { + List findClubMembersByClubId(Long clubId); -} + @Modifying + @Transactional + @Query("delete from ClubMember c where c.id in :memberIds") + void deleteAllById(List memberIds); +} \ No newline at end of file diff --git a/src/main/java/ddingdong/ddingdongBE/domain/club/service/ClubMemberService.java b/src/main/java/ddingdong/ddingdongBE/domain/club/service/ClubMemberService.java index e30c5acd..91c26189 100644 --- a/src/main/java/ddingdong/ddingdongBE/domain/club/service/ClubMemberService.java +++ b/src/main/java/ddingdong/ddingdongBE/domain/club/service/ClubMemberService.java @@ -7,7 +7,9 @@ import ddingdong.ddingdongBE.domain.club.entity.ClubMember; import ddingdong.ddingdongBE.domain.club.repository.ClubMemberRepository; import ddingdong.ddingdongBE.domain.club.repository.ClubRepository; +import java.util.Collections; import java.util.List; +import java.util.stream.Collectors; import javax.transaction.Transactional; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -24,11 +26,19 @@ public void updateClubMembers(Long userId, UpdateClubMemberRequest request) { Club club = clubRepository.findByUserId(userId) .orElseThrow(() -> new IllegalArgumentException(NO_SUCH_CLUB.getText())); + List memberIds = clubMemberRepository.findClubMembersByClubId(club.getId()) + .stream() + .map(ClubMember::getId) + .toList(); + List requestedClubMembers = request.getClubMemberList().stream() .map(clubMemberDto -> clubMemberDto.toEntity(club)) .toList(); - clubMemberRepository.deleteAll(); + if (!memberIds.isEmpty()) { + clubMemberRepository.deleteAllById(memberIds); + } + clubMemberRepository.saveAll(requestedClubMembers); } -} +} \ No newline at end of file diff --git a/src/main/java/ddingdong/ddingdongBE/domain/club/service/ClubService.java b/src/main/java/ddingdong/ddingdongBE/domain/club/service/ClubService.java index 80f5b815..469c841b 100644 --- a/src/main/java/ddingdong/ddingdongBE/domain/club/service/ClubService.java +++ b/src/main/java/ddingdong/ddingdongBE/domain/club/service/ClubService.java @@ -1,6 +1,7 @@ package ddingdong.ddingdongBE.domain.club.service; import static ddingdong.ddingdongBE.common.exception.ErrorMessage.*; +import static ddingdong.ddingdongBE.domain.club.entity.RecruitmentStatus.*; import static ddingdong.ddingdongBE.domain.fileinformation.entity.FileDomainCategory.CLUB_INTRODUCE; import static ddingdong.ddingdongBE.domain.fileinformation.entity.FileDomainCategory.CLUB_PROFILE; import static ddingdong.ddingdongBE.domain.fileinformation.entity.FileTypeCategory.IMAGE; @@ -13,7 +14,8 @@ import ddingdong.ddingdongBE.domain.club.controller.dto.response.ClubResponse; import ddingdong.ddingdongBE.domain.club.controller.dto.response.DetailClubResponse; import ddingdong.ddingdongBE.domain.club.entity.Club; -import ddingdong.ddingdongBE.domain.club.entity.Score; +import ddingdong.ddingdongBE.domain.club.entity.RecruitmentStatus; +import ddingdong.ddingdongBE.domain.scorehistory.entity.Score; import ddingdong.ddingdongBE.domain.club.repository.ClubRepository; import ddingdong.ddingdongBE.domain.fileinformation.entity.FileInformation; import ddingdong.ddingdongBE.domain.fileinformation.repository.FileInformationRepository; @@ -26,150 +28,151 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; + @Service @RequiredArgsConstructor @Transactional public class ClubService { - private final ClubRepository clubRepository; - private final AuthService authService; - private final FileInformationService fileInformationService; - private final FileStore fileStore; - private final FileInformationRepository fileInformationRepository; - - public Long register(RegisterClubRequest request) { - User clubUser = authService.registerClubUser(request.getUserId(), request.getPassword(), request.getClubName()); - - Club club = request.toEntity(clubUser); - Club savedClub = clubRepository.save(club); - - return savedClub.getId(); - } - - @Transactional(readOnly = true) - public List getAllClubs(LocalDateTime now) { - return clubRepository.findAll().stream() - .map(club -> ClubResponse.of(club, - checkRecruit(now, club))) - .toList(); - } - - @Transactional(readOnly = true) - public List getAllForAdmin() { - return clubRepository.findAll().stream() - .map(club -> AdminClubResponse.of(club, fileInformationService.getImageUrls( - IMAGE.getFileType() + CLUB_PROFILE.getFileDomain() + club.getId()))) - .toList(); - } - - @Transactional(readOnly = true) - public DetailClubResponse getClub(Long clubId) { - Club club = findClubByClubId(clubId); - - List profileImageUrl = fileInformationService.getImageUrls( - IMAGE.getFileType() + CLUB_PROFILE.getFileDomain() + clubId); - - List introduceImageUrls = fileInformationService.getImageUrls( - IMAGE.getFileType() + CLUB_INTRODUCE.getFileDomain() + clubId); - - List clubMemberDtos = club.getClubMembers().stream() - .map(ClubMemberDto::from) - .toList(); - - return DetailClubResponse.of(club, profileImageUrl, introduceImageUrls, clubMemberDtos); - } - - @Transactional(readOnly = true) - public DetailClubResponse getMyClub(Long userId) { - Club club = findClubByUserId(userId); - - List profileImageUrl = fileInformationService.getImageUrls( - IMAGE.getFileType() + CLUB_PROFILE.getFileDomain() + club.getId()); - - List introduceImageUrls = fileInformationService.getImageUrls( - IMAGE.getFileType() + CLUB_INTRODUCE.getFileDomain() + club.getId()); - - List clubMemberDtos = club.getClubMembers().stream() - .map(ClubMemberDto::from) - .toList(); - - return DetailClubResponse.of(club, profileImageUrl, introduceImageUrls, clubMemberDtos); - } - - public void delete(Long clubId) { - Club club = findClubByClubId(clubId); - - clubRepository.delete(club); - } - - public int editClubScore(Long clubId, int score) { - Club club = findClubByClubId(clubId); - - return club.editScore(generateNewScore(club.getScore(), score)); - } - - public Long update(Long userId, UpdateClubRequest request) { - Club club = findClubByUserId(userId); - updateIntroduceImageInformation(request, club); - updateProfileImageInformation(request, club); - - club.updateClubInfo(request); - return club.getId(); - } - - public Club findClubByUserId(final Long userId) { - return clubRepository.findByUserId(userId) - .orElseThrow(() -> new NoSuchElementException(NO_SUCH_CLUB.getText())); - } - - public Club findClubByClubId(final Long clubId) { - return clubRepository.findById(clubId) - .orElseThrow(() -> new NoSuchElementException(NO_SUCH_CLUB.getText())); - } - - private void updateIntroduceImageInformation(UpdateClubRequest request, Club club) { - List fileInformation = fileInformationService.getFileInformation( - IMAGE.getFileType() + CLUB_INTRODUCE.getFileDomain() + club.getId()); - if (!request.getIntroduceImageUrls().isEmpty()) { - List deleteInformation = fileInformation.stream() - .filter(information -> !request.getIntroduceImageUrls() - .contains(fileStore.getImageUrlPrefix() + information.getFileTypeCategory() - .getFileType() + information.getFileDomainCategory().getFileDomain() - + information.getStoredName())) - .toList(); - - fileInformationRepository.deleteAll(deleteInformation); - } else { - fileInformationRepository.deleteAll(fileInformation); - } - } - - private void updateProfileImageInformation(UpdateClubRequest request, Club club) { - List fileInformation = fileInformationService.getFileInformation( - IMAGE.getFileType() + CLUB_PROFILE.getFileDomain() + club.getId()); - if (!request.getProfileImageUrls().isEmpty()) { - List deleteInformation = fileInformation.stream() - .filter(information -> !request.getProfileImageUrls() - .contains(fileStore.getImageUrlPrefix() + information.getFileTypeCategory() - .getFileType() + information.getFileDomainCategory().getFileDomain() - + information.getStoredName())) - .toList(); - - fileInformationRepository.deleteAll(deleteInformation); - } else { - fileInformationRepository.deleteAll(fileInformation); - } - } - - private Score generateNewScore(Score beforeUpdateScore, int value) { - return Score.of(beforeUpdateScore.getValue() + value); - } - - private boolean checkRecruit(LocalDateTime now, Club club) { - boolean isRecruit = false; - if (club.getStartRecruitPeriod() != null && club.getEndRecruitPeriod() != null) { - isRecruit = club.getStartRecruitPeriod().isBefore(now) && club.getEndRecruitPeriod().isAfter(now); - } - return isRecruit; - } + private final ClubRepository clubRepository; + private final AuthService authService; + private final FileInformationService fileInformationService; + private final FileStore fileStore; + private final FileInformationRepository fileInformationRepository; + + public Long register(RegisterClubRequest request) { + User clubUser = authService.registerClubUser(request.getUserId(), request.getPassword(), request.getClubName()); + + Club club = request.toEntity(clubUser); + Club savedClub = clubRepository.save(club); + + return savedClub.getId(); + } + + @Transactional(readOnly = true) + public List getAllClubs(LocalDateTime now) { + return clubRepository.findAll().stream() + .map(club -> ClubResponse.of(club, checkRecruit(now, club).getText())) + .toList(); + } + + @Transactional(readOnly = true) + public List getAllForAdmin() { + return clubRepository.findAll().stream() + .map(club -> AdminClubResponse.of(club, fileInformationService.getImageUrls( + IMAGE.getFileType() + CLUB_PROFILE.getFileDomain() + club.getId()))) + .toList(); + } + + @Transactional(readOnly = true) + public DetailClubResponse getClub(Long clubId) { + Club club = findClubByClubId(clubId); + + List profileImageUrl = fileInformationService.getImageUrls( + IMAGE.getFileType() + CLUB_PROFILE.getFileDomain() + clubId); + + List introduceImageUrls = fileInformationService.getImageUrls( + IMAGE.getFileType() + CLUB_INTRODUCE.getFileDomain() + clubId); + + List clubMemberDtos = club.getClubMembers().stream() + .map(ClubMemberDto::from) + .toList(); + + return DetailClubResponse.of(club, profileImageUrl, introduceImageUrls, clubMemberDtos); + } + + @Transactional(readOnly = true) + public DetailClubResponse getMyClub(Long userId) { + Club club = findClubByUserId(userId); + + List profileImageUrl = fileInformationService.getImageUrls( + IMAGE.getFileType() + CLUB_PROFILE.getFileDomain() + club.getId()); + + List introduceImageUrls = fileInformationService.getImageUrls( + IMAGE.getFileType() + CLUB_INTRODUCE.getFileDomain() + club.getId()); + + List clubMemberDtos = club.getClubMembers().stream() + .map(ClubMemberDto::from) + .toList(); + + return DetailClubResponse.of(club, profileImageUrl, introduceImageUrls, clubMemberDtos); + } + + public void delete(Long clubId) { + Club club = findClubByClubId(clubId); + + clubRepository.delete(club); + } + + public float editClubScore(Long clubId, float score) { + Club club = findClubByClubId(clubId); + + return club.editScore(generateNewScore(club.getScore(), score)); + } + + public Long update(Long userId, UpdateClubRequest request) { + Club club = findClubByUserId(userId); + updateIntroduceImageInformation(request, club); + updateProfileImageInformation(request, club); + + club.updateClubInfo(request); + return club.getId(); + } + + public Club findClubByUserId(final Long userId) { + return clubRepository.findByUserId(userId) + .orElseThrow(() -> new NoSuchElementException(NO_SUCH_CLUB.getText())); + } + + public Club findClubByClubId(final Long clubId) { + return clubRepository.findById(clubId) + .orElseThrow(() -> new NoSuchElementException(NO_SUCH_CLUB.getText())); + } + + private void updateIntroduceImageInformation(UpdateClubRequest request, Club club) { + List fileInformation = fileInformationService.getFileInformation( + IMAGE.getFileType() + CLUB_INTRODUCE.getFileDomain() + club.getId()); + if (!request.getIntroduceImageUrls().isEmpty()) { + List deleteInformation = fileInformation.stream() + .filter(information -> !request.getIntroduceImageUrls() + .contains(fileStore.getImageUrlPrefix() + information.getFileTypeCategory() + .getFileType() + information.getFileDomainCategory().getFileDomain() + + information.getStoredName())) + .toList(); + + fileInformationRepository.deleteAll(deleteInformation); + } else { + fileInformationRepository.deleteAll(fileInformation); + } + } + + private void updateProfileImageInformation(UpdateClubRequest request, Club club) { + List fileInformation = fileInformationService.getFileInformation( + IMAGE.getFileType() + CLUB_PROFILE.getFileDomain() + club.getId()); + if (!request.getProfileImageUrls().isEmpty()) { + List deleteInformation = fileInformation.stream() + .filter(information -> !request.getProfileImageUrls() + .contains(fileStore.getImageUrlPrefix() + information.getFileTypeCategory() + .getFileType() + information.getFileDomainCategory().getFileDomain() + + information.getStoredName())) + .toList(); + + fileInformationRepository.deleteAll(deleteInformation); + } else { + fileInformationRepository.deleteAll(fileInformation); + } + } + + private Score generateNewScore(Score beforeUpdateScore, float value) { + return Score.of(beforeUpdateScore.getValue() + value); + } + + private RecruitmentStatus checkRecruit(LocalDateTime now, Club club) { + if (club.getStartRecruitPeriod() == null || club.getEndRecruitPeriod() == null + || club.getStartRecruitPeriod().isAfter(now)) { + return BEFORE_RECRUIT; + } + + return club.getEndRecruitPeriod().isAfter(now) ? RECRUITING : END_RECRUIT; + } } diff --git a/src/main/java/ddingdong/ddingdongBE/domain/scorehistory/controller/dto/request/RegisterScoreRequest.java b/src/main/java/ddingdong/ddingdongBE/domain/scorehistory/controller/dto/request/RegisterScoreRequest.java index 9b60b2a4..f1b94252 100644 --- a/src/main/java/ddingdong/ddingdongBE/domain/scorehistory/controller/dto/request/RegisterScoreRequest.java +++ b/src/main/java/ddingdong/ddingdongBE/domain/scorehistory/controller/dto/request/RegisterScoreRequest.java @@ -12,9 +12,9 @@ public class RegisterScoreRequest { private String reason; - private int amount; + private float amount; - public ScoreHistory toEntity(Club club, int remainingScore) { + public ScoreHistory toEntity(Club club, float remainingScore) { return ScoreHistory.builder() .club(club) .amount(amount) diff --git a/src/main/java/ddingdong/ddingdongBE/domain/scorehistory/controller/dto/response/ScoreHistoryFilterByClubResponse.java b/src/main/java/ddingdong/ddingdongBE/domain/scorehistory/controller/dto/response/ScoreHistoryFilterByClubResponse.java index 0a1dd2e3..9938aed9 100644 --- a/src/main/java/ddingdong/ddingdongBE/domain/scorehistory/controller/dto/response/ScoreHistoryFilterByClubResponse.java +++ b/src/main/java/ddingdong/ddingdongBE/domain/scorehistory/controller/dto/response/ScoreHistoryFilterByClubResponse.java @@ -12,14 +12,14 @@ public class ScoreHistoryFilterByClubResponse { private String reason; - private int amount; + private float amount; - private int remainingScore; + private float remainingScore; private LocalDateTime createdAt; @Builder - public ScoreHistoryFilterByClubResponse(String scoreCategory, String reason, int amount, int remainingScore, LocalDateTime createdAt) { + public ScoreHistoryFilterByClubResponse(String scoreCategory, String reason, float amount, float remainingScore, LocalDateTime createdAt) { this.scoreCategory = scoreCategory; this.reason = reason; this.amount = amount; diff --git a/src/main/java/ddingdong/ddingdongBE/domain/club/entity/Score.java b/src/main/java/ddingdong/ddingdongBE/domain/scorehistory/entity/Score.java similarity index 63% rename from src/main/java/ddingdong/ddingdongBE/domain/club/entity/Score.java rename to src/main/java/ddingdong/ddingdongBE/domain/scorehistory/entity/Score.java index 763cc596..b7af860e 100644 --- a/src/main/java/ddingdong/ddingdongBE/domain/club/entity/Score.java +++ b/src/main/java/ddingdong/ddingdongBE/domain/scorehistory/entity/Score.java @@ -1,6 +1,4 @@ -package ddingdong.ddingdongBE.domain.club.entity; - -import static ddingdong.ddingdongBE.common.exception.ErrorMessage.*; +package ddingdong.ddingdongBE.domain.scorehistory.entity; import java.util.Objects; import javax.persistence.Column; @@ -15,9 +13,9 @@ public class Score { @Column(name = "score") - private int value; + private float value; - private Score(int value) { + private Score(float value) { this.value = value; } @@ -38,15 +36,9 @@ public int hashCode() { return Objects.hash(getValue()); } - public static Score of(int value) { - validateScore(value); + public static Score of(float value) { return new Score(value); } - private static void validateScore(int value) { - if (value < 0 || value > 1000) { - throw new IllegalArgumentException(INVALID_CLUB_SCORE_VALUE.getText()); - } - } } diff --git a/src/main/java/ddingdong/ddingdongBE/domain/scorehistory/entity/ScoreCategory.java b/src/main/java/ddingdong/ddingdongBE/domain/scorehistory/entity/ScoreCategory.java index 9daa75f8..33306884 100644 --- a/src/main/java/ddingdong/ddingdongBE/domain/scorehistory/entity/ScoreCategory.java +++ b/src/main/java/ddingdong/ddingdongBE/domain/scorehistory/entity/ScoreCategory.java @@ -12,7 +12,8 @@ public enum ScoreCategory { ACTIVITY_REPORT("동아리 활동 보고서"), LEADER_CONFERENCE("전동대회"), BUSINESS_PARTICIPATION("총동연 사업 참여"), - ADDITIONAL("가산점/감점"); + ADDITIONAL("가산점/감점"), + CARRYOVER_SCORE("점수 이월"); private final String category; @@ -24,4 +25,4 @@ public static ScoreCategory of(String category) { } throw new IllegalArgumentException(ILLEGAL_SCORE_CATEGORY.getText()); } -} +} \ No newline at end of file diff --git a/src/main/java/ddingdong/ddingdongBE/domain/scorehistory/entity/ScoreHistory.java b/src/main/java/ddingdong/ddingdongBE/domain/scorehistory/entity/ScoreHistory.java index 2428547b..d4e83823 100644 --- a/src/main/java/ddingdong/ddingdongBE/domain/scorehistory/entity/ScoreHistory.java +++ b/src/main/java/ddingdong/ddingdongBE/domain/scorehistory/entity/ScoreHistory.java @@ -31,17 +31,17 @@ public class ScoreHistory extends BaseEntity { @JoinColumn(name = "club_id") private Club club; - private int amount; + private float amount; @Enumerated(EnumType.STRING) private ScoreCategory scoreCategory; private String reason; - private int remainingScore; + private float remainingScore; @Builder - public ScoreHistory(Club club, int amount, ScoreCategory scoreCategory, String reason, int remainingScore) { + public ScoreHistory(Club club, float amount, ScoreCategory scoreCategory, String reason, float remainingScore) { this.club = club; this.amount = amount; this.scoreCategory = scoreCategory; diff --git a/src/main/java/ddingdong/ddingdongBE/domain/scorehistory/service/ScoreHistoryService.java b/src/main/java/ddingdong/ddingdongBE/domain/scorehistory/service/ScoreHistoryService.java index f9f9e577..a433af93 100644 --- a/src/main/java/ddingdong/ddingdongBE/domain/scorehistory/service/ScoreHistoryService.java +++ b/src/main/java/ddingdong/ddingdongBE/domain/scorehistory/service/ScoreHistoryService.java @@ -23,7 +23,9 @@ public class ScoreHistoryService { public void register(final Long clubId, RegisterScoreRequest registerScoreRequest) { Club club = clubService.findClubByClubId(clubId); - int remainingScore = clubService.editClubScore(clubId, registerScoreRequest.getAmount()); + float score = roundToThirdPoint(registerScoreRequest.getAmount()); + + float remainingScore = clubService.editClubScore(clubId, score); scoreHistoryRepository.save(registerScoreRequest.toEntity(club, remainingScore)); } @@ -44,4 +46,8 @@ public List getMyScoreHistories(final Long use .map(ScoreHistoryFilterByClubResponse::of) .toList(); } + + private static float roundToThirdPoint(float value) { + return Math.round(value * 1000.0) / 1000.0F; + } } \ No newline at end of file