-
Notifications
You must be signed in to change notification settings - Fork 28
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
키워드별 추천 포스트 어드민 기능을 구현한다 #1470
Merged
Merged
키워드별 추천 포스트 어드민 기능을 구현한다 #1470
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
583647b
feat: RecommendedPost 엔티티 추가
nuyh99 f0edbca
feat: 추천 포스트 등록, 수정, 삭제 기능 추가
nuyh99 4498cc5
test: 키워드별 추천 포스트 엔티티 테스트
nuyh99 3ed1604
feat: 어드민용 키워드별 추천 포스트 기능 컨트롤러 구현
nuyh99 6b5f624
fix: 추천 포스트 URL 길이 수정 및 FK 네임 변경
nuyh99 b268be4
feat: 키워드 조회 시 추천 포스트도 조회되도록 변경
nuyh99 fc6551a
test: 큐컴버 인수 테스트 추가
35f6479
test: 큐컴버 인수 테스트 추가
4d0d6e5
test: 큐컴버 인수 테스트 중복 조건 제거
25c3f7e
fix: RecommendedPostResponse dto 수정
6e85c29
fix: Keyword 저장 시 세션과의 연관 관계 violation 해결
nuyh99 7602e3d
fix: 예외 고도화 반영
nuyh99 07d9bfa
style: RecommendedPost 리포지토리 네이밍 변경
nuyh99 2c77205
refactor: RecommendedPost 삽입 응답값 수정
nuyh99 f3b0680
refactor: update 응답값 200 -> 204 수정
nuyh99 a8fd1e2
style: recommended post 관련 클래스 네이밍 수정
nuyh99 0c80f77
fix: test 내에서 Transactional로 롤백하던 것 DataInitializer로 대체
nuyh99 d5c7e2f
refactor: RecommendedPost 생성자 변경
nuyh99 b34e979
style: final 빠진 부분 수정
nuyh99 f0a9e62
feat: 도메인 검증 기능 추가 및 테스트
nuyh99 7124da0
feat: List로 가지던 연관 관계 Set으로 변경, Repository 메서드 네이밍 변경
nuyh99 0137acb
fix: findById 오버라이딩하도록 수정
nuyh99 10839e5
refactor: 테스트 코드 간결화 및 가독성 증진
nuyh99 c97e785
fix: RecommendedPost에서 url의 NPE 처리
nuyh99 e3c68a1
style: 개행 추가
nuyh99 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
58 changes: 58 additions & 0 deletions
58
...d/src/acceptanceTest/java/wooteco/prolog/steps/KeywordRecommendedPostStepDefinitions.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,58 @@ | ||
package wooteco.prolog.steps; | ||
|
||
import io.cucumber.java.en.Given; | ||
import io.cucumber.java.en.Then; | ||
import io.cucumber.java.en.When; | ||
import org.springframework.http.HttpStatus; | ||
import wooteco.prolog.AcceptanceSteps; | ||
import wooteco.prolog.roadmap.application.dto.RecommendedRequest; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static wooteco.prolog.fixtures.KeywordAcceptanceFixture.KEYWORD_REQUEST; | ||
|
||
public class KeywordRecommendedPostStepDefinitions extends AcceptanceSteps { | ||
|
||
@Given("{int}번 키워드에 대해 추천 포스트 {string}를 작성하고") | ||
@When("{int}번 키워드에 대해 추천 포스트 {string}를 작성하면") | ||
public void 추천_포스트를_추가하면(int keywordId, String url) { | ||
context.invokeHttpPost( | ||
"/keywords/"+keywordId+"/recommended-posts", | ||
new RecommendedRequest(url) | ||
); | ||
} | ||
|
||
@When("{int}번 키워드에 대한 {int}번 추천 포스트를 {string}로 수정하면") | ||
public void 추천_포스트를_수정하면(int keywordId, int recommendedId, String url) { | ||
context.invokeHttpPut( | ||
"/keywords/"+keywordId+"/recommended-posts/"+recommendedId, | ||
new RecommendedRequest(url)); | ||
} | ||
|
||
@When("{int}번 키워드에 대한 {int}번 추천 포스트를 삭제하면") | ||
public void 추천_포스트를_삭제하면(int keywordId, int recommendedId) { | ||
context.invokeHttpDelete( | ||
"/keywords/" + keywordId + "/recommended-posts/" + recommendedId | ||
); | ||
} | ||
|
||
@Then("추천 포스트가 생성된다") | ||
public void 추천_포스트가_생성된다() { | ||
int statusCode = context.response.statusCode(); | ||
|
||
assertThat(statusCode).isEqualTo(HttpStatus.CREATED.value()); | ||
} | ||
|
||
@Then("추천 포스트가 수정된다") | ||
public void 추천_포스트가_수정된다() { | ||
int statusCode = context.response.statusCode(); | ||
|
||
assertThat(statusCode).isEqualTo(HttpStatus.OK.value()); | ||
} | ||
|
||
@Then("추천 포스트가 삭제된다") | ||
public void 추천_포스트가_삭제된다() { | ||
int statusCode = context.response.statusCode(); | ||
|
||
assertThat(statusCode).isEqualTo(HttpStatus.NO_CONTENT.value()); | ||
} | ||
} |
6 changes: 3 additions & 3 deletions
6
backend/src/acceptanceTest/java/wooteco/prolog/steps/KeywordStepDefinitions.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
20 changes: 20 additions & 0 deletions
20
backend/src/acceptanceTest/resources/wooteco/prolog/keyword-recommended-post.feature
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,20 @@ | ||
@api | ||
Feature: 로드맵 키워드 추천 포스트 관련 기능 | ||
|
||
Background: 사전 작업 | ||
Given "2022 백엔드 레벨1" 세션을 생성하고 - 1번 세션 | ||
And 1번 세션에 "자바"라는 키워드를 순서 1, 중요도 2로 작성하고 | ||
|
||
Scenario: 키워드 추천 포스트 생성하기 | ||
When 1번 키워드에 대해 추천 포스트 "https://javajavajava"를 작성하면 | ||
Then 추천 포스트가 생성된다 | ||
|
||
Scenario: 키워드 추천 포스트 수정하기 | ||
Given 1번 키워드에 대해 추천 포스트 "https://javajavajava"를 작성하고 | ||
When 1번 키워드에 대한 1번 추천 포스트를 "https://java2java2"로 수정하면 | ||
Then 추천 포스트가 수정된다 | ||
|
||
Scenario: 키워드 추천 포스트 삭제하기 | ||
Given 1번 키워드에 대해 추천 포스트 "https://javajavajava"를 작성하고 | ||
When 1번 키워드에 대한 1번 추천 포스트를 삭제하면 | ||
Then 추천 포스트가 삭제된다 |
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
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
59 changes: 59 additions & 0 deletions
59
backend/src/main/java/wooteco/prolog/roadmap/application/RecommendedPostService.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,59 @@ | ||
package wooteco.prolog.roadmap.application; | ||
|
||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import wooteco.prolog.common.exception.BadRequestException; | ||
import wooteco.prolog.roadmap.application.dto.RecommendedRequest; | ||
import wooteco.prolog.roadmap.application.dto.RecommendedUpdateRequest; | ||
import wooteco.prolog.roadmap.domain.Keyword; | ||
import wooteco.prolog.roadmap.domain.RecommendedPost; | ||
import wooteco.prolog.roadmap.domain.repository.KeywordRepository; | ||
import wooteco.prolog.roadmap.domain.repository.RecommendedPostRepository; | ||
|
||
import static wooteco.prolog.common.exception.BadRequestCode.ROADMAP_KEYWORD_NOT_FOUND_EXCEPTION; | ||
import static wooteco.prolog.common.exception.BadRequestCode.ROADMAP_RECOMMENDED_POST_NOT_FOUND; | ||
|
||
@Transactional(readOnly = true) | ||
@Service | ||
public class RecommendedPostService { | ||
|
||
private final RecommendedPostRepository recommendedPostRepository; | ||
private final KeywordRepository keywordRepository; | ||
|
||
public RecommendedPostService(final RecommendedPostRepository recommendedPostRepository, | ||
final KeywordRepository keywordRepository) { | ||
this.recommendedPostRepository = recommendedPostRepository; | ||
this.keywordRepository = keywordRepository; | ||
} | ||
|
||
@Transactional | ||
public Long create(final Long keywordId, final RecommendedRequest request) { | ||
final Keyword keyword = findKeywordOrThrow(keywordId); | ||
final RecommendedPost post = new RecommendedPost(request.getUrl(), keyword); | ||
|
||
return recommendedPostRepository.save(post).getId(); | ||
} | ||
|
||
private Keyword findKeywordOrThrow(final Long keywordId) { | ||
return keywordRepository.findById(keywordId) | ||
.orElseThrow(() -> new BadRequestException(ROADMAP_KEYWORD_NOT_FOUND_EXCEPTION)); | ||
} | ||
|
||
@Transactional | ||
public void update(final Long recommendedId, final RecommendedUpdateRequest request) { | ||
final RecommendedPost post = findPostOrThrow(recommendedId); | ||
|
||
post.updateUrl(request.getUrl()); | ||
} | ||
|
||
private RecommendedPost findPostOrThrow(final Long recommendedId) { | ||
return recommendedPostRepository.findById(recommendedId) | ||
.orElseThrow(() -> new BadRequestException(ROADMAP_RECOMMENDED_POST_NOT_FOUND)); | ||
} | ||
|
||
@Transactional | ||
public void delete(final Long recommendedId) { | ||
final RecommendedPost recommendedPost = findPostOrThrow(recommendedId); | ||
recommendedPost.remove(); | ||
} | ||
} |
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
17 changes: 17 additions & 0 deletions
17
backend/src/main/java/wooteco/prolog/roadmap/application/dto/RecommendedPostResponse.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,17 @@ | ||
package wooteco.prolog.roadmap.application.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import wooteco.prolog.roadmap.domain.RecommendedPost; | ||
|
||
@AllArgsConstructor | ||
@Getter | ||
public class RecommendedPostResponse { | ||
|
||
private final Long id; | ||
private final String url; | ||
|
||
public static RecommendedPostResponse from(final RecommendedPost recommendedPost) { | ||
return new RecommendedPostResponse(recommendedPost.getId(), recommendedPost.getUrl()); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
backend/src/main/java/wooteco/prolog/roadmap/application/dto/RecommendedRequest.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,14 @@ | ||
package wooteco.prolog.roadmap.application.dto; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor | ||
public class RecommendedRequest { | ||
|
||
private String url; | ||
} |
14 changes: 14 additions & 0 deletions
14
backend/src/main/java/wooteco/prolog/roadmap/application/dto/RecommendedUpdateRequest.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,14 @@ | ||
package wooteco.prolog.roadmap.application.dto; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor | ||
public class RecommendedUpdateRequest { | ||
|
||
private String url; | ||
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.
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. 도메인에 검증 메서드 추가했습니다! |
||
} |
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.
여기도 마찬가지로
@NotEmpty
같은 제약 조건이 필요할 것 같습니다!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.
도메인에 검증 메서드 추가했습니다!