Skip to content

Add GET /v1/currencies endpoint#5

Merged
kamaal111 merged 5 commits into
mainfrom
copilot/add-symbols-list-endpoint
Mar 3, 2026
Merged

Add GET /v1/currencies endpoint#5
kamaal111 merged 5 commits into
mainfrom
copilot/add-symbols-list-endpoint

Conversation

Copilot AI commented Mar 2, 2026

Copy link
Copy Markdown
Contributor
  • Add NamedSymbol and CurrenciesRecord types to handlers/service.go
  • Add CurrencyNames map; derive Currencies from its keys (single source of truth)
  • Add GetAllNamedSymbols() service method
  • Create handlers/named_symbols.go with GetCurrencies handler
  • Create handlers/named_symbols_test.go with unit tests
  • Create routers/currencies.go with currenciesGroup registering GET /v1/currencies
  • Remove /v1/rates/currencies from routers/rates.go
  • Register currenciesGroup in routers/routers.go
  • Update integration test helper to use /v1/currencies
  • Update README to document GET /v1/currencies
  • Create handlers/routes.go with exported path constants (LatestPath, SymbolsPath, CurrenciesPath)
  • Update routers/rates.go and routers/currencies.go to reference the constants
  • Update all handler tests (rates_test.go, symbols_test.go, named_symbols_test.go) to reference the constants instead of hardcoded strings
  • All unit tests passing
Original prompt

Create a new endpoint that lists all symbols, just like the existing /symbols does, but instead of a flat list make it a list of objects, containing symbol, which is the symbol for example USD, and a human readable name called name, which is for USD US Dollar.
Just like the symbols endpoint you must only get the symbols which have a database entry, so if you need to extract functions out of the symbols endpoint to reuse in this new one then do so.

Make sure its well tested with integration tests that show exactly how it functions, so don't write tests just for the sake of testing, you must create clear test cases in integration style showing the success cases and failure cases.

Make sure all tests are passing before committing.

Once done then also document it in the README


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: kamaal111 <37084924+kamaal111@users.noreply.github.com>
Copilot AI changed the title [WIP] Add new endpoint for listing symbols with detailed objects Add GET /v1/rates/named-symbols endpoint Mar 2, 2026
@kamaal111 kamaal111 marked this pull request as ready for review March 2, 2026 09:54
Comment thread README.md Outdated
### Get All Available Currency Symbols with Names

```
GET /v1/rates/named-symbols

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

@copilot Please call it currencies and make sure its updated everywhere

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in commit 9e70e9c. The endpoint is now GET /v1/rates/currencies, with the handler renamed to GetCurrencies, the integration helper to GetCurrencies(), and all tests and README updated accordingly.

Comment thread README.md Outdated
```json
{
"date": "2025-12-05",
"symbols": [

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

@copilot this should be data

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in commit 9e70e9c. The response field is now dataCurrenciesRecord.Data with JSON tag "data".

Comment thread handlers/service.go
"ZAR",
}

var CurrencyNames = map[string]string{

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

@copilot you must ensure that this map contains all currency symbols above, or you can do it the other way around which is derive the currencies above from this maps keys

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in commit 9e70e9c. Currencies is now derived from the keys of CurrencyNames, so they're always in sync — adding a currency to CurrencyNames automatically makes it available in Currencies.

…data, derive Currencies from CurrencyNames

Co-authored-by: kamaal111 <37084924+kamaal111@users.noreply.github.com>
Copilot AI changed the title Add GET /v1/rates/named-symbols endpoint Add GET /v1/rates/currencies endpoint Mar 2, 2026
Comment thread README.md Outdated
### Get All Available Currencies with Names

```
GET /v1/rates/currencies

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

@copilot it does not make sense to put it under rates anymore. Please move the route to /v1/currencies

You will have to create a new route group in its own file

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in commit 4772203. The endpoint is now GET /v1/currencies, registered in a new routers/currencies.go file via a currenciesGroup function. The route has been removed from rates.go and the new group is registered in routers.go.

Co-authored-by: kamaal111 <37084924+kamaal111@users.noreply.github.com>
Copilot AI changed the title Add GET /v1/rates/currencies endpoint Add GET /v1/currencies endpoint Mar 2, 2026
@kamaal111 kamaal111 requested a review from Copilot March 2, 2026 13:02

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds a new GET /v1/currencies endpoint that mirrors the existing symbols endpoint but returns a richer, DB-backed list of currency objects (symbol + human-readable name).

Changes:

  • Added CurrencyNames mapping and a GetAllNamedSymbols() service method to enrich DB symbols with display names.
  • Added GetCurrencies handler and registered the new /v1/currencies route.
  • Added unit + integration test coverage and documented the new endpoint in the README.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
handlers/service.go Introduces named-currency response types, name mapping, and service method to enrich stored symbols with names.
handlers/named_symbols.go Implements GET /v1/currencies handler following the existing symbols handler pattern.
handlers/named_symbols_test.go Adds unit tests for the new handler behavior (success/404/500).
routers/currencies.go Registers the new /v1/currencies route.
routers/routers.go Hooks the currencies route group into server startup.
test/integration/helpers.go Adds integration test helper for calling /v1/currencies.
test/integration/integration_test.go Adds integration tests for /v1/currencies behavior and response shape/headers.
README.md Documents the new endpoint and example response.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread handlers/named_symbols_test.go Outdated

handler := TestableCurrenciesHandler(mockRepo)

req := httptest.NewRequest(http.MethodGet, "/v1/rates/currencies", nil)

Copilot AI Mar 2, 2026

Copy link

Choose a reason for hiding this comment

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

The unit test builds a request to "/v1/rates/currencies", but the route registered in routers is "/v1/currencies". Even though this handler doesn’t currently use the URL path, the test should use the real endpoint path to avoid masking future routing/path-dependent logic.

Suggested change
req := httptest.NewRequest(http.MethodGet, "/v1/rates/currencies", nil)
req := httptest.NewRequest(http.MethodGet, "/v1/currencies", nil)

Copilot uses AI. Check for mistakes.
Comment thread handlers/named_symbols_test.go Outdated

handler := TestableCurrenciesHandler(mockRepo)

req := httptest.NewRequest(http.MethodGet, "/v1/rates/currencies", nil)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

@copilot the old path is still defined here, but I see this as a bigger problem in these kind of tests because we keep have reconstruct the names and hope they remain in sync.

Make sure that we always use the production route names for these kind of tests and don't duplicate them because you might get in to this situation again

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in commit 9aac4db. Added handlers/routes.go with exported path constants (LatestPath, SymbolsPath, CurrenciesPath). The routers and all handler tests now reference these constants instead of hardcoded strings, so they can never drift out of sync again.

…and tests

Co-authored-by: kamaal111 <37084924+kamaal111@users.noreply.github.com>
@kamaal111 kamaal111 merged commit 313de3d into main Mar 3, 2026
1 check passed
@kamaal111 kamaal111 deleted the copilot/add-symbols-list-endpoint branch March 3, 2026 01:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants