Skip to content

Commit

Permalink
Change endpoints
Browse files Browse the repository at this point in the history
Change `/v1/payment/shop/info` to `/v1/shop/info/:shopId`
Change `/v1/payment/shop/withdrawal` to `/v1/shop/withdrawal/:shopId`
Change `/v1/payment/convert/currency` to `/v1/currency/convert`
Remove `/v1/payment/phone/hash` Use `/v1/phone/hash/:phone`
  • Loading branch information
MichaelKim20 committed May 21, 2024
1 parent 5cbaca7 commit 374605b
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 31 deletions.
6 changes: 3 additions & 3 deletions packages/relay/docs/loyalty-payment.md
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@

#### - HTTP Request

`GET /v1/payment/shop/info`
`GET /v1/shop/info/:shopId`

#### - 입력 파라메타들

Expand Down Expand Up @@ -317,7 +317,7 @@

#### - HTTP Request

`GET /v1/payment/shop/withdrawal`
`GET /v1/shop/withdrawal/:shopId`

#### - 입력 파라메타들

Expand Down Expand Up @@ -385,7 +385,7 @@

#### - HTTP Request

`GET /v1/payment/convert/currency`
`GET /v1/currency/convert`

#### - 입력 파라메타들

Expand Down
28 changes: 0 additions & 28 deletions packages/relay/src/routers/PaymentRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ export class PaymentRouter {
this.phone_balance.bind(this)
);

this.app.get("/v1/payment/phone/hash", [query("phone")], this.phone_hash.bind(this));

this.app.get(
"/v1/payment/convert/currency",
[query("amount").exists().custom(Validation.isAmount), query("from").exists(), query("to").exists()],
Expand Down Expand Up @@ -318,32 +316,6 @@ export class PaymentRouter {
}
}

/**
* 사용자 정보 / 전화번호 해시
* GET /v1/payment/phone/hash
* @private
*/
private async phone_hash(req: express.Request, res: express.Response) {
logger.http(`GET /v1/payment/phone/hash ${req.ip}:${JSON.stringify(req.query)}`);

const errors = validationResult(req);
if (!errors.isEmpty()) {
return res.status(200).json(ResponseMessage.getErrorMessage("2001", { validation: errors.array() }));
}

try {
const phone: string = String(req.query.phone).trim();
const hash: string = ContractUtils.getPhoneHash(phone);
this.metrics.add("success", 1);
return res.status(200).json(this.makeResponseData(0, { phone, hash }));
} catch (error: any) {
const msg = ResponseMessage.getEVMErrorMessage(error);
logger.error(`GET /v1/payment/phone/hash : ${msg.error.message}`);
this.metrics.add("failure", 1);
return res.status(200).json(this.makeResponseData(msg.code, undefined, msg.error));
}
}

/**
* 사용자 정보 / 로열티 종류와 잔고를 제공하는 엔드포인트
* GET /v1/payment/convert/currency
Expand Down
93 changes: 93 additions & 0 deletions packages/relay/src/routers/ShopRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { RelayStorage } from "../storage/RelayStorage";
import {
ContractShopStatus,
ContractShopUpdateEvent,
ContractWithdrawStatus,
MobileType,
ShopTaskData,
ShopTaskStatus,
Expand Down Expand Up @@ -250,6 +251,26 @@ export class ShopRouter {
[query("pageNumber").exists().trim().isNumeric(), query("pageSize").exists().trim().isNumeric()],
this.shop_list.bind(this)
);
this.app.get(
"/v1/shop/info/:shopId",
[
param("shopId")
.exists()
.trim()
.matches(/^(0x)[0-9a-f]{64}$/i),
],
this.shop_info.bind(this)
);
this.app.get(
"/v1/shop/withdrawal/:shopId",
[
param("shopId")
.exists()
.trim()
.matches(/^(0x)[0-9a-f]{64}$/i),
],
this.shop_withdrawal.bind(this)
);
}

private async getNonce(req: express.Request, res: express.Response) {
Expand Down Expand Up @@ -1270,4 +1291,76 @@ export class ShopRouter {
return res.status(200).json(this.makeResponseData(msg.code, undefined, msg.error));
}
}
/**
* 상점 정보 / 상점의 기본적인 정보를 제공하는 엔드포인트
* GET /v1/shop/info/:shopId
* @private
*/
private async shop_info(req: express.Request, res: express.Response) {
logger.http(`GET /v1/shop/info/:shopId ${req.ip}:${JSON.stringify(req.params)}`);

const errors = validationResult(req);
if (!errors.isEmpty()) {
return res.status(200).json(ResponseMessage.getErrorMessage("2001", { validation: errors.array() }));
}

try {
const shopId: string = String(req.params.shopId).trim();
const info = await this.contractManager.sideShopContract.shopOf(shopId);

const shopInfo = {
shopId: info.shopId,
name: info.name,
currency: info.currency,
status: info.status,
account: info.account,
delegator: info.delegator,
providedAmount: info.providedAmount.toString(),
usedAmount: info.usedAmount.toString(),
settledAmount: info.settledAmount.toString(),
withdrawnAmount: info.withdrawnAmount.toString(),
};
this.metrics.add("success", 1);
return res.status(200).json(this.makeResponseData(0, shopInfo));
} catch (error: any) {
const msg = ResponseMessage.getEVMErrorMessage(error);
logger.error(`GET /v1/shop/info/:shopId : ${msg.error.message}`);
this.metrics.add("failure", 1);
return res.status(200).json(this.makeResponseData(msg.code, undefined, msg.error));
}
}

/**
* 상점 정보 / 상점의 기본적인 정보를 제공하는 엔드포인트
* GET /v1/shop/withdrawal/:shopId
* @private
*/
private async shop_withdrawal(req: express.Request, res: express.Response) {
logger.http(`GET /v1/shop/withdrawal/:shopId ${req.ip}:${JSON.stringify(req.params)}`);

const errors = validationResult(req);
if (!errors.isEmpty()) {
return res.status(200).json(ResponseMessage.getErrorMessage("2001", { validation: errors.array() }));
}

try {
const shopId: string = String(req.params.shopId).trim();
const info = await this.contractManager.sideShopContract.shopOf(shopId);

const status = info.withdrawData.status === ContractWithdrawStatus.CLOSE ? "Closed" : "Opened";
const shopWithdrawalInfo = {
shopId: info.shopId,
withdrawAmount: info.withdrawData.amount.toString(),
withdrawStatus: status,
};

this.metrics.add("success", 1);
return res.status(200).json(this.makeResponseData(0, shopWithdrawalInfo));
} catch (error: any) {
const msg = ResponseMessage.getEVMErrorMessage(error);
logger.error(`GET /v1/shop/withdrawal/:shopId : ${msg.error.message}`);
this.metrics.add("failure", 1);
return res.status(200).json(this.makeResponseData(msg.code, undefined, msg.error));
}
}
}

0 comments on commit 374605b

Please sign in to comment.