-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
36 changed files
with
1,196 additions
and
108 deletions.
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
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(); | ||
} | ||
} |
Oops, something went wrong.