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

Luis Dourado Submission #317

Open
wants to merge 141 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
141 commits
Select commit Hold shift + click to select a range
0ea3f79
feat(structure): create initial project structure
lutefd Aug 5, 2024
b784022
feat(model): create currency and exchange rates model
lutefd Aug 5, 2024
939b176
feat(repository): create currency repository interface
lutefd Aug 5, 2024
379e89f
feat(service): create currency service and its initial implementation
lutefd Aug 5, 2024
bb29417
feat(handler): create currency handler and its initial implementation
lutefd Aug 5, 2024
87de538
feat(cache): create cache package and define its interface
lutefd Aug 5, 2024
4a1140d
feat(worker): create worker package and define the external api inter…
lutefd Aug 5, 2024
56e215a
feat(server): create config struct and its loader for server setup
lutefd Aug 5, 2024
c8d33cb
refactor(server): update server initialization to use configuration s…
lutefd Aug 5, 2024
818ae97
refactor(main): update server initialization to load configuration
lutefd Aug 5, 2024
3b96363
feat(routes): add currency routes and handlers to server
lutefd Aug 5, 2024
0633172
refactor(cache): rename redis_cache.go to cache.go
lutefd Aug 5, 2024
72facf8
chore(modules): add PostgreSQL and Redis client libraries
lutefd Aug 5, 2024
1b2a85f
refactor(config): improve configuration loading with error handling
lutefd Aug 5, 2024
9c74cc6
refactor(main): improve configuration loading and error handling in main
lutefd Aug 5, 2024
1219c12
feat(repository): add PostgreSQL currency repository implementation
lutefd Aug 5, 2024
891c1ce
feat(cache): add Redis cache implementation
lutefd Aug 5, 2024
8e82a36
feat(worker): add OpenExchangeRates API client implementation
lutefd Aug 5, 2024
8edef47
feat(worker): add rate updater implementation
lutefd Aug 5, 2024
720d663
feat(handler): implement AddCurrency and RemoveCurrency endpoints
lutefd Aug 5, 2024
7bb8a6c
feat(cache): define and implement Close connection method
lutefd Aug 5, 2024
d5b668e
feat(repository): define and implement Close connection method
lutefd Aug 5, 2024
3356b68
feat(logger): add centralized logging utility
lutefd Aug 5, 2024
0de3370
refactor(server): enhance server setup and graceful shutdown
lutefd Aug 5, 2024
ec11f2b
refactor(routes): streamline route registration
lutefd Aug 5, 2024
fba3d34
refactor(main): improve error handling and server initialization
lutefd Aug 5, 2024
054533a
feat(service): implement AddCurrency and RemoveCurrency methods
lutefd Aug 5, 2024
07374db
feat(model): add User model with roles and API key
lutefd Aug 5, 2024
05322fa
feat(worker): add initial rate population on startup
lutefd Aug 5, 2024
6925920
feat(repository): add UserRepository interface
lutefd Aug 5, 2024
b2e6483
feat(repository): add PostgreSQL user repository implementation
lutefd Aug 5, 2024
a917408
feat(handler): add user registration and login endpoints
lutefd Aug 5, 2024
a7b9d2f
feat(server): add user repository initialization
lutefd Aug 5, 2024
2d73018
feat(middleware): add authentication, role-based access control, and …
lutefd Aug 5, 2024
ad81b09
feat(routes): add authentication, role-based access, and rate limitin…
lutefd Aug 5, 2024
0b608b5
fix(user): modified user model to handle login bug
lutefd Aug 5, 2024
79f22ef
chore(modules): add new dependencies for UUID, bcrypt, and rate limiting
lutefd Aug 5, 2024
4304b3a
refactor(model): remove unecessary fields from User model
lutefd Aug 5, 2024
1129b3a
fix(service): ensure that code is always uppercase on creation
lutefd Aug 5, 2024
80f0aee
tests(service): add currency service test
lutefd Aug 5, 2024
d0f71e3
fix(handler): add input validation for the user handler
lutefd Aug 5, 2024
d4e8407
tests(handler): add user handler test
lutefd Aug 5, 2024
de8dcde
fix(handler): ensure that the currency codes from the params are uppe…
lutefd Aug 5, 2024
b91c621
fix(handler): ensure that code parameter is validated
lutefd Aug 5, 2024
4a1d71a
style: change logs and error messages to all lowercase
lutefd Aug 5, 2024
2a8ad12
feat(sql): add goose migration schemas and seed script to repo
lutefd Aug 6, 2024
6a7b357
feat(makefile): add docker and db commands to Makefile
lutefd Aug 6, 2024
e44d21c
refactor(user): separate user logic into service layer
lutefd Aug 6, 2024
3dfed75
refactor(user): implement missing methods in user repository
lutefd Aug 6, 2024
f818749
refactor(user): introduce UserServiceInterface for better testability
lutefd Aug 6, 2024
5524eac
refactor(currency): update currency handler to depend on the service …
lutefd Aug 6, 2024
1853644
tests(handler): add currency handler tests
lutefd Aug 6, 2024
460054d
refactor(model): simplify ExchangeRates struct
lutefd Aug 6, 2024
d701c09
chore(env): add sample environment configuration file
lutefd Aug 6, 2024
2976188
chore(dependencies): add testify and other indirect dependencies
lutefd Aug 6, 2024
ae30211
feat(model): add Log model for logging
lutefd Aug 6, 2024
cc16660
feat(repository): add LogRepository interface and PostgreSQL implemen…
lutefd Aug 6, 2024
b1c2ee3
feat(logger): add asynchronous logging and persistent log storage
lutefd Aug 6, 2024
f4126f1
feat(logger): add partition manager for log table partitions
lutefd Aug 6, 2024
946fc27
feat(server): integrate logging and partition management into server
lutefd Aug 6, 2024
c1430b8
chore(dependencies): add cron dependency for scheduled tasks
lutefd Aug 6, 2024
1fbd3aa
fix(logger): add error return in PartitionManager Start method
lutefd Aug 6, 2024
55f2c21
refactor(commons): update error logging and add tests for JSON responses
lutefd Aug 6, 2024
94af82e
refactor(tests): correct package name in user handler tests
lutefd Aug 6, 2024
72254b4
chore(dependencies): add new dependencies for testing and utilities
lutefd Aug 6, 2024
232681a
test(cache): add unit tests for Redis cache implementation
lutefd Aug 6, 2024
94f3902
feat(currency): add auditing fields to Currency model and update schema
lutefd Aug 6, 2024
d082b81
feat(repository): add auditing fields to currency repository methods
lutefd Aug 6, 2024
6fea961
feat(service): add UpdateCurrency method and enhance AddCurrency
lutefd Aug 6, 2024
ba3074d
feat(handler): enhance AddCurrency with user context and auditing fields
lutefd Aug 6, 2024
be913a0
feat(handler): enhance currency conversion and addition handlers
lutefd Aug 6, 2024
d8db117
feat(middleware): enhance authentication and role-based access control
lutefd Aug 6, 2024
7078fca
refactor(currency): standardize currency not found error handling
lutefd Aug 6, 2024
c41bad0
feat(currency): add update currency functionality
lutefd Aug 6, 2024
115a540
feat(routes): add route for updating currency
lutefd Aug 6, 2024
ff5d2bd
fix(handler): set CreatedAt and UpdatedAt timestamps for AddCurrency
lutefd Aug 6, 2024
daa6713
test(model): add unit tests for UserDB to User conversion
lutefd Aug 6, 2024
7478b95
feat(worker): enhance OpenExchangeRatesClient with retry policy
lutefd Aug 6, 2024
ee81124
test(worker): add tests for OpenExchangeRatesClient and RateUpdater
lutefd Aug 6, 2024
f38f468
test(worker): enhance RateUpdater tests and improve error handling in…
lutefd Aug 7, 2024
d6efb63
refactor(middleware): update tests and improve rate limit configuration
lutefd Aug 7, 2024
2522134
refactor(seed): improve seeding process and add unit tests
lutefd Aug 7, 2024
715b765
fix(repository): handle no rows affected in currency update
lutefd Aug 7, 2024
8d4fe17
test(repository): add unit tests for user, logger, and currency repos…
lutefd Aug 7, 2024
9a84aa0
chore(dependencies): add go-sqlmock dependency
lutefd Aug 7, 2024
c9a041d
feat(commons): add global constants
lutefd Aug 7, 2024
030ead5
feat(handler): enforce currency code length constraints
lutefd Aug 7, 2024
f1c6c2f
refactor(middleware): improve rate limiting and authentication
lutefd Aug 7, 2024
e4acfce
refactor(logger): externalize constants and improve maintainability
lutefd Aug 7, 2024
d59615e
refactor(repository): enhance database connection handling and add tests
lutefd Aug 7, 2024
f08d946
refactor(server): modify server exports and initialization for better…
lutefd Aug 7, 2024
eb5657f
feat(sql): expand currency code length to 5 characters
lutefd Aug 7, 2024
0376e4c
refactor(config): add constants for strconv parameters
lutefd Aug 7, 2024
ce23e8a
test(config): add tests for LoadConfig function
lutefd Aug 7, 2024
98f86e1
test(e2e): add end-to-end tests
lutefd Aug 7, 2024
250c040
refactor(seed): move seed_test.go from sql to cmd/seed
lutefd Aug 8, 2024
82d9bc2
chore(docker): enhance Dockerfile and migration script for streamline…
lutefd Aug 8, 2024
24c7349
chore(docker): optimize app Dockerfile and docker-compose configuration
lutefd Aug 8, 2024
9240db0
chore(makefile): update test command to run all tests
lutefd Aug 8, 2024
40f2c87
refactor(tests): change connection string building
lutefd Aug 8, 2024
e517518
refactor(config): split PostgreSQL connection string into individual …
lutefd Aug 8, 2024
fa1b02a
refactor(pg_currency_repository): remove debug print statement
lutefd Aug 8, 2024
9902b0f
docs(entity-map): add entity map diagram
lutefd Aug 8, 2024
02a8ccf
docs(c4): add C4 model diagram
lutefd Aug 8, 2024
5231278
fix(Dockerfile.migration): remove run_seed.sh and related commands
lutefd Aug 8, 2024
06e9841
refactor(service): update error handling for currency not found
lutefd Aug 8, 2024
a220e59
feat(handler): improve error handling and improve tests for currency …
lutefd Aug 8, 2024
3170eaa
test(e2e): enhance end-to-end tests for currency conversion
lutefd Aug 8, 2024
caed283
refactor(routes): update routes to include versioning and adjust e2e …
lutefd Aug 8, 2024
daa906d
refactor(constants): centralize and use common constants across modules
lutefd Aug 8, 2024
e4aea17
docs(swagger): add Swagger documentation for currency conversion API
lutefd Aug 8, 2024
9dc81b9
chore(dependencies): add go-scalar-api-reference module
lutefd Aug 8, 2024
0618938
chore(docker): include swagger documentation in Docker image
lutefd Aug 8, 2024
13fef25
chore(env): separate PostgreSQL connection string into individual var…
lutefd Aug 8, 2024
363157d
refactor(service): remove unused update method on user service
lutefd Aug 8, 2024
cbf524a
tests(service): add GetByAPIKey tests for user service
lutefd Aug 8, 2024
3379550
docs(diagrams): update generated diagrams for more quality
lutefd Aug 8, 2024
676ebf1
docs(dependency map): add dependency map mermaid and diagram files
lutefd Aug 8, 2024
7efefb1
docs(postman): add a postman collection to facilitate manual testing
lutefd Aug 8, 2024
81c014f
chore(makefile): update testing command
lutefd Aug 8, 2024
c43abc6
docs(README): update README.md and remove README.pt.md
lutefd Aug 8, 2024
617352d
chore(pull-request): fill out pull-request.txt file
lutefd Aug 8, 2024
bfdee23
chore(docker): leave the redis_port as hard setted to streamline setup
lutefd Aug 8, 2024
5ac4714
chore(.env.sample): set temporary api key to streamline setup for eva…
lutefd Aug 8, 2024
7f3864f
docs(README): update README.md to include sections on auto-generated …
lutefd Aug 8, 2024
1666910
chore(.env.sample): fix the comment in the .env.sample
lutefd Aug 8, 2024
6d41c8d
feat(service): Implement in-flight request deduplication and negative…
lutefd Aug 8, 2024
9f69af5
refactor(service): simplify CurrencyService by removing external API …
lutefd Aug 9, 2024
b94f2a1
docs(readme): Update README with additional instruction for `AllowedC…
lutefd Aug 9, 2024
2c4a89f
docs(readme): fix typo in README file
lutefd Aug 9, 2024
513bebc
refactor(worker): enhance logging by using logger and use commons con…
lutefd Aug 9, 2024
505a470
refactor(config): move the config functionality for the commons package
lutefd Aug 9, 2024
03e7181
feat(worker): create its own executable and service for the worker
lutefd Aug 9, 2024
040a3c8
docs(README): update README.md to reflect refactors and architecture …
lutefd Aug 9, 2024
eb07d2d
docs(models/maps): update c4 model and dependency map to reflect prev…
lutefd Aug 9, 2024
548b247
docs(README): update README.md to add the models and diagrams
lutefd Aug 9, 2024
ba9650c
feat(worker): implement worker heartbeat mechanism and its constants
lutefd Aug 9, 2024
39544bb
docs(README): update README to add new constants and possible improve…
lutefd Aug 9, 2024
d1c1c1d
docs(README): add seed admin credentials instructions in the readme
lutefd Aug 10, 2024
ddf5d54
style(comments): remove unecessary comments
lutefd Aug 13, 2024
3ec1d6f
fix(worker): add alternative currencies flag to expand currency catal…
lutefd Aug 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
POSTGRES_HOST=0.0.0.0
POSTGRES_USER=curr
POSTGRES_PASSWORD=currpass
POSTGRES_NAME=currdb
POSTGRES_PORT=5432
SERVER_PORT=8080
REDIS_ADDR="localhost:6379"
REDIS_PASSWORD=redis_pass
API_KEY=75cc9115d3524769a498914d118e093a # this is the API key for the OpenExchangeRates service it was generated only for this challenge to help the evaluators to test the API
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.env
/dist/
22 changes: 22 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM golang:1.22 AS builder

WORKDIR /app

COPY go.mod go.sum ./

RUN go mod download
COPY . .

RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main cmd/api/main.go


FROM alpine:latest

RUN apk --no-cache add ca-certificates

WORKDIR /root/

COPY --from=builder /app/main .
COPY --from=builder /app/docs/swagger /root/docs/swagger

CMD ["./main"]
12 changes: 12 additions & 0 deletions Dockerfile.migration
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM golang:1.22
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN go install github.com/pressly/goose/v3/cmd/goose@latest
RUN apt-get update && apt-get install -y postgresql-client
COPY ./sql/schema /app/migrations/
COPY run_migrations.sh /app/
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o seed cmd/seed/seed.go
RUN chmod +x run_migrations.sh
ENTRYPOINT ["/app/run_migrations.sh"]
21 changes: 21 additions & 0 deletions Dockerfile.worker
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM golang:1.22 AS builder

WORKDIR /app

COPY go.mod go.sum ./

RUN go mod download
COPY . .

RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o worker cmd/worker/worker.go


FROM alpine:latest

RUN apk --no-cache add ca-certificates

WORKDIR /root/

COPY --from=builder /app/worker .

CMD ["./worker"]
58 changes: 58 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
include .env

# Build the application
all: build

build:
@echo "Building..."
@go build -o main cmd/api/main.go

# Run the application
run:
@go run cmd/api/main.go

# Test the application
test:
@echo "Testing..."
@go test ./...

# Clean the binary
clean:
@echo "Cleaning..."
@rm -f main

# Live Reload
watch:
@if [ -x "$(GOPATH)/bin/air" ]; then \
"$(GOPATH)/bin/air"; \
@echo "Watching...";\
else \
read -p "air is not installed. Do you want to install it now? (y/n) " choice; \
if [ "$$choice" = "y" ]; then \
go install github.com/cosmtrek/air@latest; \
"$(GOPATH)/bin/air"; \
@echo "Watching...";\
else \
echo "You chose not to install air. Exiting..."; \
exit 1; \
fi; \
fi

# Docker commands
docker-build:
docker build -t myapp .

docker-run:
docker run -p 8080:8080 myapp

# DB commands
migrate-up:
goose -dir ./sql/schema postgres "$(POSTGRES_CONN)" up

migrate-down:
goose -dir ./sql/schema postgres "$(POSTGRES_CONN)" down

seed:
go run ./sql/seed.go

.PHONY: all build run test clean watch docker-build docker-run migrate-up migrate-down seed
Loading