Skip to content

Commit

Permalink
Merge pull request #31 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 6544475 + 2055275 commit 4cc7de5
Show file tree
Hide file tree
Showing 15 changed files with 378 additions and 51 deletions.
6 changes: 2 additions & 4 deletions src/main/java/mvc/promiseme/calendar/entity/Calendar.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package mvc.promiseme.calendar.entity;

import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.*;

import mvc.promiseme.project.entity.Member;
import mvc.promiseme.project.entity.Project;
Expand All @@ -20,6 +17,7 @@
@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
@Builder
public class Calendar {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import mvc.promiseme.project.dto.ProjectRequestDTO;
import mvc.promiseme.project.dto.ProjectResponseDTO;
import mvc.promiseme.project.dto.RecommendMemberRequestDTO;
import mvc.promiseme.project.dto.RecommendScheduleRequestDTO;
import mvc.promiseme.project.service.ProjectService;
import mvc.promiseme.project.service.RecommendService;
import org.springframework.http.ResponseEntity;
Expand Down Expand Up @@ -36,15 +37,18 @@ public ResponseEntity<List<String>> categoryRanking(){
}

@PostMapping("/create")
public ResponseEntity<String> insert(@RequestBody ProjectRequestDTO projectRequestDTO){
public ResponseEntity<Map<String, Long>> insert(@RequestBody ProjectRequestDTO projectRequestDTO){
Map<String, Long> result = new HashMap<>();

return ResponseEntity.ok(projectService.insert(projectRequestDTO));

result.put("projectId",projectService.insert(projectRequestDTO));
return ResponseEntity.ok(result);
}

@GetMapping("/progress")
public ResponseEntity<Map<String, Integer>> progress(@RequestParam("projectId")Long projectId){
Map<String,Integer> progressResult = new HashMap<>();
progressResult.put("Prgress", projectService.progress(projectId));
progressResult.put("progress", projectService.progress(projectId));
return ResponseEntity.ok(progressResult);
}

Expand All @@ -59,6 +63,9 @@ public ResponseEntity <Map<String,Integer>> dday(@RequestParam("projectId") Long
public ResponseEntity<Map<String,String>> recommendMember(@RequestBody RecommendMemberRequestDTO recommendMemberRequestDTO){
return ResponseEntity.ok(recommendService.recommendMember(recommendMemberRequestDTO));
}

@PostMapping("/recommend/schedule")
public ResponseEntity<List<Map<String, String>>> recommendSchedule(@RequestBody RecommendScheduleRequestDTO recommendScheduleRequestDTO){
return ResponseEntity.ok(recommendService.recommendSchedule(recommendScheduleRequestDTO));
}

}
13 changes: 13 additions & 0 deletions src/main/java/mvc/promiseme/project/dto/MemberDTO.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 MemberDTO {
private Long userId;
private String role;
}
14 changes: 14 additions & 0 deletions src/main/java/mvc/promiseme/project/dto/Message.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package mvc.promiseme.project.dto;

import lombok.*;

@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
@Builder
public class Message {
private String role;
private String content;

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package mvc.promiseme.project.dto;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.*;

import java.time.LocalDate;
import java.util.List;

@NoArgsConstructor
@AllArgsConstructor
Expand All @@ -12,7 +14,9 @@
public class ProjectRequestDTO {
private String name;
private String category;
private String topic;
@JsonFormat(pattern = "yyyy-MM-dd")
private LocalDate start;
@JsonFormat(pattern = "yyyy-MM-dd")
private LocalDate deadline;
private List<MemberDTO> memberList;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package mvc.promiseme.project.dto;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.*;

import java.time.LocalDate;
Expand All @@ -11,6 +12,10 @@
@Builder
public class RecommendMemberRequestDTO {
private String category;

@JsonFormat(pattern = "yyyy-MM-dd")
private LocalDate start;

@JsonFormat(pattern = "yyyy-MM-dd")
private LocalDate deadline;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
@Setter
@Builder
public class RecommendScheduleRequestDTO {
private Long projectId;
private String category;
private String topic;
private String member;
private LocalDate start;
private LocalDate deadline;
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/mvc/promiseme/project/entity/Project.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import lombok.NoArgsConstructor;
import mvc.promiseme.calendar.entity.Calendar;
import mvc.promiseme.meeting.entity.Meeting;
import mvc.promiseme.project.dto.ProjectRequestDTO;
import mvc.promiseme.todo.entity.Todo;

import mvc.promiseme.notice.entity.Notice;
Expand Down Expand Up @@ -66,4 +67,13 @@ public void prePersist() {

@OneToMany(mappedBy = "project")
private List<Todo> todoList = new ArrayList<>();

public Project mapToEntity(ProjectRequestDTO projectRequestDTO){
return Project.builder().name(projectRequestDTO.getName())
.createdAt(LocalDate.now())
.category(projectRequestDTO.getCategory())
.start(projectRequestDTO.getStart()).
deadline(projectRequestDTO.getDeadline())
.isProgress(Progress.PROGRESSING).build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package mvc.promiseme.project.repository;

import mvc.promiseme.project.entity.Role;
import org.springframework.data.jpa.repository.JpaRepository;

public interface RoleRepository extends JpaRepository<Role, Long> {
Role findByName(String name);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ public class ClovaStudioRecommend {

@Value("${RECOMMEND_URL}")
private String url;
@Value("${API_KEY_CLOVA_STUDIO}")
@Value("${RECOMMEND_API_KEY}")
private String apiKeyClovaStudio;
@Value("${API_KEY}")
private String apiKey;
@Value("${REQUEST_ID}")
private String requestId;
@Value("${RECOMMEND_API_GATE_WAY_KEY}")
private String apiGateWayKey;
@Value("${RECOMMEND_MEMBER_REQUEST_ID}")
private String requestMemberId;
@Value("${RECOMMEND_SCHEDULE_REQUEST_ID}")
private String requestScheduleId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public interface ProjectService {
public List<ProjectResponseDTO> projectAll(Long userId);
public List<String> categoryRanking();

public String insert (ProjectRequestDTO projectRequestDTO);
public Long insert (ProjectRequestDTO projectRequestDTO);
public int progress(Long projectId);
public int dday (Long projectId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,24 @@
import lombok.RequiredArgsConstructor;
import mvc.promiseme.common.exception.ErrorCode;
import mvc.promiseme.common.exception.UserException;
import mvc.promiseme.project.dto.MemberDTO;
import mvc.promiseme.project.dto.ProjectRequestDTO;
import mvc.promiseme.project.dto.ProjectResponseDTO;
import mvc.promiseme.project.entity.Member;
import mvc.promiseme.project.entity.MemberStatus;
import mvc.promiseme.project.entity.Project;
import mvc.promiseme.project.entity.Role;
import mvc.promiseme.project.repository.MemberRepository;
import mvc.promiseme.project.repository.ProjectRepository;
import mvc.promiseme.project.repository.RoleRepository;
import mvc.promiseme.todo.dto.TodoRequestDTO;
import mvc.promiseme.todo.entity.Todo;
import mvc.promiseme.users.entity.Users;
import mvc.promiseme.users.repository.UserRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;

@Service
@RequiredArgsConstructor
Expand All @@ -27,6 +29,7 @@ public class ProjectServiceImpl implements ProjectService {
private final ProjectRepository projectRepository;
private final UserRepository userRepository;
private final MemberRepository memberRepository;
private final RoleRepository roleRepository;
@Override
@Transactional
public List<ProjectResponseDTO> projectAll(Long userId) {
Expand All @@ -43,10 +46,33 @@ public List<ProjectResponseDTO> projectAll(Long userId) {
public List<String> categoryRanking() {
return projectRepository.getCategoryRanking();
}

@Transactional
@Override
public String insert(ProjectRequestDTO projectRequestDTO) {
return null;
public Long insert(ProjectRequestDTO projectRequestDTO) {
try{
Project p = new Project();
Project project = p.mapToEntity(projectRequestDTO);
projectRepository.save(project);
System.out.println("projectId : " + project.getProjectId());
List<MemberDTO> memberList = projectRequestDTO.getMemberList();

for(MemberDTO 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] 해당하는 사용자가 존재하지 않습니다."));
Member member = Member.builder().project(project).role(role).users(user).status(MemberStatus.PARTICIPATION).build();
memberRepository.save(member);
}
return project.getProjectId();

}catch (Exception e){
throw new UserException(ErrorCode.DUPLICATE_USER);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

import lombok.RequiredArgsConstructor;
import mvc.promiseme.project.dto.RecommendMemberRequestDTO;
import mvc.promiseme.project.dto.RecommendScheduleRequestDTO;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;



public interface RecommendService {
public Map<String, String> recommendMember(RecommendMemberRequestDTO recommendMemberRequestDTO);
}
public List<Map<String, String>> recommendSchedule(RecommendScheduleRequestDTO recommendScheduleRequestDTO);

}
Loading

0 comments on commit 4cc7de5

Please sign in to comment.