Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] 승인 대기, 완료 운영진 조회 #48

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.tave.tavewebsite.domain.member.controller;

import com.tave.tavewebsite.domain.member.dto.response.AuthorizedManagerResponseDto;
import com.tave.tavewebsite.domain.member.dto.response.UnauthorizedManagerResponseDto;
import com.tave.tavewebsite.domain.member.dto.response.ManagerResponseDto;
import com.tave.tavewebsite.domain.member.service.AdminService;
import com.tave.tavewebsite.global.success.SuccessResponse;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.web.bind.annotation.*;

@RestController
Expand All @@ -15,16 +16,11 @@ public class AdminController {

private final AdminService adminService;

@GetMapping("/unauthorized")
public SuccessResponse<List<UnauthorizedManagerResponseDto>> getUnauthorizedManager() {
List<UnauthorizedManagerResponseDto> response = adminService.getUnauthorizedManager();
return new SuccessResponse<>(response, SuccessMessage.UNAUTHORIZED_MEMBER_READ.getMessage());
}

@GetMapping("/authorized")
public SuccessResponse<List<AuthorizedManagerResponseDto>> getAuthorizedAdmins() {
List<AuthorizedManagerResponseDto> response = adminService.getAuthorizedAdmins();
return new SuccessResponse<>(response, SuccessMessage.AUTHORIZED_MEMBER_READ.getMessage());
@GetMapping("/manager")
public SuccessResponse<Page<ManagerResponseDto>> getManagers(
@RequestParam(defaultValue = "ALL", name = "status") String status,
@PageableDefault(size = 8) Pageable pageable) {
return adminService.getManagersByStatus(status, pageable);
}

@DeleteMapping("/{memberId}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
public enum SuccessMessage {
UNAUTHORIZED_MEMBER_READ("승인 대기 중인 운영진을 조회했습니다."),
AUTHORIZED_MEMBER_READ("승인된 운영진을 조회했습니다."),
MANAGER_DELETE("해당 운영진을 삭제했습니다.");
MANAGER_DELETE("해당 운영진을 삭제했습니다."),
ALL_MANAGER_READ("모든 운영진을 조회했습니다.");

private final String message;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@
import com.tave.tavewebsite.domain.member.entity.JobType;
import com.tave.tavewebsite.domain.member.entity.Member;

public record AuthorizedManagerResponseDto(
public record ManagerResponseDto(
Long id,
String username,
String nickname,
DepartmentType department,
JobType job,
String nickname,
String generation,
String agitId
) {
public static AuthorizedManagerResponseDto fromEntity(Member member) {
return new AuthorizedManagerResponseDto(
public static ManagerResponseDto fromEntity(Member member) {
return new ManagerResponseDto(
member.getId(),
member.getUsername(),
member.getNickname(),
member.getDepartment(),
member.getJob(),
member.getNickname(),
member.getGeneration(),
member.getAgitId()
);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ public enum ErrorMessage {
_NOT_MATCHED_VERIFIED_NUMBER(400, "인증 번호가 일치하지 않습니다."),
_EXPIRED_NUMBER(401, "인증번호의 만료시간이 지났습니다."),
_NOT_MATCHED_PASSWORD(400, "비밀번호가 일치하지 않습니다."),
NOT_MANAGER(400, "MANAGER이 아닙니다.");
NOT_MANAGER(400, "MANAGER이 아닙니다."),
INVALID_STATUS_VALUE(400, "유효하지 않은 상태 값입니다.");

final int code;
final String message;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.tave.tavewebsite.domain.member.exception;

import com.tave.tavewebsite.global.exception.BaseErrorException;

import static com.tave.tavewebsite.domain.member.exception.ErrorMessage.INVALID_STATUS_VALUE;

public class InvalidStatusValueExcception extends BaseErrorException {
public InvalidStatusValueExcception() {
super(INVALID_STATUS_VALUE.getCode(), INVALID_STATUS_VALUE.getMessage());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.tave.tavewebsite.domain.member.entity.Member;
import com.tave.tavewebsite.domain.member.entity.RoleType;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;
Expand All @@ -13,5 +15,5 @@ public interface MemberRepository extends JpaRepository<Member, Long> {

Optional<Member> findByNickname(String Nickname);

List<Member> findByRole(RoleType role);
Page<Member> findByRole(RoleType role, Pageable pageable);
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package com.tave.tavewebsite.domain.member.service;

import static com.tave.tavewebsite.domain.member.entity.RoleType.MANAGER;
import static com.tave.tavewebsite.domain.member.entity.RoleType.UNAUTHORIZED_MANAGER;

import com.tave.tavewebsite.domain.member.dto.response.AuthorizedManagerResponseDto;
import com.tave.tavewebsite.domain.member.dto.response.UnauthorizedManagerResponseDto;
import com.tave.tavewebsite.domain.member.controller.SuccessMessage;
import com.tave.tavewebsite.domain.member.dto.response.ManagerResponseDto;
import com.tave.tavewebsite.domain.member.entity.Member;
import com.tave.tavewebsite.domain.member.entity.RoleType;
import com.tave.tavewebsite.domain.member.exception.InvalidStatusValueExcception;
import com.tave.tavewebsite.domain.member.exception.NotFoundMemberException;
import com.tave.tavewebsite.domain.member.exception.NotManagerAccessException;
import com.tave.tavewebsite.domain.member.memberRepository.MemberRepository;
import java.util.List;
import com.tave.tavewebsite.global.success.SuccessResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -28,18 +28,29 @@ public void updateAuthentication(String memberId) {
member.updateRole();
}

@Transactional(readOnly = true)
public List<AuthorizedManagerResponseDto> getAuthorizedAdmins() {
return memberRepository.findByRole(MANAGER).stream()
.map(AuthorizedManagerResponseDto::fromEntity)
.toList();
}
public SuccessResponse<Page<ManagerResponseDto>> getManagersByStatus(String status, Pageable pageable) {
Page<Member> members;
String message;

switch (status.toUpperCase()) {
case "ALL":
members = memberRepository.findAll(pageable);
message = SuccessMessage.ALL_MANAGER_READ.getMessage();
break;
case "AUTHORIZED":
members = memberRepository.findByRole(RoleType.MANAGER, pageable);
message = SuccessMessage.AUTHORIZED_MEMBER_READ.getMessage();
break;
case "UNAUTHORIZED":
members = memberRepository.findByRole(RoleType.UNAUTHORIZED_MANAGER, pageable);
message = SuccessMessage.UNAUTHORIZED_MEMBER_READ.getMessage();
break;
default:
throw new InvalidStatusValueExcception();
}

@Transactional(readOnly = true)
public List<UnauthorizedManagerResponseDto> getUnauthorizedManager() {
return memberRepository.findByRole(UNAUTHORIZED_MANAGER).stream()
.map(UnauthorizedManagerResponseDto::fromEntity)
.toList();
Page<ManagerResponseDto> response = members.map(ManagerResponseDto::fromEntity);
return new SuccessResponse<>(response, message);
}

public Member findMemberById(Long memberId) {
Expand Down