Skip to content
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

feat, fix, chore, docs: 여러 자잘한 수정 #98

Merged
merged 4 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/deploy-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
SSH_DEST: ${{ secrets.DEV_SSH_DEST }}
SSH_KEY: ${{ secrets.DEV_SSH_KEY }}
with:
version: 0.11.8
version: 0.11.9
verb: call
module: ./cicd
args: >-
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-stag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
SSH_DEST: ${{ secrets.STAG_SSH_DEST }}
SSH_KEY: ${{ secrets.STAG_SSH_KEY }}
with:
version: 0.11.8
version: 0.11.9
verb: call
module: ./cicd
args: >-
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ public class Term extends BaseEntity {
@Column(length = 2000, nullable = false)
private String meaning;

/**
* 동의어
*/
@Column(length = 1000)
private String synonym;

@OneToMany(mappedBy = "term", fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
private List<TermSynonym> synonyms = new ArrayList<>();

Expand Down Expand Up @@ -66,13 +72,15 @@ public static Term forUpdateOf(
return result;
}

private void addAllSynonym(List<String> synonyms) {
synonyms.forEach(s -> this.synonyms.add(TermSynonym.forCreateOf(s, this)));
private void addAllSynonym(List<String> input) {
this.synonym = String.join(",", input);
input.forEach(s -> this.synonyms.add(TermSynonym.forCreateOf(s, this)));
}

public void update(Term term) {
this.term = term.getTerm();
this.meaning = term.getMeaning();
this.synonym = term.getSynonym();
this.synonyms.clear();
this.synonyms.addAll(term.getSynonyms());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package vook.server.api.domain.vocabulary.service;

import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand Down Expand Up @@ -31,17 +32,17 @@ public Term create(@Valid TermCreateCommand command) {
return termRepository.save(term);
}

public Term getByUid(String uid) {
public Term getByUid(@NotBlank String uid) {
return termRepository.findByUid(uid).orElseThrow(TermNotFoundException::new);
}

public void update(TermUpdateCommand serviceCommand) {
public void update(@Valid TermUpdateCommand serviceCommand) {
Term term = termRepository.findByUid(serviceCommand.getUid()).orElseThrow(TermNotFoundException::new);
Term updateTerm = serviceCommand.toEntity();
term.update(updateTerm);
}

public void delete(String uid) {
public void delete(@NotBlank String uid) {
Term term = termRepository.findByUid(uid).orElseThrow(TermNotFoundException::new);
term.getVocabulary().removeTerm(term);
termRepository.delete(term);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package vook.server.api.domain.vocabulary.service.data;

import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
Expand Down Expand Up @@ -28,7 +29,9 @@ public class TermCreateCommand {
private String meaning;

@NotNull
private List<String> synonyms;
@Valid
@Size(max = 10)
private List<@Size(min = 1, max = 100) String> synonyms;

@Builder
private static TermCreateCommand of(String vocabularyUid, String term, String meaning, List<String> synonyms) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package vook.server.api.domain.vocabulary.service.data;

import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
Expand All @@ -24,7 +25,9 @@ public class TermUpdateCommand {
private String meaning;

@NotNull
private List<String> synonyms;
@Valid
@Size(max = 10)
private List<@Size(min = 1, max = 100) String> synonyms;

@Builder
private static TermUpdateCommand of(String uid, String term, String meaning, List<String> synonyms) {
Expand Down
12 changes: 7 additions & 5 deletions api/src/main/java/vook/server/api/web/term/TermApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public interface TermApi {
@SecurityRequirement(name = "AccessToken")
},
description = """
비즈니스 규칙 위반 내용
## 비즈니스 규칙 위반 내용

- VocabularyNotFound: 사용자의 용어집 중 해당 ID의 용어집이 존재하지 않는 경우
- TermLimitExceeded: 사용자의 용어집에 용어를 추가할 수 있는 제한을 초과한 경우
- NotValidVocabularyOwner: 용어를 추가하려는 용어집에 대한 권한이 없는 경우"""
Expand All @@ -52,11 +53,12 @@ class TermApiCreateResponse extends CommonApiResponse<TermCreateResponse> {
@SecurityRequirement(name = "AccessToken")
},
description = """
## 허용하는 sort 키워드
term, meaning, createdAt
## 허용하는 sort 키워드
term, synonym, meaning, createdAt

사용 예시
- term,asc
- synonym,desc
- meaning,desc
- createdAt,asc

Expand All @@ -83,7 +85,7 @@ class TermApiRetrieveResponse extends CommonApiResponse<TermResponse> {
@SecurityRequirement(name = "AccessToken")
},
description = """
비즈니스 규칙 위반 내용
## 비즈니스 규칙 위반 내용
- TermNotFound: 삭제하려는 용어가 존재하지 않는 경우
- NotValidVocabularyOwner: 조회하려는 용어가 속해있는 용어집에 대한 권한이 없는 경우"""
)
Expand All @@ -95,7 +97,7 @@ class TermApiRetrieveResponse extends CommonApiResponse<TermResponse> {
@SecurityRequirement(name = "AccessToken")
},
description = """
비즈니스 규칙 위반 내용
## 비즈니스 규칙 위반 내용
- TermNotFound: 삭제하려는 용어가 존재하지 않는 경우
- NotValidVocabularyOwner: 삭제하려는 용어가 속해있는 용어집에 대한 권한이 없는 경우"""
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package vook.server.api.web.term.reqres;

import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;
import lombok.Data;
Expand All @@ -23,7 +24,9 @@ public class TermCreateRequest {
@Size(min = 1, max = 2000)
private String meaning;

private List<String> synonyms = new ArrayList<>();
@Valid
@Size(max = 10)
private List<@Size(min = 1, max = 100) String> synonyms = new ArrayList<>();

public CreateTermUseCase.Command toCommand(VookLoginUser loginUser) {
return new CreateTermUseCase.Command(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package vook.server.api.web.term.reqres;

import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;
import lombok.Data;
Expand All @@ -20,7 +21,9 @@ public class TermUpdateRequest {
@Size(min = 1, max = 2000)
private String meaning;

private List<String> synonyms = new ArrayList<>();
@Valid
@Size(max = 10)
private List<@Size(min = 1, max = 100) String> synonyms = new ArrayList<>();

public UpdateTermUseCase.Command toCommand(VookLoginUser loginUser, String termUid) {
return new UpdateTermUseCase.Command(
Expand Down
6 changes: 3 additions & 3 deletions api/src/main/java/vook/server/api/web/user/UserApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class UserApiUserInfoResponse extends CommonApiResponse<UserInfoResponse> {
@SecurityRequirement(name = "AccessToken")
},
description = """
비즈니스 규칙 위반 내용
## 비즈니스 규칙 위반 내용
- AlreadyRegistered: 이미 회원가입이 완료된 유저가 해당 API를 호출 할 경우
- WithdrawnUser: 탈퇴한 유저가 해당 API를 호출 할 경우"""
)
Expand All @@ -70,7 +70,7 @@ class UserApiUserInfoResponse extends CommonApiResponse<UserInfoResponse> {
@SecurityRequirement(name = "AccessToken")
},
description = """
비즈니스 규칙 위반 내용
## 비즈니스 규칙 위반 내용
- NotReadyToOnboarding: 회원 가입이 완료되지 않은 유저가 해당 API를 호출 할 경우
- AlreadyOnboarding: 이미 온보딩이 완료된 유저가 해당 API를 호출 할 경우"""
)
Expand All @@ -95,7 +95,7 @@ class UserApiUserInfoResponse extends CommonApiResponse<UserInfoResponse> {
@SecurityRequirement(name = "AccessToken")
},
description = """
비즈니스 규칙 위반 내용
## 비즈니스 규칙 위반 내용
- NotRegistered: 가입하지 않은 유저가 해당 API를 호출 할 경우"""
)
@ApiResponses(value = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class VocabularyApiVocabulariesResponse extends CommonApiResponse<List<Vocabular
@SecurityRequirement(name = "AccessToken")
},
description = """
비즈니스 규칙 위반 내용
## 비즈니스 규칙 위반 내용
- VocabularyLimitExceeded: 사용자의 용어집 생성 제한을 초과하여 용어집을 생성할 수 없는 경우 (3개 초과)"""
)
@ApiResponses(value = {
Expand All @@ -70,7 +70,7 @@ class VocabularyApiVocabulariesResponse extends CommonApiResponse<List<Vocabular
@SecurityRequirement(name = "AccessToken")
},
description = """
비즈니스 규칙 위반 내용
## 비즈니스 규칙 위반 내용
- VocabularyNotFound: 사용자의 용어집 중 해당 ID의 용어집이 존재하지 않는 경우"""
)
@ApiResponses(value = {
Expand Down Expand Up @@ -98,7 +98,7 @@ CommonApiResponse<Void> updateVocabulary(
@SecurityRequirement(name = "AccessToken")
},
description = """
비즈니스 규칙 위반 내용
## 비즈니스 규칙 위반 내용
- VocabularyNotFound: 사용자의 용어집 중 해당 ID의 용어집이 존재하지 않는 경우"""
)
@ApiResponses(value = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public Term createTerm(Vocabulary vocabulary, String suffix) {
.vocabularyUid(vocabulary.getUid())
.term("testTerm" + suffix)
.meaning("testMeaning" + suffix)
.synonyms(List.of("testSynonym" + suffix))
.synonyms(List.of("testSynonymA" + suffix, "testSynonymB" + suffix))
.build());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ void execute() {
Term term = termRepository.findByUid(result.uid()).orElseThrow();
assertThat(term.getTerm()).isEqualTo(command.term());
assertThat(term.getMeaning()).isEqualTo(command.meaning());
assertThat(term.getSynonym()).isEqualTo(String.join(",", command.synonyms()));
assertThat(term.getSynonyms().stream().map(TermSynonym::getSynonym))
.containsExactlyInAnyOrderElementsOf(command.synonyms());
assertThat(term.getVocabulary().termCount()).isEqualTo(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,34 @@ Collection<DynamicTest> executeSort() {
PageRequest.of(0, Integer.MAX_VALUE, Sort.Direction.DESC, "createdAt")
));

// then
assertThat(result.terms().getContent()).hasSize(3);
assertThat(result.terms().getContent().get(0).termUid()).isEqualTo(term3.getUid());
assertThat(result.terms().getContent().get(1).termUid()).isEqualTo(term2.getUid());
assertThat(result.terms().getContent().get(2).termUid()).isEqualTo(term1.getUid());
}),
DynamicTest.dynamicTest("동의어 오름차순", () -> {
// when
RetrieveTermUseCase.Result result = useCase.execute(new RetrieveTermUseCase.Command(
user.getUid(),
vocabulary.getUid(),
PageRequest.of(0, Integer.MAX_VALUE, Sort.Direction.ASC, "synonym")
));

// then
assertThat(result.terms().getContent()).hasSize(3);
assertThat(result.terms().getContent().get(0).termUid()).isEqualTo(term1.getUid());
assertThat(result.terms().getContent().get(1).termUid()).isEqualTo(term2.getUid());
assertThat(result.terms().getContent().get(2).termUid()).isEqualTo(term3.getUid());
}),
DynamicTest.dynamicTest("동의어 내림차순", () -> {
// when
RetrieveTermUseCase.Result result = useCase.execute(new RetrieveTermUseCase.Command(
user.getUid(),
vocabulary.getUid(),
PageRequest.of(0, Integer.MAX_VALUE, Sort.Direction.DESC, "synonym")
));

// then
assertThat(result.terms().getContent()).hasSize(3);
assertThat(result.terms().getContent().get(0).termUid()).isEqualTo(term3.getUid());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ void execute() {
assertThat(updatedTerm.getTerm()).isEqualTo(command.term());
assertThat(updatedTerm.getMeaning()).isEqualTo(command.meaning());
assertThat(updatedTerm.getSynonyms()).isEmpty();
assertThat(updatedTerm.getSynonym()).isEmpty();
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion cicd/dagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@
}
],
"source": "dagger",
"engineVersion": "v0.11.8"
"engineVersion": "v0.11.9"
}