Skip to content

Commit

Permalink
✨ feat : 정산 내역 조회 및 계좌 등록, 조회 추가 #494
Browse files Browse the repository at this point in the history
  • Loading branch information
hobeen-kim committed Sep 26, 2023
1 parent 2c5fca3 commit d139302
Show file tree
Hide file tree
Showing 36 changed files with 1,464 additions and 41 deletions.
5 changes: 4 additions & 1 deletion Server/src/docs/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ include::overview.adoc[]
=== Order API
* link:snippets/order/createorder.html[주문 생성/요청 API, onclick="window.location.href='snippets/order/createorder.html'"]
* link:snippets/order/cancelorder.html[주문 전체/개별 취소 API, onclick="window.location.href='snippets/order/cancelorder.html'"]
* link:snippets/order/adjustment.html[주문 정산 API, onclick="window.location.href='snippets/order/adjustment.html'"]

=== Adjustment API
* link:snippets/adjustment/adjustment.html[비디오별 정산 내역/월 및 연도별 정산액 API, onclick="window.location.href='snippets/adjustment/adjustment.html'"]
* link:snippets/adjustment/account.html[계좌 조회 및 등록 API, onclick="window.location.href='snippets/adjustment/account.html'"]

=== Video API
* link:snippets/video/getvideo.html[비디오 조회 API, onclick="window.location.href='snippets/video/getvideo.html'"]
Expand Down
42 changes: 42 additions & 0 deletions Server/src/docs/asciidoc/snippets/adjustment/account.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
:doctype: book
:icons: font
:source-highlighter: highlightjs
:toc: left
:toclevels: 2
:sectlinks:
:docinfo: shared-head

[[Account]]
= 계좌 정보 API

== 계좌 조회
=== HTTP Request
include::{snippets}/adjustment/getaccount/http-request.adoc[]
==== Request Headers
include::{snippets}/adjustment/getaccount/request-headers.adoc[]
=== HTTP Response
include::{snippets}/adjustment/getaccount/http-response.adoc[]
==== Response Fields
include::{snippets}/adjustment/getaccount/response-fields.adoc[]

== 계좌 조회(계좌 미등록 시)
=== HTTP Request
include::{snippets}/adjustment/getaccountnull/http-request.adoc[]
==== Request Headers
include::{snippets}/adjustment/getaccountnull/request-headers.adoc[]
=== HTTP Response
include::{snippets}/adjustment/getaccountnull/http-response.adoc[]
==== Response Fields
include::{snippets}/adjustment/getaccountnull/response-fields.adoc[]

== 계좌 생성/수정 (put 요청입니다.)
=== HTTP Request
include::{snippets}/adjustment/calculateamount/http-request.adoc[]
==== Request Headers
include::{snippets}/adjustment/calculateamount/request-headers.adoc[]
==== Request Query Parameters
include::{snippets}/adjustment/calculateamount/request-parameters.adoc[]
=== HTTP Response
include::{snippets}/adjustment/calculateamount/http-response.adoc[]
==== Response Fields
include::{snippets}/adjustment/calculateamount/response-fields.adoc[]
51 changes: 51 additions & 0 deletions Server/src/docs/asciidoc/snippets/adjustment/adjustment.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
:doctype: book
:icons: font
:source-highlighter: highlightjs
:toc: left
:toclevels: 2
:sectlinks:
:docinfo: shared-head

[[Adjustment]]
= 정산 내역 API

IMPORTANT: month 를 null 로 주면 연도별 조회, year 을 null 로 주면 전체 조회

[[Adjustment-list]]
== 비디오별 정산 내역
=== HTTP Request
include::{snippets}/adjustment/adjustment/http-request.adoc[]
==== Request Headers
include::{snippets}/adjustment/adjustment/request-headers.adoc[]
==== Request Query Parameters
include::{snippets}/adjustment/adjustment/request-parameters.adoc[]
=== HTTP Response
include::{snippets}/adjustment/adjustment/http-response.adoc[]
==== Response Fields
include::{snippets}/adjustment/adjustment/response-fields.adoc[]

[[Adjustment-total]]
== 특정 월의 정산 총 금액 및 월별 정산 내역
=== HTTP Request
include::{snippets}/adjustment/calculateamount/http-request.adoc[]
==== Request Headers
include::{snippets}/adjustment/calculateamount/request-headers.adoc[]
==== Request Query Parameters
include::{snippets}/adjustment/calculateamount/request-parameters.adoc[]
=== HTTP Response
include::{snippets}/adjustment/calculateamount/http-response.adoc[]
==== Response Fields
include::{snippets}/adjustment/calculateamount/response-fields.adoc[]

[[Adjustment-totalyear]]
== 특정 연도의 정산 총 금액 및 월별 정산 내역
=== HTTP Request
include::{snippets}/adjustment/calculateamountyear/http-request.adoc[]
==== Request Headers
include::{snippets}/adjustment/calculateamountyear/request-headers.adoc[]
==== Request Query Parameters
include::{snippets}/adjustment/calculateamountyear/request-parameters.adoc[]
=== HTTP Response
include::{snippets}/adjustment/calculateamountyear/http-response.adoc[]
==== Response Fields
include::{snippets}/adjustment/calculateamountyear/response-fields.adoc[]
36 changes: 36 additions & 0 deletions Server/src/docs/asciidoc/snippets/adjustment/docinfo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<script>
function ready(callbackFunc) {
if (document.readyState !== 'loading') {
// Document is already ready, call the callback directly
callbackFunc();
} else if (document.addEventListener) {
// All modern browsers to register DOMContentLoaded
document.addEventListener('DOMContentLoaded', callbackFunc);
} else {
// Old IE browsers
document.attachEvent('onreadystatechange', function () {
if (document.readyState === 'complete') {
callbackFunc();
}
});
}
}

function openPopup(event) {

const target = event.target;
if (target.className !== "popup") {
return;
}

event.preventDefault();
const screenX = event.screenX;
const screenY = event.screenY;
window.open(target.href, target.text, `left=${screenX}, top=${screenY}, width=500, height=600, status=no, menubar=no, toolbar=no, resizable=no`);
}

ready(function () {
const el = document.getElementById("content");
el.addEventListener("click", event => openPopup(event), false);
});
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
:doctype: book
:icons: font

[[VideoStatus]]

include::{snippets}/common/enums/custom-response-fields-AdjustmentStatus.adoc[]
25 changes: 0 additions & 25 deletions Server/src/docs/asciidoc/snippets/order/adjustment.adoc

This file was deleted.

1 change: 0 additions & 1 deletion Server/src/main/java/com/server/ServerApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

@SpringBootApplication
@EnableJpaAuditing
@EnableBatchProcessing
@EnableScheduling
public class ServerApplication {

Expand Down
18 changes: 18 additions & 0 deletions Server/src/main/java/com/server/domain/account/domain/Account.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

import com.server.domain.member.entity.Member;
import com.server.global.entity.BaseEntity;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

import javax.persistence.*;

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Account extends BaseEntity {

@Id
Expand All @@ -23,4 +26,19 @@ public class Account extends BaseEntity {
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member_id")
private Member member;

private Account(String name, String account, String bank, Member member) {
this.name = name;
this.account = account;
this.bank = bank;
this.member = member;
}

public static Account createAccount(String name, String accountNumber, String bank, Member member) {
Account account = new Account(name, accountNumber, bank, member);

member.updateAccount(account);

return account;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.server.domain.account.repository;

import com.server.domain.account.domain.Account;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.Optional;

public interface AccountRepository extends JpaRepository<Account, Long> {

@Query("select a from Account a where a.member.memberId = :memberId")
Optional<Account> findByMemberId(Long memberId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package com.server.domain.adjustment.controller;

import com.server.domain.adjustment.controller.dto.request.AccountUpdateApiRequest;
import com.server.domain.adjustment.service.AdjustmentService;
import com.server.domain.adjustment.service.dto.response.AccountResponse;
import com.server.domain.adjustment.service.dto.response.ToTalAdjustmentResponse;
import com.server.domain.order.controller.dto.request.AdjustmentSort;
import com.server.domain.adjustment.service.dto.response.AdjustmentResponse;
import com.server.global.annotation.LoginId;
import com.server.global.exception.businessexception.orderexception.AdjustmentDateException;
import com.server.global.reponse.ApiPageResponse;
import com.server.global.reponse.ApiSingleResponse;
import org.springframework.data.domain.Page;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;

import javax.validation.Valid;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.Positive;
import java.net.URI;

@RestController
@RequestMapping("/adjustments")
@Validated
public class AdjustmentController {

private final AdjustmentService adjustmentService;

public AdjustmentController(AdjustmentService adjustmentService) {
this.adjustmentService = adjustmentService;
}

@GetMapping
public ResponseEntity<ApiPageResponse<AdjustmentResponse>> adjustment(
@RequestParam(defaultValue = "1") @Positive(message = "{validation.positive}") int page,
@RequestParam(defaultValue = "10") @Positive(message = "{validation.positive}") int size,
@RequestParam(required = false) @Min(value = 1) @Max(value = 12) Integer month,
@RequestParam(required = false) @Min(value = 2020) Integer year,
@RequestParam(defaultValue = "video-created-date") AdjustmentSort sort,
@LoginId Long loginMemberId) {

checkValidDate(month, year);

Page<AdjustmentResponse> response = adjustmentService.adjustment(loginMemberId, page - 1, size, month, year, sort.getSort());

return ResponseEntity.ok(ApiPageResponse.ok(response, getAdjustmentMessage(month, year)));
}

@GetMapping("/total-adjustment")
public ResponseEntity<ApiSingleResponse<ToTalAdjustmentResponse>> calculateAmount(
@RequestParam(required = false) @Min(value = 1) @Max(value = 12) Integer month,
@RequestParam(required = false) @Min(value = 2020) Integer year,
@LoginId Long loginMemberId) {

checkValidDate(month, year);

ToTalAdjustmentResponse total = adjustmentService.totalAdjustment(loginMemberId, month, year);

return ResponseEntity.ok(ApiSingleResponse.ok(total, getAdjustmentMessage(month, year)));
}

@GetMapping("/account")
public ResponseEntity<ApiSingleResponse<AccountResponse>> getAccount(
@LoginId Long loginMemberId) {

AccountResponse account = adjustmentService.getAccount(loginMemberId);

String message = account.getName().equals("계좌 정보가 없습니다.") ? "계좌 정보가 없습니다." : "계좌 정보 조회 성공";

return ResponseEntity.ok(ApiSingleResponse.ok(account, message));
}

@PutMapping("/account")
public ResponseEntity<ApiSingleResponse<Void>> updateAccount(
@RequestBody @Valid AccountUpdateApiRequest request,
@LoginId Long loginMemberId) {

adjustmentService.updateAccount(loginMemberId, request.toServiceRequest());

return ResponseEntity.noContent().build();
}

private void checkValidDate(Integer month, Integer year) {
if(month != null && year == null) {
throw new AdjustmentDateException();
}
}

private String getAdjustmentMessage(Integer month, Integer year) {
if(month == null && year == null) {
return "전체 정산 내역";
}

if(month != null && year != null) {
return year + "년 " + month + "월 정산 내역";
}

return year + "년 정산 내역";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.server.domain.adjustment.controller.dto.request;

import com.server.domain.adjustment.service.dto.request.AccountUpdateServiceRequest;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

@AllArgsConstructor
@Getter
@Builder
public class AccountUpdateApiRequest {

@NotBlank(message = "{validation.account.name.notBlank}")
private String name;
@NotBlank(message = "{validation.account.account.notBlank}")
private String account;
@NotBlank(message = "{validation.account.bank.notBlank}")
private String bank;

public AccountUpdateServiceRequest toServiceRequest() {
return AccountUpdateServiceRequest.builder()
.name(name)
.account(account)
.bank(bank)
.build();
}


}
Loading

0 comments on commit d139302

Please sign in to comment.