From 359c4625aea1d7143754c6f66a2a88247352d2f3 Mon Sep 17 00:00:00 2001 From: kwonssshyeon Date: Wed, 4 Sep 2024 14:25:35 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[Feat]:=20=EB=A7=A4=EB=8B=88=EC=A0=80,=20?= =?UTF-8?q?=EC=96=B4=EB=93=9C=EB=AF=BC=20=EA=B3=84=EC=A0=95=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20api=20=EC=8A=A4=ED=8E=99=20=EC=A0=95=EC=9D=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/controller/AdminController.java | 13 +++++++ .../zzansuni/admin/controller/AdminRes.java | 34 +++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/admin/controller/AdminRes.java diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/admin/controller/AdminController.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/admin/controller/AdminController.java index e7c3ceb..d9fd656 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/admin/controller/AdminController.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/admin/controller/AdminController.java @@ -8,9 +8,13 @@ import org.haedal.zzansuni.auth.domain.AuthService; import org.haedal.zzansuni.challengegroup.domain.application.ChallengeGroupService; import org.haedal.zzansuni.core.api.ApiResponse; +import org.haedal.zzansuni.user.domain.UserModel; +import org.haedal.zzansuni.user.domain.UserService; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; +import java.util.List; + @Tag(name = "admin", description = "관리자 API") @RequiredArgsConstructor @RestController @@ -18,6 +22,7 @@ public class AdminController { private final AuthService authService; private final ChallengeGroupService challengeGroupService; + private final UserService userService; @ResponseStatus(HttpStatus.CREATED) @Operation(summary = "매니저 등록", description = "매니저를 등록한다.") @@ -27,6 +32,14 @@ public ApiResponse createManager(@RequestBody @Valid AuthReq.EmailSignupRe return ApiResponse.success(null, "매니저 등록 성공"); } + @ResponseStatus(HttpStatus.OK) + @Operation(summary = "매니저, 어드민 계정 조회", description = "매니저, 어드민 계정을 조회한다.") + @GetMapping("/api/admin/auth/manager") + public ApiResponse> getAdminAndManager() { + List managerAndAdmin = userService.getManagerAndAdmin(); + return ApiResponse.success(AdminRes.ManagerAndAdmin.from(managerAndAdmin), "매니저, 어드민 계정 조회 성공"); + } + @ResponseStatus(HttpStatus.CREATED) @Operation(summary = "챌린지 그룹 생성", description = "챌린지 그룹과 해당하는 챌린지를 생성합니다") @PostMapping("/api/admin/challengeGroups") diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/admin/controller/AdminRes.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/admin/controller/AdminRes.java new file mode 100644 index 0000000..e9abe33 --- /dev/null +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/admin/controller/AdminRes.java @@ -0,0 +1,34 @@ +package org.haedal.zzansuni.admin.controller; + +import lombok.Builder; +import org.haedal.zzansuni.user.domain.UserModel; + +import java.time.LocalDateTime; +import java.util.List; + +public class AdminRes { + @Builder + public record ManagerAndAdmin( + Long id, + String email, + String name, + String role, + LocalDateTime createdAt + ) { + public static ManagerAndAdmin from(UserModel.Admin managerAndAdmin) { + return ManagerAndAdmin.builder() + .id(managerAndAdmin.id()) + .email(managerAndAdmin.email()) + .name(managerAndAdmin.nickname()) + .role(managerAndAdmin.role().name()) + .createdAt(managerAndAdmin.createdAt()) + .build(); + } + public static List from(List managerAndAdmins) { + return managerAndAdmins.stream() + .map(ManagerAndAdmin::from) + .toList(); + } + } + +} From 940c563d30d66cc3ed5f397a6702495134924cd1 Mon Sep 17 00:00:00 2001 From: kwonssshyeon Date: Wed, 4 Sep 2024 14:26:50 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[Feat]:=20=EB=A7=A4=EB=8B=88=EC=A0=80,=20?= =?UTF-8?q?=EC=96=B4=EB=93=9C=EB=AF=BC=20=EA=B3=84=EC=A0=95=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../zzansuni/user/domain/UserModel.java | 20 +++++++++++++++++++ .../zzansuni/user/domain/UserReader.java | 2 ++ .../zzansuni/user/domain/UserService.java | 8 ++++++++ .../user/infrastructure/UserReaderImpl.java | 6 ++++++ .../user/infrastructure/UserRepository.java | 3 +++ 5 files changed, 39 insertions(+) diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/user/domain/UserModel.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/user/domain/UserModel.java index b7f9070..daebf60 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/user/domain/UserModel.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/user/domain/UserModel.java @@ -1,8 +1,10 @@ package org.haedal.zzansuni.user.domain; import lombok.Builder; +import org.haedal.zzansuni.global.security.Role; import java.time.LocalDate; +import java.time.LocalDateTime; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -71,5 +73,23 @@ public String toString() { } } + @Builder + public record Admin( + Long id, + String email, + String nickname, + LocalDateTime createdAt, + Role role + ) { + public static Admin from(User user) { + return Admin.builder() + .id(user.getId()) + .email(user.getEmail()) + .nickname(user.getNickname()) + .createdAt(user.getCreatedAt()) + .role(user.getRole()) + .build(); + } + } } \ No newline at end of file diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/user/domain/UserReader.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/user/domain/UserReader.java index adc56da..09cba40 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/user/domain/UserReader.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/user/domain/UserReader.java @@ -3,6 +3,7 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; +import java.util.List; import java.util.Optional; public interface UserReader { @@ -15,4 +16,5 @@ public interface UserReader { Optional findByAuthToken(String authToken); Page getUserPagingByRanking(Pageable pageable); + List getManagerAndAdmin(); } diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/user/domain/UserService.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/user/domain/UserService.java index a3081be..33a887b 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/user/domain/UserService.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/user/domain/UserService.java @@ -19,6 +19,14 @@ public class UserService { private final UserReader userReader; private final UserChallengeReader userChallengeReader; + @Transactional(readOnly = true) + public List getManagerAndAdmin() { + List admins = userReader.getManagerAndAdmin(); + return admins.stream() + .map(UserModel.Admin::from) + .toList(); + } + @Transactional(readOnly = true) public UserModel.Main getUserModel(Long id) { User user = userReader.getById(id); diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/user/infrastructure/UserReaderImpl.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/user/infrastructure/UserReaderImpl.java index 2deab68..945f020 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/user/infrastructure/UserReaderImpl.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/user/infrastructure/UserReaderImpl.java @@ -2,6 +2,7 @@ import com.querydsl.jpa.impl.JPAQueryFactory; import lombok.RequiredArgsConstructor; +import org.haedal.zzansuni.global.security.Role; import org.haedal.zzansuni.user.domain.QUser; import org.haedal.zzansuni.user.domain.User; import org.haedal.zzansuni.user.domain.UserReader; @@ -54,4 +55,9 @@ public Page getUserPagingByRanking(Pageable pageable) { return new PageImpl<>(users, pageable, totalCount == null ? 0 : totalCount); } + + @Override + public List getManagerAndAdmin() { + return userRepository.findByRoleIn(List.of(Role.ADMIN, Role.MANAGER)); + } } diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/user/infrastructure/UserRepository.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/user/infrastructure/UserRepository.java index cf097f0..f46d5fe 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/user/infrastructure/UserRepository.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/user/infrastructure/UserRepository.java @@ -1,8 +1,10 @@ package org.haedal.zzansuni.user.infrastructure; +import org.haedal.zzansuni.global.security.Role; import org.haedal.zzansuni.user.domain.User; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; import java.util.Optional; public interface UserRepository extends JpaRepository { @@ -10,4 +12,5 @@ public interface UserRepository extends JpaRepository { boolean existsByEmail(String email); Optional findByEmail(String email); + List findByRoleIn(List role); }