Skip to content

Commit

Permalink
Merge branch 'main' into fix/#39/api-성공-메시지-수정
Browse files Browse the repository at this point in the history
  • Loading branch information
wjd4204 committed Dec 5, 2024
2 parents a37313b + 22227c6 commit 5769cf9
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
import com.tave.tavewebsite.global.success.SuccessResponse;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/v1/admin")
Expand All @@ -20,12 +18,19 @@ public class AdminController {
@GetMapping("/unauthorized")
public SuccessResponse<List<UnauthorizedManagerResponseDto>> getUnauthorizedManager() {
List<UnauthorizedManagerResponseDto> response = adminService.getUnauthorizedManager();
return new SuccessResponse<>(response);
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);
return new SuccessResponse<>(response, SuccessMessage.AUTHORIZED_MEMBER_READ.getMessage());
}

@DeleteMapping("/{memberId}")
public SuccessResponse deleteManager(@PathVariable Long memberId) {
adminService.deleteManager(memberId);
return SuccessResponse.ok(SuccessMessage.MANAGER_DELETE.getMessage());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.tave.tavewebsite.domain.member.controller;

import lombok.AllArgsConstructor;

@AllArgsConstructor
public enum SuccessMessage {
UNAUTHORIZED_MEMBER_READ("승인 대기 중인 운영진을 조회했습니다."),
AUTHORIZED_MEMBER_READ("승인된 운영진을 조회했습니다."),
MANAGER_DELETE("해당 운영진을 삭제했습니다.");

private final String message;

public String getMessage(String generation) {
return generation +" " + message;
}

public String getMessage() {
return message;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.tave.tavewebsite.domain.member.entity.Member;

public record AuthorizedManagerResponseDto(
Long id,
String username,
String nickname,
DepartmentType department,
Expand All @@ -14,6 +15,7 @@ public record AuthorizedManagerResponseDto(
) {
public static AuthorizedManagerResponseDto fromEntity(Member member) {
return new AuthorizedManagerResponseDto(
member.getId(),
member.getUsername(),
member.getNickname(),
member.getDepartment(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ public enum ErrorMessage {
DUPLICATE_NICKNAME(400, "이미 사용중인 아이디입니다. 다른 아이디로 가입해주세요."),
_NOT_MATCHED_VERIFIED_NUMBER(400, "인증 번호가 일치하지 않습니다."),
_EXPIRED_NUMBER(401, "인증번호의 만료시간이 지났습니다."),
_NOT_MATCHED_PASSWORD(400, "비밀번호가 일치하지 않습니다.");
_NOT_MATCHED_PASSWORD(400, "비밀번호가 일치하지 않습니다."),
NOT_MANAGER(400, "MANAGER이 아닙니다.");

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

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

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

public class NotManagerAccessException extends BaseErrorException {
public NotManagerAccessException() {
super(NOT_MANAGER.getCode(), NOT_MANAGER.getMessage());

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import com.tave.tavewebsite.domain.member.dto.response.AuthorizedManagerResponseDto;
import com.tave.tavewebsite.domain.member.dto.response.UnauthorizedManagerResponseDto;
import com.tave.tavewebsite.domain.member.entity.Member;
import com.tave.tavewebsite.domain.member.entity.RoleType;
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 lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -39,4 +41,21 @@ public List<UnauthorizedManagerResponseDto> getUnauthorizedManager() {
.map(UnauthorizedManagerResponseDto::fromEntity)
.toList();
}

public Member findMemberById(Long memberId) {
return memberRepository.findById(memberId)
.orElseThrow(NotFoundMemberException::new);
}

public void deleteManager(long memberId) {
Member memberToDelete = findMemberById(memberId);

// 일반 회원 및 다른 운영진이 탈퇴를 처리하지 못하도록 예외 처리
if (!memberToDelete.getRole().equals(RoleType.MANAGER)) {
throw new NotManagerAccessException(); // 운영진만 탈퇴 가능
}

memberRepository.deleteById(memberId);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public SuccessResponse<Page<ProjectResponseDto>> getProjects(@PageableDefault(si
@RequestParam(defaultValue = "ALL", name = "generation") String generation,
@RequestParam(defaultValue = "ALL", name = "field") String field) {
Page<ProjectResponseDto> projects = projectService.getProjects(generation, field, pageable);
return new SuccessResponse<>(projects);
return new SuccessResponse<>(projects, SuccessMessage.PROJECT_READ.getMessage());
}

@PutMapping("/manager/project/{projectId}")
Expand Down

0 comments on commit 5769cf9

Please sign in to comment.