Skip to content

Commit

Permalink
Merge pull request #110 from TeamSynergyy/feature/queryDsl
Browse files Browse the repository at this point in the history
#87 프로젝트 도메인 대체키 반영
  • Loading branch information
rivkode authored Jun 11, 2024
2 parents 9bf52be + 47fab5c commit 1398d97
Show file tree
Hide file tree
Showing 42 changed files with 258 additions and 122 deletions.
8 changes: 8 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ dependencies {
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'

// MapStruct
implementation 'org.mapstruct:mapstruct:1.5.2.Final'
annotationProcessor "org.mapstruct:mapstruct-processor:1.5.2.Final"
annotationProcessor(
'org.projectlombok:lombok',
'org.projectlombok:lombok-mapstruct-binding:0.2.0'
)

// jwt
runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.2'
runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.11.2'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.seoultech.synergybe.domain.apply;

import com.seoultech.synergybe.domain.common.entity.IsDeleted;
import com.seoultech.synergybe.domain.project.Project;
import com.seoultech.synergybe.domain.project.domain.Project;
import com.seoultech.synergybe.domain.user.User;
import jakarta.persistence.*;
import lombok.AccessLevel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import com.seoultech.synergybe.domain.common.generator.IdPrefix;
import com.seoultech.synergybe.domain.common.generator.TokenGenerator;
import com.seoultech.synergybe.domain.notification.service.NotificationService;
import com.seoultech.synergybe.domain.project.Project;
import com.seoultech.synergybe.domain.project.service.ProjectService;
import com.seoultech.synergybe.domain.project.domain.Project;
import com.seoultech.synergybe.domain.project.domain.service.ProjectService;
import com.seoultech.synergybe.domain.projectuser.ProjectUser;
import com.seoultech.synergybe.domain.projectuser.repository.ProjectUserRepository;
import com.seoultech.synergybe.domain.user.User;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.seoultech.synergybe.domain.common.entity.IsDeleted;
import com.seoultech.synergybe.domain.notice.vo.NoticeContent;
import com.seoultech.synergybe.domain.notice.vo.NoticeTitle;
import com.seoultech.synergybe.domain.project.Project;
import com.seoultech.synergybe.domain.project.domain.Project;
import com.seoultech.synergybe.domain.common.BaseTime;
import lombok.AccessLevel;
import lombok.Builder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import com.seoultech.synergybe.domain.notice.repository.NoticeRepository;
import com.seoultech.synergybe.domain.notification.NotificationType;
import com.seoultech.synergybe.domain.notification.service.NotificationService;
import com.seoultech.synergybe.domain.project.Project;
import com.seoultech.synergybe.domain.project.service.ProjectService;
import com.seoultech.synergybe.domain.project.domain.Project;
import com.seoultech.synergybe.domain.project.domain.service.ProjectService;
import com.seoultech.synergybe.domain.user.User;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//package com.seoultech.synergybe.domain.project.application;
//
//import com.seoultech.synergybe.domain.project.domain.ProjectCommand;
//import com.seoultech.synergybe.domain.project.domain.service.ProjectServiceV2;
//import lombok.RequiredArgsConstructor;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.stereotype.Service;
//
//@Slf4j
//@Service
//@RequiredArgsConstructor
//public class ProjectFacade {
// private final ProjectServiceV2 projectServiceV2;
// public String registerProject(ProjectCommand.RegisterProjectRequest request) {
// var projectToken = projectServiceV2.registerProject(request);
//
// }
//}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.seoultech.synergybe.domain.project;
package com.seoultech.synergybe.domain.project.domain;

import com.seoultech.synergybe.domain.apply.Apply;
import com.seoultech.synergybe.domain.common.entity.IsDeleted;
import com.seoultech.synergybe.domain.notice.Notice;
import com.seoultech.synergybe.domain.project.dto.request.UpdateProjectRequest;
import com.seoultech.synergybe.domain.project.vo.*;
import com.seoultech.synergybe.domain.project.domain.vo.*;
import com.seoultech.synergybe.domain.project.interfaces.dto.request.UpdateProjectRequest;
import com.seoultech.synergybe.domain.projectlike.ProjectLike;
import com.seoultech.synergybe.domain.projectuser.ProjectUser;
import com.seoultech.synergybe.domain.schedule.Schedule;
Expand Down Expand Up @@ -87,7 +87,7 @@ public class Project extends BaseTime {

@Builder
public Project(Long id, String projectToken, String name, String content, ProjectField field, Point location, LocalDateTime startAt,
LocalDateTime endAt, String leaderId) {
LocalDateTime endAt, Long leaderId) {
this.id = id;
this.projectToken = projectToken;
this.name = new ProjectName(name);
Expand All @@ -104,7 +104,7 @@ public Project updateProject(UpdateProjectRequest request) {
return this;
}

public void updateProjectLeaderId(String leaderId) {
public void updateProjectLeaderId(Long leaderId) {
this.leaderId = new ProjectLeaderId(leaderId);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.seoultech.synergybe.domain.project.domain;

import com.fasterxml.jackson.annotation.JsonFormat;
import jakarta.validation.constraints.NotBlank;

import java.time.LocalDateTime;

public class ProjectCommand {
public record RegisterProjectRequest(
@NotBlank(message = "이름은 필수항목입니다.")
String name,
@NotBlank(message = "내용은 필수항목입니다.")
String content,
@NotBlank(message = "분야는 필수항목입니다.")
ProjectField field,
@NotBlank(message = "경도은 필수항목입니다.")
Double longitude,
@NotBlank(message = "위도는 필수항목입니다.")
Double latitude,
@NotBlank(message = "시작일시는 필수항목입니다.")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm", timezone = "Asia/Seoul")
LocalDateTime startAt,
@NotBlank(message = "종료일시는 필수항목입니다.")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm", timezone = "Asia/Seoul")
LocalDateTime endAt

) {
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.seoultech.synergybe.domain.project;
package com.seoultech.synergybe.domain.project.domain;

public enum ProjectField {
앱개발, 웹개발, 머신러닝, 플랫폼, 라이프스타일, 금융, 소셜, 미디어, 교육, 생산성, 블록체인, 노코드, 인공지능, 커뮤니티, 분석, 디자인, 개발, 마케팅, 게임, 이커머스, 헬스케어, 바이오, 메타버스, 세일즈, 보안, ESG, 임베디드, 영어, 컴퓨터과학, 공학, 생명과학, 사회과학, 경영, 의학, 인문학, 법학, 교육학, 커뮤니케이션, 환경과학, 농학, 체육, 음악
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.seoultech.synergybe.domain.project.domain;

public interface ProjectReader {
void getProject();
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.seoultech.synergybe.domain.project;
package com.seoultech.synergybe.domain.project.domain;

import com.seoultech.synergybe.domain.common.EnumType;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.seoultech.synergybe.domain.project.service;
package com.seoultech.synergybe.domain.project.domain.service;

import com.seoultech.synergybe.domain.common.PageInfo;
import com.seoultech.synergybe.domain.project.Project;
import com.seoultech.synergybe.domain.project.dto.response.GetListProjectResponse;
import com.seoultech.synergybe.domain.project.dto.response.GetProjectResponse;
import com.seoultech.synergybe.domain.project.domain.Project;
import com.seoultech.synergybe.domain.project.interfaces.dto.response.GetListProjectResponse;
import com.seoultech.synergybe.domain.project.interfaces.dto.response.GetProjectResponse;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
package com.seoultech.synergybe.domain.project.service;
package com.seoultech.synergybe.domain.project.domain.service;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.seoultech.synergybe.domain.common.generator.IdGenerator;
import com.seoultech.synergybe.domain.common.generator.IdPrefix;
import com.seoultech.synergybe.domain.common.generator.TokenGenerator;
import com.seoultech.synergybe.domain.common.paging.ListResponse;
import com.seoultech.synergybe.domain.project.Project;
import com.seoultech.synergybe.domain.project.dto.request.CreateProjectRequest;
import com.seoultech.synergybe.domain.project.dto.request.UpdateProjectRequest;
import com.seoultech.synergybe.domain.project.dto.response.GetListProjectResponse;
import com.seoultech.synergybe.domain.project.dto.response.GetProjectResponse;
import com.seoultech.synergybe.domain.project.domain.Project;
import com.seoultech.synergybe.domain.project.interfaces.dto.request.CreateProjectRequest;
import com.seoultech.synergybe.domain.project.interfaces.dto.request.UpdateProjectRequest;
import com.seoultech.synergybe.domain.project.interfaces.dto.response.GetListProjectResponse;
import com.seoultech.synergybe.domain.project.interfaces.dto.response.GetProjectResponse;
import com.seoultech.synergybe.domain.project.exception.ProjectBadRequestException;
import com.seoultech.synergybe.domain.project.exception.ProjectNotFoundException;
import com.seoultech.synergybe.domain.project.repository.ProjectRepository;
import com.seoultech.synergybe.domain.project.infrastructure.ProjectRepository;
import com.seoultech.synergybe.domain.projectlike.service.ProjectLikeService;
import com.seoultech.synergybe.domain.projectuser.service.ProjectUserService;
import com.seoultech.synergybe.domain.user.User;
Expand Down Expand Up @@ -42,20 +43,21 @@
@RequiredArgsConstructor
public class ProjectService {
private final ProjectRepository projectRepository;

private final ProjectUserService projectUserService;

private final ProjectLikeService projectLikeService;
private final IdGenerator idGenerator;
private final TokenGenerator tokenGenerator;
private final UserService userService;

@Transactional
public GetProjectResponse createProject(String userId, CreateProjectRequest request) {
User user = userService.getUser(userId);
String projectId = idGenerator.generateId(IdPrefix.PROJECT);
Long projectId = idGenerator.generateId();
String projectToken = tokenGenerator.generateToken(IdPrefix.POST);
Point point = new Point(request.longitude(), request.latitude());
Project project = Project.builder()
.id(projectId)
.projectToken(projectToken)
.name(request.name())
.content(request.content())
.field(request.field())
Expand All @@ -67,15 +69,15 @@ public GetProjectResponse createProject(String userId, CreateProjectRequest requ
Project savedProject = projectRepository.save(project);
projectUserService.createProjectUser(savedProject, user);
return GetProjectResponse.builder()
.projectId(savedProject.getId())
.projectToken(savedProject.getProjectToken())
.build();
}

private void validateProjectUser(String userId, String projectId) {
private void validateProjectUser(String userToken, String projectId) {
Project project = findProjectById(projectId);
List<String> userListIds = project.getProjectUsers().stream().map(projectUser -> projectUser.getUser().getId()).toList();
List<String> userListTokens = project.getProjectUsers().stream().map(projectUser -> projectUser.getUser().getUserToken()).toList();

if (!userListIds.contains(userId)) {
if (!userListTokens.contains(userToken)) {
throw new ProjectBadRequestException("프로젝트 변경 권한이 없습니다.");
}
}
Expand All @@ -89,10 +91,10 @@ private void validateProjectLeader(String leaderId, String projectId) {
}

@Transactional
public void updateProject(String userId, UpdateProjectRequest request) {
public void updateProject(String userToken, UpdateProjectRequest request) {
// todo
// 프로젝트 멤버 검증
validateProjectUser(userId, request.projectId());
validateProjectUser(userToken, request.projectId());

Project project = this.findProjectById(request.projectId());
Project updatedProject = project.updateProject(request);
Expand All @@ -114,20 +116,20 @@ public Project findProjectById(String projectId) {
return projectRepository.findById(projectId)
.orElseThrow(() -> new ProjectNotFoundException("존재하지 않는 프로젝트입니다."));
}
public GetProjectResponse getProject(String projectId) {
Project project = this.findProjectById(projectId);
public GetProjectResponse getProject(String projectToken) {
Project project = this.findProjectById(projectToken);

return GetProjectResponse.builder()
.projectId(projectId)
.projectToken(projectToken)
.name(project.getName().getName())
.content(project.getContent().getContent())
.field(project.getField().name())
.location(project.getLocation().getLocation())
.startAt(project.getPeriod().getStartAt())
.endAt(project.getPeriod().getEndAt())
.leaderId(project.getLeaderId().getLeaderId())
.leaderId(String.valueOf(project.getLeaderId().getLeaderId()))
.status(project.getStatus().getName())
.teamUserIds(project.getProjectUsers().stream().map(projectUser -> projectUser.getUser().getId()).collect(Collectors.toList()))
.teamUserIds(project.getProjectUsers().stream().map(projectUser -> projectUser.getUser().getUserToken()).collect(Collectors.toList()))
.build();
}

Expand Down Expand Up @@ -207,13 +209,13 @@ public ListResponse<GetProjectResponse> getRecommendListByUser(User user, Long e

try {
log.info("get recommend project list start");
String userId = user.getId();
log.info("user Id {}", userId);
String userToken = user.getUserToken();
log.info("user Id {}", userToken);

RestTemplate restTemplate = new RestTemplate();
log.info("rest template new");
String fastApiUrl = "http://fastapi:8000"; // 컨테이너 이름과 포트
String response = restTemplate.getForObject(fastApiUrl + "/recommend/projects/" + userId, String.class);
String response = restTemplate.getForObject(fastApiUrl + "/recommend/projects/" + userToken, String.class);

log.info("Response from FastAPI: {}", response);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.seoultech.synergybe.domain.project.domain.service;

import org.springframework.stereotype.Service;

@Service
public interface ProjectServiceV2 {
void createProject();

void validateProjectUser();

void validateProjectLeader();

void updateProject();

void deleteProject();

void search();
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.seoultech.synergybe.domain.project.vo;
package com.seoultech.synergybe.domain.project.domain.vo;

import com.seoultech.synergybe.domain.project.exception.ProjectBadRequestException;
import jakarta.persistence.Column;
import jakarta.persistence.Embeddable;
import jakarta.persistence.Embedded;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.seoultech.synergybe.domain.project.vo;
package com.seoultech.synergybe.domain.project.domain.vo;

import com.seoultech.synergybe.domain.project.exception.ProjectBadRequestException;
import jakarta.persistence.Column;
Expand All @@ -14,15 +14,15 @@
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class ProjectLeaderId {
@Column(name = "leader_id")
private String leaderId;
private Long leaderId;

public ProjectLeaderId(String value) {
public ProjectLeaderId(Long value) {
validateNotNull(value);
this.leaderId = value;
}

private void validateNotNull(String leaderId) {
if (Objects.isNull(leaderId) || leaderId.isBlank()) {
private void validateNotNull(Long leaderId) {
if (Objects.isNull(leaderId)) {
throw new ProjectBadRequestException("리더 ID는 필수 항목입니다.");
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.seoultech.synergybe.domain.project.vo;
package com.seoultech.synergybe.domain.project.domain.vo;

import com.seoultech.synergybe.domain.project.exception.ProjectBadRequestException;
import jakarta.persistence.Column;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.seoultech.synergybe.domain.project.vo;
package com.seoultech.synergybe.domain.project.domain.vo;

import com.seoultech.synergybe.domain.project.exception.ProjectBadRequestException;
import jakarta.persistence.Column;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.seoultech.synergybe.domain.project.vo;
package com.seoultech.synergybe.domain.project.domain.vo;

import com.seoultech.synergybe.domain.project.exception.ProjectBadRequestException;
import jakarta.persistence.Column;
Expand All @@ -21,13 +21,13 @@ public class ProjectPeriod {
@Column(name = "end_at")
private LocalDateTime endAt;

public ProjectPeriod(LocalDateTime startAt, LocalDateTime endAt, String leaderId) {
public ProjectPeriod(LocalDateTime startAt, LocalDateTime endAt, Long leaderId) {
validateNotNull(startAt, endAt, leaderId);
this.startAt = startAt;
this.endAt = endAt;
}

private void validateNotNull(LocalDateTime startAt, LocalDateTime endAt, String leaderId) {
private void validateNotNull(LocalDateTime startAt, LocalDateTime endAt, Long leaderId) {
if (startAt == null || endAt == null || leaderId == null) {
throw new ProjectBadRequestException("시작일자 종료일자 리더는 필수 항목 입니다.");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.seoultech.synergybe.domain.project.repository;
package com.seoultech.synergybe.domain.project.infrastructure;

import com.seoultech.synergybe.domain.project.Project;
import com.seoultech.synergybe.domain.project.domain.Project;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
Expand Down
Loading

0 comments on commit 1398d97

Please sign in to comment.