Skip to content

Commit

Permalink
Merge pull request #108 from Kernel360/feature/project-authorization-…
Browse files Browse the repository at this point in the history
…2-#82

Feature : project authorization #82
  • Loading branch information
Eseas authored Jan 24, 2025
2 parents adc4d85 + 3cbf259 commit 1834f6a
Show file tree
Hide file tree
Showing 34 changed files with 597 additions and 76 deletions.
2 changes: 1 addition & 1 deletion Common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ dependencies {

tasks.named('test') {
useJUnitPlatform()
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.seveneleven.entity.project;

import com.seveneleven.exception.BusinessException;
import com.seveneleven.response.ErrorCode;
import jakarta.persistence.Embeddable;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand All @@ -15,6 +17,18 @@ public class MemberProjectStepId implements Serializable {
private Long memberId; // 회원 ID
private Long projectStepId; // 프로젝트 단계 ID

public MemberProjectStepId(Long memberId, Long projectStepId) {
if(memberId == null) {
throw new BusinessException(ErrorCode.USER_NOT_FOUND);
}
if(projectStepId == null) {
throw new BusinessException(ErrorCode.NOT_FOUND_PROJECT_STEP);
}

this.memberId = memberId;
this.projectStepId = projectStepId;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import com.seveneleven.entity.global.YesNo;
import com.seveneleven.entity.global.converter.YesNoConverter;
import com.seveneleven.entity.member.Member;
import com.seveneleven.entity.project.constant.MemberType;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

Expand All @@ -30,19 +30,33 @@ public class ProjectAuthorization extends BaseEntity {
private ProjectStep projectStep;

@Enumerated(EnumType.STRING)
private memberType memberType; // 회원 구분 (client, developer)
private MemberType memberType; // 회원 구분 (client, developer)

private String authorizationCode; // 권한 코드

@Convert(converter = YesNoConverter.class)
private YesNo isDeleted; // 삭제 여부
private YesNo isActive; // 삭제 여부

private ProjectAuthorization(Member member, ProjectStep projectStep, MemberType memberType, String authorizationCode) {
this.id = new MemberProjectStepId(member.getId(), projectStep.getId());
this.member = member;
this.projectStep = projectStep;
this.memberType = memberType;
this.authorizationCode = authorizationCode;
this.isActive = YesNo.YES;
}

public static ProjectAuthorization create(Member member, ProjectStep projectStep, MemberType memberType, String authorizationCode) {
return new ProjectAuthorization(member, projectStep, memberType, authorizationCode);
}

@Getter
@AllArgsConstructor
enum memberType {
CLIENT("client"),
DEVELOPER("developer");
public void edit(MemberType memberType, String authorizationCode) {
this.memberType = memberType;
this.authorizationCode = authorizationCode;
}

final String description;
public ProjectAuthorizationHistory delete() {
isActive = YesNo.NO;
return ProjectAuthorizationHistory.create(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,17 @@ public class ProjectAuthorizationHistory extends BaseEntity {

@Column(nullable = false)
@Convert(converter = YesNoConverter.class)
private YesNo isDeleted; // 삭제 여부
private YesNo isActive; // 삭제 여부

private ProjectAuthorizationHistory(ProjectAuthorization authorization) {
this.memberName = authorization.getMember().getName();
this.projectStepName = authorization.getProjectStep().getStepName();
this.memberType = authorization.getMemberType().name();
this.authorizationCode = authorization.getAuthorizationCode();
this.isActive = authorization.getIsActive();
}

public static ProjectAuthorizationHistory create(ProjectAuthorization authorization) {
return new ProjectAuthorizationHistory(authorization);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.seveneleven.entity.project.constant;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public enum Authorization {
APPROVER("승인권자"),
PARTICIPANT("참가자");

private final String description;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.seveneleven.entity.project.constant;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public enum MemberType {
CLIENT("client"),
DEVELOPER("developer");

final String description;
}
3 changes: 2 additions & 1 deletion Common/src/main/java/com/seveneleven/response/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ public enum ErrorCode {

// 10000 : 알 수 없는 예외
UNKNOWN_ERROR(10000, HttpStatus.BAD_REQUEST, "알 수 없는 예외입니다,"),
ENTITY_NOT_FOUND(10001, HttpStatus.BAD_REQUEST,"정보를 찾을 수 없습니다");
ENTITY_NOT_FOUND(10001, HttpStatus.BAD_REQUEST,"정보를 찾을 수 없습니다"),
BAD_REQUEST(10002, HttpStatus.BAD_REQUEST, "잘못된 요청입니다.");
private final Integer code;
private final HttpStatus status;
private final String message;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ public enum SuccessCode {
*/
CREATED(HttpStatus.CREATED, "생성 완료"),

/*
203 Multi-Status
*/
MULTISTATUS(HttpStatus.MULTI_STATUS, "일부만 처리에 성공했습니다."),

/*
204 No Content
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ public interface PostRepository extends JpaRepository<Post, Long> {

Page<Post> findAllByProjectStepId(@Param("projectStepId") Long projectStepId, Pageable pageable);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
public interface MemberRepository extends JpaRepository<Member, Long>, JpaSpecificationExecutor<Member> {

// TODO - JOIN VS getCompany().getId() 검토 필요
@Query("SELECT m.company.id FROM Member m where m.id = :memberId AND m.status = :statusCode")
Optional<Long> findCompanyIdByIdAndStatus(Long memberId, MemberStatus statusCode);

Optional<Member> findByLoginId(String loginId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import org.springframework.web.bind.annotation.RequestMapping;

@RequestMapping("/api/project")
@Tag(name = "프로젝트 대시보드 API", description = "프로젝트 대시보드 관련 API")
@Tag(name = "Project Dashboard API", description = "프로젝트 대시보드 관련 API")
public interface MyProjectDocs {

@GetMapping("/{memberId}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,27 @@

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/projects")
@RequestMapping("/api/projects/checklists")
public class ProjectChecklistController implements ProjectChecklistDocs {

private final ProjectChecklistFacade projectChecklistFacade;

/**
* 함수명 : getStepChecklist
* 해당 단계의 체크리스트 목록을 반환하는 함수
*/
@GetMapping("/{stepId}")
public ResponseEntity<APIResponse<GetStepChecklist.Response>> getProjectChecklist(
@PathVariable Long stepId
) {
return ResponseEntity
.status(HttpStatus.OK)
.body(APIResponse.success(SuccessCode.OK, projectChecklistFacade.getStepChecklist(stepId)));
}

/**
* 함수명 : postProjectChecklist
* 해당 프로젝트 단계에 단일 체크리스트를 추가하는 함수
* 해당 프로젝트 단계에 체크리스트를 추가하는 함수
*/
@PostMapping("")
public ResponseEntity<APIResponse<PostProjectChecklist.Response>> postProjectChecklist(
Expand Down Expand Up @@ -57,6 +70,10 @@ public ResponseEntity<APIResponse<DeleteProjectChecklist.Response>> deleteProjec
.body(APIResponse.success(SuccessCode.DELETED, projectChecklistFacade.deleteProjectChecklist(checklistId)));
}

/**
* 함수명 : getProjectChecklistApplication
* 프로젝트 체크리스트에 승인 요청을 확인하는 함수
*/
@GetMapping("/applications/{applicationId}")
public ResponseEntity<APIResponse<GetProjectChecklistApplication.Response>> getProjectChecklistApplication(
@PathVariable Long applicationId
Expand All @@ -75,8 +92,6 @@ public ResponseEntity<APIResponse<PostProjectChecklistApplication.Response>> pos
@RequestBody List<MultipartFile> files,
HttpServletRequest request
) {
// TODO - 파일 관련 처리 필요.

return ResponseEntity.status(HttpStatus.OK)
.body(APIResponse.success(SuccessCode.CREATED, projectChecklistFacade.postProjectChecklistApplication(requestDto, request)));
}
Expand Down Expand Up @@ -118,8 +133,6 @@ public ResponseEntity<APIResponse<PostProjectChecklistReject.Response>> postProj
request
);

// TODO - 파일 등록 필요.

return ResponseEntity.status(SuccessCode.CREATED.getStatusCode())
.body(APIResponse.success(SuccessCode.CREATED, response));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,37 @@
import java.io.File;
import java.util.List;

@Tag(name = "프로젝트 체크리스트 API", description = "프로젝트 체크리스트 관련 API")
@Tag(name = "Project Checklist API", description = "프로젝트 체크리스트 관련 API")
@RequestMapping("/api/projects")
public interface ProjectChecklistDocs {

@GetMapping("/steps/{stepId}")
@Operation(
summary = "체크리스트 조회",
description = "특정 단계의 체크리스트를 조회합니다.",
responses = {
@ApiResponse(
responseCode = "200",
description = "성공적으로 체크리스트를 반환했습니다.",
content = @Content(
mediaType = "application/json",
schema = @Schema(implementation = GetStepChecklist.Response.class)
)
)
},
parameters = {
@Parameter(
name = "stepId",
description = "체크리스트를 조회할 단계의 ID",
required = true,
example = "1"
)
}
)
ResponseEntity<APIResponse<GetStepChecklist.Response>> getProjectChecklist(
@PathVariable Long stepId
);

@PostMapping("")
@Operation(
summary = "체크리스트 생성",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.seveneleven.project.dto.*;
import com.seveneleven.project.service.ProjectChecklistService;
import com.seveneleven.project.service.ProjectStepService;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -13,11 +14,16 @@
public class ProjectChecklistFacade {

private final ProjectChecklistService projectChecklistService;
private final ProjectStepService projectStepService;

public GetProjectChecklistApplication.Response getProjectChecklistApplication(Long applicationId) {
return projectChecklistService.getApplicationDetail(applicationId);
}

public GetStepChecklist.Response getStepChecklist(Long stepId) {
return projectStepService.getStepChecklist(stepId);
}

public PostProjectChecklist.Response postProjectChecklist(PostProjectChecklist.Request postProjectChecklist) {
return projectChecklistService.postProjectChecklist(postProjectChecklist);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

@Tag(name = "프로젝트 API", description = "프로젝트 관련 API")
@Tag(name = "Project API", description = "프로젝트 관련 API")
@RequestMapping("/api/projects")
public interface ProjectDocs {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,7 @@ public ResponseEntity<APIResponse<GetProjectStep.Response>> getProjectStepAndChe
.body(APIResponse.success(SuccessCode.OK, projectStepFacade.getProjectStepAndChecklist(projectId)));
}

/**
* 함수명 : getStepChecklist
* 해당 단계의 체크리스트 목록을 반환하는 함수
*/
@GetMapping("/{stepId}")
public ResponseEntity<APIResponse<GetStepChecklist.Response>> getProjectChecklist(
@PathVariable Long stepId
) {
return ResponseEntity
.status(HttpStatus.OK)
.body(APIResponse.success(SuccessCode.OK, projectStepFacade.getStepChecklist(stepId)));
}


/**
* 함수명 : postProjectStep
Expand Down Expand Up @@ -70,4 +59,27 @@ public ResponseEntity<APIResponse<DeleteProjectStep.Response>> deleteProjectStep
return ResponseEntity.status(SuccessCode.OK.getStatusCode())
.body(APIResponse.success(SuccessCode.OK, projectStepFacade.deleteProjectStep(requestDto)));
}

@PostMapping("/{stepId}/authorizations")
public ResponseEntity<APIResponse<PostProjectAuthorization.Response>> postProjectAuthorization(
@PathVariable Long stepId,
@RequestBody PostProjectAuthorization.Request requestDto
) {
PostProjectAuthorization.Response responseDto = projectStepFacade.postProjectAuthorization(requestDto, stepId);

if(responseDto.getFailList().isEmpty()) {
return ResponseEntity.status(SuccessCode.CREATED.getStatusCode())
.body(APIResponse.success(SuccessCode.OK, responseDto));
}
return ResponseEntity.status(SuccessCode.MULTISTATUS.getStatusCode())
.body(APIResponse.success(SuccessCode.MULTISTATUS, responseDto));
}

@GetMapping("/{stepId}/authorizations")
public ResponseEntity<APIResponse<GetProjectAuthorization.Response>> getProjectAuthorization(
@PathVariable Long stepId
) {
return ResponseEntity.status(SuccessCode.OK.getStatusCode())
.body(APIResponse.success(SuccessCode.OK, projectStepFacade.getProjectAuthorization(stepId)));
}
}
Loading

0 comments on commit 1834f6a

Please sign in to comment.