-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
189 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/main/java/com/codiary/backend/domain/project/controller/ProjectController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.codiary.backend.domain.project.controller; | ||
|
||
import com.codiary.backend.domain.member.security.CustomMemberDetails; | ||
import com.codiary.backend.domain.project.converter.ProjectConverter; | ||
import com.codiary.backend.domain.project.dto.response.ProjectResponseDTO; | ||
import com.codiary.backend.domain.project.service.ProjectService; | ||
import com.codiary.backend.global.apiPayload.ApiResponse; | ||
import com.codiary.backend.global.apiPayload.code.status.SuccessStatus; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import com.codiary.backend.domain.project.entity.Project; | ||
import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/v2/project") | ||
@Tag(name = "프로젝트 API", description = "프로젝트 조회 관련 API입니다.") | ||
public class ProjectController { | ||
|
||
private final ProjectService projectService; | ||
|
||
@Operation(summary = "개인 프로젝트 생성", description = "개인 프로젝트를 생성합니다.") | ||
@PostMapping("/create/{project_name}") | ||
public ApiResponse<ProjectResponseDTO.SimpleProjectResponseDTO> createPersonalProject(@AuthenticationPrincipal CustomMemberDetails memberDetails, | ||
@PathVariable("project_name") String projectName) { | ||
Project project = projectService.createPersonalProject(memberDetails.getId(), projectName); | ||
return ApiResponse.onSuccess(SuccessStatus.PROJECT_OK, ProjectConverter.toSimpleProjectResponseDTO(project)); | ||
} | ||
|
||
@Operation(summary = "나의 프로젝트 조회", description = "프로젝트를 조회합니다.") | ||
@GetMapping("/my") | ||
public ApiResponse<List<ProjectResponseDTO.SimpleProjectResponseDTO>> getMyProject(@AuthenticationPrincipal CustomMemberDetails memberDetails) { | ||
List<Project> projects = projectService.getMyProject(memberDetails.getId()); | ||
return ApiResponse.onSuccess(SuccessStatus.PROJECT_OK, ProjectConverter.toSimpleProjectListResponseDTO(projects)); | ||
} | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/com/codiary/backend/domain/project/converter/ProjectConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.codiary.backend.domain.project.converter; | ||
|
||
import com.codiary.backend.domain.member.converter.MemberConverter; | ||
import com.codiary.backend.domain.project.entity.Project; | ||
import com.codiary.backend.domain.project.dto.response.ProjectResponseDTO; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public class ProjectConverter { | ||
public static ProjectResponseDTO.ProjectDetailResponseDTO toProjectDetailResponseDTO(Project project) { | ||
return ProjectResponseDTO.ProjectDetailResponseDTO.builder() | ||
.projectId(project.getProjectId()) | ||
.name(project.getProjectName()) | ||
.members(project.getMemberProjectMaps().stream() | ||
.map(memberProjectMap -> MemberConverter.tosimpleMemberProfileResponseDto(memberProjectMap.getMember())) | ||
.collect(Collectors.toList())) | ||
.build(); | ||
} | ||
|
||
public static ProjectResponseDTO.SimpleProjectResponseDTO toSimpleProjectResponseDTO(Project project) { | ||
return ProjectResponseDTO.SimpleProjectResponseDTO.builder() | ||
.projectId(project.getProjectId()) | ||
.name(project.getProjectName()) | ||
.build(); | ||
} | ||
|
||
public static List<ProjectResponseDTO.SimpleProjectResponseDTO> toSimpleProjectListResponseDTO(List<Project> projects) { | ||
return projects.stream() | ||
.map(ProjectConverter::toSimpleProjectResponseDTO) | ||
.collect(Collectors.toList()); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/com/codiary/backend/domain/project/dto/response/ProjectResponseDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,31 @@ | ||
package com.codiary.backend.domain.project.dto.response; | ||
|
||
import com.codiary.backend.domain.member.dto.response.MemberResponseDTO; | ||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.databind.PropertyNamingStrategies; | ||
import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
import lombok.Builder; | ||
|
||
import java.util.List; | ||
|
||
public class ProjectResponseDTO { | ||
|
||
@Builder | ||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) | ||
public record SimpleProjectResponseDTO( | ||
Long projectId, | ||
String name | ||
) { | ||
} | ||
|
||
@Builder | ||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) | ||
public record ProjectDetailResponseDTO( | ||
Long projectId, | ||
String name, | ||
List<MemberResponseDTO.SimpleMemberProfileDTO> members | ||
) { | ||
} | ||
} |
15 changes: 11 additions & 4 deletions
15
src/main/java/com/codiary/backend/domain/project/entity/Project.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
src/main/java/com/codiary/backend/domain/project/repository/ProjectRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,15 @@ | ||
package com.codiary.backend.domain.project.repository; | ||
|
||
import com.codiary.backend.domain.member.entity.Member; | ||
import com.codiary.backend.domain.project.entity.Project; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public interface ProjectRepository extends JpaRepository<Project, Long>, ProjectRepositoryCustom { | ||
|
||
List<Project> findAllByOrderByProjectIdDesc(); | ||
|
||
Optional<Project> findByProjectNameAndDeletedAtIsNull(String projectName); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/main/java/com/codiary/backend/domain/project/service/ProjectService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.codiary.backend.domain.project.service; | ||
|
||
import com.codiary.backend.domain.member.entity.Member; | ||
import com.codiary.backend.domain.member.entity.MemberProjectMap; | ||
import com.codiary.backend.domain.project.entity.Project; | ||
import com.codiary.backend.domain.member.repository.MemberRepository; | ||
import com.codiary.backend.domain.project.repository.ProjectRepository; | ||
import com.codiary.backend.global.apiPayload.code.status.ErrorStatus; | ||
import com.codiary.backend.global.apiPayload.exception.GeneralException; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.List; | ||
|
||
@Transactional(readOnly = true) | ||
@RequiredArgsConstructor | ||
@Service | ||
public class ProjectService { | ||
private final ProjectRepository projectRepository; | ||
private final MemberRepository memberRepository; | ||
|
||
@Transactional | ||
public Project createPersonalProject(Long memberId, String projectName) { | ||
//validation | ||
Member member = memberRepository.findById(memberId) | ||
.orElseThrow(() -> new GeneralException(ErrorStatus.MEMBER_NOT_FOUND)); | ||
Project project = projectRepository.findByProjectNameAndDeletedAtIsNull(projectName) | ||
.orElse(null); | ||
|
||
//business | ||
if (project != null) { // 프로젝트 이름 중복 확인 | ||
throw new GeneralException(ErrorStatus.PROJECT_ALREADY_EXISTS); | ||
} else { | ||
project = Project.builder() | ||
.projectName(projectName) | ||
.build(); | ||
projectRepository.save(project); | ||
|
||
MemberProjectMap memberProjectMap = MemberProjectMap.builder() | ||
.member(member) | ||
.project(project) | ||
.build(); | ||
|
||
member.addProject(memberProjectMap); | ||
} | ||
|
||
//return | ||
return project; | ||
} | ||
|
||
public List<Project> getMyProject(Long id) { | ||
//validation | ||
Member member = memberRepository.findById(id) | ||
.orElseThrow(() -> new GeneralException(ErrorStatus.MEMBER_NOT_FOUND)); | ||
|
||
//return | ||
return projectRepository.findByMemberProjectMapsMember(member); | ||
} | ||
} |