Skip to content

Commit

Permalink
Merge pull request #244 from KJBig/feature/S2D-25
Browse files Browse the repository at this point in the history
feat : Question 관련 of, toEntity 메소드 추가
  • Loading branch information
KJBig authored Aug 20, 2023
2 parents 0d250e3 + 8f9a525 commit 7b316dc
Show file tree
Hide file tree
Showing 25 changed files with 455 additions and 432 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.sluv.server.domain.celeb.dto;

import com.sluv.server.domain.celeb.entity.Celeb;
import com.sluv.server.domain.celeb.entity.NewCeleb;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
Expand All @@ -27,4 +28,11 @@ public static CelebChipResDto of(Celeb celeb){
.build();
}

public static CelebChipResDto of(NewCeleb celeb){
return CelebChipResDto.builder()
.celebId(celeb.getId())
.celebName(celeb.getCelebName())
.build();
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.sluv.server.domain.celeb.entity;

import com.sluv.server.domain.celeb.exception.CelebNotFoundException;
import com.sluv.server.domain.user.entity.User;
import com.sluv.server.global.common.entity.BaseEntity;
import jakarta.persistence.*;
Expand Down Expand Up @@ -31,4 +32,11 @@ public class InterestedCeleb extends BaseEntity {
@NotNull
private Celeb celeb;

public static InterestedCeleb toEntity(User user, Celeb celeb){
return InterestedCeleb.builder()
.user(user)
.celeb(celeb)
.build();
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.sluv.server.domain.question.dto;

import com.sluv.server.domain.celeb.dto.CelebChipResDto;
import com.sluv.server.domain.question.entity.Question;
import com.sluv.server.domain.user.dto.UserInfoDto;
import com.sluv.server.domain.user.entity.User;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
Expand Down Expand Up @@ -59,6 +61,35 @@ public class QuestionGetDetailResDto {
// Question Recommend
@Schema(description = "QuestionRecommend Category 리스트")
private List<String> recommendCategoryList;
public static QuestionGetDetailResDto of(Question question, String qType, User user,
List<QuestionImgResDto> imgList, List<QuestionItemResDto> itemList,
Long likeNum, Long commentNum, Boolean hasLike, Boolean hasMine,
CelebChipResDto celeb, CelebChipResDto newCeleb,
LocalDateTime voteEndTime, Long totalVoteNum, Long voteStatus,
List<String> recommendCategoryList){

UserInfoDto writer = UserInfoDto.of(user);

return QuestionGetDetailResDto.builder()
.qType(qType)
.user(writer)
.title(question.getTitle())
.content(question.getContent())
.imgList(imgList)
.itemList(itemList)
.searchNum(question.getSearchNum())
.likeNum(likeNum)
.commentNum(commentNum)
.createdAt(question.getCreatedAt())
.hasLike(hasLike)
.hasMine(hasMine)
.voteEndTime(voteEndTime)
.totalVoteNum(totalVoteNum)
.voteStatus(voteStatus)
.celeb(celeb)
.newCeleb(newCeleb)
.recommendCategoryList(recommendCategoryList)
.build();
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.sluv.server.domain.question.dto;

import com.sluv.server.domain.question.entity.QuestionImg;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
Expand All @@ -23,4 +24,23 @@ public class QuestionImgResDto {
private Boolean representFlag;
@Schema(description = "순서")
private Integer sortOrder;

public static QuestionImgResDto of(QuestionImg questionImg, QuestionVoteDataDto voteDataDto){
return QuestionImgResDto.builder()
.imgUrl(questionImg.getImgUrl())
.description(questionImg.getDescription())
.voteNum(
voteDataDto != null
? voteDataDto.getVoteNum()
: null
)
.votePercent(
voteDataDto != null
? voteDataDto.getVotePercent()
: null
)
.representFlag(questionImg.getRepresentFlag())
.sortOrder(questionImg.getSortOrder())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.sluv.server.domain.question.dto;

import com.sluv.server.domain.item.entity.ItemImg;
import com.sluv.server.domain.question.entity.QuestionImg;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
Expand All @@ -15,4 +17,18 @@ public class QuestionImgSimpleResDto {
private String imgUrl;
@Schema(description = "이미지 순서")
private Long sortOrder;

public static QuestionImgSimpleResDto of(QuestionImg questionImg){
return QuestionImgSimpleResDto.builder()
.imgUrl(questionImg.getImgUrl())
.sortOrder( (long) questionImg.getSortOrder())
.build();
}

public static QuestionImgSimpleResDto of(ItemImg itemImg){
return QuestionImgSimpleResDto.builder()
.imgUrl(itemImg.getItemImgUrl())
.sortOrder( (long) itemImg.getSortOrder())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.sluv.server.domain.question.dto;

import com.sluv.server.domain.item.dto.ItemSimpleResDto;
import com.sluv.server.domain.question.entity.QuestionItem;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
Expand All @@ -24,4 +25,23 @@ public class QuestionItemResDto {
private Boolean representFlag;
@Schema(description = "순서")
private Integer sortOrder;

public static QuestionItemResDto of(QuestionItem questionItem, ItemSimpleResDto itemSimpleResDto, QuestionVoteDataDto voteDataDto){
return QuestionItemResDto.builder()
.item(itemSimpleResDto)
.description(questionItem.getDescription())
.voteNum(
voteDataDto != null
? voteDataDto.getVoteNum()
: null
)
.votePercent(
voteDataDto != null
? voteDataDto.getVotePercent()
: null
)
.representFlag(questionItem.getRepresentFlag())
.sortOrder(questionItem.getSortOrder())
.build();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,10 @@
public class QuestionPostResDto {
@Schema(description = "생성된 Question의 Id")
private Long id;

public static QuestionPostResDto of(Long questionId){
return QuestionPostResDto.builder()
.id(questionId)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.sluv.server.domain.question.dto;

import com.sluv.server.domain.question.entity.Question;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
Expand Down Expand Up @@ -35,4 +36,20 @@ public class QuestionSimpleResDto {
//추천해 줘
@Schema(description = "QuestionRecommend 게시글 카테고리 리스트")
private List<String> categoryName;
public static QuestionSimpleResDto of(String qType, Question question,
String celebName,
List<QuestionImgSimpleResDto> imgList, List<QuestionImgSimpleResDto> itemImgList,
List<String> categoryName){

return QuestionSimpleResDto.builder()
.qType(qType)
.id(question.getId())
.title(question.getTitle())
.content(question.getContent())
.celebName(celebName)
.imgList(imgList)
.itemImgList(itemImgList)
.categoryName(categoryName)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.sluv.server.domain.question.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;

@Data
@AllArgsConstructor
@Builder
public class QuestionVoteDataDto {
@Schema(description = "투표 수")
private Long voteNum;
@Schema(description = "투표 퍼센트")
private Double votePercent;

public static QuestionVoteDataDto of(Long voteNum, Double votePercent) {
return QuestionVoteDataDto.builder()
.voteNum(voteNum)
.votePercent(votePercent)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ public class Question{
private String content;

@NotNull
private Long searchNum;
private Long searchNum = 0L;

@Enumerated(EnumType.STRING)
@Column(columnDefinition = "varchar(45) default 'ACTIVE'")
private QuestionStatus questionStatus;
private QuestionStatus questionStatus = QuestionStatus.ACTIVE;

@CreatedDate
@Column(updatable = false)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package com.sluv.server.domain.question.entity;

import com.sluv.server.domain.celeb.entity.Celeb;
import com.sluv.server.domain.celeb.entity.NewCeleb;
import com.sluv.server.domain.question.dto.QuestionBuyPostReqDto;
import com.sluv.server.domain.question.dto.QuestionFindPostReqDto;
import com.sluv.server.domain.question.enums.QuestionStatus;
import com.sluv.server.domain.user.entity.User;
import jakarta.persistence.DiscriminatorValue;
Expand All @@ -25,4 +29,19 @@ public QuestionBuy(Long id, User user, String title, String content, Long search
super(id, user, title, content, searchNum, questionStatus);
this.voteEndTime = voteEndTime;
}

public static QuestionBuy toEntity(User user, QuestionBuyPostReqDto postReqDto){
QuestionBuyBuilder builder = QuestionBuy.builder();

if(postReqDto.getId() != null) {
builder
.id(postReqDto.getId());
}

return builder
.user(user)
.title(postReqDto.getTitle())
.voteEndTime(postReqDto.getVoteEndTime())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.sluv.server.domain.celeb.entity.Celeb;
import com.sluv.server.domain.celeb.entity.NewCeleb;
import com.sluv.server.domain.question.dto.QuestionFindPostReqDto;
import com.sluv.server.domain.question.dto.QuestionHowaboutPostReqDto;
import com.sluv.server.domain.question.enums.QuestionStatus;
import com.sluv.server.domain.user.entity.User;
import jakarta.persistence.DiscriminatorValue;
Expand Down Expand Up @@ -35,4 +37,21 @@ public QuestionFind(Long id, User user, String title, String content, Long searc
this.celeb = celeb;
this.newCeleb = newCeleb;
}

public static QuestionFind toEntity(User user, QuestionFindPostReqDto postReqDto, Celeb celeb, NewCeleb newCeleb){
QuestionFindBuilder builder = QuestionFind.builder();

if(postReqDto.getId() != null){
builder
.id(postReqDto.getId());
}

return builder
.user(user)
.title(postReqDto.getTitle())
.content(postReqDto.getContent())
.celeb(celeb)
.newCeleb(newCeleb)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package com.sluv.server.domain.question.entity;

import com.sluv.server.domain.question.dto.QuestionHowaboutPostReqDto;
import com.sluv.server.domain.question.enums.QuestionStatus;
import com.sluv.server.domain.user.entity.User;
import jakarta.persistence.DiscriminatorValue;
import jakarta.persistence.Entity;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

import java.time.LocalDateTime;

@Entity
@NoArgsConstructor
Expand All @@ -21,4 +18,19 @@ public class QuestionHowabout extends Question{
public QuestionHowabout(Long id, User user, String title, String content, Long searchNum, QuestionStatus questionStatus) {
super(id, user, title, content, searchNum, questionStatus);
}

public static QuestionHowabout toEntity(User user, QuestionHowaboutPostReqDto postReqDto){
QuestionHowaboutBuilder builder = QuestionHowabout.builder();

if(postReqDto.getId() != null){
builder
.id(postReqDto.getId());
}

return builder
.user(user)
.title(postReqDto.getTitle())
.content(postReqDto.getContent())
.build();
}
}
Loading

0 comments on commit 7b316dc

Please sign in to comment.