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
26 changes: 19 additions & 7 deletions router/transaction.go
Hueter57 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,19 @@ import (
"go.uber.org/zap"
)

type Transaction struct {
type TransactionNewCreate struct {
ID uuid.UUID `json:"id"`
Title string `json:"title"`
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"`
Title string `json:"title"`
Amount int `json:"amount"`
Expand Down Expand Up @@ -140,7 +152,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 @@ -161,7 +173,7 @@ func (h Handlers) GetTransactions(c echo.Context) error {
UpdatedAt: tx.Group.UpdatedAt,
}
}
return &Transaction{
return &TransactionNewCreate{
ID: tx.ID,
Title: tx.Title,
Amount: tx.Amount,
Expand All @@ -185,7 +197,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 @@ -220,7 +232,7 @@ func (h Handlers) PostTransaction(c echo.Context) error {
UpdatedAt: created.Group.UpdatedAt,
}
}
res := Transaction{
res := TransactionNewCreate{
ID: created.ID,
Title: created.Title,
Amount: created.Amount,
Expand Down Expand Up @@ -271,7 +283,7 @@ func (h Handlers) GetTransaction(c echo.Context) error {
UpdatedAt: tx.Group.UpdatedAt,
}
}
res := Transaction{
res := TransactionCorrection{
ID: tx.ID,
Title: tx.Title,
Amount: tx.Amount,
Expand Down Expand Up @@ -331,7 +343,7 @@ func (h Handlers) PutTransaction(c echo.Context) error {
UpdatedAt: updated.Group.UpdatedAt,
}
}
res := Transaction{
res := TransactionCorrection{
ID: updated.ID,
Title: updated.Title,
Amount: updated.Amount,
Expand Down
30 changes: 15 additions & 15 deletions router/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,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 @@ -120,7 +120,7 @@ func TestHandlers_GetTransactions(t *testing.T) {
CreatedAt: tx.Group.CreatedAt,
UpdatedAt: tx.Group.UpdatedAt,
}
return &Transaction{
return &TransactionNewCreate{
ID: tx.ID,
Title: tx.Title,
Amount: tx.Amount,
Expand Down Expand Up @@ -218,7 +218,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 @@ -236,7 +236,7 @@ func TestHandlers_GetTransactions(t *testing.T) {
CreatedAt: tx.Group.CreatedAt,
UpdatedAt: tx.Group.UpdatedAt,
}
return &Transaction{
return &TransactionNewCreate{
ID: tx.ID,
Title: tx.Title,
Amount: tx.Amount,
Expand Down Expand Up @@ -335,7 +335,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 @@ -353,7 +353,7 @@ func TestHandlers_GetTransactions(t *testing.T) {
CreatedAt: tx.Group.CreatedAt,
UpdatedAt: tx.Group.UpdatedAt,
}
return &Transaction{
return &TransactionNewCreate{
ID: tx.ID,
Title: tx.Title,
Amount: tx.Amount,
Expand Down Expand Up @@ -457,7 +457,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 @@ -475,7 +475,7 @@ func TestHandlers_GetTransactions(t *testing.T) {
CreatedAt: tx.Group.CreatedAt,
UpdatedAt: tx.Group.UpdatedAt,
}
return &Transaction{
return &TransactionNewCreate{
ID: tx.ID,
Title: tx.Title,
Amount: tx.Amount,
Expand Down Expand Up @@ -562,7 +562,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 @@ -580,7 +580,7 @@ func TestHandlers_GetTransactions(t *testing.T) {
CreatedAt: tx.Group.CreatedAt,
UpdatedAt: tx.Group.UpdatedAt,
}
return &Transaction{
return &TransactionNewCreate{
ID: tx.ID,
Title: tx.Title,
Amount: tx.Amount,
Expand Down Expand Up @@ -673,7 +673,7 @@ func TestHandlers_PostTransaction(t *testing.T) {
tx1.Title, 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 @@ -691,7 +691,7 @@ func TestHandlers_PostTransaction(t *testing.T) {
CreatedAt: tx.Group.CreatedAt,
UpdatedAt: tx.Group.UpdatedAt,
}
return &Transaction{
return &TransactionNewCreate{
ID: tx.ID,
Title: tx.Title,
Amount: tx.Amount,
Expand Down Expand Up @@ -810,7 +810,7 @@ func TestHandlers_PostTransaction(t *testing.T) {
CreatedAt: tx.Group.CreatedAt,
UpdatedAt: tx.Group.UpdatedAt,
}
res := []*Transaction{
res := []*TransactionNewCreate{
{
ID: tx.ID,
Title: tx.Title,
Expand Down Expand Up @@ -905,7 +905,7 @@ func TestHandlers_GetTransaction(t *testing.T) {
CreatedAt: tx.Group.CreatedAt,
UpdatedAt: tx.Group.UpdatedAt,
}
resOverview := Transaction{
resOverview := TransactionCorrection{
ID: tx.ID,
Title: tx.Title,
Amount: tx.Amount,
Expand Down Expand Up @@ -1034,7 +1034,7 @@ func TestHandlers_PutTransaction(t *testing.T) {
CreatedAt: updated.Group.CreatedAt,
UpdatedAt: updated.Group.UpdatedAt,
}
resOverview := Transaction{
resOverview := TransactionCorrection{
ID: tx.ID,
Title: updated.Title,
Amount: updated.Amount,
Expand Down
Loading
Loading