From 68da776bd09a973d1478f60cbf0112e92236cca2 Mon Sep 17 00:00:00 2001 From: UU_jeong <80961726+oU-Ua@users.noreply.github.com> Date: Sun, 17 Dec 2023 04:16:21 +0900 Subject: [PATCH 1/2] =?UTF-8?q?chore=20:=20project=20Create=20parameter=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mvc/promiseme/project/dto/MemberRequestDTO.java | 13 +++++++++++++ .../promiseme/project/dto/ProjectRequestDTO.java | 2 +- .../project/service/ProjectServiceImpl.java | 7 ++++--- 3 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 src/main/java/mvc/promiseme/project/dto/MemberRequestDTO.java diff --git a/src/main/java/mvc/promiseme/project/dto/MemberRequestDTO.java b/src/main/java/mvc/promiseme/project/dto/MemberRequestDTO.java new file mode 100644 index 0000000..4143674 --- /dev/null +++ b/src/main/java/mvc/promiseme/project/dto/MemberRequestDTO.java @@ -0,0 +1,13 @@ +package mvc.promiseme.project.dto; + +import lombok.*; + +@NoArgsConstructor +@AllArgsConstructor +@Getter +@Setter +@Builder +public class MemberRequestDTO { + private String email; + private String role; +} diff --git a/src/main/java/mvc/promiseme/project/dto/ProjectRequestDTO.java b/src/main/java/mvc/promiseme/project/dto/ProjectRequestDTO.java index f370b70..2ea0c02 100644 --- a/src/main/java/mvc/promiseme/project/dto/ProjectRequestDTO.java +++ b/src/main/java/mvc/promiseme/project/dto/ProjectRequestDTO.java @@ -18,5 +18,5 @@ public class ProjectRequestDTO { private LocalDate start; @JsonFormat(pattern = "yyyy-MM-dd") private LocalDate deadline; - private List memberList; + private List memberList; } diff --git a/src/main/java/mvc/promiseme/project/service/ProjectServiceImpl.java b/src/main/java/mvc/promiseme/project/service/ProjectServiceImpl.java index d4e0a05..77b1563 100644 --- a/src/main/java/mvc/promiseme/project/service/ProjectServiceImpl.java +++ b/src/main/java/mvc/promiseme/project/service/ProjectServiceImpl.java @@ -4,6 +4,7 @@ import mvc.promiseme.common.exception.ErrorCode; import mvc.promiseme.common.exception.UserException; import mvc.promiseme.project.dto.MemberDTO; +import mvc.promiseme.project.dto.MemberRequestDTO; import mvc.promiseme.project.dto.ProjectRequestDTO; import mvc.promiseme.project.dto.ProjectResponseDTO; import mvc.promiseme.project.entity.Member; @@ -54,9 +55,9 @@ public Long insert(ProjectRequestDTO projectRequestDTO) { Project project = p.mapToEntity(projectRequestDTO); projectRepository.save(project); System.out.println("projectId : " + project.getProjectId()); - List memberList = projectRequestDTO.getMemberList(); + List memberList = projectRequestDTO.getMemberList(); - for(MemberDTO m : memberList){ + for(MemberRequestDTO m : memberList){ Role r = new Role(); Role role = roleRepository.findByName(m.getRole()); if(role==null) { @@ -64,7 +65,7 @@ public Long insert(ProjectRequestDTO projectRequestDTO) { roleRepository.save(role); } System.out.println("role name "+role.getName()); - Users user = userRepository.findById(m.getUserId()).orElseThrow(() -> new NoSuchElementException("[ERROR] 해당하는 사용자가 존재하지 않습니다.")); + Users user = userRepository.findByEmailIgnoreCase(m.getEmail()); Member member = Member.builder().project(project).role(role).users(user).status(MemberStatus.PARTICIPATION).build(); memberRepository.save(member); } From 6f9a88c452ac87987274aad60ddc1d7e9dd5c85a Mon Sep 17 00:00:00 2001 From: UU_jeong <80961726+oU-Ua@users.noreply.github.com> Date: Sun, 17 Dec 2023 04:44:57 +0900 Subject: [PATCH 2/2] =?UTF-8?q?chore=20:=20project=20Create=20parameter=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mvc/promiseme/project/service/ProjectServiceImpl.java | 5 +++++ .../java/mvc/promiseme/todo/repository/TodoRepository.java | 3 +++ 2 files changed, 8 insertions(+) diff --git a/src/main/java/mvc/promiseme/project/service/ProjectServiceImpl.java b/src/main/java/mvc/promiseme/project/service/ProjectServiceImpl.java index 77b1563..847cf83 100644 --- a/src/main/java/mvc/promiseme/project/service/ProjectServiceImpl.java +++ b/src/main/java/mvc/promiseme/project/service/ProjectServiceImpl.java @@ -16,6 +16,7 @@ import mvc.promiseme.project.repository.RoleRepository; import mvc.promiseme.todo.dto.TodoRequestDTO; import mvc.promiseme.todo.entity.Todo; +import mvc.promiseme.todo.repository.TodoRepository; import mvc.promiseme.users.entity.Users; import mvc.promiseme.users.repository.UserRepository; import org.springframework.stereotype.Service; @@ -31,6 +32,7 @@ public class ProjectServiceImpl implements ProjectService { private final UserRepository userRepository; private final MemberRepository memberRepository; private final RoleRepository roleRepository; + private final TodoRepository todoRepository; @Override @Transactional public List projectAll(Long userId) { @@ -78,6 +80,9 @@ public Long insert(ProjectRequestDTO projectRequestDTO) { @Override public int progress(Long projectId) { + Project project= projectRepository.findById(projectId).orElseThrow(()->new NoSuchElementException("프로젝트를 찾을 수 없습니다.")); + List todoList= todoRepository.findByProject(project); + if(todoList.isEmpty()) return 0; return projectRepository.getProgress(projectId); } diff --git a/src/main/java/mvc/promiseme/todo/repository/TodoRepository.java b/src/main/java/mvc/promiseme/todo/repository/TodoRepository.java index 6337266..f23f18a 100644 --- a/src/main/java/mvc/promiseme/todo/repository/TodoRepository.java +++ b/src/main/java/mvc/promiseme/todo/repository/TodoRepository.java @@ -1,6 +1,7 @@ package mvc.promiseme.todo.repository; import mvc.promiseme.project.entity.Member; +import mvc.promiseme.project.entity.Project; import mvc.promiseme.todo.entity.Todo; import org.springframework.data.jpa.repository.JpaRepository; @@ -9,4 +10,6 @@ public interface TodoRepository extends JpaRepository { List findByMemberAndAndTodoDate(Member member, LocalDate todoDate); + + List findByProject(Project project); }