Skip to content

Commit

Permalink
Merge pull request #47 from potenday-project/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
oU-Ua authored Dec 16, 2023
2 parents 78fb860 + a9e42d3 commit df9f995
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
13 changes: 13 additions & 0 deletions src/main/java/mvc/promiseme/project/dto/MemberRequestDTO.java
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ public class ProjectRequestDTO {
private LocalDate start;
@JsonFormat(pattern = "yyyy-MM-dd")
private LocalDate deadline;
private List<MemberDTO> memberList;
private List<MemberRequestDTO> memberList;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -15,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;
Expand All @@ -30,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<ProjectResponseDTO> projectAll(Long userId) {
Expand All @@ -54,17 +57,17 @@ public Long insert(ProjectRequestDTO projectRequestDTO) {
Project project = p.mapToEntity(projectRequestDTO);
projectRepository.save(project);
System.out.println("projectId : " + project.getProjectId());
List<MemberDTO> memberList = projectRequestDTO.getMemberList();
List<MemberRequestDTO> memberList = projectRequestDTO.getMemberList();

for(MemberDTO m : memberList){
for(MemberRequestDTO m : memberList){
Role r = new Role();
Role role = roleRepository.findByName(m.getRole());
if(role==null) {
role = Role.builder().name(m.getRole()).build();
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);
}
Expand All @@ -77,6 +80,9 @@ public Long insert(ProjectRequestDTO projectRequestDTO) {

@Override
public int progress(Long projectId) {
Project project= projectRepository.findById(projectId).orElseThrow(()->new NoSuchElementException("프로젝트를 찾을 수 없습니다."));
List<Todo> todoList= todoRepository.findByProject(project);
if(todoList.isEmpty()) return 0;
return projectRepository.getProgress(projectId);

}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -9,4 +10,6 @@

public interface TodoRepository extends JpaRepository<Todo,Long> {
List<Todo> findByMemberAndAndTodoDate(Member member, LocalDate todoDate);

List<Todo> findByProject(Project project);
}

0 comments on commit df9f995

Please sign in to comment.