Skip to content

Commit

Permalink
feat: remove mapping and batch (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
gfyrag authored and flemzord committed May 12, 2023
1 parent a3bc45b commit efa43a9
Show file tree
Hide file tree
Showing 30 changed files with 398 additions and 2,206 deletions.
136 changes: 1 addition & 135 deletions openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -300,67 +300,6 @@ paths:
schema:
$ref: '#/components/schemas/ErrorResponse'

/{ledger}/mapping:
get:
tags:
- Mapping
operationId: getMapping
summary: Get the mapping of a ledger
parameters:
- name: ledger
in: path
description: Name of the ledger.
required: true
schema:
type: string
example: ledger001
responses:
"200":
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/MappingResponse'
default:
description: Error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'

put:
tags:
- Mapping
operationId: updateMapping
summary: Update the mapping of a ledger
parameters:
- name: ledger
in: path
description: Name of the ledger.
required: true
schema:
type: string
example: ledger001
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/Mapping'
required: true
responses:
"200":
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/MappingResponse'
default:
description: Error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'

/{ledger}/script:
post:
deprecated: true
Expand Down Expand Up @@ -721,7 +660,7 @@ paths:
content:
application/json:
schema:
$ref: '#/components/schemas/TransactionsResponse'
$ref: '#/components/schemas/TransactionResponse'
default:
description: Error
content:
Expand Down Expand Up @@ -843,40 +782,6 @@ paths:
schema:
$ref: '#/components/schemas/ErrorResponse'

/{ledger}/transactions/batch:
post:
tags:
- Transactions
summary: Create a new batch of transactions to a ledger
operationId: CreateTransactions
parameters:
- name: ledger
in: path
description: Name of the ledger.
required: true
schema:
type: string
example: ledger001
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/Transactions'
required: true
responses:
"200":
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/TransactionsResponse'
default:
description: Error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'

/{ledger}/balances:
get:
tags:
Expand Down Expand Up @@ -1362,29 +1267,6 @@ components:
USD: 100
EUR: 12

Contract:
type: object
properties:
account:
type: string
example: users:001
expr:
type: object
required:
- accounts
- expr

Mapping:
type: object
nullable: true
required:
- contracts
properties:
contracts:
type: array
items:
$ref: '#/components/schemas/Contract'

Posting:
type: object
properties:
Expand Down Expand Up @@ -1559,16 +1441,6 @@ components:
- hash
- date

TransactionsResponse:
type: object
properties:
data:
items:
$ref: '#/components/schemas/Transaction'
type: array
required:
- data

TransactionResponse:
properties:
data:
Expand All @@ -1585,12 +1457,6 @@ components:
required:
- data

MappingResponse:
properties:
data:
$ref: '#/components/schemas/Mapping'
type: object

ConfigInfoResponse:
properties:
data:
Expand Down
1 change: 0 additions & 1 deletion pkg/api/controllers/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,4 @@ var Module = fx.Options(
fx.Provide(NewAccountController),
fx.Provide(NewTransactionController),
fx.Provide(NewBalanceController),
fx.Provide(NewMappingController),
)
45 changes: 0 additions & 45 deletions pkg/api/controllers/mapping_controller.go

This file was deleted.

76 changes: 0 additions & 76 deletions pkg/api/controllers/mapping_controller_test.go

This file was deleted.

8 changes: 3 additions & 5 deletions pkg/api/controllers/pagination_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ func testGetPagination(t *testing.T, api *api.API, txsPages, additionalTxs int)
return func(ctx context.Context) error {
numTxs := txsPages*pageSize + additionalTxs
if numTxs > 0 {
txsData := make([]core.TransactionData, numTxs)
for i := 0; i < numTxs; i++ {
txsData[i] = core.TransactionData{
rec := internal.PostTransaction(t, api, controllers.PostTransaction{
Postings: core.Postings{
{
Source: "world",
Expand All @@ -57,10 +56,9 @@ func testGetPagination(t *testing.T, api *api.API, txsPages, additionalTxs int)
},
},
Reference: fmt.Sprintf("ref:%06d", i),
}
}, false)
require.Equal(t, http.StatusOK, rec.Code, rec.Body.String())
}
rsp := internal.PostTransactionBatch(t, api, core.Transactions{Transactions: txsData})
require.Equal(t, http.StatusOK, rsp.Code, rsp.Body.String())
}

rsp := internal.CountTransactions(api, url.Values{})
Expand Down
40 changes: 2 additions & 38 deletions pkg/api/controllers/transaction_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func (ctl *TransactionController) PostTransaction(w http.ResponseWriter, r *http
Reference: payload.Reference,
Metadata: payload.Metadata,
}
res, err := l.ExecuteTxsData(r.Context(), preview, txData)
res, err := l.ExecuteScript(r.Context(), preview, core.TxToScriptData(txData))
if err != nil {
apierrors.ResponseError(w, r, err)
return
Expand All @@ -222,7 +222,7 @@ func (ctl *TransactionController) PostTransaction(w http.ResponseWriter, r *http
return
}

sharedapi.Ok(w, []core.ExpandedTransaction{res})
sharedapi.Ok(w, res)
}

func (ctl *TransactionController) GetTransaction(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -290,39 +290,3 @@ func (ctl *TransactionController) PostTransactionMetadata(w http.ResponseWriter,

sharedapi.NoContent(w)
}

func (ctl *TransactionController) PostTransactionsBatch(w http.ResponseWriter, r *http.Request) {
l := LedgerFromContext(r.Context())

var txs core.Transactions
if err := json.NewDecoder(r.Body).Decode(&txs); err != nil {
apierrors.ResponseError(w, r, ledger.NewValidationError("invalid transactions format"))
return
}

if len(txs.Transactions) == 0 {
apierrors.ResponseError(w, r, ledger.NewValidationError("no transaction to insert"))
return
}

for i, tx := range txs.Transactions {
if len(tx.Postings) == 0 {
apierrors.ResponseError(w, r, ledger.NewValidationError(errors.New(fmt.Sprintf(
"invalid transaction %d: no postings", i)).Error()))
return
}
if j, err := tx.Postings.Validate(); err != nil {
apierrors.ResponseError(w, r, ledger.NewValidationError(errors.Wrap(err,
fmt.Sprintf("invalid transaction %d: posting %d", i, j)).Error()))
return
}
}

res, err := l.ExecuteTxsData(r.Context(), false, txs.Transactions...)
if err != nil {
apierrors.ResponseError(w, r, err)
return
}

sharedapi.Ok(w, res)
}
Loading

0 comments on commit efa43a9

Please sign in to comment.