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

Add CreateTransaction endpoint #334

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

AmirAgassi
Copy link
Member

@AmirAgassi AmirAgassi commented Jan 4, 2025

Description

Adds a new endpoint for recording blockchain transactions associated with specific projects.

Linked Issues

Testing

  • backend/internal/tests/transactions_test.go

Checklist

Before opening this PR, make sure the PR:

  • Has an assignee or group of assignees.
  • Has a reviewer or a group of reviewers.
  • Is labelled properly.
  • Has the SPUR project assigned to it.
  • Has an assigned milestone.

Additionally, make sure that:

  • I have commented my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation.
  • My changes generate no new warnings.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • Any dependent changes have been merged and published in downstream modules.

@AmirAgassi AmirAgassi added enhancement New feature or request backend Related to the backend of the project api Related to the backend routes and endpoints labels Jan 4, 2025
@AmirAgassi AmirAgassi added this to the Complete the project MVP milestone Jan 4, 2025
@AmirAgassi AmirAgassi self-assigned this Jan 4, 2025
@AmirAgassi AmirAgassi linked an issue Jan 4, 2025 that may be closed by this pull request
4 tasks
Comment on lines +13 to +26
var req CreateTransactionRequest
if err := c.Bind(&req); err != nil {
return v1_common.Fail(c, http.StatusBadRequest, "Invalid request body", err)
}

// Validate request
if err := c.Validate(&req); err != nil {
return v1_common.Fail(c, http.StatusBadRequest, "Validation failed", err)
}

// Validate project ID format
if _, err := uuid.Parse(req.ProjectID); err != nil {
return v1_common.Fail(c, http.StatusBadRequest, "Invalid project ID format", err)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we not taking advantage of the validate tags and the request validator middleware?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also we have helpers functions that simplify some of this logic

Comment on lines +10 to +24
ProjectID string `json:"project_id" validate:"required,uuid4"`
TxHash string `json:"tx_hash" validate:"required"`
FromAddress string `json:"from_address" validate:"required"`
ToAddress string `json:"to_address" validate:"required"`
ValueAmount string `json:"value_amount" validate:"required,numeric"`
}

type TransactionResponse struct {
ID string `json:"id"`
ProjectID string `json:"project_id"`
CompanyID string `json:"company_id"`
TxHash string `json:"tx_hash"`
FromAddress string `json:"from_address"`
ToAddress string `json:"to_address"`
ValueAmount string `json:"value_amount"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can add validate tags here so that request objects can be validated using the request validator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Related to the backend routes and endpoints backend Related to the backend of the project enhancement New feature or request
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

[BE Feat] Create CreateTransaction endpoint
3 participants