-
Notifications
You must be signed in to change notification settings - Fork 13
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
[feature/#209] 정책 관련 API 구현 #210
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a6e8a76
[feature/#209] policy 관련 entity, dto 생성
whitem4rk 5a020fe
[feature/#209] policy 관련 controller, service 생성
whitem4rk 8c5f73d
[feature/#209] policy 관련 entity, dto test code
whitem4rk 5d157df
[feature/#209] policy 관련 service, controller test code
whitem4rk b8ddc04
[feature/#209] policy 관련 보안설정
whitem4rk 32e568a
[feature/#209] test 간단한 수정
whitem4rk 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
40 changes: 40 additions & 0 deletions
40
resource-server/src/main/java/com/inhabas/api/domain/policy/domain/PolicyTerm.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,40 @@ | ||
package com.inhabas.api.domain.policy.domain; | ||
|
||
import com.inhabas.api.domain.BaseEntity; | ||
import com.inhabas.api.domain.board.domain.valueObject.Content; | ||
import com.inhabas.api.domain.policy.dto.SavePolicyTernDto; | ||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import javax.persistence.*; | ||
|
||
@Entity | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Table(name = "POLICY_TERM") | ||
@Getter | ||
public class PolicyTerm extends BaseEntity { | ||
|
||
@Id | ||
@GeneratedValue | ||
private Long id; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY, optional = false) | ||
@JoinColumn(name = "POLICY_TYPE_ID") | ||
private PolicyType policyType; | ||
|
||
@Embedded | ||
private Content content; | ||
|
||
@Builder | ||
public PolicyTerm(PolicyType policyType, String content) { | ||
this.policyType = policyType; | ||
this.content = new Content(content); | ||
} | ||
|
||
public void updatePolicyTerm(SavePolicyTernDto savePolicyTernDto) { | ||
this.content = new Content(savePolicyTernDto.getContent()); | ||
} | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
resource-server/src/main/java/com/inhabas/api/domain/policy/domain/PolicyType.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,26 @@ | ||
package com.inhabas.api.domain.policy.domain; | ||
|
||
import com.inhabas.api.domain.board.domain.valueObject.Title; | ||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import javax.persistence.*; | ||
|
||
@Entity | ||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class PolicyType { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@Column(name = "TITLE") | ||
private Title title; | ||
|
||
public PolicyType(String title) { | ||
this.title = new Title(title); | ||
} | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
resource-server/src/main/java/com/inhabas/api/domain/policy/dto/PolicyTermDto.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,25 @@ | ||
package com.inhabas.api.domain.policy.dto; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import javax.validation.constraints.NotNull; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
public class PolicyTermDto { | ||
|
||
@NotNull | ||
private String title; | ||
|
||
@NotNull | ||
private String content; | ||
|
||
@Builder | ||
public PolicyTermDto(String title, String content) { | ||
this.title = title; | ||
this.content = content; | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
resource-server/src/main/java/com/inhabas/api/domain/policy/dto/SavePolicyTernDto.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,21 @@ | ||
package com.inhabas.api.domain.policy.dto; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import javax.validation.constraints.NotNull; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
public class SavePolicyTernDto { | ||
|
||
@NotNull | ||
private String content; | ||
|
||
@Builder | ||
public SavePolicyTernDto(String content) { | ||
this.content = content; | ||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
...-server/src/main/java/com/inhabas/api/domain/policy/respository/PolicyTermRepository.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.inhabas.api.domain.policy.respository; | ||
|
||
import com.inhabas.api.domain.policy.domain.PolicyTerm; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface PolicyTermRepository extends JpaRepository<PolicyTerm, Long> { | ||
} |
12 changes: 12 additions & 0 deletions
12
resource-server/src/main/java/com/inhabas/api/domain/policy/usecase/PolicyTermService.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.inhabas.api.domain.policy.usecase; | ||
|
||
import com.inhabas.api.domain.policy.dto.PolicyTermDto; | ||
import com.inhabas.api.domain.policy.dto.SavePolicyTernDto; | ||
|
||
public interface PolicyTermService { | ||
|
||
PolicyTermDto findPolicyTerm(Long policyTermId); | ||
|
||
void updatePolicyTerm(Long policyTermId, SavePolicyTernDto savePolicyTernDto); | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
...rce-server/src/main/java/com/inhabas/api/domain/policy/usecase/PolicyTermServiceImpl.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,40 @@ | ||
package com.inhabas.api.domain.policy.usecase; | ||
|
||
import com.inhabas.api.auth.domain.error.businessException.NotFoundException; | ||
import com.inhabas.api.domain.policy.domain.PolicyTerm; | ||
import com.inhabas.api.domain.policy.dto.PolicyTermDto; | ||
import com.inhabas.api.domain.policy.dto.SavePolicyTernDto; | ||
import com.inhabas.api.domain.policy.respository.PolicyTermRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class PolicyTermServiceImpl implements PolicyTermService{ | ||
|
||
private final PolicyTermRepository policyTermRepository; | ||
|
||
@Override | ||
@Transactional(readOnly = true) | ||
public PolicyTermDto findPolicyTerm(Long policyTermId) { | ||
|
||
PolicyTerm policyTerm = policyTermRepository.findById(policyTermId).orElseThrow(NotFoundException::new); | ||
|
||
return PolicyTermDto.builder() | ||
.title(policyTerm.getPolicyType().getTitle().getValue()) | ||
.content(policyTerm.getContent().getValue()) | ||
.build(); | ||
|
||
} | ||
|
||
@Override | ||
@Transactional | ||
public void updatePolicyTerm(Long policyTermId, SavePolicyTernDto savePolicyTernDto) { | ||
|
||
PolicyTerm policyTerm = policyTermRepository.findById(policyTermId).orElseThrow(NotFoundException::new); | ||
policyTerm.updatePolicyTerm(savePolicyTernDto); | ||
|
||
} | ||
|
||
} |
82 changes: 82 additions & 0 deletions
82
resource-server/src/main/java/com/inhabas/api/web/PolicyTermController.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,82 @@ | ||
package com.inhabas.api.web; | ||
|
||
import com.inhabas.api.auth.domain.error.ErrorResponse; | ||
import com.inhabas.api.domain.policy.dto.PolicyTermDto; | ||
import com.inhabas.api.domain.policy.dto.SavePolicyTernDto; | ||
import com.inhabas.api.domain.policy.usecase.PolicyTermService; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.media.Content; | ||
import io.swagger.v3.oas.annotations.media.ExampleObject; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
import io.swagger.v3.oas.annotations.security.SecurityRequirements; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import javax.validation.Valid; | ||
|
||
@Tag(name = "정책 관리") | ||
@RestController | ||
@RequiredArgsConstructor | ||
public class PolicyTermController { | ||
|
||
private final PolicyTermService policyTermService; | ||
|
||
@GetMapping("/policy/{policyTermId}") | ||
@SecurityRequirements(value = {}) | ||
@Operation(summary = "해당 정책을 조회한다.", | ||
description = "policyTermId는 1,2,3만 존재") | ||
@ApiResponses({ | ||
@ApiResponse(responseCode = "200", content = @Content( | ||
schema = @Schema(implementation = PolicyTermDto.class) | ||
)), | ||
@ApiResponse(responseCode = "400 ", description = "입력값이 없거나, 타입이 유효하지 않습니다.", content = @Content( | ||
schema = @Schema(implementation = ErrorResponse.class), | ||
examples = @ExampleObject( | ||
value = "{\"status\": 400, \"code\": \"G003\", \"message\": \"입력값이 없거나, 타입이 유효하지 않습니다.\"}" | ||
) | ||
)), | ||
@ApiResponse(responseCode = "404", description = "데이터가 존재하지 않습니다.", content = @Content( | ||
schema = @Schema(implementation = ErrorResponse.class), | ||
examples = @ExampleObject( | ||
value = "{\"status\": 404, \"code\": \"G004\", \"message\": \"데이터가 존재하지 않습니다.\"}" | ||
) | ||
)) | ||
}) | ||
public ResponseEntity<PolicyTermDto> findPolicyTerm(@PathVariable Long policyTermId) { | ||
|
||
PolicyTermDto policyTermDto = policyTermService.findPolicyTerm(policyTermId); | ||
return ResponseEntity.ok(policyTermDto); | ||
|
||
} | ||
|
||
@PutMapping("/policy/{policyTermId}") | ||
@Operation(summary = "해당 정책을 수정한다.", | ||
description = "policyTermId는 1,2,3만 존재") | ||
@ApiResponses({ | ||
@ApiResponse(responseCode = "204"), | ||
@ApiResponse(responseCode = "400 ", description = "입력값이 없거나, 타입이 유효하지 않습니다.", content = @Content( | ||
schema = @Schema(implementation = ErrorResponse.class), | ||
examples = @ExampleObject( | ||
value = "{\"status\": 400, \"code\": \"G003\", \"message\": \"입력값이 없거나, 타입이 유효하지 않습니다.\"}" | ||
) | ||
)), | ||
@ApiResponse(responseCode = "404", description = "데이터가 존재하지 않습니다.", content = @Content( | ||
schema = @Schema(implementation = ErrorResponse.class), | ||
examples = @ExampleObject( | ||
value = "{\"status\": 404, \"code\": \"G004\", \"message\": \"데이터가 존재하지 않습니다.\"}" | ||
) | ||
)) | ||
}) | ||
public ResponseEntity<PolicyTermDto> updatePolicyTerm(@PathVariable Long policyTermId, | ||
@Valid @RequestBody SavePolicyTernDto savePolicyTernDto) { | ||
|
||
policyTermService.updatePolicyTerm(policyTermId, savePolicyTernDto); | ||
return ResponseEntity.noContent().build(); | ||
|
||
} | ||
|
||
} |
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
40 changes: 40 additions & 0 deletions
40
resource-server/src/test/java/com/inhabas/api/domain/policy/domain/PolicyTermTest.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,40 @@ | ||
package com.inhabas.api.domain.policy.domain; | ||
|
||
import com.inhabas.api.auth.domain.error.businessException.InvalidInputException; | ||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class PolicyTermTest { | ||
|
||
@DisplayName("Content는 null 일 수 없다.") | ||
@Test | ||
void Content_Notnull() { | ||
//given | ||
PolicyType policyType = new PolicyType("goodTitle"); | ||
String nullString = null; | ||
|
||
//then | ||
Assertions.assertThatThrownBy(() -> new PolicyTerm(policyType, nullString)) | ||
.isInstanceOf(InvalidInputException.class) | ||
.hasMessage("입력값이 없거나, 타입이 유효하지 않습니다."); | ||
|
||
} | ||
|
||
@DisplayName("올바른 PolicyTerm을 생성한다.") | ||
@Test | ||
void createPolicyTerm() { | ||
//given | ||
PolicyType policyType = new PolicyType("goodTitle"); | ||
String goodContent = "goodContent"; | ||
|
||
//when | ||
PolicyTerm policyTerm = new PolicyTerm(policyType, goodContent); | ||
|
||
|
||
//then | ||
Assertions.assertThat(policyTerm.getContent().getValue()).isEqualTo(goodContent); | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.
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.
혹시 이 테스트 성공했는지 궁금합니다. InvalidInputException.class 가 생겼을 때 한국어로 "입력값이 없거나, 타입이 유효하지 않습니다" 라고 나오나요?
왜냐하면 보통 기본 오류들은 영어로 나오는거로 알고 있어서요!
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.
이 테스트 실행해서 통과한거면 상관은 없습니다!
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.
errorhandler로 저렇게 동작하도록 했어.
ExceptionController
관련 코드 참고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.
@whitem4rk 확인했습니다. 감사합니다!