Skip to content

Commit

Permalink
�[COT-166] Feature: 회원 탈퇴 정책 조회 API 구현 (#272)
Browse files Browse the repository at this point in the history
* feat: 정책 종류 필드 추가

* feat: 정책 조회 API 구현
  • Loading branch information
Youthhing committed Jan 22, 2025
1 parent 58aba66 commit bd2c711
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
package org.cotato.csquiz.api.policy.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.cotato.csquiz.api.policy.dto.CheckMemberPoliciesRequest;
import org.cotato.csquiz.api.policy.dto.FindMemberPolicyResponse;
import org.cotato.csquiz.api.policy.dto.PoliciesResponse;
import org.cotato.csquiz.domain.auth.entity.Member;
import org.cotato.csquiz.domain.auth.enums.PolicyCategory;
import org.cotato.csquiz.domain.auth.service.PolicyService;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "회원 정책 API")
Expand All @@ -39,9 +42,16 @@ public ResponseEntity<Void> checkPolicies(@RequestBody @Valid CheckMemberPolicie
return ResponseEntity.noContent().build();
}

@Deprecated(since = "회원 탈퇴 기능 작업 이후")
@Operation(summary = "회원 가입 시 보여줘야 할 정책 목록 반환 API")
@GetMapping
public ResponseEntity<PoliciesResponse> getPolicies() {
return ResponseEntity.ok().body(policyService.findPolicies());
}

@Operation(summary = "특정 카테고리에 맞는 정책 목록 반환 API")
@GetMapping(params = "category")
public ResponseEntity<PoliciesResponse> getPolicies(@RequestParam PolicyCategory category) {
return ResponseEntity.ok().body(policyService.findPolicies(category));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.cotato.csquiz.common.entity.BaseTimeEntity;
import org.cotato.csquiz.domain.auth.enums.PolicyCategory;
import org.cotato.csquiz.domain.auth.enums.PolicyType;
import org.hibernate.annotations.ColumnDefault;
import org.hibernate.annotations.DynamicInsert;
Expand All @@ -31,6 +32,10 @@ public class Policy extends BaseTimeEntity {
@ColumnDefault(value = "'ESSENTIAL'")
private PolicyType policyType;

@Column(name = "policy_category", nullable = false)
@Enumerated(EnumType.STRING)
private PolicyCategory category;

@Column(name = "policy_title", nullable = false)
private String title;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.cotato.csquiz.domain.auth.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public enum PolicyCategory {
PERSONAL_INFORMATION("개인정보 관련된 정책"),
LEAVING("회원 탈퇴 시 필요한 정책"),
;

private final String description;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

import java.util.List;
import org.cotato.csquiz.domain.auth.entity.Policy;
import org.cotato.csquiz.domain.auth.enums.PolicyCategory;
import org.cotato.csquiz.domain.auth.enums.PolicyType;
import org.springframework.data.jpa.repository.JpaRepository;

public interface PolicyRepository extends JpaRepository<Policy, Long> {
List<Policy> findAllByPolicyType(PolicyType policyType);

List<Policy> findAllByIdIn(List<Long> ids);

List<Policy> findAllByCategory(PolicyCategory category);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.cotato.csquiz.domain.auth.entity.Member;
import org.cotato.csquiz.domain.auth.entity.MemberPolicy;
import org.cotato.csquiz.domain.auth.entity.Policy;
import org.cotato.csquiz.domain.auth.enums.PolicyCategory;
import org.cotato.csquiz.domain.auth.enums.PolicyType;
import org.cotato.csquiz.domain.auth.repository.MemberPolicyRepository;
import org.cotato.csquiz.domain.auth.repository.PolicyRepository;
Expand Down Expand Up @@ -104,4 +105,11 @@ public PoliciesResponse findPolicies() {
.toList();
return new PoliciesResponse(policies);
}

public PoliciesResponse findPolicies(PolicyCategory category) {
List<PolicyInfoResponse> policies = policyRepository.findAllByCategory(category).stream()
.map(PolicyInfoResponse::from)
.toList();
return new PoliciesResponse(policies);
}
}

0 comments on commit bd2c711

Please sign in to comment.