From e0eb77fe184adfda93b5da089e362227a25c785a Mon Sep 17 00:00:00 2001 From: hyxklee Date: Fri, 10 Jan 2025 14:33:04 +0900 Subject: [PATCH 01/30] =?UTF-8?q?feat:=20=EA=B8=B0=EC=88=98=20=EC=97=94?= =?UTF-8?q?=ED=8B=B0=ED=8B=B0=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/user/domain/entity/Cardinal.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/main/java/leets/weeth/domain/user/domain/entity/Cardinal.java diff --git a/src/main/java/leets/weeth/domain/user/domain/entity/Cardinal.java b/src/main/java/leets/weeth/domain/user/domain/entity/Cardinal.java new file mode 100644 index 00000000..1533b060 --- /dev/null +++ b/src/main/java/leets/weeth/domain/user/domain/entity/Cardinal.java @@ -0,0 +1,27 @@ +package leets.weeth.domain.user.domain.entity; + +import jakarta.persistence.*; +import leets.weeth.global.common.entity.BaseEntity; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; + +@Entity +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@SuperBuilder +public class Cardinal extends BaseEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "cardinal_id") + private Long id; + + @Column(unique = true, nullable = false) + private Integer cardinalNumber; + + private Integer year; + + private Integer semester; +} From e940059b3ccd7c287ee746a21b139555f094cb4c Mon Sep 17 00:00:00 2001 From: hyxklee Date: Fri, 10 Jan 2025 14:33:24 +0900 Subject: [PATCH 02/30] =?UTF-8?q?feat:=20=EA=B8=B0=EC=88=98=20-=20?= =?UTF-8?q?=EC=9C=A0=EC=A0=80=20=EC=97=94=ED=8B=B0=ED=8B=B0=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/domain/entity/UserCardinal.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/main/java/leets/weeth/domain/user/domain/entity/UserCardinal.java diff --git a/src/main/java/leets/weeth/domain/user/domain/entity/UserCardinal.java b/src/main/java/leets/weeth/domain/user/domain/entity/UserCardinal.java new file mode 100644 index 00000000..42b5fb10 --- /dev/null +++ b/src/main/java/leets/weeth/domain/user/domain/entity/UserCardinal.java @@ -0,0 +1,33 @@ +package leets.weeth.domain.user.domain.entity; + +import jakarta.persistence.*; +import leets.weeth.global.common.entity.BaseEntity; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; + +@Entity +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@SuperBuilder +public class UserCardinal extends BaseEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "user_cardinal_id") + private Long id; + + @ManyToOne + @JoinColumn(name = "user_id") + private User user; + + @ManyToOne + @JoinColumn(name = "cardinal_id") + private Cardinal cardinal; + + public UserCardinal(User user, Cardinal cardinal) { + this.user = user; + this.cardinal = cardinal; + } +} From 2975ac9886a75fd7a3215c6d7e308d149c0bcc00 Mon Sep 17 00:00:00 2001 From: hyxklee Date: Fri, 10 Jan 2025 14:34:33 +0900 Subject: [PATCH 03/30] =?UTF-8?q?feat:=20=EA=B8=B0=EC=88=98=20API=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/presentation/CardinalController.java | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/main/java/leets/weeth/domain/user/presentation/CardinalController.java diff --git a/src/main/java/leets/weeth/domain/user/presentation/CardinalController.java b/src/main/java/leets/weeth/domain/user/presentation/CardinalController.java new file mode 100644 index 00000000..859bb596 --- /dev/null +++ b/src/main/java/leets/weeth/domain/user/presentation/CardinalController.java @@ -0,0 +1,42 @@ +package leets.weeth.domain.user.presentation; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.validation.Valid; +import leets.weeth.domain.user.application.dto.request.CardinalSaveRequest; +import leets.weeth.domain.user.application.dto.response.CardinalResponse; +import leets.weeth.domain.user.application.usecase.CardinalUseCase; +import leets.weeth.global.common.response.CommonResponse; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +import static leets.weeth.domain.user.presentation.ResponseMessage.CARDINAL_FIND_ALL_SUCCESS; +import static leets.weeth.domain.user.presentation.ResponseMessage.CARDINAL_SAVE_SUCCESS; + +@Tag(name = "CARDINAL") +@RestController +@RequiredArgsConstructor +@RequestMapping("/api/v1/cardinals") +public class CardinalController { + + private final CardinalUseCase cardinalUseCase; + + @GetMapping + @Operation(summary = "현재 저장된 기수 목록 조회 API") + public CommonResponse> findAllCardinals() { + List response = cardinalUseCase.findAll(); + + return CommonResponse.createSuccess(CARDINAL_FIND_ALL_SUCCESS.getMessage(), response); + } + + @PostMapping + @Operation(summary = "새로운 기수 정보 저장 API") + public CommonResponse save(@RequestBody @Valid CardinalSaveRequest dto) { + cardinalUseCase.save(dto); + + return CommonResponse.createSuccess(CARDINAL_SAVE_SUCCESS.getMessage()); + } + +} From cb773891cd6b7883212c04eacca41140e42148ca Mon Sep 17 00:00:00 2001 From: hyxklee Date: Fri, 10 Jan 2025 14:34:52 +0900 Subject: [PATCH 04/30] =?UTF-8?q?feat:=20=EA=B8=B0=EC=88=98=20=EB=B9=84?= =?UTF-8?q?=EC=A6=88=EB=8B=88=EC=8A=A4=20=EB=A1=9C=EC=A7=81=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/usecase/CardinalUseCase.java | 36 +++++++++++++++++++ .../domain/service/CardinalGetService.java | 30 ++++++++++++++++ .../domain/service/CardinalSaveService.java | 17 +++++++++ 3 files changed, 83 insertions(+) create mode 100644 src/main/java/leets/weeth/domain/user/application/usecase/CardinalUseCase.java create mode 100644 src/main/java/leets/weeth/domain/user/domain/service/CardinalGetService.java create mode 100644 src/main/java/leets/weeth/domain/user/domain/service/CardinalSaveService.java diff --git a/src/main/java/leets/weeth/domain/user/application/usecase/CardinalUseCase.java b/src/main/java/leets/weeth/domain/user/application/usecase/CardinalUseCase.java new file mode 100644 index 00000000..b32380ff --- /dev/null +++ b/src/main/java/leets/weeth/domain/user/application/usecase/CardinalUseCase.java @@ -0,0 +1,36 @@ +package leets.weeth.domain.user.application.usecase; + +import io.swagger.v3.oas.annotations.tags.Tag; +import leets.weeth.domain.user.application.dto.request.CardinalSaveRequest; +import leets.weeth.domain.user.application.dto.response.CardinalResponse; +import leets.weeth.domain.user.application.mapper.CardinalMapper; +import leets.weeth.domain.user.domain.entity.Cardinal; +import leets.weeth.domain.user.domain.service.CardinalGetService; +import leets.weeth.domain.user.domain.service.CardinalSaveService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + +@Service +@RequiredArgsConstructor +public class CardinalUseCase { + + private final CardinalGetService cardinalGetService; + private final CardinalSaveService cardinalSaveService; + + private final CardinalMapper cardinalMapper; + + @Transactional + public void save(CardinalSaveRequest dto) { + cardinalSaveService.save(cardinalMapper.from(dto)); + } + + public List findAll() { + List cardinals = cardinalGetService.findAll(); + return cardinals.stream() + .map(cardinalMapper::to) + .toList(); + } +} diff --git a/src/main/java/leets/weeth/domain/user/domain/service/CardinalGetService.java b/src/main/java/leets/weeth/domain/user/domain/service/CardinalGetService.java new file mode 100644 index 00000000..00ff155a --- /dev/null +++ b/src/main/java/leets/weeth/domain/user/domain/service/CardinalGetService.java @@ -0,0 +1,30 @@ +package leets.weeth.domain.user.domain.service; + +import leets.weeth.domain.user.application.exception.CardinalNotFoundException; +import leets.weeth.domain.user.domain.entity.Cardinal; +import leets.weeth.domain.user.domain.repository.CardinalRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +@RequiredArgsConstructor +public class CardinalGetService { + + private final CardinalRepository cardinalRepository; + + public Cardinal find(Integer cardinal) { + return cardinalRepository.findByCardinalNumber(cardinal) + .orElseThrow(CardinalNotFoundException::new); + } + + public List findAll() { + return cardinalRepository.findAll(); + } + + public void validateCardinal(Integer cardinal) { + cardinalRepository.findByCardinalNumber(cardinal) + .orElseThrow(CardinalNotFoundException::new); + } +} diff --git a/src/main/java/leets/weeth/domain/user/domain/service/CardinalSaveService.java b/src/main/java/leets/weeth/domain/user/domain/service/CardinalSaveService.java new file mode 100644 index 00000000..aae6ebe0 --- /dev/null +++ b/src/main/java/leets/weeth/domain/user/domain/service/CardinalSaveService.java @@ -0,0 +1,17 @@ +package leets.weeth.domain.user.domain.service; + +import leets.weeth.domain.user.domain.entity.Cardinal; +import leets.weeth.domain.user.domain.repository.CardinalRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class CardinalSaveService { + + private final CardinalRepository cardinalRepository; + + public void save(Cardinal cardinal) { + cardinalRepository.save(cardinal); + } +} From b7b0f05b915dacbd318e3341e8d94655d26911f2 Mon Sep 17 00:00:00 2001 From: hyxklee Date: Fri, 10 Jan 2025 14:35:17 +0900 Subject: [PATCH 05/30] =?UTF-8?q?feat:=20=EA=B8=B0=EC=88=98=20dto=20?= =?UTF-8?q?=EB=B0=8F=20=EB=A7=A4=ED=8D=BC=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/request/CardinalSaveRequest.java | 10 ++++++++++ .../dto/response/CardinalResponse.java | 13 +++++++++++++ .../user/application/mapper/CardinalMapper.java | 16 ++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 src/main/java/leets/weeth/domain/user/application/dto/request/CardinalSaveRequest.java create mode 100644 src/main/java/leets/weeth/domain/user/application/dto/response/CardinalResponse.java create mode 100644 src/main/java/leets/weeth/domain/user/application/mapper/CardinalMapper.java diff --git a/src/main/java/leets/weeth/domain/user/application/dto/request/CardinalSaveRequest.java b/src/main/java/leets/weeth/domain/user/application/dto/request/CardinalSaveRequest.java new file mode 100644 index 00000000..3723866e --- /dev/null +++ b/src/main/java/leets/weeth/domain/user/application/dto/request/CardinalSaveRequest.java @@ -0,0 +1,10 @@ +package leets.weeth.domain.user.application.dto.request; + +import jakarta.validation.constraints.NotNull; + +public record CardinalSaveRequest ( + @NotNull Integer cardinalNumber, + @NotNull Integer year, + @NotNull Integer semester +){ +} diff --git a/src/main/java/leets/weeth/domain/user/application/dto/response/CardinalResponse.java b/src/main/java/leets/weeth/domain/user/application/dto/response/CardinalResponse.java new file mode 100644 index 00000000..79c51239 --- /dev/null +++ b/src/main/java/leets/weeth/domain/user/application/dto/response/CardinalResponse.java @@ -0,0 +1,13 @@ +package leets.weeth.domain.user.application.dto.response; + +import java.time.LocalDateTime; + +public record CardinalResponse( + Long id, + Integer cardinalNumber, + Integer year, + Integer semester, + LocalDateTime createdAt, + LocalDateTime modified_at +) { +} diff --git a/src/main/java/leets/weeth/domain/user/application/mapper/CardinalMapper.java b/src/main/java/leets/weeth/domain/user/application/mapper/CardinalMapper.java new file mode 100644 index 00000000..4ed33b06 --- /dev/null +++ b/src/main/java/leets/weeth/domain/user/application/mapper/CardinalMapper.java @@ -0,0 +1,16 @@ +package leets.weeth.domain.user.application.mapper; + +import leets.weeth.domain.user.application.dto.request.CardinalSaveRequest; +import leets.weeth.domain.user.application.dto.response.CardinalResponse; +import leets.weeth.domain.user.domain.entity.Cardinal; +import org.mapstruct.Mapper; +import org.mapstruct.MappingConstants; +import org.mapstruct.ReportingPolicy; + +@Mapper(componentModel = MappingConstants.ComponentModel.SPRING, unmappedTargetPolicy = ReportingPolicy.IGNORE) +public interface CardinalMapper { + + Cardinal from(CardinalSaveRequest dto); + + CardinalResponse to(Cardinal cardinal); +} From 4be470671f4b236c4e30d8fb8bc7bdb61ecbfa4e Mon Sep 17 00:00:00 2001 From: hyxklee Date: Fri, 10 Jan 2025 14:35:22 +0900 Subject: [PATCH 06/30] =?UTF-8?q?feat:=20=EA=B8=B0=EC=88=98=20=EC=A0=80?= =?UTF-8?q?=EC=9E=A5=EC=86=8C=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/domain/repository/CardinalRepository.java | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/main/java/leets/weeth/domain/user/domain/repository/CardinalRepository.java diff --git a/src/main/java/leets/weeth/domain/user/domain/repository/CardinalRepository.java b/src/main/java/leets/weeth/domain/user/domain/repository/CardinalRepository.java new file mode 100644 index 00000000..efc7e0e7 --- /dev/null +++ b/src/main/java/leets/weeth/domain/user/domain/repository/CardinalRepository.java @@ -0,0 +1,11 @@ +package leets.weeth.domain.user.domain.repository; + +import leets.weeth.domain.user.domain.entity.Cardinal; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.Optional; + +public interface CardinalRepository extends JpaRepository { + + Optional findByCardinalNumber(Integer cardinal); +} From 801fd488fe68e31c44f4bcd1097b3bb9e9f6999f Mon Sep 17 00:00:00 2001 From: hyxklee Date: Fri, 10 Jan 2025 14:35:53 +0900 Subject: [PATCH 07/30] =?UTF-8?q?feat:=20=EA=B8=B0=EC=88=98=20=EC=9D=91?= =?UTF-8?q?=EB=8B=B5=20=EB=A9=94=EC=8B=9C=EC=A7=80=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weeth/domain/user/presentation/ResponseMessage.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/leets/weeth/domain/user/presentation/ResponseMessage.java b/src/main/java/leets/weeth/domain/user/presentation/ResponseMessage.java index 10c09a39..4c192d31 100644 --- a/src/main/java/leets/weeth/domain/user/presentation/ResponseMessage.java +++ b/src/main/java/leets/weeth/domain/user/presentation/ResponseMessage.java @@ -24,7 +24,11 @@ public enum ResponseMessage { SOCIAL_REGISTER_SUCCESS("소셜 회원가입에 성공했습니다."), SOCIAL_AUTH_SUCCESS("소셜 인증에 성공했습니다."), SOCIAL_INTEGRATE_SUCCESS("소셜 로그인 연동에 성공했습니다."), - JWT_REFRESH_SUCCESS("토큰 재발급에 성공했습니다."); + JWT_REFRESH_SUCCESS("토큰 재발급에 성공했습니다."), + + // CardinalController 관련 + CARDINAL_FIND_ALL_SUCCESS("전체 기수 조회에 성공했습니다."), + CARDINAL_SAVE_SUCCESS("기수 저장에 성공했습니다."); private final String message; } From f90fa84b664218960a62a0b934c70241ce21a1b6 Mon Sep 17 00:00:00 2001 From: hyxklee Date: Sat, 11 Jan 2025 21:56:04 +0900 Subject: [PATCH 08/30] =?UTF-8?q?feat:=20todo=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../attendance/application/usecase/AttendanceUseCaseImpl.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/leets/weeth/domain/attendance/application/usecase/AttendanceUseCaseImpl.java b/src/main/java/leets/weeth/domain/attendance/application/usecase/AttendanceUseCaseImpl.java index 939a1cbd..d3fd9240 100644 --- a/src/main/java/leets/weeth/domain/attendance/application/usecase/AttendanceUseCaseImpl.java +++ b/src/main/java/leets/weeth/domain/attendance/application/usecase/AttendanceUseCaseImpl.java @@ -63,6 +63,9 @@ public AttendanceDTO.Main find(Long userId) { return mapper.toMainDto(user, todayMeeting); } + /* + todo 출석 끝난 후 다음 기수 진행 시 다음 기수의 출석 정보만 나오는지 확인 필요 + */ @Override public AttendanceDTO.Detail findAll(Long userId) { User user = userGetService.find(userId); From d1614754951d3b05dd15a0572c9d475041ec29d8 Mon Sep 17 00:00:00 2001 From: hyxklee Date: Sat, 11 Jan 2025 21:57:11 +0900 Subject: [PATCH 09/30] =?UTF-8?q?feat:=20=EC=9C=A0=EC=A0=80-=EA=B8=B0?= =?UTF-8?q?=EC=88=98=20=EC=A4=91=EA=B0=84=20=ED=85=8C=EC=9D=B4=EB=B8=94=20?= =?UTF-8?q?=EC=A0=80=EC=9E=A5=EC=86=8C=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/UserCardinalRepository.java | 7 +++++++ .../domain/service/UserCardinalSaveService.java | 17 +++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 src/main/java/leets/weeth/domain/user/domain/repository/UserCardinalRepository.java create mode 100644 src/main/java/leets/weeth/domain/user/domain/service/UserCardinalSaveService.java diff --git a/src/main/java/leets/weeth/domain/user/domain/repository/UserCardinalRepository.java b/src/main/java/leets/weeth/domain/user/domain/repository/UserCardinalRepository.java new file mode 100644 index 00000000..533593f1 --- /dev/null +++ b/src/main/java/leets/weeth/domain/user/domain/repository/UserCardinalRepository.java @@ -0,0 +1,7 @@ +package leets.weeth.domain.user.domain.repository; + +import leets.weeth.domain.user.domain.entity.UserCardinal; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface UserCardinalRepository extends JpaRepository { +} diff --git a/src/main/java/leets/weeth/domain/user/domain/service/UserCardinalSaveService.java b/src/main/java/leets/weeth/domain/user/domain/service/UserCardinalSaveService.java new file mode 100644 index 00000000..a1c695a9 --- /dev/null +++ b/src/main/java/leets/weeth/domain/user/domain/service/UserCardinalSaveService.java @@ -0,0 +1,17 @@ +package leets.weeth.domain.user.domain.service; + +import leets.weeth.domain.user.domain.entity.UserCardinal; +import leets.weeth.domain.user.domain.repository.UserCardinalRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class UserCardinalSaveService { + + private final UserCardinalRepository userCardinalRepository; + + public void save(UserCardinal userCardinal) { + userCardinalRepository.save(userCardinal); + } +} From e4b39db642a3fe1922e4c029aa7d626a8d9758e5 Mon Sep 17 00:00:00 2001 From: hyxklee Date: Sat, 11 Jan 2025 22:22:35 +0900 Subject: [PATCH 10/30] =?UTF-8?q?feat:=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20=EC=BD=94=EB=93=9C=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/user/domain/service/UserUpdateService.java | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/main/java/leets/weeth/domain/user/domain/service/UserUpdateService.java b/src/main/java/leets/weeth/domain/user/domain/service/UserUpdateService.java index 4870986e..ec8e4c4e 100644 --- a/src/main/java/leets/weeth/domain/user/domain/service/UserUpdateService.java +++ b/src/main/java/leets/weeth/domain/user/domain/service/UserUpdateService.java @@ -2,7 +2,9 @@ import jakarta.transaction.Transactional; import leets.weeth.domain.user.application.dto.request.UserRequestDto; +import leets.weeth.domain.user.domain.entity.Cardinal; import leets.weeth.domain.user.domain.entity.User; +import leets.weeth.domain.user.domain.entity.UserCardinal; import lombok.RequiredArgsConstructor; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Service; @@ -18,9 +20,7 @@ public class UserUpdateService { public void update(User user, Update dto, PasswordEncoder passwordEncoder) { user.update(dto, passwordEncoder); } - public void update(User user, Register dto) { - user.update(dto); - } + public void accept(User user) { user.accept(); } @@ -29,10 +29,6 @@ public void update(User user, String role) { user.update(role); } - public void applyOB(User user, Integer cardinal) { - user.applyOB(cardinal); - } - public void reset(User user, PasswordEncoder passwordEncoder) { user.reset(passwordEncoder); } From e5783e90b944075ab43458897f81f2b1f8f8e31d Mon Sep 17 00:00:00 2001 From: hyxklee Date: Sat, 11 Jan 2025 23:14:25 +0900 Subject: [PATCH 11/30] =?UTF-8?q?feat:=20=EC=9D=BC=EB=8C=80=EB=8B=A4=20?= =?UTF-8?q?=EB=A7=A4=ED=95=91=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weeth/domain/user/domain/entity/User.java | 45 +------------------ 1 file changed, 2 insertions(+), 43 deletions(-) diff --git a/src/main/java/leets/weeth/domain/user/domain/entity/User.java b/src/main/java/leets/weeth/domain/user/domain/entity/User.java index 837cc097..27f8ee3b 100644 --- a/src/main/java/leets/weeth/domain/user/domain/entity/User.java +++ b/src/main/java/leets/weeth/domain/user/domain/entity/User.java @@ -2,9 +2,6 @@ import jakarta.persistence.*; import leets.weeth.domain.attendance.domain.entity.Attendance; -import leets.weeth.domain.penalty.domain.entity.Penalty; -import leets.weeth.domain.user.application.converter.CardinalListConverter; -import leets.weeth.domain.user.application.exception.CardinalNotFoundException; import leets.weeth.domain.user.domain.entity.enums.Department; import leets.weeth.domain.user.domain.entity.enums.Position; import leets.weeth.domain.user.domain.entity.enums.Role; @@ -20,7 +17,6 @@ import java.util.ArrayList; import java.util.List; -import static leets.weeth.domain.user.application.dto.request.UserRequestDto.Register; import static leets.weeth.domain.user.application.dto.request.UserRequestDto.Update; @Entity @@ -54,12 +50,6 @@ public class User extends BaseEntity { @Enumerated(EnumType.STRING) private Department department; - /* - todo 차후 기수가 많아지면 관리가 어려울 수 있음 - */ - @Convert(converter = CardinalListConverter.class) - private List cardinals; - @Enumerated(EnumType.STRING) private Status status; @@ -77,9 +67,6 @@ public class User extends BaseEntity { @OneToMany(mappedBy = "user", cascade = CascadeType.REMOVE, orphanRemoval = true) private List attendances = new ArrayList<>(); - @OneToMany(mappedBy = "user", cascade = CascadeType.REMOVE, orphanRemoval = true) - private List penalties = new ArrayList<>(); - @PrePersist public void init() { status = Status.WAITING; @@ -98,10 +85,6 @@ public void leave() { this.status = Status.LEFT; } - public void applyOB(Integer cardinal) { - this.cardinals.add(cardinal); - } - /* todo 차후 일반 로그인 비활성화시 해당 메서드에서 예외를 날리도록 수정 */ @@ -118,15 +101,6 @@ public void update(Update dto, PasswordEncoder passwordEncoder) { this.department = Department.to(dto.department()); } - public void update(Register dto) { - this.name = dto.name(); - this.studentId = dto.studentId(); - this.tel = dto.tel(); - this.department = Department.to(dto.department()); - this.cardinals = List.of(dto.cardinal()); - this.position = Position.valueOf(dto.position()); - } - public void accept() { this.status = Status.ACTIVE; } @@ -139,10 +113,6 @@ public void update(String role) { this.role = Role.valueOf(role); } - public boolean notContains(Integer cardinal) { - return !this.cardinals.contains(cardinal); - } - public void reset(PasswordEncoder passwordEncoder) { this.password = passwordEncoder.encode(studentId); } @@ -151,10 +121,6 @@ public void add(Attendance attendance) { this.attendances.add(attendance); } - public void addPenalty(Penalty penalty) { - this.penalties.add(penalty); - } - public void initAttendance() { this.attendances.clear(); this.attendanceCount = 0; @@ -162,20 +128,13 @@ public void initAttendance() { this.attendanceRate = 0; } - public boolean isCurrent(Integer cardinal) { - Integer max = this.cardinals.stream().max(Integer::compareTo) - .orElseThrow(CardinalNotFoundException::new); - - return max < cardinal; - } - public void attend() { attendanceCount++; calculateRate(); } public void removeAttend() { - if(attendanceCount > 0) { + if (attendanceCount > 0) { attendanceCount--; calculateRate(); } @@ -187,7 +146,7 @@ public void absent() { } public void removeAbsent() { - if(absenceCount > 0) { + if (absenceCount > 0) { absenceCount--; calculateRate(); } From e5d4676af3c88ff11480167df1c9bd4fafde601d Mon Sep 17 00:00:00 2001 From: hyxklee Date: Sat, 11 Jan 2025 23:17:26 +0900 Subject: [PATCH 12/30] =?UTF-8?q?feat:=20=EA=B8=B0=EC=88=98=EB=A1=9C=20?= =?UTF-8?q?=EC=9C=A0=EC=A0=80=20=EC=A1=B0=ED=9A=8C=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weeth/domain/user/domain/repository/UserRepository.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/leets/weeth/domain/user/domain/repository/UserRepository.java b/src/main/java/leets/weeth/domain/user/domain/repository/UserRepository.java index a8cdfa0c..42e9b670 100644 --- a/src/main/java/leets/weeth/domain/user/domain/repository/UserRepository.java +++ b/src/main/java/leets/weeth/domain/user/domain/repository/UserRepository.java @@ -1,5 +1,6 @@ package leets.weeth.domain.user.domain.repository; +import leets.weeth.domain.user.domain.entity.Cardinal; import leets.weeth.domain.user.domain.entity.User; import leets.weeth.domain.user.domain.entity.enums.Status; import org.springframework.data.jpa.repository.JpaRepository; @@ -24,6 +25,6 @@ public interface UserRepository extends JpaRepository { List findAllByStatusOrderByName(Status status); List findAllByOrderByNameAsc(); - @Query(value = "SELECT * FROM users u WHERE JSON_CONTAINS(u.cardinals, CAST(:cardinal AS JSON), '$')", nativeQuery = true) - List findByCardinal(@Param("cardinal") int cardinal); + @Query("SELECT uc.user FROM UserCardinal uc WHERE uc.cardinal = :cardinal AND uc.user.status = :status") + List findAllByCardinalAndStatus(@Param("cardinal") Cardinal cardinal, @Param("status") Status status); } From fc5ed9fd30bbbc46a08dafd638ae9cb5d2db1cc4 Mon Sep 17 00:00:00 2001 From: hyxklee Date: Sat, 11 Jan 2025 23:17:36 +0900 Subject: [PATCH 13/30] =?UTF-8?q?feat:=20=EC=82=AC=EC=9A=A9=ED=95=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EB=8A=94=20=EB=A9=94=EC=84=9C=EB=93=9C=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weeth/domain/user/application/usecase/UserUseCase.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/leets/weeth/domain/user/application/usecase/UserUseCase.java b/src/main/java/leets/weeth/domain/user/application/usecase/UserUseCase.java index 27606818..32d144d7 100644 --- a/src/main/java/leets/weeth/domain/user/application/usecase/UserUseCase.java +++ b/src/main/java/leets/weeth/domain/user/application/usecase/UserUseCase.java @@ -24,9 +24,7 @@ public interface UserUseCase { UserResponseDto.Response find(Long userId); - Map> findAll(); - - Map> findAllUser(); + List findAllUser(); UserResponseDto.UserResponse findUserDetails(Long userId); From 31fa97af7a095b59a84d0cd7b54b2cf2388a6103 Mon Sep 17 00:00:00 2001 From: hyxklee Date: Sat, 11 Jan 2025 23:18:07 +0900 Subject: [PATCH 14/30] =?UTF-8?q?refactor:=20=EA=B8=B0=EC=88=98=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC=EB=A1=9C=20=EC=9D=B8=ED=95=9C=20=EA=B0=80?= =?UTF-8?q?=EC=9E=85=20=EC=8A=B9=EC=9D=B8,=20=EB=8B=A4=EC=9D=8C=20?= =?UTF-8?q?=EA=B8=B0=EC=88=98=20=EC=A7=84=ED=96=89=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../usecase/UserManageUseCaseImpl.java | 34 +++++++++++-------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/src/main/java/leets/weeth/domain/user/application/usecase/UserManageUseCaseImpl.java b/src/main/java/leets/weeth/domain/user/application/usecase/UserManageUseCaseImpl.java index 3458ff0f..e086cae9 100644 --- a/src/main/java/leets/weeth/domain/user/application/usecase/UserManageUseCaseImpl.java +++ b/src/main/java/leets/weeth/domain/user/application/usecase/UserManageUseCaseImpl.java @@ -6,12 +6,12 @@ import leets.weeth.domain.schedule.domain.service.MeetingGetService; import leets.weeth.domain.user.application.exception.InvalidUserOrderException; import leets.weeth.domain.user.application.mapper.UserMapper; +import leets.weeth.domain.user.domain.entity.Cardinal; import leets.weeth.domain.user.domain.entity.User; +import leets.weeth.domain.user.domain.entity.UserCardinal; import leets.weeth.domain.user.domain.entity.enums.StatusPriority; import leets.weeth.domain.user.domain.entity.enums.UsersOrderBy; -import leets.weeth.domain.user.domain.service.UserDeleteService; -import leets.weeth.domain.user.domain.service.UserGetService; -import leets.weeth.domain.user.domain.service.UserUpdateService; +import leets.weeth.domain.user.domain.service.*; import leets.weeth.global.auth.jwt.service.JwtRedisService; import lombok.RequiredArgsConstructor; import org.springframework.security.crypto.password.PasswordEncoder; @@ -20,10 +20,9 @@ import java.util.Comparator; import java.util.EnumSet; import java.util.List; -import java.util.stream.Collectors; import static leets.weeth.domain.user.application.dto.response.UserResponseDto.AdminResponse; -import static leets.weeth.domain.user.domain.entity.enums.UsersOrderBy.*; +import static leets.weeth.domain.user.domain.entity.enums.UsersOrderBy.NAME_ASCENDING; @Service @RequiredArgsConstructor @@ -36,21 +35,24 @@ public class UserManageUseCaseImpl implements UserManageUseCase { private final AttendanceSaveService attendanceSaveService; private final MeetingGetService meetingGetService; private final JwtRedisService jwtRedisService; + private final CardinalGetService cardinalGetService; + private final UserCardinalSaveService userCardinalSaveService; + private final UserCardinalGetService userCardinalGetService; private final UserMapper mapper; private final PasswordEncoder passwordEncoder; @Override public List findAllByAdmin(UsersOrderBy orderBy) { - if(orderBy == null || !EnumSet.allOf(UsersOrderBy.class).contains(orderBy)){ + if (orderBy == null || !EnumSet.allOf(UsersOrderBy.class).contains(orderBy)) { throw new InvalidUserOrderException(); } - if(orderBy.equals(NAME_ASCENDING)){ + if (orderBy.equals(NAME_ASCENDING)) { return userGetService.findAll().stream() - .sorted(Comparator.comparingInt((user->(StatusPriority.fromStatus(user.getStatus())).getPriority()))) - .map(mapper::toAdminResponse) - .toList(); + .sorted(Comparator.comparingInt((user -> (StatusPriority.fromStatus(user.getStatus())).getPriority()))) + .map(mapper::toAdminResponse) + .toList(); } // To do : 추후 기수 분리 후 작업 예정 @@ -62,9 +64,11 @@ public List findAllByAdmin(UsersOrderBy orderBy) { public void accept(Long userId) { User user = userGetService.find(userId); + Integer cardinal = userCardinalGetService.getCurrentCardinal(user).getCardinalNumber(); + if (user.isInactive()) { userUpdateService.accept(user); - List meetings = meetingGetService.find(user.getCardinals().get(0)); + List meetings = meetingGetService.find(cardinal); attendanceSaveService.init(user, meetings); } } @@ -95,15 +99,17 @@ public void ban(Long userId) { @Transactional public void applyOB(Long userId, Integer cardinal) { User user = userGetService.find(userId); + Cardinal nextCardinal = cardinalGetService.find(cardinal); - if (user.notContains(cardinal)) { - if (user.isCurrent(cardinal)) { + if (userCardinalGetService.notContains(user, nextCardinal)) { + if (userCardinalGetService.isCurrent(user, nextCardinal)) { user.initAttendance(); List meetings = meetingGetService.find(cardinal); attendanceSaveService.init(user, meetings); } + UserCardinal userCardinal = new UserCardinal(user, nextCardinal); - userUpdateService.applyOB(user, cardinal); + userCardinalSaveService.save(userCardinal); } } From 5af5e32d9cde122eb8ba146d0fb96009f045895b Mon Sep 17 00:00:00 2001 From: hyxklee Date: Sat, 11 Jan 2025 23:18:18 +0900 Subject: [PATCH 15/30] =?UTF-8?q?feat:=20=EA=B8=B0=EC=88=98=EB=A1=9C=20?= =?UTF-8?q?=EC=9C=A0=EC=A0=80=20=EC=A1=B0=ED=9A=8C=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weeth/domain/user/domain/service/UserGetService.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/leets/weeth/domain/user/domain/service/UserGetService.java b/src/main/java/leets/weeth/domain/user/domain/service/UserGetService.java index d71b72ac..16a36cad 100644 --- a/src/main/java/leets/weeth/domain/user/domain/service/UserGetService.java +++ b/src/main/java/leets/weeth/domain/user/domain/service/UserGetService.java @@ -1,5 +1,6 @@ package leets.weeth.domain.user.domain.service; +import leets.weeth.domain.user.domain.entity.Cardinal; import leets.weeth.domain.user.domain.entity.User; import leets.weeth.domain.user.domain.entity.enums.Status; import leets.weeth.domain.user.domain.repository.UserRepository; @@ -38,14 +39,14 @@ public List findAllByStatus(Status status) { return userRepository.findAllByStatusOrderByName(status); } - public List findAllByCardinal(int cardinal) { - return userRepository.findByCardinal(cardinal); - } - public List findAll() { return userRepository.findAllByOrderByNameAsc(); } + public List findAllByCardinal(Cardinal cardinal) { + return userRepository.findAllByCardinalAndStatus(cardinal, Status.ACTIVE); + } + public boolean validateStudentId(String studentId) { return userRepository.existsByStudentId(studentId); } From a2d2a9b9477291ed33277dce4cb3c6349f3a7a8d Mon Sep 17 00:00:00 2001 From: hyxklee Date: Sat, 11 Jan 2025 23:18:45 +0900 Subject: [PATCH 16/30] =?UTF-8?q?refactor:=20=EC=9D=BC=EB=8C=80=EB=8B=A4?= =?UTF-8?q?=20=EC=A0=9C=EA=B1=B0=EB=A1=9C=20=EC=9D=B8=ED=95=9C=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/penalty/application/usecase/PenaltyUsecaseImpl.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/leets/weeth/domain/penalty/application/usecase/PenaltyUsecaseImpl.java b/src/main/java/leets/weeth/domain/penalty/application/usecase/PenaltyUsecaseImpl.java index ca8213a8..cc2cd73b 100644 --- a/src/main/java/leets/weeth/domain/penalty/application/usecase/PenaltyUsecaseImpl.java +++ b/src/main/java/leets/weeth/domain/penalty/application/usecase/PenaltyUsecaseImpl.java @@ -37,7 +37,6 @@ public void save(PenaltyDTO.Save dto) { penaltySaveService.save(penalty); - user.addPenalty(penalty); user.incrementPenaltyCount(); } From f1b19b734e40974b9ccda0ce8da8928a5797d020 Mon Sep 17 00:00:00 2001 From: hyxklee Date: Sun, 12 Jan 2025 16:17:40 +0900 Subject: [PATCH 17/30] =?UTF-8?q?feat:=20=EA=B8=B0=EC=88=98=20=EA=B4=80?= =?UTF-8?q?=EB=A0=A8=20=EB=A7=A4=ED=8D=BC=20=EB=A9=94=EC=84=9C=EB=93=9C=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/mapper/CardinalMapper.java | 7 ++++ .../user/application/mapper/UserMapper.java | 35 +++++++++++++------ 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/src/main/java/leets/weeth/domain/user/application/mapper/CardinalMapper.java b/src/main/java/leets/weeth/domain/user/application/mapper/CardinalMapper.java index 4ed33b06..8f8c78dd 100644 --- a/src/main/java/leets/weeth/domain/user/application/mapper/CardinalMapper.java +++ b/src/main/java/leets/weeth/domain/user/application/mapper/CardinalMapper.java @@ -2,15 +2,22 @@ import leets.weeth.domain.user.application.dto.request.CardinalSaveRequest; import leets.weeth.domain.user.application.dto.response.CardinalResponse; +import leets.weeth.domain.user.application.dto.response.UserCardinalDto; import leets.weeth.domain.user.domain.entity.Cardinal; +import leets.weeth.domain.user.domain.entity.User; +import leets.weeth.domain.user.domain.entity.UserCardinal; import org.mapstruct.Mapper; import org.mapstruct.MappingConstants; import org.mapstruct.ReportingPolicy; +import java.util.List; + @Mapper(componentModel = MappingConstants.ComponentModel.SPRING, unmappedTargetPolicy = ReportingPolicy.IGNORE) public interface CardinalMapper { Cardinal from(CardinalSaveRequest dto); CardinalResponse to(Cardinal cardinal); + + UserCardinalDto toUserCardinalDto(User user, List userCardinals); } diff --git a/src/main/java/leets/weeth/domain/user/application/mapper/UserMapper.java b/src/main/java/leets/weeth/domain/user/application/mapper/UserMapper.java index 14ecbfaf..e41866ec 100644 --- a/src/main/java/leets/weeth/domain/user/application/mapper/UserMapper.java +++ b/src/main/java/leets/weeth/domain/user/application/mapper/UserMapper.java @@ -1,15 +1,17 @@ package leets.weeth.domain.user.application.mapper; -import leets.weeth.domain.user.application.dto.response.UserResponseDto.*; import leets.weeth.domain.user.application.dto.response.UserResponseDto; -import leets.weeth.domain.user.application.dto.response.UserResponseDto.SummaryResponse; -import leets.weeth.domain.user.application.dto.response.UserResponseDto.UserResponse; import leets.weeth.domain.user.domain.entity.User; +import leets.weeth.domain.user.domain.entity.UserCardinal; import leets.weeth.domain.user.domain.entity.enums.Department; import leets.weeth.global.auth.jwt.application.dto.JwtDto; import org.mapstruct.*; import org.springframework.security.crypto.password.PasswordEncoder; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + import static leets.weeth.domain.user.application.dto.request.UserRequestDto.Register; import static leets.weeth.domain.user.application.dto.request.UserRequestDto.SignUp; import static leets.weeth.domain.user.application.dto.response.UserResponseDto.*; @@ -18,27 +20,28 @@ public interface UserMapper { @Mappings({ - @Mapping(target = "cardinals", expression = "java( java.util.List.of(dto.cardinal()) )"), @Mapping(target = "password", expression = "java( passwordEncoder.encode(dto.password()) )"), @Mapping(target = "department", expression = "java( leets.weeth.domain.user.domain.entity.enums.Department.to(dto.department()) )") }) User from(SignUp dto, @Context PasswordEncoder passwordEncoder); @Mappings({ - @Mapping(target = "cardinals", expression = "java( java.util.List.of(dto.cardinal()) )"), @Mapping(target = "department", expression = "java( leets.weeth.domain.user.domain.entity.enums.Department.to(dto.department()) )") }) User from(Register dto); @Mapping(target = "department", expression = "java( toString(user.getDepartment()) )") - Response to(User user); + @Mapping(target = "cardinals", expression = "java( toCardinalNumbers(userCardinals) )") + Response to(User user, List userCardinals); @Mappings({ // 수정: 출석률, 출석 횟수, 결석 횟수 매핑 추후 추가 예정 + @Mapping(target = "cardinals", expression = "java( toCardinalNumbers(userCardinals) )") }) - AdminResponse toAdminResponse(User user); + AdminResponse toAdminResponse(User user, List userCardinals); - SummaryResponse toSummaryResponse(User user); + @Mapping(target = "cardinals", expression = "java( toCardinalNumbers(userCardinals) )") + SummaryResponse toSummaryResponse(User user, List userCardinals); SocialAuthResponse toSocialAuthResponse(Long kakaoId); @@ -56,13 +59,25 @@ public interface UserMapper { @Mappings({ // 상세 데이터 매핑 + @Mapping(target = "cardinals", expression = "java( toCardinalNumbers(userCardinals) )") }) - UserResponse toUserResponse(User user); + UserResponse toUserResponse(User user, List userCardinals); - UserResponseDto.UserInfo toUserInfoDto(User user); + @Mapping(target = "cardinals", expression = "java( toCardinalNumbers(userCardinals) )") + UserResponseDto.UserInfo toUserInfoDto(User user, List userCardinals); default String toString(Department department) { return department.getValue(); } + + default List toCardinalNumbers(List userCardinals) { + if (userCardinals == null || userCardinals.isEmpty()) { + return Collections.emptyList(); + } + + return userCardinals.stream() + .map(uc -> uc.getCardinal().getCardinalNumber()) + .collect(Collectors.toList()); + } } From 539f4f2999b7c972a35c9fa049b227f06a50960c Mon Sep 17 00:00:00 2001 From: hyxklee Date: Sun, 12 Jan 2025 16:19:27 +0900 Subject: [PATCH 18/30] =?UTF-8?q?feat:=20=EC=A1=B0=ED=9A=8C=EC=8B=9C=20?= =?UTF-8?q?=EA=B8=B0=EC=88=98=20=EC=A0=95=EB=B3=B4=EB=A5=BC=20=ED=95=A8?= =?UTF-8?q?=EA=BB=98=20=EC=A0=84=EB=8B=AC=ED=95=98=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/response/UserCardinalDto.java | 12 +++ .../application/usecase/UserUseCaseImpl.java | 94 ++++++++++++------- 2 files changed, 71 insertions(+), 35 deletions(-) create mode 100644 src/main/java/leets/weeth/domain/user/application/dto/response/UserCardinalDto.java diff --git a/src/main/java/leets/weeth/domain/user/application/dto/response/UserCardinalDto.java b/src/main/java/leets/weeth/domain/user/application/dto/response/UserCardinalDto.java new file mode 100644 index 00000000..31146e28 --- /dev/null +++ b/src/main/java/leets/weeth/domain/user/application/dto/response/UserCardinalDto.java @@ -0,0 +1,12 @@ +package leets.weeth.domain.user.application.dto.response; + +import leets.weeth.domain.user.domain.entity.User; +import leets.weeth.domain.user.domain.entity.UserCardinal; + +import java.util.List; + +public record UserCardinalDto( + User user, + List cardinals +) { +} diff --git a/src/main/java/leets/weeth/domain/user/application/usecase/UserUseCaseImpl.java b/src/main/java/leets/weeth/domain/user/application/usecase/UserUseCaseImpl.java index 58f275a1..8d5002cd 100644 --- a/src/main/java/leets/weeth/domain/user/application/usecase/UserUseCaseImpl.java +++ b/src/main/java/leets/weeth/domain/user/application/usecase/UserUseCaseImpl.java @@ -1,15 +1,17 @@ package leets.weeth.domain.user.application.usecase; +import leets.weeth.domain.user.application.dto.response.UserCardinalDto; import leets.weeth.domain.user.application.dto.response.UserResponseDto; import leets.weeth.domain.user.application.exception.PasswordMismatchException; import leets.weeth.domain.user.application.exception.StudentIdExistsException; import leets.weeth.domain.user.application.exception.TelExistsException; import leets.weeth.domain.user.application.exception.UserInActiveException; +import leets.weeth.domain.user.application.mapper.CardinalMapper; import leets.weeth.domain.user.application.mapper.UserMapper; +import leets.weeth.domain.user.domain.entity.Cardinal; import leets.weeth.domain.user.domain.entity.User; -import leets.weeth.domain.user.domain.service.UserGetService; -import leets.weeth.domain.user.domain.service.UserSaveService; -import leets.weeth.domain.user.domain.service.UserUpdateService; +import leets.weeth.domain.user.domain.entity.UserCardinal; +import leets.weeth.domain.user.domain.service.*; import leets.weeth.global.auth.jwt.application.dto.JwtDto; import leets.weeth.global.auth.jwt.application.usecase.JwtManageUseCase; import leets.weeth.global.auth.kakao.KakaoAuthService; @@ -17,21 +19,22 @@ import leets.weeth.global.auth.kakao.dto.KakaoUserInfoResponse; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Slice; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.AbstractMap; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Optional; import java.util.stream.Collectors; -import java.util.stream.Stream; import static leets.weeth.domain.user.application.dto.request.UserRequestDto.*; import static leets.weeth.domain.user.application.dto.response.UserResponseDto.SocialAuthResponse; import static leets.weeth.domain.user.application.dto.response.UserResponseDto.SocialLoginResponse; -import static leets.weeth.domain.user.domain.entity.enums.Status.ACTIVE; @Slf4j @Service @@ -43,8 +46,12 @@ public class UserUseCaseImpl implements UserUseCase { private final UserGetService userGetService; private final UserUpdateService userUpdateService; private final KakaoAuthService kakaoAuthService; + private final CardinalGetService cardinalGetService; + private final UserCardinalSaveService userCardinalSaveService; + private final UserCardinalGetService userCardinalGetService; private final UserMapper mapper; + private final CardinalMapper cardinalMapper; private final PasswordEncoder passwordEncoder; @Override @@ -93,40 +100,36 @@ public SocialLoginResponse integrate(NormalLogin dto) { } @Override - public Map> findAll() { - return userGetService.findAllByStatus(ACTIVE).stream() - .flatMap(user -> Stream.concat( - user.getCardinals().stream() - .map(cardinal -> new AbstractMap.SimpleEntry<>(cardinal, mapper.to(user))), // 기수별 Map - Stream.of(new AbstractMap.SimpleEntry<>(0, mapper.to(user))) // 모든 기수는 cardinal 0에 저장 - )) - .collect(Collectors.groupingBy(Map.Entry::getKey, // key = 기수, value = 유저 정보 - Collectors.mapping(Map.Entry::getValue, Collectors.toList()))); - } + public Slice findAllUser(int pageNumber, int pageSize) { - @Override - public Map> findAllUser() { - return userGetService.findAllByStatus(ACTIVE).stream() - .map(user -> new AbstractMap.SimpleEntry<>(user.getCardinals(), mapper.toSummaryResponse(user))) - .flatMap(entry -> Stream.concat( - entry.getKey().stream().map(cardinal -> new AbstractMap.SimpleEntry<>(cardinal, entry.getValue())), // 기수별 Map - Stream.of(new AbstractMap.SimpleEntry<>(0, entry.getValue())) // 모든 기수는 cardinal 0에 저장 - )) - .collect(Collectors.groupingBy( - Map.Entry::getKey, // key = 기수 - Collectors.mapping(Map.Entry::getValue, Collectors.toList()) // value = 요약 정보 리스트 - )); + Pageable pageable = PageRequest.of(pageNumber, pageSize); + Slice users = userGetService.findAll(pageable); + + + List allUserCardinals = userCardinalGetService.findAll(users.getContent()); + + Map> userCardinalMap = allUserCardinals.stream() + .collect(Collectors.groupingBy(userCardinal -> userCardinal.getUser().getId())); + + return users.map(user -> { + List userCardinals = userCardinalMap.getOrDefault(user.getId(), Collections.emptyList()); + + return mapper.toSummaryResponse(user, userCardinals); + }); } @Override public UserResponseDto.UserResponse findUserDetails(Long userId) { - User user = userGetService.find(userId); - return mapper.toUserResponse(user); + UserCardinalDto dto = getUserCardinalDto(userId); + + return mapper.toUserResponse(dto.user(), dto.cardinals()); } @Override public UserResponseDto.Response find(Long userId) { - return mapper.to(userGetService.find(userId)); + UserCardinalDto dto = getUserCardinalDto(userId); + + return mapper.to(dto.user(), dto.cardinals()); } @Override @@ -139,14 +142,27 @@ public void update(Update dto, Long userId) { @Override public void apply(SignUp dto) { validate(dto); - userSaveService.save(mapper.from(dto, passwordEncoder)); + + Cardinal cardinal = cardinalGetService.find(dto.cardinal()); + User user = mapper.from(dto, passwordEncoder); + UserCardinal userCardinal = new UserCardinal(user, cardinal); + + userSaveService.save(user); + userCardinalSaveService.save(userCardinal); } @Override @Transactional public void socialRegister(Register dto) { validate(dto); - userSaveService.save(mapper.from(dto)); + + Cardinal cardinal = cardinalGetService.find(dto.cardinal()); + + User user = mapper.from(dto); + UserCardinal userCardinal = new UserCardinal(user, cardinal); + + userSaveService.save(user); + userCardinalSaveService.save(userCardinal); } @Override @@ -163,10 +179,11 @@ public JwtDto refresh(String refreshToken) { @Override public UserResponseDto.UserInfo findUserInfo(Long userId) { - User user = userGetService.find(userId); + UserCardinalDto dto = getUserCardinalDto(userId); - return mapper.toUserInfoDto(user); + return mapper.toUserInfoDto(dto.user(), dto.cardinals()); } + private long getKakaoId(Login dto) { KakaoTokenResponse tokenResponse = kakaoAuthService.getKakaoToken(dto.authCode()); KakaoUserInfoResponse userInfo = kakaoAuthService.getUserInfo(tokenResponse.access_token()); @@ -196,4 +213,11 @@ private void validate(Register dto) { throw new TelExistsException(); } } + + private UserCardinalDto getUserCardinalDto(Long userId) { + User user = userGetService.find(userId); + List userCardinals = userCardinalGetService.getUserCardinals(user); + + return cardinalMapper.toUserCardinalDto(user, userCardinals); + } } From 5f799a97a965378f5b5db992341b04a3ebb35f02 Mon Sep 17 00:00:00 2001 From: hyxklee Date: Sun, 12 Jan 2025 16:20:39 +0900 Subject: [PATCH 19/30] =?UTF-8?q?feat:=20=EC=9C=A0=EC=A0=80-=EA=B8=B0?= =?UTF-8?q?=EC=88=98=20=ED=85=8C=EC=9D=B4=EB=B8=94=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/UserCardinalRepository.java | 10 ++++ .../service/UserCardinalGetService.java | 53 +++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 src/main/java/leets/weeth/domain/user/domain/service/UserCardinalGetService.java diff --git a/src/main/java/leets/weeth/domain/user/domain/repository/UserCardinalRepository.java b/src/main/java/leets/weeth/domain/user/domain/repository/UserCardinalRepository.java index 533593f1..4d58a556 100644 --- a/src/main/java/leets/weeth/domain/user/domain/repository/UserCardinalRepository.java +++ b/src/main/java/leets/weeth/domain/user/domain/repository/UserCardinalRepository.java @@ -1,7 +1,17 @@ package leets.weeth.domain.user.domain.repository; +import leets.weeth.domain.user.domain.entity.Cardinal; +import leets.weeth.domain.user.domain.entity.User; import leets.weeth.domain.user.domain.entity.UserCardinal; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; + +import java.util.List; public interface UserCardinalRepository extends JpaRepository { + + List findAllByUser(User user); + + @Query("SELECT uc FROM UserCardinal uc WHERE uc.user IN :users") + List findAllByUsers(List users); } diff --git a/src/main/java/leets/weeth/domain/user/domain/service/UserCardinalGetService.java b/src/main/java/leets/weeth/domain/user/domain/service/UserCardinalGetService.java new file mode 100644 index 00000000..3c69a9a8 --- /dev/null +++ b/src/main/java/leets/weeth/domain/user/domain/service/UserCardinalGetService.java @@ -0,0 +1,53 @@ +package leets.weeth.domain.user.domain.service; + +import leets.weeth.domain.user.application.exception.CardinalNotFoundException; +import leets.weeth.domain.user.domain.entity.Cardinal; +import leets.weeth.domain.user.domain.entity.User; +import leets.weeth.domain.user.domain.entity.UserCardinal; +import leets.weeth.domain.user.domain.repository.UserCardinalRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import java.util.Comparator; +import java.util.List; + +@Service +@RequiredArgsConstructor +public class UserCardinalGetService { + + private final UserCardinalRepository userCardinalRepository; + + public List getUserCardinals(User user) { + return userCardinalRepository.findAllByUser(user); + } + + public List findAll() { + return userCardinalRepository.findAll(); + } + + public List findAll(List users) { + return userCardinalRepository.findAllByUsers(users); + } + + public boolean notContains(User user, Cardinal cardinal) { + return getUserCardinals(user).stream() + .noneMatch(userCardinal -> userCardinal.getCardinal().equals(cardinal)); + } + + public boolean isCurrent(User user, Cardinal cardinal) { + Integer maxCardinalNumber = getUserCardinals(user).stream() + .map(UserCardinal::getCardinal) + .map(Cardinal::getCardinalNumber) + .max(Integer::compareTo) + .orElseThrow(CardinalNotFoundException::new); + + return maxCardinalNumber < cardinal.getCardinalNumber(); + } + + public Cardinal getCurrentCardinal(User user) { + return getUserCardinals(user).stream() + .map(UserCardinal::getCardinal) + .max(Comparator.comparing(Cardinal::getCardinalNumber)) + .orElseThrow(CardinalNotFoundException::new); + } +} From 5e637d25e2d0d72e670734223f88a146f3a0d2ca Mon Sep 17 00:00:00 2001 From: hyxklee Date: Sun, 12 Jan 2025 16:20:58 +0900 Subject: [PATCH 20/30] =?UTF-8?q?feat:=20=EB=A9=A4=EB=B2=84=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=EC=8B=9C=20slice=EB=A1=9C=20=EB=B0=98=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/user/application/usecase/UserUseCaseImpl.java | 5 ++--- .../weeth/domain/user/domain/service/UserGetService.java | 6 ++++++ .../weeth/domain/user/presentation/UserController.java | 6 ++++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main/java/leets/weeth/domain/user/application/usecase/UserUseCaseImpl.java b/src/main/java/leets/weeth/domain/user/application/usecase/UserUseCaseImpl.java index 8d5002cd..0a6cb215 100644 --- a/src/main/java/leets/weeth/domain/user/application/usecase/UserUseCaseImpl.java +++ b/src/main/java/leets/weeth/domain/user/application/usecase/UserUseCaseImpl.java @@ -105,10 +105,9 @@ public Slice findAllUser(int pageNumber, int pa Pageable pageable = PageRequest.of(pageNumber, pageSize); Slice users = userGetService.findAll(pageable); + List sliceUserCardinals = userCardinalGetService.findAll(users.getContent()); - List allUserCardinals = userCardinalGetService.findAll(users.getContent()); - - Map> userCardinalMap = allUserCardinals.stream() + Map> userCardinalMap = sliceUserCardinals.stream() .collect(Collectors.groupingBy(userCardinal -> userCardinal.getUser().getId())); return users.map(user -> { diff --git a/src/main/java/leets/weeth/domain/user/domain/service/UserGetService.java b/src/main/java/leets/weeth/domain/user/domain/service/UserGetService.java index 16a36cad..266c2543 100644 --- a/src/main/java/leets/weeth/domain/user/domain/service/UserGetService.java +++ b/src/main/java/leets/weeth/domain/user/domain/service/UserGetService.java @@ -6,6 +6,8 @@ import leets.weeth.domain.user.domain.repository.UserRepository; import leets.weeth.domain.user.application.exception.UserNotFoundException; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Slice; import org.springframework.stereotype.Service; import java.util.List; @@ -47,6 +49,10 @@ public List findAllByCardinal(Cardinal cardinal) { return userRepository.findAllByCardinalAndStatus(cardinal, Status.ACTIVE); } + public Slice findAll(Pageable pageable) { + return userRepository.findAllByStatusOrderedByCardinalAndName(Status.ACTIVE, pageable); + } + public boolean validateStudentId(String studentId) { return userRepository.existsByStudentId(studentId); } diff --git a/src/main/java/leets/weeth/domain/user/presentation/UserController.java b/src/main/java/leets/weeth/domain/user/presentation/UserController.java index 304d5dae..ee6fbb8d 100644 --- a/src/main/java/leets/weeth/domain/user/presentation/UserController.java +++ b/src/main/java/leets/weeth/domain/user/presentation/UserController.java @@ -14,6 +14,7 @@ import leets.weeth.global.auth.jwt.application.dto.JwtDto; import leets.weeth.global.common.response.CommonResponse; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Slice; import org.springframework.web.bind.annotation.*; import java.util.List; @@ -76,8 +77,9 @@ public CommonResponse checkEmail(@RequestParam String email) { @GetMapping("/all") @Operation(summary = "동아리 멤버 전체 조회(전체/기수별)") - public CommonResponse>> findAllUser() { - return CommonResponse.createSuccess(USER_FIND_ALL_SUCCESS.getMessage(), userUseCase.findAllUser()); + public CommonResponse> findAllUser(@RequestParam("pageNumber") int pageNumber, + @RequestParam("pageSize") int pageSize) { + return CommonResponse.createSuccess(USER_FIND_ALL_SUCCESS.getMessage(), userUseCase.findAllUser(pageNumber, pageSize)); } @GetMapping("/details") From 682bd11bce5d08bc899deac8ee2fdc90c0ef8051 Mon Sep 17 00:00:00 2001 From: hyxklee Date: Sun, 12 Jan 2025 16:21:21 +0900 Subject: [PATCH 21/30] =?UTF-8?q?refactor:=20=EC=96=B4=EB=93=9C=EB=AF=BC?= =?UTF-8?q?=20=EB=A9=A4=EB=B2=84=20=EC=A1=B0=ED=9A=8C=EC=8B=9C=20=EA=B8=B0?= =?UTF-8?q?=EC=88=98=EB=A5=BC=20=EB=B0=98=EB=B3=B5=ED=95=B4=EC=84=9C=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/application/usecase/UserManageUseCaseImpl.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/leets/weeth/domain/user/application/usecase/UserManageUseCaseImpl.java b/src/main/java/leets/weeth/domain/user/application/usecase/UserManageUseCaseImpl.java index e086cae9..9205c149 100644 --- a/src/main/java/leets/weeth/domain/user/application/usecase/UserManageUseCaseImpl.java +++ b/src/main/java/leets/weeth/domain/user/application/usecase/UserManageUseCaseImpl.java @@ -51,7 +51,10 @@ public List findAllByAdmin(UsersOrderBy orderBy) { if (orderBy.equals(NAME_ASCENDING)) { return userGetService.findAll().stream() .sorted(Comparator.comparingInt((user -> (StatusPriority.fromStatus(user.getStatus())).getPriority()))) - .map(mapper::toAdminResponse) + .map(user -> { + List userCardinals = userCardinalGetService.getUserCardinals(user); + return mapper.toAdminResponse(user, userCardinals); + }) .toList(); } // To do : 추후 기수 분리 후 작업 예정 From 8834175e315fc4140d16dfb6aa47c417f71a9b07 Mon Sep 17 00:00:00 2001 From: hyxklee Date: Sun, 12 Jan 2025 16:21:30 +0900 Subject: [PATCH 22/30] =?UTF-8?q?refactor:=20=EC=9D=91=EB=8B=B5=20?= =?UTF-8?q?=EB=A9=94=EC=8B=9C=EC=A7=80=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../leets/weeth/domain/user/presentation/ResponseMessage.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/leets/weeth/domain/user/presentation/ResponseMessage.java b/src/main/java/leets/weeth/domain/user/presentation/ResponseMessage.java index 4c192d31..7a66c9d6 100644 --- a/src/main/java/leets/weeth/domain/user/presentation/ResponseMessage.java +++ b/src/main/java/leets/weeth/domain/user/presentation/ResponseMessage.java @@ -7,7 +7,7 @@ @AllArgsConstructor public enum ResponseMessage { // UserAdminController 관련 - USER_FIND_ALL_SUCCESS("관리자가 모든 회원 정보를 성공적으로 조회했습니다."), + USER_FIND_ALL_SUCCESS("모든 회원 정보를 성공적으로 조회했습니다."), USER_DETAILS_SUCCESS("특정 회원의 상세 정보를 성공적으로 조회했습니다."), USER_ACCEPT_SUCCESS("회원 가입 승인이 성공적으로 처리되었습니다."), USER_BAN_SUCCESS("회원이 성공적으로 차단되었습니다."), From fd613d94b799d149ac2cf711ef42255fbc135dbb Mon Sep 17 00:00:00 2001 From: hyxklee Date: Sun, 12 Jan 2025 16:21:44 +0900 Subject: [PATCH 23/30] =?UTF-8?q?feat:=20=EB=A9=A4=EB=B2=84=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=EC=8B=9C=20slice=EB=A1=9C=20=EB=B0=98=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weeth/domain/user/application/usecase/UserUseCase.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/leets/weeth/domain/user/application/usecase/UserUseCase.java b/src/main/java/leets/weeth/domain/user/application/usecase/UserUseCase.java index 32d144d7..9171ba0b 100644 --- a/src/main/java/leets/weeth/domain/user/application/usecase/UserUseCase.java +++ b/src/main/java/leets/weeth/domain/user/application/usecase/UserUseCase.java @@ -3,6 +3,7 @@ import leets.weeth.domain.user.application.dto.request.UserRequestDto; import leets.weeth.domain.user.application.dto.response.UserResponseDto; import leets.weeth.global.auth.jwt.application.dto.JwtDto; +import org.springframework.data.domain.Slice; import java.util.List; import java.util.Map; @@ -24,7 +25,7 @@ public interface UserUseCase { UserResponseDto.Response find(Long userId); - List findAllUser(); + Slice findAllUser(int pageNumber, int pageSize); UserResponseDto.UserResponse findUserDetails(Long userId); From 23a152a41f2f02c0413ab154ba4ae0e8e880275b Mon Sep 17 00:00:00 2001 From: hyxklee Date: Sun, 12 Jan 2025 16:22:24 +0900 Subject: [PATCH 24/30] =?UTF-8?q?feat:=20=EB=A9=A4=EB=B2=84=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=EC=8B=9C=20slice=EB=A1=9C=20=EC=A1=B0=ED=9A=8C?= =?UTF-8?q?=ED=95=98=EB=8A=94=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/domain/repository/UserRepository.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main/java/leets/weeth/domain/user/domain/repository/UserRepository.java b/src/main/java/leets/weeth/domain/user/domain/repository/UserRepository.java index 42e9b670..6dc7db83 100644 --- a/src/main/java/leets/weeth/domain/user/domain/repository/UserRepository.java +++ b/src/main/java/leets/weeth/domain/user/domain/repository/UserRepository.java @@ -3,6 +3,8 @@ import leets.weeth.domain.user.domain.entity.Cardinal; import leets.weeth.domain.user.domain.entity.User; import leets.weeth.domain.user.domain.entity.enums.Status; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Slice; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; @@ -13,18 +15,29 @@ public interface UserRepository extends JpaRepository { Optional findByEmail(String email); + Optional findByKakaoId(long kakaoId); boolean existsByEmail(String email); + boolean existsByStudentId(String studentId); + boolean existsByTel(String tel); boolean existsByStudentIdAndIdIsNot(String studentId, Long id); + boolean existsByTelAndIdIsNot(String tel, Long id); List findAllByStatusOrderByName(Status status); + List findAllByOrderByNameAsc(); @Query("SELECT uc.user FROM UserCardinal uc WHERE uc.cardinal = :cardinal AND uc.user.status = :status") List findAllByCardinalAndStatus(@Param("cardinal") Cardinal cardinal, @Param("status") Status status); + + @Query("SELECT uc.user FROM UserCardinal uc " + + "JOIN uc.cardinal c " + + "WHERE uc.user.status = :status " + + "ORDER BY c.cardinalNumber DESC, uc.user.name ASC") + Slice findAllByStatusOrderedByCardinalAndName(@Param("status") Status status, Pageable pageable); } From 1f282af810e1fcac6bcd37c6a4156786ee912286 Mon Sep 17 00:00:00 2001 From: hyxklee Date: Sun, 12 Jan 2025 16:29:09 +0900 Subject: [PATCH 25/30] =?UTF-8?q?refactor:=20=EA=B8=B0=EC=88=98=EB=A1=9C?= =?UTF-8?q?=20=EA=B2=80=EC=83=89=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../schedule/application/usecase/MeetingUseCaseImpl.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/leets/weeth/domain/schedule/application/usecase/MeetingUseCaseImpl.java b/src/main/java/leets/weeth/domain/schedule/application/usecase/MeetingUseCaseImpl.java index 4cf14391..f423b41c 100644 --- a/src/main/java/leets/weeth/domain/schedule/application/usecase/MeetingUseCaseImpl.java +++ b/src/main/java/leets/weeth/domain/schedule/application/usecase/MeetingUseCaseImpl.java @@ -11,7 +11,10 @@ import leets.weeth.domain.schedule.domain.service.MeetingGetService; import leets.weeth.domain.schedule.domain.service.MeetingSaveService; import leets.weeth.domain.schedule.domain.service.MeetingUpdateService; +import leets.weeth.domain.user.domain.entity.Cardinal; import leets.weeth.domain.user.domain.entity.User; +import leets.weeth.domain.user.domain.service.CardinalGetService; +import leets.weeth.domain.user.domain.service.UserCardinalGetService; import leets.weeth.domain.user.domain.service.UserGetService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -37,6 +40,7 @@ public class MeetingUseCaseImpl implements MeetingUseCase { private final AttendanceSaveService attendanceSaveService; private final AttendanceDeleteService attendanceDeleteService; private final AttendanceUpdateService attendanceUpdateService; + private final CardinalGetService cardinalGetService; @Override public Response find(Long meetingId) { @@ -47,7 +51,9 @@ public Response find(Long meetingId) { @Transactional public void save(Save dto, Long userId) { User user = userGetService.find(userId); - List userList = userGetService.findAllByCardinal(dto.cardinal()); + Cardinal cardinal = cardinalGetService.find(dto.cardinal()); + + List userList = userGetService.findAllByCardinal(cardinal); Meeting meeting = mapper.from(dto, user); meetingSaveService.save(meeting); From dd82c9e0ac8053f2c979f7a207876edec38ce79e Mon Sep 17 00:00:00 2001 From: hyxklee Date: Sun, 12 Jan 2025 17:21:35 +0900 Subject: [PATCH 26/30] =?UTF-8?q?refactor:=20=EA=B8=B0=EC=88=98=20?= =?UTF-8?q?=EC=A0=80=EC=9E=A5=EC=8B=9C=20=EC=A4=91=EB=B3=B5=20=EC=B2=B4?= =?UTF-8?q?=ED=81=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/application/dto/response/CardinalResponse.java | 2 +- .../exception/DuplicateCardinalException.java | 9 +++++++++ .../domain/user/application/usecase/CardinalUseCase.java | 2 ++ .../domain/user/domain/service/CardinalGetService.java | 6 ++++-- 4 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 src/main/java/leets/weeth/domain/user/application/exception/DuplicateCardinalException.java diff --git a/src/main/java/leets/weeth/domain/user/application/dto/response/CardinalResponse.java b/src/main/java/leets/weeth/domain/user/application/dto/response/CardinalResponse.java index 79c51239..d59deaaf 100644 --- a/src/main/java/leets/weeth/domain/user/application/dto/response/CardinalResponse.java +++ b/src/main/java/leets/weeth/domain/user/application/dto/response/CardinalResponse.java @@ -8,6 +8,6 @@ public record CardinalResponse( Integer year, Integer semester, LocalDateTime createdAt, - LocalDateTime modified_at + LocalDateTime modifiedAt ) { } diff --git a/src/main/java/leets/weeth/domain/user/application/exception/DuplicateCardinalException.java b/src/main/java/leets/weeth/domain/user/application/exception/DuplicateCardinalException.java new file mode 100644 index 00000000..11d1092d --- /dev/null +++ b/src/main/java/leets/weeth/domain/user/application/exception/DuplicateCardinalException.java @@ -0,0 +1,9 @@ +package leets.weeth.domain.user.application.exception; + +import leets.weeth.global.common.exception.BusinessLogicException; + +public class DuplicateCardinalException extends BusinessLogicException { + public DuplicateCardinalException() { + super(400, "이미 존재하는 기수 입니다."); + } +} diff --git a/src/main/java/leets/weeth/domain/user/application/usecase/CardinalUseCase.java b/src/main/java/leets/weeth/domain/user/application/usecase/CardinalUseCase.java index b32380ff..178f51c2 100644 --- a/src/main/java/leets/weeth/domain/user/application/usecase/CardinalUseCase.java +++ b/src/main/java/leets/weeth/domain/user/application/usecase/CardinalUseCase.java @@ -24,6 +24,8 @@ public class CardinalUseCase { @Transactional public void save(CardinalSaveRequest dto) { + cardinalGetService.validateCardinal(dto.cardinalNumber()); + cardinalSaveService.save(cardinalMapper.from(dto)); } diff --git a/src/main/java/leets/weeth/domain/user/domain/service/CardinalGetService.java b/src/main/java/leets/weeth/domain/user/domain/service/CardinalGetService.java index 00ff155a..a6b12bd0 100644 --- a/src/main/java/leets/weeth/domain/user/domain/service/CardinalGetService.java +++ b/src/main/java/leets/weeth/domain/user/domain/service/CardinalGetService.java @@ -1,6 +1,7 @@ package leets.weeth.domain.user.domain.service; import leets.weeth.domain.user.application.exception.CardinalNotFoundException; +import leets.weeth.domain.user.application.exception.DuplicateCardinalException; import leets.weeth.domain.user.domain.entity.Cardinal; import leets.weeth.domain.user.domain.repository.CardinalRepository; import lombok.RequiredArgsConstructor; @@ -24,7 +25,8 @@ public List findAll() { } public void validateCardinal(Integer cardinal) { - cardinalRepository.findByCardinalNumber(cardinal) - .orElseThrow(CardinalNotFoundException::new); + if (cardinalRepository.findByCardinalNumber(cardinal).isPresent()) { + throw new DuplicateCardinalException(); + } } } From 0d9ae368dc01ee0886728341ed6a0f8f3134dfd8 Mon Sep 17 00:00:00 2001 From: hyxklee Date: Sun, 12 Jan 2025 17:21:43 +0900 Subject: [PATCH 27/30] =?UTF-8?q?refactor:=20admin=20=EA=B2=BD=EB=A1=9C=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weeth/domain/user/presentation/CardinalController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/leets/weeth/domain/user/presentation/CardinalController.java b/src/main/java/leets/weeth/domain/user/presentation/CardinalController.java index 859bb596..665658b0 100644 --- a/src/main/java/leets/weeth/domain/user/presentation/CardinalController.java +++ b/src/main/java/leets/weeth/domain/user/presentation/CardinalController.java @@ -18,7 +18,7 @@ @Tag(name = "CARDINAL") @RestController @RequiredArgsConstructor -@RequestMapping("/api/v1/cardinals") +@RequestMapping("/api/v1/admin/cardinals") public class CardinalController { private final CardinalUseCase cardinalUseCase; From 397f1bc9c38cc8091289c9553661890b138a14af Mon Sep 17 00:00:00 2001 From: hyxklee Date: Sun, 12 Jan 2025 17:21:57 +0900 Subject: [PATCH 28/30] =?UTF-8?q?refactor:=20=EC=A4=91=EB=B3=B5=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/usecase/UserUseCaseImpl.java | 4 ++-- .../domain/repository/UserRepository.java | 20 +++++++++++++++---- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/main/java/leets/weeth/domain/user/application/usecase/UserUseCaseImpl.java b/src/main/java/leets/weeth/domain/user/application/usecase/UserUseCaseImpl.java index 0a6cb215..f6632aa9 100644 --- a/src/main/java/leets/weeth/domain/user/application/usecase/UserUseCaseImpl.java +++ b/src/main/java/leets/weeth/domain/user/application/usecase/UserUseCaseImpl.java @@ -105,9 +105,9 @@ public Slice findAllUser(int pageNumber, int pa Pageable pageable = PageRequest.of(pageNumber, pageSize); Slice users = userGetService.findAll(pageable); - List sliceUserCardinals = userCardinalGetService.findAll(users.getContent()); + List allUserCardinals = userCardinalGetService.findAll(users.getContent()); - Map> userCardinalMap = sliceUserCardinals.stream() + Map> userCardinalMap = allUserCardinals.stream() .collect(Collectors.groupingBy(userCardinal -> userCardinal.getUser().getId())); return users.map(user -> { diff --git a/src/main/java/leets/weeth/domain/user/domain/repository/UserRepository.java b/src/main/java/leets/weeth/domain/user/domain/repository/UserRepository.java index 6dc7db83..5db8c958 100644 --- a/src/main/java/leets/weeth/domain/user/domain/repository/UserRepository.java +++ b/src/main/java/leets/weeth/domain/user/domain/repository/UserRepository.java @@ -35,9 +35,21 @@ public interface UserRepository extends JpaRepository { @Query("SELECT uc.user FROM UserCardinal uc WHERE uc.cardinal = :cardinal AND uc.user.status = :status") List findAllByCardinalAndStatus(@Param("cardinal") Cardinal cardinal, @Param("status") Status status); - @Query("SELECT uc.user FROM UserCardinal uc " + - "JOIN uc.cardinal c " + - "WHERE uc.user.status = :status " + - "ORDER BY c.cardinalNumber DESC, uc.user.name ASC") + /* + todo 차후 리팩토링 + */ + @Query(""" + SELECT u FROM User u + JOIN UserCardinal uc ON uc.user.id = u.id + JOIN Cardinal c ON c.id = uc.cardinal.id + WHERE u.status = :status + AND c.cardinalNumber = ( + SELECT MAX(subC.cardinalNumber) + FROM Cardinal subC + JOIN UserCardinal subUc ON subUc.cardinal.id = subC.id + WHERE subUc.user.id = u.id + ) + ORDER BY u.name ASC + """) Slice findAllByStatusOrderedByCardinalAndName(@Param("status") Status status, Pageable pageable); } From b52a16c3ca20f441dfb6242190675a9bdfae852b Mon Sep 17 00:00:00 2001 From: hyxklee Date: Mon, 13 Jan 2025 11:54:38 +0900 Subject: [PATCH 29/30] =?UTF-8?q?refactor:=20=ED=8A=B8=EB=9E=9C=EC=9E=AD?= =?UTF-8?q?=EC=85=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weeth/domain/user/application/usecase/UserUseCaseImpl.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/leets/weeth/domain/user/application/usecase/UserUseCaseImpl.java b/src/main/java/leets/weeth/domain/user/application/usecase/UserUseCaseImpl.java index f6632aa9..fa1d8500 100644 --- a/src/main/java/leets/weeth/domain/user/application/usecase/UserUseCaseImpl.java +++ b/src/main/java/leets/weeth/domain/user/application/usecase/UserUseCaseImpl.java @@ -139,6 +139,7 @@ public void update(Update dto, Long userId) { } @Override + @Transactional public void apply(SignUp dto) { validate(dto); From 42636690fec6357d28119b0e0e80724d44f978b1 Mon Sep 17 00:00:00 2001 From: hyxklee Date: Tue, 14 Jan 2025 10:18:14 +0900 Subject: [PATCH 30/30] =?UTF-8?q?refactor:=20API=20=EC=97=94=EB=93=9C?= =?UTF-8?q?=ED=8F=AC=EC=9D=B8=ED=8A=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/user/presentation/CardinalController.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/leets/weeth/domain/user/presentation/CardinalController.java b/src/main/java/leets/weeth/domain/user/presentation/CardinalController.java index 665658b0..acd53933 100644 --- a/src/main/java/leets/weeth/domain/user/presentation/CardinalController.java +++ b/src/main/java/leets/weeth/domain/user/presentation/CardinalController.java @@ -18,12 +18,12 @@ @Tag(name = "CARDINAL") @RestController @RequiredArgsConstructor -@RequestMapping("/api/v1/admin/cardinals") +@RequestMapping("/api/v1") public class CardinalController { private final CardinalUseCase cardinalUseCase; - @GetMapping + @GetMapping("/cardinals") @Operation(summary = "현재 저장된 기수 목록 조회 API") public CommonResponse> findAllCardinals() { List response = cardinalUseCase.findAll(); @@ -31,8 +31,8 @@ public CommonResponse> findAllCardinals() { return CommonResponse.createSuccess(CARDINAL_FIND_ALL_SUCCESS.getMessage(), response); } - @PostMapping - @Operation(summary = "새로운 기수 정보 저장 API") + @PostMapping("/admin/cardinals") + @Operation(summary = "[admin] 새로운 기수 정보 저장 API") public CommonResponse save(@RequestBody @Valid CardinalSaveRequest dto) { cardinalUseCase.save(dto);