Skip to content

Commit

Permalink
Merge pull request #77 from KNU-HAEDAL/issue/#76
Browse files Browse the repository at this point in the history
Issue/#76
  • Loading branch information
bayy1216 authored Sep 3, 2024
2 parents 6780bdf + a261b5e commit bd51e55
Show file tree
Hide file tree
Showing 28 changed files with 189 additions and 678 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import jakarta.validation.constraints.NotNull;
import org.haedal.zzansuni.challengegroup.domain.ChallengeCategory;
import org.haedal.zzansuni.challengegroup.domain.ChallengeGroupCommand;
import org.haedal.zzansuni.challengegroup.domain.DayType;

import java.time.LocalDate;
import java.util.List;
Expand Down Expand Up @@ -37,9 +36,6 @@ public record CreateChallengeRequest(
@NotNull(message = "startDate는 필수값입니다.")
LocalDate startDate,
@NotNull(message = "endDate는 필수값입니다.")
LocalDate endDate,
@NotNull(message = "dayType은 필수값입니다.")
DayType dayType,
@NotNull(message = "requiredCount는 필수값입니다.")
Integer requiredCount,
@NotNull(message = "onceExp는 필수값입니다.")
Expand All @@ -51,9 +47,6 @@ public record CreateChallengeRequest(
){
public ChallengeGroupCommand.CreateChallenge toCommand() {
return ChallengeGroupCommand.CreateChallenge.builder()
.startDate(startDate)
.endDate(endDate)
.dayType(dayType)
.requiredCount(requiredCount)
.onceExp(onceExp)
.successExp(successExp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import org.haedal.zzansuni.user.controller.UserRes;
import org.haedal.zzansuni.challengegroup.domain.ChallengeCategory;
import org.haedal.zzansuni.challengegroup.domain.application.ChallengeGroupModel;
import org.haedal.zzansuni.challengegroup.domain.DayType;
import org.haedal.zzansuni.challengegroup.domain.application.ChallengeModel;
import org.haedal.zzansuni.userchallenge.domain.application.ChallengeGroupRankingModel;
import org.springframework.data.domain.Page;
Expand Down Expand Up @@ -109,7 +108,6 @@ public record Challenge(
Integer difficulty,
Integer onceExp,
Integer successExp,
DayType dayType,
Integer dayCount
) {
public static Challenge from(
Expand All @@ -121,7 +119,6 @@ public static Challenge from(
.difficulty(challenge.difficulty())
.onceExp(challenge.onceExp())
.successExp(challenge.successExp())
.dayType(challenge.dayType())
.dayCount(challenge.requiredCount())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@ public class Challenge extends BaseTimeEntity {
@JoinColumn(name = "challenge_group_id")
private ChallengeGroup challengeGroup;

@Column(nullable = false)
private Integer requiredCount;

@Enumerated(EnumType.STRING)
@Column(nullable = false)
private DayType dayType;

@Column(nullable = false)
private Integer onceExp;
Expand All @@ -42,22 +36,20 @@ public class Challenge extends BaseTimeEntity {
private Integer difficulty;

@Column(nullable = false)
private LocalDate startDate;
private Integer requiredCount;

@Column(nullable = false)
private LocalDate endDate;
private Integer activePeriod;


public static Challenge create(ChallengeGroupCommand.CreateChallenge command, ChallengeGroup group) {
return Challenge.builder()
.challengeGroup(group)
.requiredCount(command.getRequiredCount())
.dayType(command.getDayType())
.onceExp(command.getOnceExp())
.successExp(command.getSuccessExp())
.difficulty(command.getDifficulty())
.startDate(command.getStartDate())
.endDate(command.getEndDate())
.requiredCount(command.getRequiredCount())
.activePeriod(command.getActivePeriod())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,25 +50,6 @@ public VerificationCreate(String content, String imageUrl) {
}
}

@Getter
public static class ReviewCreate extends SelfValidating<ReviewCreate> {

@NotBlank(message = "내용은 필수입니다.")
private final String content;

@NotNull(message = "평점은 필수입니다.")
@Min(1)
@Max(5)
private final Integer rating;

@Builder
public ReviewCreate(String content, Integer rating) {
this.content = content;
this.rating = rating;
this.validateSelf();
}


}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import lombok.NoArgsConstructor;
import org.haedal.zzansuni.common.domain.BaseTimeEntity;

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

Expand All @@ -16,24 +17,39 @@
@AllArgsConstructor
@Builder
@Getter
@Table(
indexes = {
@Index(
name = "idx_challenge_group_join_start_date_join_end_date_category",
columnList = "join_start_date, join_end_date, category"
),
}
)
public class ChallengeGroup extends BaseTimeEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(nullable = false, length = 100)
private String title;

@Column(nullable = false, length = 1000)
private String content;

@Column(nullable = false, length = 1000)
private String guide;

@Enumerated(EnumType.STRING)
@Column(nullable = false)
private ChallengeCategory category;

@Column(nullable = false)
private String title;
private LocalDate joinStartDate;

@Column(nullable = false)
private String content;
private LocalDate joinEndDate;

@Column(nullable = false)
private String guide;

@Column(nullable = false)
private Integer cumulativeCount;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,6 @@ public Create(String title, String content, String guide, ChallengeCategory cate

@Getter
public static class CreateChallenge extends SelfValidating<CreateChallenge> {
@NotNull(message = "startDate는 필수값입니다.")
private final LocalDate startDate;
@NotNull(message = "endDate는 필수값입니다.")
private final LocalDate endDate;
@NotNull(message = "dayType은 필수값입니다.")
private final DayType dayType;
@NotNull(message = "requiredCount는 필수값입니다.")
private final Integer requiredCount;
@NotNull(message = "onceExp는 필수값입니다.")
Expand All @@ -50,16 +44,16 @@ public static class CreateChallenge extends SelfValidating<CreateChallenge> {
private final Integer successExp;
@NotNull(message = "difficulty는 필수값입니다.")
private final Integer difficulty;
@NotNull(message = "activePeriod는 필수값입니다.")
private final Integer activePeriod;

@Builder
public CreateChallenge(LocalDate startDate, LocalDate endDate, DayType dayType, Integer requiredCount, Integer onceExp, Integer successExp, Integer difficulty) {
this.startDate = startDate;
this.endDate = endDate;
this.dayType = dayType;
public CreateChallenge(Integer requiredCount, Integer onceExp, Integer successExp, Integer difficulty, Integer activePeriod) {
this.requiredCount = requiredCount;
this.onceExp = onceExp;
this.successExp = successExp;
this.difficulty = difficulty;
this.activePeriod = activePeriod;
this.validateSelf();
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import lombok.Builder;
import lombok.Getter;
import org.haedal.zzansuni.challengegroup.domain.Challenge;
import org.haedal.zzansuni.challengegroup.domain.DayType;

import java.time.LocalDate;

Expand All @@ -16,7 +15,6 @@ public class ChallengeModel {
public record Main(
Long id,
Integer requiredCount,
DayType dayType,
Integer onceExp,
Integer successExp,
Integer difficulty,
Expand All @@ -27,12 +25,9 @@ public static Main from(Challenge challenge) {
return Main.builder()
.id(challenge.getId())
.requiredCount(challenge.getRequiredCount())
.dayType(challenge.getDayType())
.onceExp(challenge.getOnceExp())
.successExp(challenge.getSuccessExp())
.difficulty(challenge.getDifficulty())
.startDate(challenge.getStartDate())
.endDate(challenge.getEndDate())
.build();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.haedal.zzansuni.common.controller.PagingRequest;
import org.haedal.zzansuni.common.controller.PagingResponse;
import org.haedal.zzansuni.core.api.ApiResponse;
import org.haedal.zzansuni.userchallenge.controller.ChallengeReq;
import org.haedal.zzansuni.challengereview.domain.ChallengeReviewModel.ChallengeReviewWithChallenge;
import org.haedal.zzansuni.challengereview.domain.ChallengeReviewModel.ChallengeReviewWithUserInfo;
import org.haedal.zzansuni.challengereview.domain.ChallengeReviewService;
import org.haedal.zzansuni.common.controller.PagingRequest;
import org.haedal.zzansuni.common.controller.PagingResponse;
import org.haedal.zzansuni.core.api.ApiResponse;
import org.haedal.zzansuni.global.jwt.JwtUser;
import org.springframework.data.domain.Page;
import org.springframework.http.HttpStatus;
Expand Down Expand Up @@ -67,7 +66,7 @@ public ApiResponse<PagingResponse<ChallengeReviewRes.InfoWithChallenge>> getChal
public ApiResponse<Long> challengeReviewCreate(
@PathVariable Long challengeId,
@AuthenticationPrincipal JwtUser jwtUser,
@RequestBody ChallengeReq.ReviewCreate request
@RequestBody ChallengeReviewReq.Create request
) {
Long response = challengeReviewService.createReview(request.toCommand(), challengeId,
jwtUser.getId());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.haedal.zzansuni.challengereview.controller;

import io.swagger.v3.oas.annotations.media.Schema;
import org.haedal.zzansuni.challengereview.domain.ChallengeReviewCommand;

public class ChallengeReviewReq {
public record Create(
String content,
@Schema(description = "평점", example = "5")
Integer rating
) {

public ChallengeReviewCommand.Create toCommand() {
return ChallengeReviewCommand.Create.builder()
.content(content)
.rating(rating)
.build();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package org.haedal.zzansuni.challengereview.domain;

import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.*;
import org.haedal.zzansuni.common.domain.BaseTimeEntity;
import org.haedal.zzansuni.challengegroup.domain.ChallengeCommand;
import org.haedal.zzansuni.userchallenge.domain.UserChallenge;

@Entity
@AllArgsConstructor
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Getter
@Builder
@Table(
indexes = {
@Index(name = "idx_challenge_review_challenge_group_id", columnList = "challenge_group_id"),
}
)
public class ChallengeReview extends BaseTimeEntity {

@Id
Expand All @@ -25,7 +25,7 @@ public class ChallengeReview extends BaseTimeEntity {
@JoinColumn(name = "user_challenge_id", nullable = false)
private UserChallenge userChallenge;

@Column(nullable = false)
@Column(nullable = false, length = 1000)
private String content;

@Column(nullable = false)
Expand All @@ -35,7 +35,7 @@ public class ChallengeReview extends BaseTimeEntity {
@Column(nullable = false)
private Long challengeGroupId;

public static ChallengeReview create(UserChallenge userChallenge, ChallengeCommand.ReviewCreate command) {
public static ChallengeReview create(UserChallenge userChallenge, ChallengeReviewCommand.Create command) {
Long challengeGroupId = userChallenge.getChallenge().getChallengeGroupId();
return ChallengeReview.builder()
.userChallenge(userChallenge)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.haedal.zzansuni.challengereview.domain;

import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Builder;
import lombok.Getter;
import org.haedal.zzansuni.core.utils.SelfValidating;

public class ChallengeReviewCommand {
@Getter
public static class Create extends SelfValidating<Create> {

@NotBlank(message = "내용은 필수입니다.")
private final String content;

@NotNull(message = "평점은 필수입니다.")
@Min(1)
@Max(5)
private final Integer rating;

@Builder
public Create(String content, Integer rating) {
this.content = content;
this.rating = rating;
this.validateSelf();
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.haedal.zzansuni.challengegroup.domain.ChallengeCommand;
import org.haedal.zzansuni.userchallenge.domain.port.UserChallengeReader;
import org.haedal.zzansuni.userchallenge.domain.UserChallenge;
import org.springframework.data.domain.Page;
Expand All @@ -25,7 +24,7 @@ public class ChallengeReviewService {
* 챌린지 리뷰 작성하기
*/
@Transactional
public Long createReview(ChallengeCommand.ReviewCreate command, Long challengeId, Long userId) {
public Long createReview(ChallengeReviewCommand.Create command, Long challengeId, Long userId) {
UserChallenge userChallenge = userChallengeReader.findByUserIdAndChallengeId(userId,
challengeId).orElseThrow(() -> new IllegalStateException("해당 챌린지 참여 기록이 없습니다."));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
public class BaseTimeEntity {

@CreatedDate
@Column(name = "created_at")
@Column(name = "created_at", columnDefinition = "DATETIME(0)")
private LocalDateTime createdAt;

@LastModifiedDate
@Column(name = "last_modified_at")
private LocalDateTime lastModifiedAt;
@Column(name = "modified_at", columnDefinition = "DATETIME(0)")
private LocalDateTime modifiedAt;
}
Loading

0 comments on commit bd51e55

Please sign in to comment.