{"id":25085842,"url":"https://github.com/pablorodrigo52/transactions-api","last_synced_at":"2025-04-01T13:42:21.562Z","repository":{"id":270512025,"uuid":"909522946","full_name":"pablorodrigo52/transactions-api","owner":"pablorodrigo52","description":"Go REST API with Layered Architecture","archived":false,"fork":false,"pushed_at":"2025-01-02T14:27:05.000Z","size":1558,"stargazers_count":0,"open_issues_count":5,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-07T08:35:37.859Z","etag":null,"topics":["go","golang","layered-architecture","rest-api","restful-api","third-party"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pablorodrigo52.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-12-29T00:39:18.000Z","updated_at":"2025-01-19T01:33:24.000Z","dependencies_parsed_at":"2024-12-31T20:28:15.514Z","dependency_job_id":"8ab05aa1-ad2d-426a-b86f-80ad9a37f00e","html_url":"https://github.com/pablorodrigo52/transactions-api","commit_stats":null,"previous_names":["pablorodrigo52/transactions-api"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pablorodrigo52%2Ftransactions-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pablorodrigo52%2Ftransactions-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pablorodrigo52%2Ftransactions-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pablorodrigo52%2Ftransactions-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pablorodrigo52","download_url":"https://codeload.github.com/pablorodrigo52/transactions-api/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246651149,"owners_count":20811989,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","golang","layered-architecture","rest-api","restful-api","third-party"],"created_at":"2025-02-07T08:29:53.900Z","updated_at":"2025-04-01T13:42:21.545Z","avatar_url":"https://github.com/pablorodrigo52.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# transactions-api \n\u003cimg src=\"docs/assets/Go-Logo_Blue.png\" alt=\"golang blue logo\" style=\" width: 50px;\"\u003e\u003cbr/\u003e \n----\n\nThis is a Go API that communicate with [Treasury Reporting Rates of Exchange API](https://fiscaldata.treasury.gov/datasets/treasury-reporting-rates-exchange/treasury-reporting-rates-of-exchange) to recover the dollar exchange rate in other countries by reportings done by agencies of the government.\n\nTo validate this communication this API is a backend that delivers a transaction CRUD that is the simulation of a product purchase in dollars. In a transaction we need to inform: \n- description: some description about transaction\n- transaction_date: a valid date\n- purhcase_amount: in US-dollar\n\n## Pattern\n\nI choose to use a layered architecture for this project:\n- It's a simple way to implement a project like this quickly;\n- The API still remains with separated reponsabilitities which it is easy to mantain and test;\n- If necessary, its easy to escalate for another architecture more robust.\n\n![pattern](docs/assets/image-1.png)\n\n## Data model\n\nFor this project I choose to use a simple table to store the transactions. The table contains the following fields:\n```sql\nCREATE TABLE IF NOT EXISTS transactions (\n    id INTEGER PRIMARY KEY AUTOINCREMENT, -- auto incremented field starting from 1\n    description TEXT NOT NULL,\n    transaction_date TEXT NOT NULL,\n    purchase_amount REAL NOT NULL,\n    deleted INTEGER NOT NULL DEFAULT 0\n);\n```\nThis database run using a SQLite database, so no external dependencies is needed and the files can de founded in the `db/` and `scripts/` folder.\n\n## Communication with external APIs\n\nTo communicate with the external API I choose to use the [http](https://pkg.go.dev/net/http) package from Go. This package is a simple way to make requests to external APIs and it's easy to use.\nThe communication with [Treasury Reporting Rates of Exchange API](https://fiscaldata.treasury.gov/datasets/treasury-reporting-rates-exchange/treasury-reporting-rates-of-exchange) was builded with the following parameters:\n\n```\nfields=record_date,country,exchange_rate,currency,effective_date\u0026\nfilter=country:eq:%s\u0026\nsort=-record_date\u0026\npage[number]=1\u0026\npage[size]=1\u0026\nformat=json\n```\nThis guarantees that I will recover from the server only the necessary data and the most recent data from the country that I want to convert the currency.\n\n## How to Run\n\nThis project run with a local database [sqlite](https://www.sqlite.org/) so no external dependencies is needed. \u003cbr/\u003e\nThis project was built with go [v1.23](https://go.dev/dl/).\u003cbr\u003e\n\nTo run this project just download the repository and inside the `cmd/` folder run the go program with the command: \n```sh\n    go run main.go\n```\n\n## Endpoints\n\nTo help I [created this postman collection](docs/assets/transaction-api.postman_collection) \u003cimg src=\"docs/assets/postman.png\" alt=\"golang blue logo\" style=\" width: 20px;\"\u003e\u003cbr/\u003e \n\n**GET /ping**\n\n#### Responses\n- `200`: Server is alive\n----\n### Get transaction by ID\n\n**GET /v1/transaction/{id}**\n\n#### Parameters\n- `id` (path, required): The ID of the transaction\n\n#### Responses\n- `200`: Transaction details\n- `400`: Validations errors in request body and parameters\n- `404`: Transaction not found\n- `500`: Errors in stable communication with database\n  \n\u003cimg src=\"docs/assets/sequence-get-without-cache.png\" alt=\"sequence-diagram-get-without-cache\"\u003e\u003cbr/\u003e\n\u003cimg src=\"docs/assets/sequence-get-cache.png\" alt=\"sequence-diagram-get-with-cache\"\u003e\u003cbr/\u003e\n\n----\n### Create a new transaction\n\n**POST /v1/transaction**\n\n#### Request Body\n- `purchase_amount` (float, required): The amount of the transaction\n- `description` (string, required): The description of the transaction\n- `transaction_date` (string, required): The transaction date in the format YYYY-MM-DDTHH:mm:ssZ\n\n#### Responses\n- `201`: Transaction created\n- `400`: Validations errors in request body and parameters\n- `500`: Errors in stable communication with database\n\n\u003cimg src=\"docs/assets/sequence-post.png\" alt=\"sequence-diagram-post\"\u003e\u003cbr/\u003e\n\n----\n### Update transaction by ID\n\n**PUT /v1/transaction/{id}**\n\n#### Parameters\n- `id` (path, required): The ID of the transaction\n\n#### Request Body\n- `purchase_amount` (float, required): The amount of the transaction\n- `description` (string, required): The description of the transaction\n- `transaction_date` (string, required): The transaction date in the format YYYY-MM-DDTHH:mm:ssZ\n  \n#### Responses\n- `200`: Transaction updated\n- `400`: Validations errors in request body and parameters\n- `404`: Transaction not found\n- `500`: Errors in stable communication with database\n----\n### Delete transaction by ID\n\n**DELETE /v1/transaction/{id}**\n\n#### Parameters\n- `id` (path, required): The ID of the transaction\n\n#### Responses\n- `200`: Transaction updated\n- `400`: Validations errors in request body and parameters\n- `404`: Transaction not found\n- `500`: Errors in stable communication with database\n----\n### Get transaction currency conversion\n\n**GET /v1/converter/transaction/{id}/currency/{country}**\n\n#### Parameters\n- `id` (path, required): The ID of the transaction\n- `country` (path, required): The country name for currency conversion. The country names can be found [here](https://fiscaldata.treasury.gov/datasets/treasury-reporting-rates-exchange/treasury-reporting-rates-of-exchange).\n\n#### Responses\n- `200`: Currency conversion details\n- `400`: Validations errors in request body and parameters\n- `404`: Transaction or country not found\n- `424`: Errors in stable communication with database\n- `502`: Errors in stable communication https://fiscaldata.treasury.gov\n\n\u003cimg src=\"docs/assets/sequence-currency.png\"\u003e\u003cbr/\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpablorodrigo52%2Ftransactions-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpablorodrigo52%2Ftransactions-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpablorodrigo52%2Ftransactions-api/lists"}