Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correction webhook eventhandler #815

Merged
merged 9 commits into from
Dec 27, 2024
4 changes: 2 additions & 2 deletions router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@
apiTransactions.POST(
"",
h.PostTransaction,
middleware.BodyDump(service.WebhookEventHandler),
middleware.BodyDump(service.WebhookPostEventHandler),

Check warning on line 75 in router/router.go

View check run for this annotation

Codecov / codecov/patch

router/router.go#L75

Added line #L75 was not covered by tests
h.CheckAdminMiddleware)
apiTransactions.GET("/:transactionID", h.GetTransaction)
apiTransactions.PUT(
"/:transactionID",
h.PutTransaction,
middleware.BodyDump(service.WebhookEventHandler),
middleware.BodyDump(service.WebhookPutEventHandler),

Check warning on line 81 in router/router.go

View check run for this annotation

Codecov / codecov/patch

router/router.go#L81

Added line #L81 was not covered by tests
h.CheckAdminMiddleware)
}

Expand Down
25 changes: 18 additions & 7 deletions router/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,18 @@ import (
"go.uber.org/zap"
)

type Transaction struct {
type TransactionNewCreate struct {
ID uuid.UUID `json:"id"`
Amount int `json:"amount"`
Target string `json:"target"`
Request *uuid.UUID `json:"request"`
Tags []*TagOverview `json:"tags"`
Group *GroupOverview `json:"group"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}

type TransactionCorrection struct {
ID uuid.UUID `json:"id"`
Amount int `json:"amount"`
Target string `json:"target"`
Expand Down Expand Up @@ -137,7 +148,7 @@ func (h Handlers) GetTransactions(c echo.Context) error {
return echo.NewHTTPError(http.StatusInternalServerError, err)
}

res := lo.Map(txs, func(tx *model.TransactionResponse, _ int) *Transaction {
res := lo.Map(txs, func(tx *model.TransactionResponse, _ int) *TransactionNewCreate {
tags := lo.Map(tx.Tags, func(tag *model.Tag, _ int) *TagOverview {
return &TagOverview{
ID: tag.ID,
Expand All @@ -158,7 +169,7 @@ func (h Handlers) GetTransactions(c echo.Context) error {
UpdatedAt: tx.Group.UpdatedAt,
}
}
return &Transaction{
return &TransactionNewCreate{
ID: tx.ID,
Amount: tx.Amount,
Target: tx.Target,
Expand All @@ -180,7 +191,7 @@ func (h Handlers) PostTransaction(c echo.Context) error {
return echo.NewHTTPError(http.StatusBadRequest, err)
}

transactions := []*Transaction{}
transactions := []*TransactionNewCreate{}
ctx := c.Request().Context()
for _, target := range tx.Targets {
if target == nil {
Expand Down Expand Up @@ -215,7 +226,7 @@ func (h Handlers) PostTransaction(c echo.Context) error {
UpdatedAt: created.Group.UpdatedAt,
}
}
res := Transaction{
res := TransactionNewCreate{
ID: created.ID,
Amount: created.Amount,
Target: created.Target,
Expand Down Expand Up @@ -265,7 +276,7 @@ func (h Handlers) GetTransaction(c echo.Context) error {
UpdatedAt: tx.Group.UpdatedAt,
}
}
res := Transaction{
res := TransactionCorrection{
ID: tx.ID,
Amount: tx.Amount,
Target: tx.Target,
Expand Down Expand Up @@ -323,7 +334,7 @@ func (h Handlers) PutTransaction(c echo.Context) error {
UpdatedAt: updated.Group.UpdatedAt,
}
}
res := Transaction{
res := TransactionCorrection{
ID: updated.ID,
Amount: updated.Amount,
Target: updated.Target,
Expand Down
34 changes: 17 additions & 17 deletions router/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func TestHandlers_GetTransactions(t *testing.T) {
}).
Return(txs, nil)

res := lo.Map(txs, func(tx *model.TransactionResponse, _ int) *Transaction {
res := lo.Map(txs, func(tx *model.TransactionResponse, _ int) *TransactionNewCreate {
tag := lo.Map(tx.Tags, func(modelTag *model.Tag, _ int) *TagOverview {
return &TagOverview{
ID: modelTag.ID,
Expand All @@ -118,7 +118,7 @@ func TestHandlers_GetTransactions(t *testing.T) {
CreatedAt: tx.Group.CreatedAt,
UpdatedAt: tx.Group.UpdatedAt,
}
return &Transaction{
return &TransactionNewCreate{
ID: tx.ID,
Amount: tx.Amount,
Target: tx.Target,
Expand Down Expand Up @@ -213,7 +213,7 @@ func TestHandlers_GetTransactions(t *testing.T) {
}).
Return(txs, nil)

res := lo.Map(txs, func(tx *model.TransactionResponse, _ int) *Transaction {
res := lo.Map(txs, func(tx *model.TransactionResponse, _ int) *TransactionNewCreate {
tag := lo.Map(tx.Tags, func(modelTag *model.Tag, _ int) *TagOverview {
return &TagOverview{
ID: modelTag.ID,
Expand All @@ -231,7 +231,7 @@ func TestHandlers_GetTransactions(t *testing.T) {
CreatedAt: tx.Group.CreatedAt,
UpdatedAt: tx.Group.UpdatedAt,
}
return &Transaction{
return &TransactionNewCreate{
ID: tx.ID,
Amount: tx.Amount,
Target: tx.Target,
Expand Down Expand Up @@ -327,7 +327,7 @@ func TestHandlers_GetTransactions(t *testing.T) {
}).
Return(txs, nil)

res := lo.Map(txs, func(tx *model.TransactionResponse, _ int) *Transaction {
res := lo.Map(txs, func(tx *model.TransactionResponse, _ int) *TransactionNewCreate {
tag := lo.Map(tx.Tags, func(modelTag *model.Tag, _ int) *TagOverview {
return &TagOverview{
ID: modelTag.ID,
Expand All @@ -345,7 +345,7 @@ func TestHandlers_GetTransactions(t *testing.T) {
CreatedAt: tx.Group.CreatedAt,
UpdatedAt: tx.Group.UpdatedAt,
}
return &Transaction{
return &TransactionNewCreate{
ID: tx.ID,
Amount: tx.Amount,
Target: tx.Target,
Expand Down Expand Up @@ -446,7 +446,7 @@ func TestHandlers_GetTransactions(t *testing.T) {
}).
Return(txs, nil)

res := lo.Map(txs, func(tx *model.TransactionResponse, _ int) *Transaction {
res := lo.Map(txs, func(tx *model.TransactionResponse, _ int) *TransactionNewCreate {
tag := lo.Map(tx.Tags, func(modelTag *model.Tag, _ int) *TagOverview {
return &TagOverview{
ID: modelTag.ID,
Expand All @@ -464,7 +464,7 @@ func TestHandlers_GetTransactions(t *testing.T) {
CreatedAt: tx.Group.CreatedAt,
UpdatedAt: tx.Group.UpdatedAt,
}
return &Transaction{
return &TransactionNewCreate{
ID: tx.ID,
Amount: tx.Amount,
Target: tx.Target,
Expand Down Expand Up @@ -549,7 +549,7 @@ func TestHandlers_GetTransactions(t *testing.T) {
}).
Return(txs, nil)

res := lo.Map(txs, func(tx *model.TransactionResponse, _ int) *Transaction {
res := lo.Map(txs, func(tx *model.TransactionResponse, _ int) *TransactionNewCreate {
tag := lo.Map(tx.Tags, func(modelTag *model.Tag, _ int) *TagOverview {
return &TagOverview{
ID: modelTag.ID,
Expand All @@ -567,7 +567,7 @@ func TestHandlers_GetTransactions(t *testing.T) {
CreatedAt: tx.Group.CreatedAt,
UpdatedAt: tx.Group.UpdatedAt,
}
return &Transaction{
return &TransactionNewCreate{
ID: tx.ID,
Amount: tx.Amount,
Target: tx.Target,
Expand Down Expand Up @@ -655,7 +655,7 @@ func TestHandlers_PostTransaction(t *testing.T) {
CreateTransaction(c.Request().Context(), tx1.Amount, tx1.Target, tags, &group, nil).
Return(tx1, nil)

res := lo.Map(txs, func(tx *model.TransactionResponse, _ int) *Transaction {
res := lo.Map(txs, func(tx *model.TransactionResponse, _ int) *TransactionNewCreate {
tag := lo.Map(tx.Tags, func(modelTag *model.Tag, _ int) *TagOverview {
return &TagOverview{
ID: modelTag.ID,
Expand All @@ -673,7 +673,7 @@ func TestHandlers_PostTransaction(t *testing.T) {
CreatedAt: tx.Group.CreatedAt,
UpdatedAt: tx.Group.UpdatedAt,
}
return &Transaction{
return &TransactionNewCreate{
ID: tx.ID,
Amount: tx.Amount,
Target: tx.Target,
Expand Down Expand Up @@ -788,7 +788,7 @@ func TestHandlers_PostTransaction(t *testing.T) {
CreatedAt: tx.Group.CreatedAt,
UpdatedAt: tx.Group.UpdatedAt,
}
res := []*Transaction{
res := []*TransactionNewCreate{
{
ID: tx.ID,
Amount: tx.Amount,
Expand Down Expand Up @@ -861,7 +861,7 @@ func TestHandlers_GetTransaction(t *testing.T) {
GetTransaction(c.Request().Context(), tx.ID).
Return(tx, nil)

var resOverview Transaction
var resOverview TransactionCorrection
to := lo.Map(tx.Tags, func(modelTag *model.Tag, _ int) *TagOverview {
return &TagOverview{
ID: modelTag.ID,
Expand All @@ -879,7 +879,7 @@ func TestHandlers_GetTransaction(t *testing.T) {
CreatedAt: tx.Group.CreatedAt,
UpdatedAt: tx.Group.UpdatedAt,
}
resOverview = Transaction{
resOverview = TransactionCorrection{
ID: tx.ID,
Amount: tx.Amount,
Target: tx.Target,
Expand Down Expand Up @@ -990,7 +990,7 @@ func TestHandlers_PutTransaction(t *testing.T) {
updatedTags, nil, nil).
Return(updated, nil)

var resOverview Transaction
var resOverview TransactionCorrection
to := lo.Map(updated.Tags, func(modelTag *model.Tag, _ int) *TagOverview {
return &TagOverview{
ID: modelTag.ID,
Expand All @@ -1007,7 +1007,7 @@ func TestHandlers_PutTransaction(t *testing.T) {
CreatedAt: updated.Group.CreatedAt,
UpdatedAt: updated.Group.UpdatedAt,
}
resOverview = Transaction{
resOverview = TransactionCorrection{
ID: tx.ID,
Amount: updated.Amount,
Target: updated.Target,
Expand Down
Loading
Loading