Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: application Response DTO 변경 #72

Merged
merged 4 commits into from
Feb 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ public record ApplicationRes(
Boolean is_decision,
String application,
String recruit_part,
List<String> category
List<String> category,
String recruit_role,
List<String> stackName

) {
public static ApplicationRes of(Apply apply,List<String> category){
return new ApplicationRes(apply.getIsDecision(),apply.getApplication(), apply.getRecruit_part(),category);
public static ApplicationRes of(Apply apply, List<String> category,List<String> stackName){
return new ApplicationRes(apply.getIsDecision(),apply.getApplication(), apply.getRecruit_part(), category, apply.getRecruit_role(), stackName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,21 @@
import com.gongjakso.server.domain.member.entity.Member;
import com.gongjakso.server.domain.post.entity.Category;
import com.gongjakso.server.domain.post.entity.Post;
import com.gongjakso.server.domain.post.entity.StackName;
import com.gongjakso.server.domain.post.enumerate.CategoryType;
import com.gongjakso.server.domain.post.enumerate.PostStatus;
import com.gongjakso.server.domain.post.repository.CategoryRepository;
import com.gongjakso.server.domain.post.repository.PostRepository;
import com.gongjakso.server.domain.post.repository.StackNameRepository;
import com.gongjakso.server.global.exception.ApplicationException;
import com.gongjakso.server.global.exception.ErrorCode;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.ArrayList;
Expand All @@ -34,6 +36,7 @@ public class ApplyService {
private final ApplyRepository applyRepository;
private final PostRepository postRepository;
private final CategoryRepository categoryRepository;
private final StackNameRepository stackNameRepository;
public void save(Member member, Long post_id, ApplyReq req){
Post post = postRepository.findByPostId(post_id);
if (post == null) {
Expand Down Expand Up @@ -191,14 +194,21 @@ public ApplicationRes findApplication(Long apply_id,Long post_id){
List<String> list = new ArrayList<>();
if(categoryList!=null) {
for (Category category : categoryList) {
for (int i = 0; i < category.getSize(); i++) {
list.add(String.valueOf(category.getCategoryType()));
}
}
}else {
throw new ApplicationException(ErrorCode.NOT_FOUND_CATEGORY_EXCEPTION);
}
ApplicationRes applicationRes = ApplicationRes.of(apply,list);
List<StackName> stackNameList = stackNameRepository.findStackNameByPost(post);
List<String> stackList = new ArrayList<>();
if(stackNameList!=null) {
for (StackName stackName : stackNameList) {
stackList.add(String.valueOf(stackName.getStackNameType()));
}
}else {
throw new ApplicationException(ErrorCode.NOT_FOUND_CATEGORY_EXCEPTION);
}
ApplicationRes applicationRes = ApplicationRes.of(apply,list, stackList);
return applicationRes;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
package com.gongjakso.server.domain.post.dto;

import com.gongjakso.server.domain.post.entity.Category;
import com.gongjakso.server.domain.post.entity.Post;
import com.gongjakso.server.domain.post.enumerate.PostStatus;
import lombok.Builder;
import lombok.Getter;

import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.List;

@Getter
public class GetContestRes {
private Long postId;
private String title;
private String name; //팀장명
private PostStatus status;
private LocalDateTime startDate;
private LocalDateTime endDate;
private long daysRemaining;
private List<Category> categories;
private long scrapCount;

@Builder
public GetContestRes(Long postId, String title, String name, PostStatus status, LocalDateTime startDate, LocalDateTime endDate,
LocalDateTime finishDate, List<Category> categories,long scrapCount){
this.postId = postId;
this.title = title;
this.name = name;
this.status = status;
this.startDate = startDate;
this.endDate = endDate;
this.daysRemaining = finishDate.isBefore(LocalDateTime.now()) ? -1 : ChronoUnit.DAYS.between(LocalDateTime.now(), finishDate);
this.categories = categories;
this.scrapCount = scrapCount;
@Builder
public record GetContestRes (
Long postId,
String title,
String name, //팀장명
PostStatus status,
LocalDateTime startDate,
LocalDateTime endDate,
LocalDateTime finishDate,
long daysRemaining,
List<Category> categories,
long scrapCount
){ public static GetContestRes of(Post post){
return GetContestRes.builder()
.postId(post.getPostId())
.title(post.getTitle())
.name(post.getMember().getName())
.status(post.getStatus())
.startDate(post.getStartDate())
.endDate(post.getEndDate())
.daysRemaining(post.getFinishDate().isBefore(LocalDateTime.now()) ? -1 : ChronoUnit.DAYS.between(LocalDateTime.now(), post.getFinishDate()))
.categories(post.getCategories())
.scrapCount(post.getScrapCount())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
package com.gongjakso.server.domain.post.dto;

import com.gongjakso.server.domain.post.entity.Category;
import com.gongjakso.server.domain.post.entity.Post;
import com.gongjakso.server.domain.post.enumerate.PostStatus;
import lombok.Builder;
import lombok.Getter;

import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.List;

@Getter
public class GetProjectRes {
private Long postId;
private String title;
private String name; //팀장명
private PostStatus status;
private LocalDateTime startDate;
private LocalDateTime endDate;
private long daysRemaining;
private List<Category> categories;
private long scrapCount;

@Builder
public GetProjectRes(Long postId, String title, String name, PostStatus status, LocalDateTime startDate,
LocalDateTime endDate, LocalDateTime finishDate, List<Category> categories,long scrapCount ){
this.postId = postId;
this.title = title;
this.name = name;
this.status = status;
this.startDate = startDate;
this.endDate = endDate;
this.daysRemaining = finishDate.isBefore(LocalDateTime.now()) ? -1 : ChronoUnit.DAYS.between(LocalDateTime.now(), finishDate);
this.categories = categories;
this.scrapCount = scrapCount;
}
@Builder
public record GetProjectRes (
Long postId,
String title,
String name, //팀장명
PostStatus status,
LocalDateTime startDate,
LocalDateTime endDate,
LocalDateTime finishDate,
long daysRemaining,
List<Category> categories,
long scrapCount
){ public static GetProjectRes of(Post post){
return GetProjectRes.builder()
.postId(post.getPostId())
.title(post.getTitle())
.name(post.getMember().getName())
.status(post.getStatus())
.startDate(post.getStartDate())
.endDate(post.getEndDate())
.daysRemaining(post.getFinishDate().isBefore(LocalDateTime.now()) ? -1 : ChronoUnit.DAYS.between(LocalDateTime.now(), post.getFinishDate()))
.categories(post.getCategories())
.scrapCount(post.getScrapCount())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
package com.gongjakso.server.domain.post.dto;

import com.gongjakso.server.domain.member.entity.Member;
import com.gongjakso.server.domain.post.entity.Post;
import lombok.Builder;
import lombok.Getter;

@Getter
public class PostDeleteRes {
private Long postId;
private Long memberId;

@Builder
public PostDeleteRes(Long postId, Long memberId){
this.postId = postId;
this.memberId = memberId;
@Builder
public record PostDeleteRes(
Long postId,
Long memberId
){
public static PostDeleteRes of(Post post, Member member){
return PostDeleteRes.builder()
.postId(post.getPostId())
.memberId(member.getMemberId())
.build();
}

}
79 changes: 32 additions & 47 deletions src/main/java/com/gongjakso/server/domain/post/dto/PostRes.java
Original file line number Diff line number Diff line change
@@ -1,61 +1,46 @@
package com.gongjakso.server.domain.post.dto;

import com.gongjakso.server.domain.post.entity.Category;
import com.gongjakso.server.domain.post.entity.Post;
import com.gongjakso.server.domain.post.entity.StackName;
import com.gongjakso.server.domain.post.enumerate.MeetingMethod;
import com.gongjakso.server.domain.post.enumerate.PostStatus;
import lombok.Builder;
import lombok.Getter;

import java.time.LocalDateTime;
import java.util.List;

@Getter
public class PostRes {
private Long postId;
private Long memberId;
private String title;
private String contents;
private String contestLink;
private PostStatus status;
private LocalDateTime startDate;
private LocalDateTime endDate;
private LocalDateTime finishDate;
private Long maxPerson;
private List<StackName> stackNames;
private List<Category> categories;
private MeetingMethod meetingMethod;
private String meetingArea;
private boolean questionMethod;
private String questionLink;
private boolean postType;
private LocalDateTime createdAt;
private LocalDateTime modifiedAt;
private LocalDateTime deletedAt;
@Builder
public record PostRes(Long postId, Long memberId, String title, String contents, String contestLink, PostStatus status, LocalDateTime startDate,
LocalDateTime endDate, LocalDateTime finishDate, Long maxPerson, List<StackName> stackNames,
List<Category> categories, MeetingMethod meetingMethod, String meetingArea,
boolean questionMethod, String questionLink, boolean postType, LocalDateTime createdAt, LocalDateTime modifiedAt, LocalDateTime deletedAt){
public static PostRes of(Post post){
return PostRes.builder()
.postId(post.getPostId())
.title(post.getTitle())
.contents(post.getContents())
.contestLink(post.getContestLink())
.status(post.getStatus())
.startDate(post.getStartDate())
.endDate(post.getEndDate())
.finishDate(post.getFinishDate())
.maxPerson(post.getMaxPerson())
.stackNames(post.getStackNames())
.categories(post.getCategories())
.meetingMethod(post.getMeetingMethod())
.meetingArea(post.getMeetingArea())
.questionMethod(post.isQuestionMethod())
.questionLink(post.getQuestionLink())
.postType(post.isPostType())
.createdAt(post.getCreatedAt())
.modifiedAt(post.getModifiedAt())
.deletedAt(post.getDeletedAt())
.build();

@Builder
public PostRes(Long postId, Long memberId, String title, String contents, String contestLink, PostStatus status, LocalDateTime startDate, LocalDateTime endDate,
LocalDateTime finishDate, Long maxPerson, List<StackName> stackNames, List<Category> categories, MeetingMethod meetingMethod, String meetingArea, boolean questionMethod, String questionLink,
boolean postType, LocalDateTime createdAt, LocalDateTime modifiedAt, LocalDateTime deletedAt) {
this.postId = postId;
this.memberId = memberId;
this.title = title;
this.contents = contents;
this.contestLink = contestLink;
this.status = status;
this.startDate = startDate;
this.endDate = endDate;
this.finishDate = finishDate;
this.maxPerson = maxPerson;
this.stackNames = stackNames;
this.categories = categories;
this.meetingArea = meetingArea;
this.meetingMethod = meetingMethod;
this.questionMethod = questionMethod;
this.questionLink = questionLink;
this.postType = postType;
this.createdAt = createdAt;
this.modifiedAt = modifiedAt;
this.deletedAt = deletedAt;
}

public boolean isPostType() {
return postType;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ public class Post extends BaseTimeEntity {
@Column(name="scrap_count", nullable = false, columnDefinition = "bigint")
private long scrapCount;

public long getDaysRemaining(){
return finishDate.isBefore(LocalDateTime.now()) ? -1 : ChronoUnit.DAYS.between(LocalDateTime.now(), finishDate);
}

@Builder
public Post(String title, Member member, String contents, String contestLink, LocalDateTime startDate,
LocalDateTime endDate, LocalDateTime finishDate, Long maxPerson, MeetingMethod meetingMethod,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.gongjakso.server.domain.post.repository;

import com.gongjakso.server.domain.post.entity.Post;
import com.gongjakso.server.domain.post.entity.StackName;
import com.gongjakso.server.domain.post.enumerate.StackNameType;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

public interface StackNameRepository extends JpaRepository<StackName, Long> {
List<StackName> findStackNameByPost(Post post);
StackName findStackNameByPostAndStackNameType(Post post, StackNameType stackNameType);
}
Loading
Loading