-
Notifications
You must be signed in to change notification settings - Fork 5
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
[BE] issue120: 스터디 리뷰 작성 #140
Merged
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
ef0e0ff
fix: 생성일자에 null이 들어와서 검증 시 발생하는 예외 처리
sc0116 38dad80
test: 필수 데이터 없는 경우 401 반환하는 인수 테스트 추가
sc0116 7ea0057
feat: 필수 데이터 없는 경우 401 반환하는 기능 구현
sc0116 c7fa3cc
feat: 스터디 시작 전에 후기 작성 시 예외 반환 기능 구현
sc0116 1a42d6b
feat: 스터디 참여 여부 기능 구현
sc0116 51fb4d8
feat: 리뷰 작성 기능 구현
sc0116 b07fc33
refactor: BaseTime 제거
sc0116 1230c32
test: 리뷰 관련 인수테스트 실패
sc0116 56f8bc3
test: 리뷰 관련 인수테스트 작성
sc0116 54644f4
test: 리뷰 인수테스트 및 HTTP 요청 테스트 추가
sc0116 4d0b365
refactor: 예외 메세지 및 메소드명 수정
sc0116 7cdfb2f
refactor: 사용하지 않는 클래스 제거 및 메소드명 수정
sc0116 eea26ed
refactor: 스터디 시작 전에 후기 작성 시 예외 반환 기능 로직 변경
sc0116 81b19ff
style: EOF 처리
sc0116 94dcdf4
style: 상수명 대문자로 변경
sc0116 68cac97
test: DisplayName 및 메소드명 수정
sc0116 b07373d
refactor: 정적 팩터리 메소드 대신 new 생성자로 변경
sc0116 196b3dc
refactor: 리뷰를 작성할 스터디에 참여했는지 판단하는 로직 수정
sc0116 dca3c70
refactor: 리뷰 작성 로직에서 검증과 생성 순서 변경
sc0116 643bfb0
test: 리뷰 관련 테스트 수정
sc0116 2bb5f55
refactor: 리뷰 관련 Controller와 Service에서 명령을 위한 것과 사용자 조회를 위한 것으로 분리
sc0116 36d8a34
style: EOF 처리
sc0116 11fe2f1
refactor: 리뷰 작성 시 해당 스터디 참여 여부 로직에서 스터디장 판단 로직 추가
sc0116 6a61f2b
chore: develop merge 충돌 해결
sc0116 f41383e
refactor: 사용하지 않는 부분 제거
sc0116 9bab968
chore: develop merge 충돌 해결
sc0116 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
8 changes: 8 additions & 0 deletions
8
backend/src/main/java/com/woowacourse/moamoa/common/exception/BadRequestException.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,8 @@ | ||
package com.woowacourse.moamoa.common.exception; | ||
|
||
public class BadRequestException extends RuntimeException { | ||
|
||
public BadRequestException(final String message) { | ||
super(message); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
backend/src/main/java/com/woowacourse/moamoa/common/exception/NotFoundException.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,8 @@ | ||
package com.woowacourse.moamoa.common.exception; | ||
|
||
public class NotFoundException extends RuntimeException { | ||
|
||
public NotFoundException(final String message) { | ||
super(message); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
import com.woowacourse.moamoa.member.domain.Member; | ||
import com.woowacourse.moamoa.member.domain.repository.MemberRepository; | ||
import com.woowacourse.moamoa.member.query.data.MemberData; | ||
import com.woowacourse.moamoa.member.service.exception.InvalidMemberException; | ||
import com.woowacourse.moamoa.member.service.exception.MemberNotFoundException; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
@@ -24,7 +24,7 @@ public void saveOrUpdate(final Member member) { | |
|
||
public MemberData searchBy(final Long githubId) { | ||
final Member member = memberRepository.findByGithubId(githubId) | ||
.orElseThrow(() -> new InvalidMemberException("사용자를 찾을 수 없습니다.")); | ||
.orElseThrow(MemberNotFoundException::new); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 명확해서 좋아요 👍 |
||
return new MemberData(member.getGithubId(), member.getUsername(), member.getImageUrl(), member.getProfileUrl()); | ||
} | ||
} |
9 changes: 0 additions & 9 deletions
9
...src/main/java/com/woowacourse/moamoa/member/service/exception/InvalidMemberException.java
This file was deleted.
Oops, something went wrong.
10 changes: 10 additions & 0 deletions
10
...rc/main/java/com/woowacourse/moamoa/member/service/exception/MemberNotFoundException.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,10 @@ | ||
package com.woowacourse.moamoa.member.service.exception; | ||
|
||
import com.woowacourse.moamoa.common.exception.NotFoundException; | ||
|
||
public class MemberNotFoundException extends NotFoundException { | ||
|
||
public MemberNotFoundException() { | ||
super("회원을 찾을 수 없습니다."); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
.../java/com/woowacourse/moamoa/member/service/exception/NotParticipatedMemberException.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,10 @@ | ||
package com.woowacourse.moamoa.member.service.exception; | ||
|
||
import com.woowacourse.moamoa.common.exception.UnauthorizedException; | ||
|
||
public class NotParticipatedMemberException extends UnauthorizedException { | ||
|
||
public NotParticipatedMemberException() { | ||
super("스터디에 참여한 회원만 후기를 작성할 수 있습니다."); | ||
} | ||
} |
25 changes: 14 additions & 11 deletions
25
backend/src/main/java/com/woowacourse/moamoa/review/controller/ReviewController.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,29 +1,32 @@ | ||
package com.woowacourse.moamoa.review.controller; | ||
|
||
import com.woowacourse.moamoa.auth.config.AuthenticationPrincipal; | ||
import com.woowacourse.moamoa.review.service.ReviewService; | ||
import com.woowacourse.moamoa.review.service.request.SizeRequest; | ||
import com.woowacourse.moamoa.review.service.response.ReviewsResponse; | ||
import com.woowacourse.moamoa.review.service.request.WriteReviewRequest; | ||
import java.net.URI; | ||
import javax.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/api/studies") | ||
@RequestMapping("/api/studies/{study-id}/reviews") | ||
@RequiredArgsConstructor | ||
public class ReviewController { | ||
|
||
private final ReviewService reviewService; | ||
|
||
@GetMapping("/{study-id}/reviews") | ||
public ResponseEntity<ReviewsResponse> getReviews( | ||
@PathVariable(name = "study-id") Long studyId, | ||
@RequestParam(name = "size", required = false, defaultValue = "") SizeRequest sizeRequest | ||
@PostMapping | ||
public ResponseEntity<Void> writeReview( | ||
@AuthenticationPrincipal final Long githubId, | ||
@PathVariable(name = "study-id") final Long studyId, | ||
@Valid @RequestBody final WriteReviewRequest writeReviewRequest | ||
) { | ||
final ReviewsResponse reviewsResponse = reviewService.getReviewsByStudy(studyId, sizeRequest); | ||
return ResponseEntity.ok(reviewsResponse); | ||
final Long id = reviewService.writeReview(githubId, studyId, writeReviewRequest); | ||
return ResponseEntity.created(URI.create("/api/studies/" + studyId + "/reviews/" + id)).build(); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...end/src/main/java/com/woowacourse/moamoa/review/controller/SearchingReviewController.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,29 @@ | ||
package com.woowacourse.moamoa.review.controller; | ||
|
||
import com.woowacourse.moamoa.review.service.SearchingReviewService; | ||
import com.woowacourse.moamoa.review.service.request.SizeRequest; | ||
import com.woowacourse.moamoa.review.service.response.ReviewsResponse; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/api/studies/{study-id}/reviews") | ||
@RequiredArgsConstructor | ||
public class SearchingReviewController { | ||
|
||
private final SearchingReviewService searchingReviewService; | ||
|
||
@GetMapping | ||
public ResponseEntity<ReviewsResponse> getReviews( | ||
@PathVariable(name = "study-id") Long studyId, | ||
@RequestParam(name = "size", required = false, defaultValue = "") SizeRequest sizeRequest | ||
) { | ||
final ReviewsResponse reviewsResponse = searchingReviewService.getReviewsByStudy(studyId, sizeRequest); | ||
return ResponseEntity.ok(reviewsResponse); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,9 +19,9 @@ | |
import org.springframework.data.annotation.LastModifiedDate; | ||
|
||
@Entity | ||
@Getter | ||
@NoArgsConstructor(access = PROTECTED) | ||
@AllArgsConstructor | ||
@Getter | ||
public class Review { | ||
|
||
@Id | ||
|
@@ -39,10 +39,17 @@ public class Review { | |
private String content; | ||
|
||
@CreatedDate | ||
@Column(nullable = false) | ||
@Column(nullable = false, updatable = false) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
private LocalDateTime createdDate; | ||
|
||
@LastModifiedDate | ||
@Column(nullable = false) | ||
private LocalDateTime lastModifiedDate; | ||
|
||
public Review( | ||
final AssociatedStudy associatedStudy, final Member member, final String content, | ||
final LocalDateTime createdDate, final LocalDateTime lastModifiedDate | ||
) { | ||
this(null, associatedStudy, member, content, createdDate, lastModifiedDate); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...java/com/woowacourse/moamoa/review/domain/exception/WritingReviewBadRequestException.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,10 @@ | ||
package com.woowacourse.moamoa.review.domain.exception; | ||
|
||
import com.woowacourse.moamoa.common.exception.BadRequestException; | ||
|
||
public class WritingReviewBadRequestException extends BadRequestException { | ||
|
||
public WritingReviewBadRequestException() { | ||
super("스터디 시작 전 후기를 작성할 수 없습니다."); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...nd/src/main/java/com/woowacourse/moamoa/review/domain/repository/JpaReviewRepository.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,7 @@ | ||
package com.woowacourse.moamoa.review.domain.repository; | ||
|
||
import com.woowacourse.moamoa.review.domain.Review; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface JpaReviewRepository extends JpaRepository<Review, Long>, ReviewRepository { | ||
} |
12 changes: 12 additions & 0 deletions
12
backend/src/main/java/com/woowacourse/moamoa/review/domain/repository/ReviewRepository.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,12 @@ | ||
package com.woowacourse.moamoa.review.domain.repository; | ||
|
||
import com.woowacourse.moamoa.review.domain.AssociatedStudy; | ||
import com.woowacourse.moamoa.review.domain.Review; | ||
import java.util.List; | ||
|
||
public interface ReviewRepository { | ||
|
||
Review save(Review review); | ||
|
||
List<Review> findAllByAssociatedStudy(AssociatedStudy associatedStudy); | ||
} |
50 changes: 37 additions & 13 deletions
50
backend/src/main/java/com/woowacourse/moamoa/review/service/ReviewService.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,29 +1,53 @@ | ||
package com.woowacourse.moamoa.review.service; | ||
|
||
import com.woowacourse.moamoa.review.query.ReviewDao; | ||
import com.woowacourse.moamoa.review.query.data.ReviewData; | ||
import com.woowacourse.moamoa.review.service.request.SizeRequest; | ||
import com.woowacourse.moamoa.review.service.response.ReviewsResponse; | ||
import java.util.List; | ||
import com.woowacourse.moamoa.member.domain.Member; | ||
import com.woowacourse.moamoa.member.domain.repository.MemberRepository; | ||
import com.woowacourse.moamoa.member.service.exception.MemberNotFoundException; | ||
import com.woowacourse.moamoa.member.service.exception.NotParticipatedMemberException; | ||
import com.woowacourse.moamoa.review.domain.AssociatedStudy; | ||
import com.woowacourse.moamoa.review.domain.Review; | ||
import com.woowacourse.moamoa.review.domain.exception.WritingReviewBadRequestException; | ||
import com.woowacourse.moamoa.review.domain.repository.ReviewRepository; | ||
import com.woowacourse.moamoa.review.service.request.WriteReviewRequest; | ||
import com.woowacourse.moamoa.study.domain.Participant; | ||
import com.woowacourse.moamoa.study.domain.Study; | ||
import com.woowacourse.moamoa.study.domain.repository.StudyRepository; | ||
import com.woowacourse.moamoa.study.service.exception.StudyNotFoundException; | ||
import java.time.LocalDateTime; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@Transactional(readOnly = true) | ||
@Transactional | ||
@RequiredArgsConstructor | ||
public class ReviewService { | ||
|
||
private final ReviewDao reviewDao; | ||
private final ReviewRepository reviewRepository; | ||
private final MemberRepository memberRepository; | ||
private final StudyRepository studyRepository; | ||
|
||
public ReviewsResponse getReviewsByStudy(Long studyId, SizeRequest sizeRequest) { | ||
final List<ReviewData> allReviews = reviewDao.findAllByStudyId(studyId); | ||
public Long writeReview(final Long githubId, final Long studyId, final WriteReviewRequest writeReviewRequest) { | ||
final Study study = studyRepository.findById(studyId) | ||
.orElseThrow(StudyNotFoundException::new); | ||
final Member member = memberRepository.findByGithubId(githubId) | ||
.orElseThrow(MemberNotFoundException::new); | ||
|
||
if (sizeRequest.isEmpty() || sizeRequest.isMoreThan(allReviews.size())) { | ||
return new ReviewsResponse(allReviews); | ||
final Participant participant = new Participant(member.getId()); | ||
if (!study.isParticipated(participant)) { | ||
throw new NotParticipatedMemberException(); | ||
} | ||
|
||
return new ReviewsResponse(allReviews.subList(0, sizeRequest.getValue()), allReviews.size()); | ||
} | ||
final LocalDateTime reviewCreatedDate = LocalDateTime.now(); | ||
if (study.isBeforeThanStudyStartDate(reviewCreatedDate.toLocalDate())) { | ||
throw new WritingReviewBadRequestException(); | ||
} | ||
|
||
final AssociatedStudy associatedStudy = new AssociatedStudy(studyId); | ||
final Review review = new Review( | ||
associatedStudy, member, writeReviewRequest.getContent(), reviewCreatedDate, reviewCreatedDate | ||
); | ||
|
||
return reviewRepository.save(review).getId(); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
굿굿!!👍