-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[Feature] 리뷰 진행하기
- Loading branch information
Showing
36 changed files
with
969 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 5 additions & 4 deletions
9
src/main/java/com/_119/wepro/member/domain/repository/MemberRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,19 @@ | ||
package com._119.wepro.member.domain.repository; | ||
|
||
import com._119.wepro.global.exception.RestApiException; | ||
import com._119.wepro.global.exception.errorcode.UserErrorCode; | ||
import com._119.wepro.member.domain.Member; | ||
import com._119.wepro.member.domain.OauthInfo; | ||
import io.lettuce.core.dynamic.annotation.Param; | ||
import java.util.Optional; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface MemberRepository extends JpaRepository<Member, Long> { | ||
|
||
Optional<Member> findByOauthInfo(OauthInfo oauthInfo); | ||
|
||
@Query("SELECT m FROM Member m WHERE m.oauthInfo.providerId = :providerId") | ||
Optional<Member> findByProviderId(@Param("providerId") String providerId); | ||
default Member findByIdOrThrow(Long memberId) { | ||
return findById(memberId).orElseThrow(() -> new RestApiException(UserErrorCode.USER_NOT_FOUND)); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/com/_119/wepro/project/domain/repository/ProjectRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,13 @@ | ||
package com._119.wepro.project.domain.repository; | ||
|
||
import com._119.wepro.global.exception.RestApiException; | ||
import com._119.wepro.global.exception.errorcode.ProjectErrorCode; | ||
import com._119.wepro.project.domain.Project; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface ProjectRepository extends JpaRepository<Project, Long> { | ||
|
||
default Project findByIdOrThrow(Long projectId) { | ||
return findById(projectId).orElseThrow(() -> new RestApiException(ProjectErrorCode.PROJECT_NOT_FOUND)); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/main/java/com/_119/wepro/review/domain/ChoiceAnswer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com._119.wepro.review.domain; | ||
|
||
import com._119.wepro.review.dto.ChoiceAnswerDto; | ||
import java.util.Objects; | ||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor | ||
@Getter | ||
@Builder | ||
public class ChoiceAnswer { | ||
|
||
private Long optionId; | ||
|
||
private Long questionId; | ||
|
||
|
||
public static ChoiceAnswer of(ChoiceAnswerDto answerDto) { | ||
return ChoiceAnswer.builder() | ||
.questionId(answerDto.getQuestionId()) | ||
.optionId(answerDto.getOptionId()) | ||
.build(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
ChoiceAnswer that = (ChoiceAnswer) o; | ||
return Objects.equals(questionId, that.questionId) && | ||
Objects.equals(optionId, that.optionId); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(questionId, optionId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
src/main/java/com/_119/wepro/review/domain/ReviewRecord.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package com._119.wepro.review.domain; | ||
|
||
import com._119.wepro.global.BaseEntity; | ||
import com._119.wepro.member.domain.Member; | ||
import com._119.wepro.review.domain.converter.ChoiceAnswerConverter; | ||
import com._119.wepro.review.domain.converter.SubAnswerConverter; | ||
import com._119.wepro.review.dto.request.ReviewRequest.ReviewSaveRequest; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Convert; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.FetchType; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.ManyToOne; | ||
import java.util.List; | ||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.hibernate.annotations.JdbcTypeCode; | ||
import org.hibernate.type.SqlTypes; | ||
|
||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor | ||
@Entity | ||
@Getter | ||
@Builder | ||
public class ReviewRecord extends BaseEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@Builder.Default | ||
@Column(nullable = false) | ||
private Boolean isDraft = true; | ||
|
||
@Builder.Default | ||
@Column(nullable = false) | ||
private Boolean isPublic = false; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "receiver_id") | ||
private Member receiver; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "writer_id") | ||
private Member writer; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "review_form_id") | ||
private ReviewForm reviewForm; | ||
|
||
@Column(columnDefinition = "json") | ||
@JdbcTypeCode(SqlTypes.JSON) | ||
@Convert(converter = ChoiceAnswerConverter.class) | ||
private List<ChoiceAnswer> choiceAnswers; | ||
|
||
@Column(columnDefinition = "json") | ||
@JdbcTypeCode(SqlTypes.JSON) | ||
@Convert(converter = SubAnswerConverter.class) | ||
private List<SubAnswer> subAnswers; | ||
|
||
public static ReviewRecord of(Member writer, ReviewForm reviewForm, ReviewSaveRequest request) { | ||
List<ChoiceAnswer> choiceAnswers = request.getChoiceAnswerList().stream() | ||
.map(ChoiceAnswer::of) | ||
.toList(); | ||
|
||
List<SubAnswer> subAnswers = request.getSubAnswerList().stream() | ||
.map(SubAnswer::of) | ||
.toList(); | ||
|
||
return ReviewRecord.builder() | ||
.writer(writer) | ||
.receiver(reviewForm.getMember()) | ||
.reviewForm(reviewForm) | ||
.choiceAnswers(choiceAnswers) | ||
.subAnswers(subAnswers) | ||
.build(); | ||
} | ||
|
||
public void update(ReviewSaveRequest request) { | ||
List<ChoiceAnswer> choiceAnswers = request.getChoiceAnswerList().stream() | ||
.map(ChoiceAnswer::of) | ||
.toList(); | ||
|
||
List<SubAnswer> subAnswers = request.getSubAnswerList().stream() | ||
.map(SubAnswer::of) | ||
.toList(); | ||
|
||
this.choiceAnswers = choiceAnswers; | ||
this.subAnswers = subAnswers; | ||
} | ||
|
||
public void submit(){ | ||
this.isDraft = false; | ||
} | ||
} |
Oops, something went wrong.