From 647e7643acbf2c6250e7573e799843b2dd0e75cb Mon Sep 17 00:00:00 2001 From: Nam Nguyen Date: Thu, 11 Jan 2024 00:59:09 +0700 Subject: [PATCH 1/2] feat: check withdraw cond api --- docs/docs.go | 155 ++++++++++++++++-- docs/swagger.json | 155 ++++++++++++++++-- docs/swagger.yaml | 110 +++++++++++-- go.mod | 2 +- go.sum | 2 + pkg/config/config.go | 11 ++ pkg/controller/controller.go | 3 + pkg/controller/withdrawal/check.go | 50 ++++++ pkg/controller/withdrawal/confirm.go | 27 +++ pkg/controller/withdrawal/new.go | 44 +++++ pkg/controller/withdrawal/request_transfer.go | 25 +++ pkg/handler/bankaccount/bank_account.go | 2 +- pkg/handler/handler.go | 3 + pkg/handler/icy/request/request.go | 10 ++ pkg/handler/metadata/interface.go | 1 + pkg/handler/metadata/metadata.go | 41 +++++ pkg/handler/metadata/request/request.go | 6 + pkg/handler/withdrawal/interface.go | 7 + pkg/handler/withdrawal/request/request.go | 10 ++ pkg/handler/withdrawal/withdraw.go | 81 +++++++++ pkg/model/withdrawal.go | 7 + pkg/routes/v1.go | 5 + pkg/routes/v1_test.go | 6 + pkg/store/bank/bank.go | 67 ++++++++ pkg/store/bank/interface.go | 15 ++ pkg/store/store.go | 3 + pkg/view/bank.go | 78 +++------ pkg/view/bank_account.go | 65 ++++++++ pkg/view/withdrawal.go | 21 +++ 29 files changed, 917 insertions(+), 95 deletions(-) create mode 100644 pkg/controller/withdrawal/check.go create mode 100644 pkg/controller/withdrawal/confirm.go create mode 100644 pkg/controller/withdrawal/new.go create mode 100644 pkg/controller/withdrawal/request_transfer.go create mode 100644 pkg/handler/icy/request/request.go create mode 100644 pkg/handler/withdrawal/interface.go create mode 100644 pkg/handler/withdrawal/request/request.go create mode 100644 pkg/handler/withdrawal/withdraw.go create mode 100644 pkg/model/withdrawal.go create mode 100644 pkg/store/bank/bank.go create mode 100644 pkg/store/bank/interface.go create mode 100644 pkg/view/bank_account.go create mode 100644 pkg/view/withdrawal.go diff --git a/docs/docs.go b/docs/docs.go index 63eae4caa..77c64ba51 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -274,6 +274,56 @@ const docTemplate = `{ } } }, + "/banks": { + "get": { + "description": "Get all bank by given filter params", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Metadata" + ], + "summary": "Get all banks", + "operationId": "getBanksList", + "parameters": [ + { + "type": "string", + "description": "Bank ID", + "name": "id", + "in": "query" + }, + { + "type": "string", + "description": "Bin", + "name": "bin", + "in": "query" + }, + { + "type": "string", + "description": "Swift SwiftCode", + "name": "swiftCode", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/ListBankResponse" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/ErrorResponse" + } + } + } + } + }, "/brainery-logs": { "post": { "security": [ @@ -1769,7 +1819,7 @@ const docTemplate = `{ "BearerAuth": [] } ], - "description": "Check salary advance by discord id", + "description": "Check withdraw condition by discord id", "consumes": [ "application/json" ], @@ -1777,26 +1827,23 @@ const docTemplate = `{ "application/json" ], "tags": [ - "Employee" + "Withdraw" ], - "summary": "Check salary advance by discord id", - "operationId": "checkSalaryAdvance", + "summary": "Check withdraw condition by discord id", + "operationId": "checkWithdrawCondition", "parameters": [ { - "description": "Check Salary Advance Request", - "name": "checkSalaryAdvanceRequest", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/SalaryAdvanceRequest" - } + "type": "string", + "description": "DiscordID", + "name": "discordID", + "in": "query" } ], "responses": { "200": { "description": "OK", "schema": { - "$ref": "#/definitions/CheckSalaryAdvanceResponse" + "$ref": "#/definitions/CheckWithdrawConditionResponse" } }, "400": { @@ -7064,6 +7111,32 @@ const docTemplate = `{ } } }, + "Bank": { + "type": "object", + "properties": { + "bin": { + "type": "string" + }, + "code": { + "type": "string" + }, + "id": { + "type": "string" + }, + "logo": { + "type": "string" + }, + "name": { + "type": "string" + }, + "shortName": { + "type": "string" + }, + "swiftCode": { + "type": "string" + } + } + }, "BankAccount": { "type": "object", "properties": { @@ -7439,6 +7512,28 @@ const docTemplate = `{ } } }, + "CheckWithdrawCondition": { + "type": "object", + "properties": { + "icyAmount": { + "type": "number" + }, + "icyVNDRate": { + "type": "number" + }, + "vndAmount": { + "type": "number" + } + } + }, + "CheckWithdrawConditionResponse": { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/CheckWithdrawCondition" + } + } + }, "CitiesResponse": { "type": "object", "properties": { @@ -8352,7 +8447,11 @@ const docTemplate = `{ }, "status": { "description": "working info", - "type": "string" + "allOf": [ + { + "$ref": "#/definitions/WorkingStatus" + } + ] }, "teamEmail": { "type": "string" @@ -9378,6 +9477,17 @@ const docTemplate = `{ } } }, + "ListBankResponse": { + "type": "object", + "properties": { + "data": { + "type": "array", + "items": { + "$ref": "#/definitions/Bank" + } + } + } + }, "ListFeedbackResponse": { "type": "object", "properties": { @@ -12317,7 +12427,7 @@ const docTemplate = `{ "type": "object", "properties": { "employeeStatus": { - "type": "string" + "$ref": "#/definitions/WorkingStatus" } } }, @@ -12786,6 +12896,23 @@ const docTemplate = `{ "WorkUnitTypeLearning" ] }, + "WorkingStatus": { + "type": "string", + "enum": [ + "on-boarding", + "left", + "probation", + "full-time", + "contractor" + ], + "x-enum-varnames": [ + "WorkingStatusOnBoarding", + "WorkingStatusLeft", + "WorkingStatusProbation", + "WorkingStatusFullTime", + "WorkingStatusContractor" + ] + }, "github_com_dwarvesf_fortress-api_pkg_model.SortOrder": { "type": "string", "enum": [ diff --git a/docs/swagger.json b/docs/swagger.json index fc09407c3..a68f38fbc 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -267,6 +267,56 @@ } } }, + "/banks": { + "get": { + "description": "Get all bank by given filter params", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Metadata" + ], + "summary": "Get all banks", + "operationId": "getBanksList", + "parameters": [ + { + "type": "string", + "description": "Bank ID", + "name": "id", + "in": "query" + }, + { + "type": "string", + "description": "Bin", + "name": "bin", + "in": "query" + }, + { + "type": "string", + "description": "Swift SwiftCode", + "name": "swiftCode", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/ListBankResponse" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/ErrorResponse" + } + } + } + } + }, "/brainery-logs": { "post": { "security": [ @@ -1762,7 +1812,7 @@ "BearerAuth": [] } ], - "description": "Check salary advance by discord id", + "description": "Check withdraw condition by discord id", "consumes": [ "application/json" ], @@ -1770,26 +1820,23 @@ "application/json" ], "tags": [ - "Employee" + "Withdraw" ], - "summary": "Check salary advance by discord id", - "operationId": "checkSalaryAdvance", + "summary": "Check withdraw condition by discord id", + "operationId": "checkWithdrawCondition", "parameters": [ { - "description": "Check Salary Advance Request", - "name": "checkSalaryAdvanceRequest", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/SalaryAdvanceRequest" - } + "type": "string", + "description": "DiscordID", + "name": "discordID", + "in": "query" } ], "responses": { "200": { "description": "OK", "schema": { - "$ref": "#/definitions/CheckSalaryAdvanceResponse" + "$ref": "#/definitions/CheckWithdrawConditionResponse" } }, "400": { @@ -7057,6 +7104,32 @@ } } }, + "Bank": { + "type": "object", + "properties": { + "bin": { + "type": "string" + }, + "code": { + "type": "string" + }, + "id": { + "type": "string" + }, + "logo": { + "type": "string" + }, + "name": { + "type": "string" + }, + "shortName": { + "type": "string" + }, + "swiftCode": { + "type": "string" + } + } + }, "BankAccount": { "type": "object", "properties": { @@ -7432,6 +7505,28 @@ } } }, + "CheckWithdrawCondition": { + "type": "object", + "properties": { + "icyAmount": { + "type": "number" + }, + "icyVNDRate": { + "type": "number" + }, + "vndAmount": { + "type": "number" + } + } + }, + "CheckWithdrawConditionResponse": { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/CheckWithdrawCondition" + } + } + }, "CitiesResponse": { "type": "object", "properties": { @@ -8345,7 +8440,11 @@ }, "status": { "description": "working info", - "type": "string" + "allOf": [ + { + "$ref": "#/definitions/WorkingStatus" + } + ] }, "teamEmail": { "type": "string" @@ -9371,6 +9470,17 @@ } } }, + "ListBankResponse": { + "type": "object", + "properties": { + "data": { + "type": "array", + "items": { + "$ref": "#/definitions/Bank" + } + } + } + }, "ListFeedbackResponse": { "type": "object", "properties": { @@ -12310,7 +12420,7 @@ "type": "object", "properties": { "employeeStatus": { - "type": "string" + "$ref": "#/definitions/WorkingStatus" } } }, @@ -12779,6 +12889,23 @@ "WorkUnitTypeLearning" ] }, + "WorkingStatus": { + "type": "string", + "enum": [ + "on-boarding", + "left", + "probation", + "full-time", + "contractor" + ], + "x-enum-varnames": [ + "WorkingStatusOnBoarding", + "WorkingStatusLeft", + "WorkingStatusProbation", + "WorkingStatusFullTime", + "WorkingStatusContractor" + ] + }, "github_com_dwarvesf_fortress-api_pkg_model.SortOrder": { "type": "string", "enum": [ diff --git a/docs/swagger.yaml b/docs/swagger.yaml index becc677bf..1e6b7c53b 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -324,6 +324,23 @@ definitions: type: type: string type: object + Bank: + properties: + bin: + type: string + code: + type: string + id: + type: string + logo: + type: string + name: + type: string + shortName: + type: string + swiftCode: + type: string + type: object BankAccount: properties: accountNumber: @@ -568,6 +585,20 @@ definitions: data: $ref: '#/definitions/CheckSalaryAdvance' type: object + CheckWithdrawCondition: + properties: + icyAmount: + type: number + icyVNDRate: + type: number + vndAmount: + type: number + type: object + CheckWithdrawConditionResponse: + properties: + data: + $ref: '#/definitions/CheckWithdrawCondition' + type: object CitiesResponse: properties: data: @@ -1174,8 +1205,9 @@ definitions: $ref: '#/definitions/Stack' type: array status: + allOf: + - $ref: '#/definitions/WorkingStatus' description: working info - type: string teamEmail: type: string updatedAt: @@ -1847,6 +1879,13 @@ definitions: $ref: '#/definitions/BankAccount' type: array type: object + ListBankResponse: + properties: + data: + items: + $ref: '#/definitions/Bank' + type: array + type: object ListFeedbackResponse: properties: data: @@ -3810,7 +3849,7 @@ definitions: UpdateWorkingStatusRequest: properties: employeeStatus: - type: string + $ref: '#/definitions/WorkingStatus' type: object UpdatedProject: properties: @@ -4118,6 +4157,20 @@ definitions: - WorkUnitTypeManagement - WorkUnitTypeTraining - WorkUnitTypeLearning + WorkingStatus: + enum: + - on-boarding + - left + - probation + - full-time + - contractor + type: string + x-enum-varnames: + - WorkingStatusOnBoarding + - WorkingStatusLeft + - WorkingStatusProbation + - WorkingStatusFullTime + - WorkingStatusContractor github_com_dwarvesf_fortress-api_pkg_model.SortOrder: enum: - asc @@ -4302,6 +4355,39 @@ paths: summary: Get all bank accounts tags: - Bank + /banks: + get: + consumes: + - application/json + description: Get all bank by given filter params + operationId: getBanksList + parameters: + - description: Bank ID + in: query + name: id + type: string + - description: Bin + in: query + name: bin + type: string + - description: Swift SwiftCode + in: query + name: swiftCode + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/ListBankResponse' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/ErrorResponse' + summary: Get all banks + tags: + - Metadata /brainery-logs: post: consumes: @@ -5588,22 +5674,20 @@ paths: post: consumes: - application/json - description: Check salary advance by discord id - operationId: checkSalaryAdvance + description: Check withdraw condition by discord id + operationId: checkWithdrawCondition parameters: - - description: Check Salary Advance Request - in: body - name: checkSalaryAdvanceRequest - required: true - schema: - $ref: '#/definitions/SalaryAdvanceRequest' + - description: DiscordID + in: query + name: discordID + type: string produces: - application/json responses: "200": description: OK schema: - $ref: '#/definitions/CheckSalaryAdvanceResponse' + $ref: '#/definitions/CheckWithdrawConditionResponse' "400": description: Bad Request schema: @@ -5618,9 +5702,9 @@ paths: $ref: '#/definitions/ErrorResponse' security: - BearerAuth: [] - summary: Check salary advance by discord id + summary: Check withdraw condition by discord id tags: - - Employee + - Withdraw /employees/search: post: consumes: diff --git a/go.mod b/go.mod index 4da0283ae..3a1356123 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/antchfx/htmlquery v1.3.0 github.com/bwmarrin/discordgo v0.27.1 github.com/cenkalti/backoff/v4 v4.2.1 - github.com/consolelabs/mochi-go-sdk v0.0.7 + github.com/consolelabs/mochi-go-sdk v0.0.8 github.com/dstotijn/go-notion v0.11.0 github.com/ethereum/go-ethereum v1.13.5 github.com/gin-contrib/cors v1.4.0 diff --git a/go.sum b/go.sum index 6e057f3ad..2492e057a 100644 --- a/go.sum +++ b/go.sum @@ -137,6 +137,8 @@ github.com/consensys/gnark-crypto v0.12.1 h1:lHH39WuuFgVHONRl3J0LRBtuYdQTumFSDtJ github.com/consensys/gnark-crypto v0.12.1/go.mod h1:v2Gy7L/4ZRosZ7Ivs+9SfUDr0f5UlG+EM5t7MPHiLuY= github.com/consolelabs/mochi-go-sdk v0.0.7 h1:Rq4yegQxHx/wE1xGGEgllUrKYQFL8r5cSdPbFpjcbxY= github.com/consolelabs/mochi-go-sdk v0.0.7/go.mod h1:h5kA4wzRRMYf9kSs2XSsQnZuMlyi92/5zNwzaN0P98Q= +github.com/consolelabs/mochi-go-sdk v0.0.8 h1:7vVjLVXBKdoIxiwxrr7Q42wk6AC8fwQC0Y8K/INSIos= +github.com/consolelabs/mochi-go-sdk v0.0.8/go.mod h1:h5kA4wzRRMYf9kSs2XSsQnZuMlyi92/5zNwzaN0P98Q= github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/cpuguy83/go-md2man/v2 v2.0.3 h1:qMCsGGgs+MAzDFyp9LpAe1Lqy/fY/qCovCm0qnXZOBM= diff --git a/pkg/config/config.go b/pkg/config/config.go index 9176619a0..0d0beb523 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -38,6 +38,9 @@ type Config struct { Env string JWTSecretKey string FortressURL string + + // Mochi App + MochiWithdraw Mochi } type DBConnection struct { @@ -95,6 +98,7 @@ type Mochi struct { ApplicationID string ApplicationName string APIKey string + DefaultTokenID string } type MochiPay struct { @@ -272,6 +276,13 @@ func Generate(v ENV) *Config { ApplicationName: v.GetString("MOCHI_APPLICATION_NAME"), APIKey: v.GetString("MOCHI_API_KEY"), }, + MochiWithdraw: Mochi{ + BaseURL: v.GetString("MOCHI_WITHDRAW_BASE_URL"), + ApplicationID: v.GetString("MOCHI_WITHDRAW_ID"), + ApplicationName: v.GetString("MOCHI_WITHDRAW_NAME"), + APIKey: v.GetString("MOCHI_WITHDRAW_API_KEY"), + }, + MochiPay: MochiPay{ BaseURL: v.GetString("MOCHI_PAY_BASE_URL"), }, diff --git a/pkg/controller/controller.go b/pkg/controller/controller.go index 746d424e7..44228909d 100644 --- a/pkg/controller/controller.go +++ b/pkg/controller/controller.go @@ -11,6 +11,7 @@ import ( "github.com/dwarvesf/fortress-api/pkg/controller/employee" "github.com/dwarvesf/fortress-api/pkg/controller/icy" "github.com/dwarvesf/fortress-api/pkg/controller/invoice" + "github.com/dwarvesf/fortress-api/pkg/controller/withdrawal" "github.com/dwarvesf/fortress-api/pkg/logger" "github.com/dwarvesf/fortress-api/pkg/service" "github.com/dwarvesf/fortress-api/pkg/store" @@ -27,6 +28,7 @@ type Controller struct { Invoice invoice.IController Discord discord.IController Icy icy.IController + Withdrawal withdrawal.IController } func New(store *store.Store, repo store.DBRepo, service *service.Service, worker *worker.Worker, logger logger.Logger, cfg *config.Config) *Controller { @@ -40,5 +42,6 @@ func New(store *store.Store, repo store.DBRepo, service *service.Service, worker Invoice: invoice.New(store, repo, service, worker, logger, cfg), Discord: discord.New(store, repo, service, logger, cfg), Icy: icy.New(service, logger, cfg), + Withdrawal: withdrawal.New(service, logger, cfg), } } diff --git a/pkg/controller/withdrawal/check.go b/pkg/controller/withdrawal/check.go new file mode 100644 index 000000000..756f1c2b1 --- /dev/null +++ b/pkg/controller/withdrawal/check.go @@ -0,0 +1,50 @@ +package withdrawal + +import ( + "github.com/dwarvesf/fortress-api/pkg/logger" + "github.com/dwarvesf/fortress-api/pkg/model" + "github.com/dwarvesf/fortress-api/pkg/utils" +) + +type CheckWithdrawInput struct { + DiscordID string `json:"discordID"` +} + +const icyUsdRate = 1.5 + +// CheckWithdrawalCondition means check condition to withdraw. +func (c *controller) CheckWithdrawalCondition(in CheckWithdrawInput) (*model.WithdrawalCondition, error) { + l := c.logger.Fields(logger.Fields{ + "controller": "withdrawal", + "method": "Withdraw", + }) + + profile, err := c.mochiAppClient.GetByDiscordID(in.DiscordID) + if err != nil { + l.Error(err, "failed to get mochi profile") + return nil, err + } + + userICYBalance, err := c.mochiAppClient.GetUserBalances(profile.ID) + if err != nil { + l.Error(err, "failed to get user balance") + return nil, err + } + + currentICYAmount := utils.ConvertFromString(userICYBalance[0].Amount, int64(userICYBalance[0].Token.Decimal)) + currentICYAmount.SetPrec(5) + + // Get current ICY/USD rate + icyAmount, _ := currentICYAmount.Float64() + amountUSD := icyAmount * icyUsdRate + convertedICYAmount, rate, err := c.service.Wise.Convert(amountUSD, "USD", "VND") + if err != nil { + return nil, err + } + + return &model.WithdrawalCondition{ + ICYVNDRate: rate * icyUsdRate, + ICYAmount: icyAmount, + VNDAmount: convertedICYAmount, + }, nil +} diff --git a/pkg/controller/withdrawal/confirm.go b/pkg/controller/withdrawal/confirm.go new file mode 100644 index 000000000..7582f2b3d --- /dev/null +++ b/pkg/controller/withdrawal/confirm.go @@ -0,0 +1,27 @@ +package withdrawal + +type ConfirmTransactionInput struct { + Timestamp int64 + TransactionID int64 + Amount string + TokenName string + ProfileID string + RequestCode string + Status string + Description string + + BankAccount string + SwiftCode string + Bin string +} + +// ConfirmTransaction means the user has been deposit token to the app. +// The app will transfer the money to then bank account. +func (c *controller) ConfirmTransaction(in ConfirmTransactionInput) error { + //l := c.logger.Fields(logger.Fields{ + // "controller": "moneywithdrawal", + // "method": "ConfirmTransaction", + //}) + + return nil +} diff --git a/pkg/controller/withdrawal/new.go b/pkg/controller/withdrawal/new.go new file mode 100644 index 000000000..b4ba054da --- /dev/null +++ b/pkg/controller/withdrawal/new.go @@ -0,0 +1,44 @@ +package withdrawal + +import ( + mochisdk "github.com/consolelabs/mochi-go-sdk/mochi" + mochicfg "github.com/consolelabs/mochi-go-sdk/mochi/config" + "github.com/dwarvesf/fortress-api/pkg/config" + "github.com/dwarvesf/fortress-api/pkg/logger" + "github.com/dwarvesf/fortress-api/pkg/model" + "github.com/dwarvesf/fortress-api/pkg/service" +) + +type IController interface { + CheckWithdrawalCondition(in CheckWithdrawInput) (*model.WithdrawalCondition, error) + RequestTransfer(in WithdrawInput) (string, error) + ConfirmTransaction(in ConfirmTransactionInput) error +} + +type controller struct { + service *service.Service + // mochiAppClient is mochi withdraw money app client + mochiAppClient mochisdk.APIClient + logger logger.Logger + config *config.Config +} + +func New(service *service.Service, logger logger.Logger, cfg *config.Config) IController { + return &controller{ + service: service, + logger: logger, + config: cfg, + mochiAppClient: mochisdk.NewClient( + &mochicfg.Config{ + MochiPay: mochicfg.MochiPay{ + BaseURL: cfg.MochiWithdraw.BaseURL, + ApplicationID: cfg.MochiWithdraw.ApplicationID, + ApplicationName: cfg.MochiWithdraw.ApplicationName, + APIKey: cfg.MochiWithdraw.APIKey, + IsPreview: false, + }, + MochiProfile: mochicfg.MochiProfile{}, + }, + ), + } +} diff --git a/pkg/controller/withdrawal/request_transfer.go b/pkg/controller/withdrawal/request_transfer.go new file mode 100644 index 000000000..ccfd3591e --- /dev/null +++ b/pkg/controller/withdrawal/request_transfer.go @@ -0,0 +1,25 @@ +package withdrawal + +import "fmt" + +type WithdrawInput struct { + DiscordID string `json:"discordID"` + Amount string `json:"amount"` +} + +// RequestTransfer request to transfer token to APP. +func (c *controller) RequestTransfer(in WithdrawInput) (string, error) { + //l := c.logger.Fields(logger.Fields{ + // "controller": "withdrawal", + // "method": "Withdraw", + //}) + + profile, err := c.mochiAppClient.GetByDiscordID(in.DiscordID) + if err != nil { + return "", err + } + + fmt.Println(profile) + + return profile.ProfileName, nil +} diff --git a/pkg/handler/bankaccount/bank_account.go b/pkg/handler/bankaccount/bank_account.go index de629d2d5..fd6886a71 100644 --- a/pkg/handler/bankaccount/bank_account.go +++ b/pkg/handler/bankaccount/bank_account.go @@ -43,7 +43,7 @@ func New(store *store.Store, repo store.DBRepo, service *service.Service, logger // @Router /bank-accounts [get] func (h *handler) List(c *gin.Context) { l := h.logger.Fields(logger.Fields{ - "handler": "bank", + "handler": "bankaccount", "method": "List", }) diff --git a/pkg/handler/handler.go b/pkg/handler/handler.go index 3976afffd..08d128243 100644 --- a/pkg/handler/handler.go +++ b/pkg/handler/handler.go @@ -30,6 +30,7 @@ import ( "github.com/dwarvesf/fortress-api/pkg/handler/valuation" "github.com/dwarvesf/fortress-api/pkg/handler/vault" "github.com/dwarvesf/fortress-api/pkg/handler/webhook" + "github.com/dwarvesf/fortress-api/pkg/handler/withdrawal" "github.com/dwarvesf/fortress-api/pkg/logger" "github.com/dwarvesf/fortress-api/pkg/service" "github.com/dwarvesf/fortress-api/pkg/store" @@ -63,6 +64,7 @@ type Handler struct { Webhook webhook.IHandler Vault vault.IHandler Icy icy.IHandler + Withdrawal withdrawal.IHandler } func New(store *store.Store, repo store.DBRepo, service *service.Service, ctrl *controller.Controller, worker *worker.Worker, logger logger.Logger, cfg *config.Config) *Handler { @@ -93,5 +95,6 @@ func New(store *store.Store, repo store.DBRepo, service *service.Service, ctrl * Webhook: webhook.New(ctrl, store, repo, service, logger, cfg, worker), Vault: vault.New(store, repo, service, logger, cfg), Icy: icy.New(ctrl, logger), + Withdrawal: withdrawal.New(ctrl, logger), } } diff --git a/pkg/handler/icy/request/request.go b/pkg/handler/icy/request/request.go new file mode 100644 index 000000000..c1869cb9e --- /dev/null +++ b/pkg/handler/icy/request/request.go @@ -0,0 +1,10 @@ +package request + +type CheckICYBalanceRequest struct { + DiscordID string `json:"discordID"` +} // @name CheckICYBalanceRequest + +type WithdrawMoneyRequest struct { + DiscordID string `json:"discordID"` + Amount string `json:"amount"` +} // @name SalaryAdvanceRequest diff --git a/pkg/handler/metadata/interface.go b/pkg/handler/metadata/interface.go index a424e654d..3ffe6c2c6 100644 --- a/pkg/handler/metadata/interface.go +++ b/pkg/handler/metadata/interface.go @@ -3,6 +3,7 @@ package metadata import "github.com/gin-gonic/gin" type IHandler interface { + Banks(c *gin.Context) Chapters(c *gin.Context) CreatePosition(c *gin.Context) CreateStack(c *gin.Context) diff --git a/pkg/handler/metadata/metadata.go b/pkg/handler/metadata/metadata.go index 4b0757e56..f1674a236 100644 --- a/pkg/handler/metadata/metadata.go +++ b/pkg/handler/metadata/metadata.go @@ -11,10 +11,12 @@ import ( "github.com/dwarvesf/fortress-api/pkg/config" "github.com/dwarvesf/fortress-api/pkg/handler/metadata/errs" "github.com/dwarvesf/fortress-api/pkg/handler/metadata/request" + "github.com/dwarvesf/fortress-api/pkg/logger" "github.com/dwarvesf/fortress-api/pkg/model" "github.com/dwarvesf/fortress-api/pkg/service" "github.com/dwarvesf/fortress-api/pkg/store" + bankRepo "github.com/dwarvesf/fortress-api/pkg/store/bank" "github.com/dwarvesf/fortress-api/pkg/view" ) @@ -721,3 +723,42 @@ func (h *handler) GetCurrencies(c *gin.Context) { c.JSON(http.StatusOK, view.CreateResponse[any](view.ToCurrencies(rs), nil, nil, nil, "")) } + +// Banks godoc +// @Summary Get all banks +// @Description Get all bank by given filter params +// @id getBanksList +// @Tags Metadata +// @Accept json +// @Produce json +// @Param id query string false "Bank ID" +// @Param bin query string false "Bin" +// @Param swiftCode query string false "Swift SwiftCode" +// @Success 200 {object} ListBankResponse +// @Failure 500 {object} ErrorResponse +// @Router /banks [get] +func (h *handler) Banks(c *gin.Context) { + l := h.logger.Fields(logger.Fields{ + "handler": "bank", + "method": "List", + }) + + query := request.GetBankRequest{} + if err := c.ShouldBindQuery(&query); err != nil { + c.JSON(http.StatusBadRequest, view.CreateResponse[any](nil, nil, err, query, "")) + return + } + + res, err := h.store.Bank.All(h.repo.DB(), bankRepo.GetBanksInput{ + ID: query.ID, + Bin: query.Bin, + SwiftCode: query.SwiftCode, + }) + if err != nil { + l.Error(err, "failed to get all banks") + c.JSON(http.StatusInternalServerError, view.CreateResponse[any](nil, nil, err, nil, "")) + return + } + + c.JSON(http.StatusOK, view.CreateResponse[any](view.ToListBank(res), nil, nil, nil, "")) +} diff --git a/pkg/handler/metadata/request/request.go b/pkg/handler/metadata/request/request.go index 5e21a55e4..a1d14450a 100644 --- a/pkg/handler/metadata/request/request.go +++ b/pkg/handler/metadata/request/request.go @@ -57,3 +57,9 @@ type GetStacksInput struct { model.Pagination Keyword string `json:"keyword" form:"keyword"` } + +type GetBankRequest struct { + ID string `json:"id" form:"id" ` + Bin string `json:"bin" form:"bin"` + SwiftCode string `json:"swiftCode" form:"swiftCode"` +} diff --git a/pkg/handler/withdrawal/interface.go b/pkg/handler/withdrawal/interface.go new file mode 100644 index 000000000..4a348eca7 --- /dev/null +++ b/pkg/handler/withdrawal/interface.go @@ -0,0 +1,7 @@ +package withdrawal + +import "github.com/gin-gonic/gin" + +type IHandler interface { + CheckWithdrawCondition(c *gin.Context) +} diff --git a/pkg/handler/withdrawal/request/request.go b/pkg/handler/withdrawal/request/request.go new file mode 100644 index 000000000..23a2b41a7 --- /dev/null +++ b/pkg/handler/withdrawal/request/request.go @@ -0,0 +1,10 @@ +package request + +type CheckWithdrawConditionRequest struct { + DiscordID string `json:"discordID" form:"discordID" binding:"required"` +} // @name CheckWithdrawConditionRequest + +type WithdrawMoneyRequest struct { + DiscordID string `json:"discordID"` + Amount string `json:"amount"` +} // @name WithdrawMoneyRequest diff --git a/pkg/handler/withdrawal/withdraw.go b/pkg/handler/withdrawal/withdraw.go new file mode 100644 index 000000000..ad1ef7378 --- /dev/null +++ b/pkg/handler/withdrawal/withdraw.go @@ -0,0 +1,81 @@ +package withdrawal + +import ( + "net/http" + + "github.com/gin-gonic/gin" + + "github.com/dwarvesf/fortress-api/pkg/controller" + withdrawalCtrl "github.com/dwarvesf/fortress-api/pkg/controller/withdrawal" + "github.com/dwarvesf/fortress-api/pkg/handler/withdrawal/request" + "github.com/dwarvesf/fortress-api/pkg/logger" + "github.com/dwarvesf/fortress-api/pkg/view" +) + +type handler struct { + controller *controller.Controller + logger logger.Logger +} + +func New( + controller *controller.Controller, + logger logger.Logger, +) IHandler { + return &handler{ + controller: controller, + logger: logger, + } +} + +// CheckWithdrawCondition means check condition to withdraw money from ICY +// @Summary Check withdraw condition by discord id +// @Description Check withdraw condition by discord id +// @id checkWithdrawCondition +// @Tags Withdraw +// @Accept json +// @Produce json +// @Security BearerAuth +// @Param discordID query string false "DiscordID" +// @Success 200 {object} CheckWithdrawConditionResponse +// @Failure 400 {object} ErrorResponse +// @Failure 404 {object} ErrorResponse +// @Failure 500 {object} ErrorResponse +// @Router /employees/check-advance-salary [post] +func (h *handler) CheckWithdrawCondition(c *gin.Context) { + l := h.logger.Fields(logger.Fields{ + "handler": "icy", + "method": "Balance", + }) + + query := request.CheckWithdrawConditionRequest{} + if err := c.ShouldBindQuery(&query); err != nil { + c.JSON(http.StatusBadRequest, view.CreateResponse[any](nil, nil, err, query, "")) + return + } + + rs, err := h.controller.Withdrawal.CheckWithdrawalCondition(withdrawalCtrl.CheckWithdrawInput{ + DiscordID: query.DiscordID, + }) + if err != nil { + l.Error(err, "failed to check withdraw condition") + c.JSON(http.StatusInternalServerError, view.CreateResponse[any](nil, nil, err, nil, "failed to check with withdraw condition")) + return + } + + c.JSON(http.StatusOK, view.CreateResponse[any](view.ToCheckWithdrawCondition(rs), nil, nil, nil, "")) +} + +// +//func (h *handler) WithdrawMoney(c *gin.Context) { +// l := h.logger.Fields(logger.Fields{ +// "handler": "icy", +// "method": "Withdraw", +// }) +// +// var req request.WithdrawMoneyRequest +// if err := c.ShouldBindJSON(&req); err != nil { +// l.Error(err, "failed to bind json") +// c.JSON(http.StatusBadRequest, view.CreateResponse[any](nil, nil, err, nil, "failed to bind json")) +// return +// } +//} diff --git a/pkg/model/withdrawal.go b/pkg/model/withdrawal.go new file mode 100644 index 000000000..4912603c5 --- /dev/null +++ b/pkg/model/withdrawal.go @@ -0,0 +1,7 @@ +package model + +type WithdrawalCondition struct { + ICYAmount float64 + ICYVNDRate float64 + VNDAmount float64 +} diff --git a/pkg/routes/v1.go b/pkg/routes/v1.go index b1703df8d..b03a236d0 100644 --- a/pkg/routes/v1.go +++ b/pkg/routes/v1.go @@ -114,6 +114,7 @@ func loadV1Routes(r *gin.Engine, h *handler.Handler, repo store.DBRepo, s *store metadataRoute := v1.Group("/metadata") { metadataRoute.GET("/working-status", h.Metadata.WorkingStatuses) + metadataRoute.GET("/banks", h.Metadata.Banks) metadataRoute.GET("/stacks", h.Metadata.Stacks) metadataRoute.GET("/seniorities", h.Metadata.Seniorities) metadataRoute.GET("/chapters", h.Metadata.Chapters) @@ -361,6 +362,10 @@ func loadV1Routes(r *gin.Engine, h *handler.Handler, repo store.DBRepo, s *store discordGroup.GET("/:discord_id/earns/total", amw.WithAuth, pmw.WithPerm(model.PermissionEmployeesDiscordRead), h.Employee.GetEmployeeTotalEarn) discordGroup.GET("/icy-accounting", amw.WithAuth, pmw.WithPerm(model.PermissionEmployeesDiscordRead), h.Icy.Accounting) + withdrawGroup := discordGroup.Group("/withdraw") + { + withdrawGroup.GET("/check", amw.WithAuth, pmw.WithPerm(model.PermissionEmployeesDiscordRead), h.Withdrawal.CheckWithdrawCondition) + } } conversionRateGroup := v1.Group("/conversion-rates") diff --git a/pkg/routes/v1_test.go b/pkg/routes/v1_test.go index 1bd2d66bb..92a5c4e1a 100644 --- a/pkg/routes/v1_test.go +++ b/pkg/routes/v1_test.go @@ -71,6 +71,12 @@ func Test_loadV1Routes(t *testing.T) { Handler: "github.com/dwarvesf/fortress-api/pkg/handler/employee.IHandler.GetLineManagers-fm", }, }, + "/api/v1/metadata/banks": { + "GET": { + Method: "GET", + Handler: "github.com/dwarvesf/fortress-api/pkg/handler/metadata.IHandler.Banks-fm", + }, + }, "/api/v1/metadata/working-status": { "GET": { Method: "GET", diff --git a/pkg/store/bank/bank.go b/pkg/store/bank/bank.go new file mode 100644 index 000000000..a37807aa0 --- /dev/null +++ b/pkg/store/bank/bank.go @@ -0,0 +1,67 @@ +package bank + +import ( + "gorm.io/gorm" + + "github.com/dwarvesf/fortress-api/pkg/model" +) + +type store struct{} + +func New() IStore { + return &store{} +} + +// One get bank account by id +func (s *store) One(db *gorm.DB, id string) (*model.Bank, error) { + var bankAccount *model.Bank + return bankAccount, db.Where("id = ?", id).First(&bankAccount).Error +} + +type GetBanksInput struct { + ID string + Bin string + SwiftCode string +} + +// All get all bank account +func (s *store) All(db *gorm.DB, in GetBanksInput) ([]*model.Bank, error) { + var banks []*model.Bank + + query := db.Where("deleted_at IS NULL") + if in.ID != "" { + query = query.Where("id = ?", in.ID) + } + if in.Bin != "" { + query = query.Where("bin = ?", in.Bin) + } + if in.SwiftCode != "" { + query = query.Where("swift_code = ?", in.SwiftCode) + } + + return banks, query.Find(&banks).Error +} + +// IsExist check bank account existence +func (s *store) IsExist(db *gorm.DB, id string) (bool, error) { + type res struct { + Result bool + } + + result := res{} + query := db.Raw("SELECT EXISTS (SELECT * FROM banks WHERE id = ?) as result", id) + + return result.Result, query.Scan(&result).Error +} + +// OneByBin get bank account by bin +func (s *store) OneByBin(db *gorm.DB, bin string) (bank *model.Bank, err error) { + var bankAccount *model.Bank + return bankAccount, db.Where("bin = ?", bin).First(&bankAccount).Error +} + +// OneBySwiftCode get bank account by swift code +func (s *store) OneBySwiftCode(db *gorm.DB, code string) (bank *model.Bank, err error) { + var bankAccount *model.Bank + return bankAccount, db.Where("swift_code = ?", code).First(&bankAccount).Error +} diff --git a/pkg/store/bank/interface.go b/pkg/store/bank/interface.go new file mode 100644 index 000000000..0e7ce134e --- /dev/null +++ b/pkg/store/bank/interface.go @@ -0,0 +1,15 @@ +package bank + +import ( + "gorm.io/gorm" + + "github.com/dwarvesf/fortress-api/pkg/model" +) + +type IStore interface { + One(db *gorm.DB, id string) (bank *model.Bank, err error) + OneByBin(db *gorm.DB, bin string) (bank *model.Bank, err error) + OneBySwiftCode(db *gorm.DB, code string) (bank *model.Bank, err error) + All(db *gorm.DB, in GetBanksInput) ([]*model.Bank, error) + IsExist(db *gorm.DB, id string) (exists bool, err error) +} diff --git a/pkg/store/store.go b/pkg/store/store.go index 759ce3afa..003fb688b 100644 --- a/pkg/store/store.go +++ b/pkg/store/store.go @@ -11,6 +11,7 @@ import ( "github.com/dwarvesf/fortress-api/pkg/store/auditcycle" "github.com/dwarvesf/fortress-api/pkg/store/audititem" "github.com/dwarvesf/fortress-api/pkg/store/auditparticipant" + "github.com/dwarvesf/fortress-api/pkg/store/bank" "github.com/dwarvesf/fortress-api/pkg/store/bankaccount" "github.com/dwarvesf/fortress-api/pkg/store/basesalary" "github.com/dwarvesf/fortress-api/pkg/store/brainerylog" @@ -89,6 +90,7 @@ type Store struct { AuditItem audititem.IStore AuditParticipant auditparticipant.IStore SalaryAdvance salaryadvance.IStore + Bank bank.IStore BankAccount bankaccount.IStore BaseSalary basesalary.IStore Bonus employeebonus.IStore @@ -167,6 +169,7 @@ func New() *Store { AuditItem: audititem.New(), AuditParticipant: auditparticipant.New(), SalaryAdvance: salaryadvance.New(), + Bank: bank.New(), BankAccount: bankaccount.New(), BaseSalary: basesalary.New(), Bonus: employeebonus.New(), diff --git a/pkg/view/bank.go b/pkg/view/bank.go index 88b55f34b..56ef0220a 100644 --- a/pkg/view/bank.go +++ b/pkg/view/bank.go @@ -2,63 +2,37 @@ package view import "github.com/dwarvesf/fortress-api/pkg/model" -type ListBankAccountResponse struct { - Data []BankAccount `json:"data"` -} // @name ListBankAccountResponse +type ListBankResponse struct { + Data []Bank `json:"data"` +} // @name ListBankResponse -type BankAccount struct { - ID string `json:"id"` - AccountNumber string `json:"accountNumber"` - BankName string `json:"bankName"` - OwnerName string `json:"ownerName"` - Address *string `json:"address"` - SwiftCode string `json:"swiftCode"` - IntermediaryBankAddress string `json:"intermediaryBankAddress"` - IntermediaryBankName string `json:"intermediaryBankName"` - RoutingNumber string `json:"routingNumber"` - Name string `json:"name"` - UKSortCode string `json:"ukSortCode"` - CurrencyID string `json:"currencyID"` - Currency Currency `json:"currency"` -} // @name BankAccount +type Bank struct { + ID string `json:"id"` + Name string `json:"name"` + Code string `json:"code"` + Bin string `json:"bin"` + ShortName string `json:"shortName"` + Logo string `json:"logo"` + SwiftCode string `json:"swiftCode"` +} // @name Bank -func ToBankAccount(account *model.BankAccount) *BankAccount { - return &BankAccount{ - ID: account.ID.String(), - AccountNumber: account.AccountNumber, - BankName: account.BankName, - OwnerName: account.OwnerName, - Address: account.Address, - SwiftCode: account.SwiftCode, - RoutingNumber: account.RoutingNumber, - Name: account.Name, - UKSortCode: account.UKSortCode, - IntermediaryBankName: account.IntermediaryBankName, - IntermediaryBankAddress: account.IntermediaryBankAddress, - CurrencyID: account.CurrencyID.String(), - Currency: *toCurrency(account.Currency), +func ToBank(in *model.Bank) *Bank { + return &Bank{ + ID: in.ID.String(), + Name: in.Name, + Code: in.Code, + Bin: in.Bin, + ShortName: in.ShortName, + Logo: in.Logo, + SwiftCode: in.SwiftCode, } } -func ToListBankAccount(accounts []*model.BankAccount) []BankAccount { - res := make([]BankAccount, 0) - - for _, acc := range accounts { - res = append(res, BankAccount{ - ID: acc.ID.String(), - AccountNumber: acc.AccountNumber, - BankName: acc.BankName, - OwnerName: acc.OwnerName, - Address: acc.Address, - SwiftCode: acc.SwiftCode, - RoutingNumber: acc.RoutingNumber, - Name: acc.Name, - UKSortCode: acc.UKSortCode, - IntermediaryBankName: acc.IntermediaryBankName, - IntermediaryBankAddress: acc.IntermediaryBankAddress, - CurrencyID: acc.CurrencyID.String(), - Currency: *toCurrency(acc.Currency), - }) +func ToListBank(banks []*model.Bank) []Bank { + res := make([]Bank, 0) + for _, bank := range banks { + b := ToBank(bank) + res = append(res, *b) } return res diff --git a/pkg/view/bank_account.go b/pkg/view/bank_account.go new file mode 100644 index 000000000..88b55f34b --- /dev/null +++ b/pkg/view/bank_account.go @@ -0,0 +1,65 @@ +package view + +import "github.com/dwarvesf/fortress-api/pkg/model" + +type ListBankAccountResponse struct { + Data []BankAccount `json:"data"` +} // @name ListBankAccountResponse + +type BankAccount struct { + ID string `json:"id"` + AccountNumber string `json:"accountNumber"` + BankName string `json:"bankName"` + OwnerName string `json:"ownerName"` + Address *string `json:"address"` + SwiftCode string `json:"swiftCode"` + IntermediaryBankAddress string `json:"intermediaryBankAddress"` + IntermediaryBankName string `json:"intermediaryBankName"` + RoutingNumber string `json:"routingNumber"` + Name string `json:"name"` + UKSortCode string `json:"ukSortCode"` + CurrencyID string `json:"currencyID"` + Currency Currency `json:"currency"` +} // @name BankAccount + +func ToBankAccount(account *model.BankAccount) *BankAccount { + return &BankAccount{ + ID: account.ID.String(), + AccountNumber: account.AccountNumber, + BankName: account.BankName, + OwnerName: account.OwnerName, + Address: account.Address, + SwiftCode: account.SwiftCode, + RoutingNumber: account.RoutingNumber, + Name: account.Name, + UKSortCode: account.UKSortCode, + IntermediaryBankName: account.IntermediaryBankName, + IntermediaryBankAddress: account.IntermediaryBankAddress, + CurrencyID: account.CurrencyID.String(), + Currency: *toCurrency(account.Currency), + } +} + +func ToListBankAccount(accounts []*model.BankAccount) []BankAccount { + res := make([]BankAccount, 0) + + for _, acc := range accounts { + res = append(res, BankAccount{ + ID: acc.ID.String(), + AccountNumber: acc.AccountNumber, + BankName: acc.BankName, + OwnerName: acc.OwnerName, + Address: acc.Address, + SwiftCode: acc.SwiftCode, + RoutingNumber: acc.RoutingNumber, + Name: acc.Name, + UKSortCode: acc.UKSortCode, + IntermediaryBankName: acc.IntermediaryBankName, + IntermediaryBankAddress: acc.IntermediaryBankAddress, + CurrencyID: acc.CurrencyID.String(), + Currency: *toCurrency(acc.Currency), + }) + } + + return res +} diff --git a/pkg/view/withdrawal.go b/pkg/view/withdrawal.go new file mode 100644 index 000000000..b63a9d4e0 --- /dev/null +++ b/pkg/view/withdrawal.go @@ -0,0 +1,21 @@ +package view + +import "github.com/dwarvesf/fortress-api/pkg/model" + +type CheckWithdrawConditionResponse struct { + Data CheckWithdrawCondition `json:"data"` +} // @name CheckWithdrawConditionResponse + +type CheckWithdrawCondition struct { + ICYAmount float64 `json:"icyAmount"` + ICYVNDRate float64 `json:"icyVNDRate"` + VNDAmount float64 `json:"vndAmount"` +} // @name CheckWithdrawCondition + +func ToCheckWithdrawCondition(in *model.WithdrawalCondition) CheckWithdrawCondition { + return CheckWithdrawCondition{ + ICYAmount: in.ICYAmount, + ICYVNDRate: in.ICYVNDRate, + VNDAmount: in.VNDAmount, + } +} From 535daa2edc4d5c211fed2d41e4afe3236cb66f51 Mon Sep 17 00:00:00 2001 From: Nam Nguyen Date: Tue, 16 Jan 2024 01:18:56 +0700 Subject: [PATCH 2/2] feat: check withdraw cond api --- .../schemas/20240110125922-update_banks.sql | 4 ++ pkg/handler/withdrawal/request/request.go | 11 +++-- pkg/handler/withdrawal/withdraw.go | 45 ++++++++++++------- pkg/store/bank/bank.go | 2 +- 4 files changed, 42 insertions(+), 20 deletions(-) create mode 100644 migrations/schemas/20240110125922-update_banks.sql diff --git a/migrations/schemas/20240110125922-update_banks.sql b/migrations/schemas/20240110125922-update_banks.sql new file mode 100644 index 000000000..a12e8ab3e --- /dev/null +++ b/migrations/schemas/20240110125922-update_banks.sql @@ -0,0 +1,4 @@ +-- +migrate Up +ALTER TABLE "banks" ADD COLUMN "is_active" BOOLEAN NOT NULL DEFAULT FALSE; +-- +migrate Down +ALTER TABLE "banks" DROP COLUMN "is_active"; diff --git a/pkg/handler/withdrawal/request/request.go b/pkg/handler/withdrawal/request/request.go index 23a2b41a7..125ae5854 100644 --- a/pkg/handler/withdrawal/request/request.go +++ b/pkg/handler/withdrawal/request/request.go @@ -4,7 +4,10 @@ type CheckWithdrawConditionRequest struct { DiscordID string `json:"discordID" form:"discordID" binding:"required"` } // @name CheckWithdrawConditionRequest -type WithdrawMoneyRequest struct { - DiscordID string `json:"discordID"` - Amount string `json:"amount"` -} // @name WithdrawMoneyRequest +type PaymentRequestInput struct { + DiscordID string `json:"discordID"` + ICYAmount string `json:"icyAmount"` + BankSwiftCode string `json:"bankSwiftCode"` + BankAccountNumber string `json:"bankAccountNumber"` + BankAccountOwner string `json:"bankAccountOwner"` +} // @name PaymentRequestInput diff --git a/pkg/handler/withdrawal/withdraw.go b/pkg/handler/withdrawal/withdraw.go index ad1ef7378..1e82f0288 100644 --- a/pkg/handler/withdrawal/withdraw.go +++ b/pkg/handler/withdrawal/withdraw.go @@ -40,7 +40,7 @@ func New( // @Failure 400 {object} ErrorResponse // @Failure 404 {object} ErrorResponse // @Failure 500 {object} ErrorResponse -// @Router /employees/check-advance-salary [post] +// @Router /discords/withdraw/check [get] func (h *handler) CheckWithdrawCondition(c *gin.Context) { l := h.logger.Fields(logger.Fields{ "handler": "icy", @@ -65,17 +65,32 @@ func (h *handler) CheckWithdrawCondition(c *gin.Context) { c.JSON(http.StatusOK, view.CreateResponse[any](view.ToCheckWithdrawCondition(rs), nil, nil, nil, "")) } -// -//func (h *handler) WithdrawMoney(c *gin.Context) { -// l := h.logger.Fields(logger.Fields{ -// "handler": "icy", -// "method": "Withdraw", -// }) -// -// var req request.WithdrawMoneyRequest -// if err := c.ShouldBindJSON(&req); err != nil { -// l.Error(err, "failed to bind json") -// c.JSON(http.StatusBadRequest, view.CreateResponse[any](nil, nil, err, nil, "failed to bind json")) -// return -// } -//} +// ICYPaymentRequest means send to user request to send ICY to vault +// @Summary send to user request to send ICY to vault +// @Description send to user request to send ICY to vault +// @id icyPaymentRequest +// @Tags Withdraw +// @Accept json +// @Produce json +// @Security BearerAuth +// @Param Body body PaymentRequestInput true "Body" +// @Success 200 {object} CheckWithdrawConditionResponse +// @Failure 400 {object} ErrorResponse +// @Failure 404 {object} ErrorResponse +// @Failure 500 {object} ErrorResponse +// @Router /discords/withdraw/request-payment [post] +func (h *handler) ICYPaymentRequest(c *gin.Context) { + l := h.logger.Fields(logger.Fields{ + "handler": "withdrawal", + "method": "ICYPaymentRequest", + }) + + var req request.PaymentRequestInput + if err := c.ShouldBindJSON(&req); err != nil { + l.Error(err, "failed to bind json") + c.JSON(http.StatusBadRequest, view.CreateResponse[any](nil, nil, err, nil, "failed to bind json")) + return + } + + return +} diff --git a/pkg/store/bank/bank.go b/pkg/store/bank/bank.go index a37807aa0..96fd29eff 100644 --- a/pkg/store/bank/bank.go +++ b/pkg/store/bank/bank.go @@ -28,7 +28,7 @@ type GetBanksInput struct { func (s *store) All(db *gorm.DB, in GetBanksInput) ([]*model.Bank, error) { var banks []*model.Bank - query := db.Where("deleted_at IS NULL") + query := db.Where("is_active IS TRUE") if in.ID != "" { query = query.Where("id = ?", in.ID) }