Skip to content

Commit

Permalink
feat: get bank api (#681)
Browse files Browse the repository at this point in the history
  • Loading branch information
namnhce authored Jan 10, 2024
1 parent 8ee1bb6 commit 1499bcd
Show file tree
Hide file tree
Showing 14 changed files with 463 additions and 53 deletions.
87 changes: 87 additions & 0 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down Expand Up @@ -7064,6 +7114,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": {
Expand Down Expand Up @@ -9378,6 +9454,17 @@ const docTemplate = `{
}
}
},
"ListBankResponse": {
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"$ref": "#/definitions/Bank"
}
}
}
},
"ListFeedbackResponse": {
"type": "object",
"properties": {
Expand Down
87 changes: 87 additions & 0 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down Expand Up @@ -7057,6 +7107,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": {
Expand Down Expand Up @@ -9371,6 +9447,17 @@
}
}
},
"ListBankResponse": {
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"$ref": "#/definitions/Bank"
}
}
}
},
"ListFeedbackResponse": {
"type": "object",
"properties": {
Expand Down
57 changes: 57 additions & 0 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -1847,6 +1864,13 @@ definitions:
$ref: '#/definitions/BankAccount'
type: array
type: object
ListBankResponse:
properties:
data:
items:
$ref: '#/definitions/Bank'
type: array
type: object
ListFeedbackResponse:
properties:
data:
Expand Down Expand Up @@ -4302,6 +4326,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:
Expand Down
2 changes: 1 addition & 1 deletion pkg/handler/bankaccount/bank_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
})

Expand Down
1 change: 1 addition & 0 deletions pkg/handler/metadata/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
41 changes: 41 additions & 0 deletions pkg/handler/metadata/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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, ""))
}
6 changes: 6 additions & 0 deletions pkg/handler/metadata/request/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
1 change: 1 addition & 0 deletions pkg/routes/v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions pkg/routes/v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading

0 comments on commit 1499bcd

Please sign in to comment.