-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
17 changed files
with
721 additions
and
2 deletions.
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.