Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
13b5df5
chore: implement initial structure
jpeccia Apr 2, 2025
c6c6f33
build: install gin framework
jpeccia Apr 2, 2025
4c923a3
build: install gorm
jpeccia Apr 2, 2025
605018a
build: install postgres driver
jpeccia Apr 2, 2025
7d8645b
build: install godot env
jpeccia Apr 2, 2025
71415ce
chore: create .env.example
jpeccia Apr 2, 2025
73f77f1
feat: create main.go initial structure with gin run and loading env vars
jpeccia Apr 2, 2025
42ecb15
ops: create a docker-compose file to run db in dev env
jpeccia Apr 2, 2025
8b771a8
feat: create connection database config file
jpeccia Apr 2, 2025
910341d
feat: add ConnectDatabase function starts in main.go
jpeccia Apr 2, 2025
14919b7
chore: update .gitignore
jpeccia Apr 2, 2025
592abc3
feat: create User Entity Model
jpeccia Apr 2, 2025
f416b5b
style: adding a gorm unique missing in email
jpeccia Apr 2, 2025
973c0dc
feat: create RegisterUserDTO to validate data input
jpeccia Apr 2, 2025
f6b9527
feat: create User Repository and Create User e FindUserByEmail functions
jpeccia Apr 2, 2025
35bda7d
build: install google uuid
jpeccia Apr 2, 2025
fa17805
feat: create User Service and Register User with reference points fun…
jpeccia Apr 2, 2025
1e39b8e
feat: create User Handler
jpeccia Apr 2, 2025
3621833
feat: create routes and add POST signup to Register User
jpeccia Apr 2, 2025
2a2ca42
feat: add setup routes in main.go
jpeccia Apr 2, 2025
92b2510
feat: create database migrations
jpeccia Apr 2, 2025
fbcb62b
feat: add FindUserByReferralCode and UpdateUser functions in UserRepo…
jpeccia Apr 2, 2025
62b6ab9
feat: add function FindUserByReferralCode in interface
jpeccia Apr 2, 2025
c228625
feat: switch find user by email to find user by referralcode
jpeccia Apr 2, 2025
e932bf2
feat: add share link in register response in user handler
jpeccia Apr 2, 2025
2891125
feat: create config file with load env function
jpeccia Apr 2, 2025
3457019
feat: add call function Load env in main
jpeccia Apr 2, 2025
d5d1f3a
feat: create email service to send emails
jpeccia Apr 2, 2025
0147e6e
feat: add send email after register
jpeccia Apr 2, 2025
d736f44
feat: create competition handler and get winners function
jpeccia Apr 2, 2025
50d792b
feat: create competition service and get top winners function
jpeccia Apr 2, 2025
4cab580
feat: add FindTopUsersByPoints function
jpeccia Apr 2, 2025
f2c4cd9
feat: configure routes and add winners get route
jpeccia Apr 2, 2025
5538dde
feat: define router with new routes in main
jpeccia Apr 2, 2025
070ab2a
feat: add EndCompetition function to call winners in Handler
jpeccia Apr 2, 2025
bb30595
feat: add NotifyWinners function to send email to winners in service
jpeccia Apr 2, 2025
6f49bb5
feat: add route post /end-competition to end and send email in routes.go
jpeccia Apr 2, 2025
0edd223
fix: referral points and referred by now can works normally
jpeccia Apr 2, 2025
028fb24
chore: add smtp vars to send mail with mailtrap example in env.example
jpeccia Apr 2, 2025
e0925c6
fix: before referred by in db is empty and now i acrescented and fix …
jpeccia Apr 2, 2025
174808e
feat: add verify if referred code dont exist
jpeccia Apr 2, 2025
0112dd4
feat: add get ref code in url and add
jpeccia Apr 2, 2025
8fd2687
build: install swagger
jpeccia Apr 2, 2025
1655447
feat: create initial structure swagger
jpeccia Apr 2, 2025
566fed3
build: remove swaggo
jpeccia Apr 2, 2025
ba9062c
docs: add insomnia test routes
jpeccia Apr 2, 2025
5da78bb
chore: defining name input with name
jpeccia Apr 2, 2025
09c8cea
ops: create Dockerfile to deploy enviroment
jpeccia Apr 2, 2025
7e22d0f
docs: create Makefile
jpeccia Apr 2, 2025
e8cf0d3
build: install cors
jpeccia Apr 2, 2025
f888956
feat: create Cors config
jpeccia Apr 2, 2025
25b9b6e
chore: add front end url var in .env.example
jpeccia Apr 2, 2025
dedaf50
feat: add env vars in link front end
jpeccia Apr 2, 2025
5093c22
fix: error caused by a / in env var front end url cors error
jpeccia Apr 3, 2025
f2c733d
perf: add go routines to send email assync and add more performance i…
jpeccia Apr 3, 2025
90df499
ops: remove copy .env in dockerfile for deploy
jpeccia Apr 3, 2025
6dae1ce
ops: add copy .env in dockerfile again to deploy with security
jpeccia Apr 3, 2025
6802c01
chore: remove .env
jpeccia Apr 3, 2025
0fb1a79
ops: add env_file in docker-compose
jpeccia Apr 3, 2025
df5616a
fix: load env error in deploy
jpeccia Apr 3, 2025
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
12 changes: 12 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
DB_HOST=
DB_USER=
DB_PASS=
DB_NAME=
DB_PORT=

FRONTEND_URL=

SMTP_HOST=sandbox.smtp.mailtrap.io
SMTP_PORT=2525
SMTP_EMAIL=
SMTP_PASSWORD=
29 changes: 29 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Created by https://www.toptal.com/developers/gitignore/api/go
# Edit at https://www.toptal.com/developers/gitignore?templates=go

### Go ###
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

# Go workspace file
go.work

# End of https://www.toptal.com/developers/gitignore/api/go
.env
.air.toml
18 changes: 18 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM golang:1.23-alpine AS builder
RUN apk add --no-cache git

WORKDIR /app

COPY go.mod go.sum ./
RUN go mod download

COPY . .

RUN go build -o main .

FROM alpine:latest
WORKDIR /root/
COPY --from=builder /app/main .
EXPOSE 8080

CMD ["./main"]
201 changes: 201 additions & 0 deletions Insomnia_2025-04-02.har
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
{
"log": {
"version": "1.2",
"creator": {
"name": "Insomnia REST Client",
"version": "insomnia.desktop.app:v11.0.1"
},
"entries": [
{
"startedDateTime": "2025-04-02T22:10:32.798Z",
"time": 2.291,
"request": {
"method": "GET",
"url": "http://localhost:8080/api/winners",
"httpVersion": "HTTP/1.1",
"cookies": [],
"headers": [
{
"name": "User-Agent",
"value": "insomnia/11.0.1"
}
],
"queryString": [],
"postData": {
"mimeType": "",
"text": ""
},
"headersSize": -1,
"bodySize": -1
},
"response": {
"status": 200,
"statusText": "OK",
"httpVersion": "HTTP/1.1",
"cookies": [],
"headers": [
{
"name": "Content-Type",
"value": "application/json; charset=utf-8"
},
{
"name": "Date",
"value": "Wed, 02 Apr 2025 22:09:45 GMT"
},
{
"name": "Content-Length",
"value": "2"
}
],
"content": {
"size": 2,
"mimeType": "application/json; charset=utf-8",
"text": "[]"
},
"redirectURL": "",
"headersSize": -1,
"bodySize": -1
},
"cache": {},
"timings": {
"blocked": -1,
"dns": -1,
"connect": -1,
"send": 0,
"wait": 2.291,
"receive": 0,
"ssl": -1
},
"comment": "Listar os vencedores da competição"
},
{
"startedDateTime": "2025-04-02T22:10:32.798Z",
"time": 2.706,
"request": {
"method": "POST",
"url": "http://localhost:8080/api/end-competition",
"httpVersion": "HTTP/1.1",
"cookies": [],
"headers": [
{
"name": "User-Agent",
"value": "insomnia/11.0.1"
}
],
"queryString": [],
"postData": {
"mimeType": "",
"text": ""
},
"headersSize": -1,
"bodySize": -1
},
"response": {
"status": 200,
"statusText": "OK",
"httpVersion": "HTTP/1.1",
"cookies": [],
"headers": [
{
"name": "Content-Type",
"value": "application/json; charset=utf-8"
},
{
"name": "Date",
"value": "Wed, 02 Apr 2025 22:09:50 GMT"
},
{
"name": "Content-Length",
"value": "60"
}
],
"content": {
"size": 60,
"mimeType": "application/json; charset=utf-8",
"text": "{\"message\":\"Competition ended, winners have been notified!\"}"
},
"redirectURL": "",
"headersSize": -1,
"bodySize": -1
},
"cache": {},
"timings": {
"blocked": -1,
"dns": -1,
"connect": -1,
"send": 0,
"wait": 2.706,
"receive": 0,
"ssl": -1
},
"comment": "Finalizar Competição"
},
{
"startedDateTime": "2025-04-02T22:10:32.798Z",
"time": 4140.493,
"request": {
"method": "POST",
"url": "http://localhost:8080/api/signup",
"httpVersion": "HTTP/1.1",
"cookies": [],
"headers": [
{
"name": "Content-Type",
"value": "application/json"
},
{
"name": "User-Agent",
"value": "insomnia/11.0.1"
}
],
"queryString": [],
"postData": {
"mimeType": "application/json",
"text": "{\n\t\t\"name\": \"t harumi\",\n \"email\": \"test@email.com\",\n\t \"phone_number\": \"12342256789\",\n\t\t\"referred_by\": \"33ba65a2-7ea8-4118-880b-7f560e42d4ce\"\n}"
},
"headersSize": -1,
"bodySize": -1
},
"response": {
"status": 201,
"statusText": "Created",
"httpVersion": "HTTP/1.1",
"cookies": [],
"headers": [
{
"name": "Content-Type",
"value": "application/json; charset=utf-8"
},
{
"name": "Date",
"value": "Wed, 02 Apr 2025 22:07:07 GMT"
},
{
"name": "Content-Length",
"value": "177"
}
],
"content": {
"size": 177,
"mimeType": "application/json; charset=utf-8",
"text": "{\"message\":\"User registered successfully\",\"referral_code\":\"b284f7f9-d062-43aa-b20e-f7a34dc0a949\",\"share_link\":\"https://test.com/signup?ref=b284f7f9-d062-43aa-b20e-f7a34dc0a949\"}"
},
"redirectURL": "",
"headersSize": -1,
"bodySize": -1
},
"cache": {},
"timings": {
"blocked": -1,
"dns": -1,
"connect": -1,
"send": 0,
"wait": 4140.493,
"receive": 0,
"ssl": -1
},
"comment": "Cadastrar Usuário"
}
]
}
}
91 changes: 91 additions & 0 deletions Insomnia_2025-04-02.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
type: collection.insomnia.rest/5.0
name: BACK-END-TEST-COMPETITION
meta:
id: wrk_b13d67c651604252b1d7f224c975c901
created: 1743630557310
modified: 1743630557310
collection:
- url: http://localhost:8080/api/signup
name: Cadastrar Usuário
meta:
id: req_5acf0c81419d4b12ae35bd5a1c7fbcfb
created: 1743630565594
modified: 1743631623100
isPrivate: false
sortKey: -1743630565594
method: POST
body:
mimeType: application/json
text: |-
{
"name": "name",
"email": "test@email.com",
"phone_number": "12342256789",
"referred_by": ""
}
headers:
- name: Content-Type
value: application/json
- name: User-Agent
value: insomnia/11.0.1
settings:
renderRequestBody: true
encodeUrl: true
followRedirects: global
cookies:
send: true
store: true
rebuildPath: true
- url: http://localhost:8080/api/end-competition
name: Finalizar Competição
meta:
id: req_01fbead0b8034164a6bbcbb56118b836
created: 1743630612973
modified: 1743631681617
isPrivate: false
sortKey: -1743630612973
method: POST
headers:
- name: User-Agent
value: insomnia/11.0.1
settings:
renderRequestBody: true
encodeUrl: true
followRedirects: global
cookies:
send: true
store: true
rebuildPath: true
- url: http://localhost:8080/api/winners
name: Listar os vencedores da competição
meta:
id: req_8c0627869b614988aa79b4d007fe32e3
created: 1743630630346
modified: 1743631785681
isPrivate: false
sortKey: -1743630630346
method: GET
headers:
- name: User-Agent
value: insomnia/11.0.1
settings:
renderRequestBody: true
encodeUrl: true
followRedirects: global
cookies:
send: true
store: true
rebuildPath: true
cookieJar:
name: Default Jar
meta:
id: jar_130abd7a0ddc52cf3e136adf08dbcf2dbdca2d00
created: 1743630557314
modified: 1743630557314
environments:
name: Base Environment
meta:
id: env_130abd7a0ddc52cf3e136adf08dbcf2dbdca2d00
created: 1743630557312
modified: 1743630557312
isPrivate: false
33 changes: 33 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
.PHONY: build run air stop logs db-up db-down clean

# Nome do container do banco de dados
DB_CONTAINER = postgres_competition

# 🔹 Subir apenas o banco de dados com docker-compose
db-up:
docker-compose up -d db

# 🔹 Parar e remover o banco de dados
db-down:
docker-compose down

# 🔹 Rodar a aplicação Go normalmente
run:
go run main.go

# 🔹 Rodar a aplicação com live reload (precisa do Air instalado)
air:
air

# 🔹 Parar o banco de dados e limpar containers
stop:
docker stop $(DB_CONTAINER) || true
docker rm $(DB_CONTAINER) || true

# 🔹 Ver logs do banco de dados
logs:
docker logs -f $(DB_CONTAINER)

# 🔹 Limpar volumes e imagens não usadas
clean: stop db-down
docker volume rm $(shell docker volume ls -q) || true
Loading