-
Notifications
You must be signed in to change notification settings - Fork 3
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
1 parent
fa79797
commit 51744d3
Showing
11 changed files
with
306 additions
and
35 deletions.
There are no files selected for viewing
86 changes: 86 additions & 0 deletions
86
src/main/java/com/t3t/bookstoreapi/member/controller/MemberGradeController.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,86 @@ | ||
package com.t3t.bookstoreapi.member.controller; | ||
|
||
import com.t3t.bookstoreapi.member.model.dto.MemberGradeDto; | ||
import com.t3t.bookstoreapi.member.model.dto.MemberGradePolicyDto; | ||
import com.t3t.bookstoreapi.member.model.entity.MemberGrade; | ||
import com.t3t.bookstoreapi.member.model.request.CreateMemberGradePolicyRequest; | ||
import com.t3t.bookstoreapi.member.model.request.MemberGradeCreationRequest; | ||
import com.t3t.bookstoreapi.member.model.response.MemberGradePolicyResponse; | ||
import com.t3t.bookstoreapi.member.service.MemberGradeService; | ||
import com.t3t.bookstoreapi.model.response.BaseResponse; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.List; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
public class MemberGradeController { | ||
private final MemberGradeService memberGradeService; | ||
@GetMapping("/admin/member-grades") | ||
public ResponseEntity<BaseResponse<List<MemberGradeDto>>> getMemberGradeList() { | ||
List<MemberGradeDto> memberGradePolicyList = memberGradeService.getMemberGradeList(); | ||
return ResponseEntity.ok(new BaseResponse<List<MemberGradeDto>>().data(memberGradePolicyList)); | ||
} | ||
|
||
/** | ||
* 특정 ID를 기반으로 한 회원 등급 정책 조회 | ||
* @param policyId 조회할 회원 등급 정책의 ID | ||
* @return 조회된 회원 등급 정책을 포함한 BaseResponse 객체 반환 | ||
* | ||
* @author hydrationn(박수화) | ||
*/ | ||
@GetMapping("/admin/member-grade-policies/{policyId}") | ||
public ResponseEntity<BaseResponse<MemberGradeDto>> getMemberGrade(@PathVariable("policyId") Long policyId) { | ||
MemberGradeDto memberGrade = memberGradeService.getMemberGrade(policyId); | ||
return ResponseEntity.ok(new BaseResponse<MemberGradeDto>().data(memberGrade)); | ||
} | ||
|
||
/** | ||
* 새로운 회원 등급 정책 생성 | ||
* @param request 생성할 회원 등급 정책의 정보를 담은 요청 객체 | ||
* @return 생성된 회원 등급 정책을 포함한 BaseResponse 객체 반환 | ||
* | ||
* @author hydrationn(박수화) | ||
*/ | ||
@PostMapping("/admin/member-grade-policy") | ||
public ResponseEntity<BaseResponse<MemberGradeDto>> createMemberGrade(@RequestBody MemberGradeCreationRequest request) { | ||
MemberGradeDto memberGrade = memberGradeService.createMemberGrade(request); | ||
return ResponseEntity.ok(new BaseResponse<MemberGradeDto>().data(memberGrade)); | ||
} | ||
|
||
/** | ||
* 기존의 회원 등급 정책 업데이트 | ||
* @param policyId 업데이트할 회원 등급 정책의 ID | ||
* @param startAmount 기준 시작 금액 | ||
* @param endAmount 기준 종료 금액 | ||
* @param rate 포인트 적립 비율 | ||
* @return 업데이트된 회원 등급 정책을 포함한 BaseResponse 객체 반환 | ||
* | ||
* @author hydrationn(박수화) | ||
*/ | ||
@PutMapping("/admin/member-grade-policy/{policyId}/default") | ||
public ResponseEntity<BaseResponse<Void>> updateMemberGrade(@PathVariable("policyId") Long policyId, | ||
@RequestParam("startAmount") BigDecimal startAmount, | ||
@RequestParam("endAmount") BigDecimal endAmount, | ||
@RequestParam("rate") int rate) { | ||
memberGradeService.updateMemberGrade(policyId, startAmount, endAmount, rate); | ||
return ResponseEntity.ok(new BaseResponse<Void>().message("회원 등급 정책 업데이트 요청이 정상적으로 처리되었습니다. ")); | ||
} | ||
|
||
/** | ||
* 특정 ID를 가진 회원 등급 정책 삭제 | ||
* @param policyId 삭제할 회원 등급 정책의 ID | ||
* @return 삭제 성공 메시지를 포함한 BaseResponse 객체 반환 | ||
* | ||
* @author hydrationn(박수화) | ||
*/ | ||
@DeleteMapping("/admin/member-grade-policy/{policyId}") | ||
public ResponseEntity<BaseResponse<Void>> deleteMemberGradePolicy(@PathVariable("policyId") Long policyId) { | ||
memberGradeService.deleteMemberGrade(policyId); | ||
return ResponseEntity.status(HttpStatus.NO_CONTENT).body(new BaseResponse<Void>().message("회원 등급 정책 삭제 요청이 성공적으로 처리되었습니다. ")); | ||
} | ||
} |
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
22 changes: 22 additions & 0 deletions
22
src/main/java/com/t3t/bookstoreapi/member/model/dto/MemberGradeDto.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,22 @@ | ||
package com.t3t.bookstoreapi.member.model.dto; | ||
|
||
import com.t3t.bookstoreapi.member.model.entity.MemberGrade; | ||
import com.t3t.bookstoreapi.member.model.entity.MemberGradePolicy; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@Builder | ||
public class MemberGradeDto { | ||
private int gradeId; | ||
private String name; | ||
private MemberGradePolicy policy; | ||
|
||
public static MemberGradeDto of(MemberGrade memberGrade) { | ||
return MemberGradeDto.builder() | ||
.gradeId(memberGrade.getGradeId()) | ||
.name(memberGrade.getName()) | ||
.policy(memberGrade.getPolicy()) | ||
.build(); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/com/t3t/bookstoreapi/member/model/request/MemberGradeCreationRequest.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,18 @@ | ||
package com.t3t.bookstoreapi.member.model.request; | ||
|
||
import com.t3t.bookstoreapi.member.model.entity.MemberGradePolicy; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Builder | ||
public class MemberGradeCreationRequest { | ||
|
||
private int gradeId; | ||
private String name; | ||
private MemberGradePolicy policy; | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/com/t3t/bookstoreapi/member/model/response/MemberGradePolicyResponse.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,27 @@ | ||
package com.t3t.bookstoreapi.member.model.response; | ||
|
||
import com.t3t.bookstoreapi.member.model.entity.MemberGradePolicy; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.math.BigDecimal; | ||
|
||
@Data | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class MemberGradePolicyResponse { | ||
private BigDecimal startAmount; | ||
private BigDecimal endAmount; | ||
private int rate; | ||
|
||
public static MemberGradePolicyResponse of(MemberGradePolicy memberGradePolicy) { | ||
return MemberGradePolicyResponse.builder() | ||
.startAmount(memberGradePolicy.getStartAmount()) | ||
.endAmount(memberGradePolicy.getEndAmount()) | ||
.rate(memberGradePolicy.getRate()) | ||
.build(); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/com/t3t/bookstoreapi/member/model/response/MemberGradeResponse.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,22 @@ | ||
package com.t3t.bookstoreapi.member.model.response; | ||
|
||
import com.t3t.bookstoreapi.member.model.entity.MemberGradePolicy; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import org.hibernate.annotations.Comment; | ||
|
||
import javax.persistence.FetchType; | ||
import javax.persistence.JoinColumn; | ||
import javax.persistence.ManyToOne; | ||
|
||
@Data | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class MemberGradeResponse { | ||
|
||
private String name; | ||
private MemberGradePolicy policy; | ||
} |
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
9 changes: 9 additions & 0 deletions
9
src/main/java/com/t3t/bookstoreapi/member/repository/MemberGradeRepository.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 |
---|---|---|
@@ -1,10 +1,19 @@ | ||
package com.t3t.bookstoreapi.member.repository; | ||
|
||
import com.t3t.bookstoreapi.member.model.entity.MemberGrade; | ||
import com.t3t.bookstoreapi.member.model.entity.MemberGradePolicy; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public interface MemberGradeRepository extends JpaRepository<MemberGrade, Integer> { | ||
Optional<MemberGrade> findByName(String name); | ||
|
||
@Query("SELECT m.policy FROM MemberGrade m JOIN FETCH MemberGradePolicy mg WHERE m.policy.policyId = mg.policyId") | ||
List<MemberGrade> findAll(); | ||
|
||
@Query("SELECT m.policy FROM MemberGrade m JOIN FETCH MemberGradePolicy mg WHERE m.policy.policyId = mg.policyId") | ||
Optional<MemberGrade> findByPolicyId(Long policyId); | ||
} |
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
Oops, something went wrong.