Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
297 commits
Select commit Hold shift + click to select a range
7621bec
feat: use new `FailResponse` helper
ayaanqui Apr 4, 2022
c977a2f
refactor: simplify response helpers + set header once
ayaanqui Apr 4, 2022
67818fd
feat: use response helpers
ayaanqui Apr 4, 2022
e1ad8dd
feat: use auth message const
ayaanqui Apr 4, 2022
77143d6
fix: cast context `AuthKey` as `types.Auth`
ayaanqui Apr 4, 2022
783c066
feat: add `POST` `/products` route
ayaanqui Apr 4, 2022
38c2a66
refactor: remove redundant types
ayaanqui Apr 4, 2022
c4615f6
build: rename main file as `server.go`
ayaanqui Apr 4, 2022
82df98a
docs: update README
ayaanqui Apr 4, 2022
58c5e47
ci: use make commands
ayaanqui Apr 4, 2022
3612aba
build: watch files with extention of `.go`
ayaanqui Apr 4, 2022
c3fd725
feat: auth context parser
ayaanqui Apr 4, 2022
73dd303
feat: use `utils.ParseAuthContext`
ayaanqui Apr 4, 2022
1685a5b
feat: add get user function
ayaanqui Apr 7, 2022
0a59dc3
feat: compare with empty object
ayaanqui Apr 7, 2022
c5031a6
test: add unit tests for auth context parser
ayaanqui Apr 7, 2022
54044d1
refactor: create json file mapper function
ayaanqui Apr 7, 2022
1617b8d
feat: user services improvements
ayaanqui Apr 7, 2022
5fa8378
feat: create user struct
ayaanqui Apr 7, 2022
7039751
feat: create user service
ayaanqui Apr 7, 2022
272a7a1
feat: table name constant
ayaanqui Apr 7, 2022
2f8cbd5
feat: switch back to using string ids in user services for convenience
ayaanqui Apr 7, 2022
3dcf7e9
feat: update get or create service function
ayaanqui Apr 7, 2022
efd168e
refactor: create and add user service to `AppBase`
ayaanqui Apr 7, 2022
7163957
refactor: rename user services file
ayaanqui Apr 7, 2022
76eaa79
refactor: create base service
ayaanqui Apr 7, 2022
5fb1e84
feat: add category services
ayaanqui Apr 8, 2022
c0586a1
build: run `go mod tidy`
ayaanqui Apr 8, 2022
64c581b
refactor: add middlewares as AppBase
ayaanqui Apr 10, 2022
f560ecf
refactor: remove http.HanderFunc nesting
ayaanqui Apr 16, 2022
020d4d4
feat: create app base type
ayaanqui Apr 16, 2022
8f994e6
refactor: create new package to handle controllers
ayaanqui Apr 16, 2022
1c67153
refactor: move middlewares to utils package
ayaanqui Apr 16, 2022
ae33e22
refactor: rename `CategoryService` to `CategoryServices`
ayaanqui Apr 17, 2022
8a8bb96
feat: add find or create method for category service
ayaanqui Apr 17, 2022
ca90f86
feat: add products service
ayaanqui Apr 17, 2022
c4e2291
feat: add products controller
ayaanqui Apr 17, 2022
a38b75e
fix: prevent creating new uuids and dates unless values not defined
ayaanqui Apr 17, 2022
361f76c
refactor: json field name typo
ayaanqui Apr 17, 2022
50c6530
feat: join category to product object
ayaanqui Apr 17, 2022
b9e40d0
feat: add `/products/{id}` route
ayaanqui Apr 17, 2022
d1df457
refactor: convert all json fields to `camelCase`
ayaanqui Apr 17, 2022
cf1b297
fix: column name `snake_case`
ayaanqui Apr 17, 2022
d3e9c32
feat: join and load sub struct
ayaanqui Apr 17, 2022
d861e7a
feat: create product validation
ayaanqui Apr 17, 2022
6236b94
feat: update product if already exists
ayaanqui Apr 18, 2022
0e2d469
perf: avoid making copies of object
ayaanqui Apr 19, 2022
1dc08dd
fix: use create or update method
ayaanqui Apr 19, 2022
a00dd9d
perf: remove double pointers
ayaanqui Apr 19, 2022
b9b34c4
build: update repo urls
ayaanqui Apr 20, 2022
7e24bda
feat: define base path for `CreateRoutes` function
ayaanqui Apr 23, 2022
8846791
refactor: move auth middleware to controller
ayaanqui Apr 26, 2022
80d5e27
feat: create home controller
ayaanqui Apr 26, 2022
d043100
test: add home controller test
ayaanqui Apr 26, 2022
498fe40
refactor: use tabs in-place of spaces
ayaanqui Apr 26, 2022
38145f8
refactor: home controller tests
ayaanqui Apr 28, 2022
67eb9b2
Merge branch 'v2' of github.com:giftxtrade/api into v2
ayaanqui Apr 28, 2022
f608eec
feat: add public auto migrate function
ayaanqui May 1, 2022
7bbd95e
feat: add 404 route
ayaanqui May 1, 2022
4b2acde
build: install go-sqlmock
ayaanqui May 13, 2022
7d3cbe7
feat: create mock db for testing
ayaanqui May 13, 2022
1bcbde8
refactor: create new function to build dns string and db connection
ayaanqui May 14, 2022
da78743
feat: return error with user service functions
ayaanqui May 15, 2022
24e6106
feat: create connection with test db
ayaanqui May 15, 2022
fb53fab
test: add test cases for create user service
ayaanqui May 15, 2022
acdd791
refactor: private test setup function
ayaanqui May 15, 2022
fd3550f
ci: create postgres db before running tests
ayaanqui May 19, 2022
d056577
ci: fix
ayaanqui May 19, 2022
4a25980
ci: update for gh actions
ayaanqui May 20, 2022
0d0be54
ci: fix postgres
ayaanqui May 20, 2022
8786644
ci: reorder postgres env
ayaanqui May 20, 2022
ef55c57
ci: remove step
ayaanqui May 20, 2022
1149db9
feat: add created return value to `UserService.FindOrCreate`
ayaanqui May 20, 2022
b0fc3ce
test: more coverage on user service
ayaanqui May 20, 2022
2fc85ea
feat: db connection options with logger toggle
ayaanqui May 20, 2022
292aaa4
refactor: organize tests
ayaanqui May 21, 2022
268e92f
test: add new case for Find method
ayaanqui May 21, 2022
339ee1b
feat: remove find method from user service
ayaanqui May 21, 2022
c2ea045
test: add final `UserService.FindByIdOrEmail` method test
ayaanqui May 21, 2022
2c5e43f
refactor: public auth controller functions
ayaanqui May 21, 2022
99712dd
refactor: move mock service setup to test connections file
ayaanqui May 21, 2022
866bebc
test: add test cases for get profile controller
ayaanqui May 21, 2022
cad51d0
test: auth middleware
ayaanqui May 24, 2022
e75eedb
test: auth middleware with valid jwt
ayaanqui May 24, 2022
2cf6b61
test: invalid jwt
ayaanqui May 24, 2022
5dac018
test: add admin only authentication
ayaanqui May 28, 2022
0ac5bb2
refactor: return error
ayaanqui May 29, 2022
0d16d93
test: create category
ayaanqui May 29, 2022
d8d1c11
refactor: simplify `user_services.FindOrCreate` function
ayaanqui May 31, 2022
1277e05
feat: add bool return value to determine if new category is created
ayaanqui May 31, 2022
2881b75
fix: create dates on db
ayaanqui May 31, 2022
8406ee2
test: find category
ayaanqui May 31, 2022
70d0f42
fix: pointer issues
ayaanqui May 31, 2022
8b8cd19
fix: issues with find product function
ayaanqui May 31, 2022
300d661
feat: omitempty on category struct
ayaanqui Jun 4, 2022
7507139
refactor: rename plural
ayaanqui Jun 7, 2022
673d3ce
refactor: add services.New function
ayaanqui Jun 7, 2022
86c89f3
refactor: rename services.ProductService field name
ayaanqui Jun 7, 2022
7a98988
test: product create function
ayaanqui Jun 9, 2022
3c4f4b9
test: finish cases for `ProductService.Create`
ayaanqui Jun 10, 2022
dac9c61
test: finish cases for `ProductService.Create`
ayaanqui Jun 10, 2022
6484cb4
Merge branch 'v2' of github.com:giftxtrade/api into v2
ayaanqui Jun 10, 2022
92342a8
test: case for incorrect urls
ayaanqui Jun 10, 2022
428763b
test: input validation testing for `ProductService.Create`
ayaanqui Jun 10, 2022
748714b
fix: ensure product key is unique
ayaanqui Jun 10, 2022
7993268
test: new cases for `ProductService.Find` + type fixes and input vali…
ayaanqui Jun 10, 2022
46b3e7d
test: add test cases for `ProductService.CreateOrUpdate` method
ayaanqui Jun 10, 2022
beef399
refactor: cleanup
ayaanqui Jun 10, 2022
a880763
fix: return create error
ayaanqui Jun 10, 2022
e749616
perf: remove join clause to speed up query
ayaanqui Jun 10, 2022
d46f0db
feat: filter products
ayaanqui Jun 11, 2022
687ccbe
fix: offset function + sort
ayaanqui Jun 12, 2022
e1ef406
refactor: convert page to offset
ayaanqui Jun 12, 2022
668139b
test: `ProductService.Search`
ayaanqui Jun 12, 2022
0825107
refactor: rename service fields
ayaanqui Jun 15, 2022
2e6ad9a
refactor: organize methods
ayaanqui Jun 15, 2022
6e3bef8
perf: avoid returning pointer in user service
ayaanqui Jun 15, 2022
f0bb5ab
fix: user service test
ayaanqui Jun 15, 2022
4c05583
perf: avoid creating heap allocations with category service
ayaanqui Jun 15, 2022
6bb992d
perf: reduce heap allocations for product service
ayaanqui Jun 15, 2022
18d2321
Merge pull request #14 from giftxtrade/perf/produce-minimal-garbage
ayaanqui Jul 8, 2022
14332cb
build: install go-playground/validator
ayaanqui Jul 8, 2022
66f60f1
feat: use validator for simpler field validation
ayaanqui Jul 8, 2022
dfd075c
feat: use validator
ayaanqui Jul 8, 2022
5f9c90a
feat: search products using product filter struct
ayaanqui Jul 9, 2022
d5c1982
feat: omit search field
ayaanqui Jul 10, 2022
99d7c99
refactor: simplify service usage
ayaanqui Jul 11, 2022
4f0f76a
feat: required `originalUrl` field
ayaanqui Jul 12, 2022
e81b673
Merge pull request #15 from giftxtrade/refactor/service
ayaanqui Jul 12, 2022
ecde25e
refactor: create variables for mapped jwt values
ayaanqui Jul 13, 2022
ccf0d39
build: replace nodemon with justdoit
ayaanqui Jul 13, 2022
7308b1a
build: install fiber
ayaanqui Jul 16, 2022
ac7dc39
build: install goth_fiber + mod tidy
ayaanqui Jul 19, 2022
1ddb429
feat: replace net/http and mux with fiber and fasthttp
ayaanqui Jul 19, 2022
9d2f795
build: update gitignore
ayaanqui Jul 19, 2022
d57e6b6
build: mod tidy
ayaanqui Jul 19, 2022
ba349c7
feat: add callbackUrl field to oauth tokens
ayaanqui Jul 19, 2022
90439cf
feat: update middleware to use fiber
ayaanqui Jul 19, 2022
21750cf
feat: update home and auth controllers
ayaanqui Jul 19, 2022
ad78e75
refactor: separate middleware
ayaanqui Jul 19, 2022
23d3b7b
build: go mod
ayaanqui Jul 19, 2022
253f4f3
fix: use token callback urls
ayaanqui Jul 19, 2022
18d55c6
fix: incorrect error returns on `authenticate_user` method
ayaanqui Jul 19, 2022
054a22a
feat: update response functions to use fiber
ayaanqui Jul 19, 2022
c13a9f4
feat: update all existing controllers to fiber
ayaanqui Jul 19, 2022
b92dfae
test: use fiber
ayaanqui Jul 20, 2022
9436a65
fix: auth middleware use `utils.FailResponseUnauthorized`
ayaanqui Jul 23, 2022
b90fa14
fix: return with 401 on admin auth
ayaanqui Jul 23, 2022
88d73c8
test: fix middleware test cases
ayaanqui Jul 23, 2022
2beb356
test: fix all cases
ayaanqui Jul 23, 2022
119fcbd
test: fix all cases
ayaanqui Jul 24, 2022
4a162bc
refactor: cleanup json response returns
ayaanqui Jul 24, 2022
0dce1cf
docs: update readme
ayaanqui Jul 24, 2022
ca87576
Merge pull request #16 from giftxtrade/perf/fiber
ayaanqui Jul 24, 2022
236eaf2
refactor: use `utils.FailResponse`
ayaanqui Jul 25, 2022
2a668b9
feat: return status code 201 if new user created
ayaanqui Jul 25, 2022
8ebd831
feat: add comments
ayaanqui Jul 25, 2022
106d3cd
Merge branch 'perf/fiber' into v2
ayaanqui Jul 25, 2022
b863b30
Feat: Events (#17)
ayaanqui Sep 20, 2022
3b08482
feat: add create event controller
ayaanqui Sep 20, 2022
4f35a50
refactor: simplify test setup
ayaanqui Sep 21, 2022
3870149
feat: use validator from app context
ayaanqui Sep 21, 2022
0e84d02
feat: validator output with json field name
ayaanqui Sep 21, 2022
8616937
refactor: new mock server function
ayaanqui Sep 21, 2022
2b1deeb
feat: valid close and draw dates
ayaanqui Sep 21, 2022
308c5b8
refactor: move `DbConfig` function
ayaanqui Sep 26, 2022
66a82b0
build: update to go 1.18
ayaanqui Oct 17, 2022
6550a4b
build: run updates
ayaanqui Nov 7, 2022
272cce9
perf: use joins for faster queries
ayaanqui Nov 7, 2022
dea39a2
feat: add /events
ayaanqui Nov 7, 2022
93e8541
fix: explicit table ref
ayaanqui Nov 7, 2022
0915237
fix: gorm logger
ayaanqui Nov 7, 2022
583fe04
perf: replace preload with joins #19
ayaanqui Nov 7, 2022
2c9df34
feat: Participants #20
ayaanqui Nov 13, 2022
6c6e248
Feat: Create Participants Through `EventService` (#22)
ayaanqui Dec 18, 2022
a1fe4ea
feat: panic on db connection
ayaanqui Mar 3, 2023
4796f72
build: configure go-migration-tool
ayaanqui Mar 4, 2023
bdba83b
build: update `go-migration-tool`
ayaanqui Mar 4, 2023
988564e
feat: add migration file
ayaanqui Mar 5, 2023
1beb6b4
build: upgrade go-migration-tool
ayaanqui Mar 5, 2023
15dad9f
fix: remove db setup query
ayaanqui Mar 5, 2023
9037afc
fix: remove gorm auto migrate
ayaanqui Mar 5, 2023
87896bf
fix: error finding migrations directory for tests
ayaanqui Mar 6, 2023
dce8484
fix: drop entire schema
ayaanqui Mar 6, 2023
658654c
fix: postgres test password
ayaanqui Mar 6, 2023
7aace09
feat: add fail now
ayaanqui Dec 10, 2023
12d8b54
build: upgrade go and other packages + install sqlc,
ayaanqui Dec 11, 2023
7ebcc47
Create schema.sql
ayaanqui Dec 11, 2023
004730b
Update schema.sql
ayaanqui Dec 11, 2023
968d84a
feat: setup sqlc
ayaanqui Dec 12, 2023
5968b26
feat: init data
ayaanqui Dec 12, 2023
3d08fee
Merge branch 'v2' of github.com:giftxtrade/api into feat/sqlc
ayaanqui Dec 12, 2023
23039c2
build: configure db stuff
ayaanqui Dec 12, 2023
de5ad0e
refactor: move migrations directory
ayaanqui Dec 12, 2023
2106456
feat: generate sqlc
ayaanqui Dec 12, 2023
2f2d07f
refactor: db config file
ayaanqui Dec 12, 2023
17e2f03
build: add docker file
ayaanqui Dec 12, 2023
5ac0cab
feat: update `db_config.json` types
ayaanqui Dec 12, 2023
05bf6aa
fix: type issues
ayaanqui Dec 12, 2023
9f7144e
fix: sql miss translation
ayaanqui Dec 12, 2023
52e2b7b
refactor: controllers + avoid cyclical imports
ayaanqui Dec 12, 2023
5477f8c
feat: add user queries
ayaanqui Dec 12, 2023
e87b7f0
fix: dependencies
ayaanqui Dec 12, 2023
391969d
fix: service dependencies
ayaanqui Dec 12, 2023
62c4508
fix: add querier param
ayaanqui Dec 12, 2023
7efece1
refactor: move home_controller to base controller
Dec 12, 2023
1449d3d
build: add database field
Dec 12, 2023
41ac7b9
refactor: add quotations for migration files
Dec 12, 2023
9375364
feat: add on delete constraints + currency enums
Dec 12, 2023
b26bdce
build: update sqlc config
Dec 12, 2023
1ec7222
feat: implement filter product
Dec 12, 2023
21ffcbd
fix: reorder tables by occurrence
Dec 12, 2023
7a36ada
refactor: rename product columns
Dec 12, 2023
db8b151
feat: add update or create service + query
Dec 12, 2023
67ba4b2
feat: add category methods
ayaanqui Dec 13, 2023
f1848af
fix: typo
ayaanqui Dec 13, 2023
e74be00
feat: new `SetUserAsAdmin` method
ayaanqui Dec 13, 2023
acdb55f
fix: interface conversion errors
ayaanqui Dec 13, 2023
17b6c86
fix: test db
ayaanqui Dec 14, 2023
c459d57
feat: add sqlc querier to mock app method
ayaanqui Dec 14, 2023
f1474fa
fix: test issues
ayaanqui Dec 14, 2023
463caf4
refactor: remove redundant tests
ayaanqui Dec 14, 2023
e15de15
fix: auth and parser test cases
ayaanqui Dec 14, 2023
0ce4139
ci: fix docker test db
ayaanqui Dec 14, 2023
000c970
test: fix user related test cases
ayaanqui Dec 14, 2023
44315dc
fix: update product query null values
ayaanqui Dec 15, 2023
841e60d
feat: add product input validation + parse url
ayaanqui Dec 17, 2023
c99c73b
test: fix products service tests
ayaanqui Dec 17, 2023
1c5ad85
ci: add sqlc generate step
ayaanqui Dec 17, 2023
55e62e1
ci: update go version to `1.21`
ayaanqui Dec 17, 2023
0c10f04
fix: remove initial data migration file
ayaanqui Dec 17, 2023
a9230fc
Implement sqlc (#23)
ayaanqui Dec 17, 2023
d66ba8d
test: unit tests for category
ayaanqui Dec 19, 2023
026242a
feat: send created status with product
ayaanqui Dec 19, 2023
0eda77a
Merge branch into v2
ayaanqui Dec 19, 2023
63dc0bf
feat: set category id validity to true
ayaanqui Dec 19, 2023
68f605f
feat: seed data for products
ayaanqui Dec 19, 2023
b1d3a2a
test: remove Cleanup function
ayaanqui Dec 20, 2023
2e7a1f0
feat: refined product ordering + calculate limit
ayaanqui Dec 20, 2023
71ec399
test: simple product filter test
ayaanqui Dec 20, 2023
f6dbbe4
refactor: remove `product.modified` column
ayaanqui Dec 20, 2023
66ee186
build: install and configure github.com/cosmtrek/air
ayaanqui Dec 20, 2023
dbc5b5f
build: run `mod tidy`
ayaanqui Dec 20, 2023
b0218de
ft/Events (#24)
ayaanqui Jan 1, 2024
7676f82
Feat/event-link (#25)
ayaanqui Jan 7, 2024
9707ebc
Participant Management (#27)
ayaanqui Jan 9, 2024
f337e8e
Product Filtering (#28)
ayaanqui Feb 4, 2024
e863a64
Wishlist (#29)
ayaanqui Feb 18, 2024
58c475c
Go Jet - SQL Query Builder (#30)
ayaanqui Oct 22, 2024
e9ed9ae
Use Jet Queries in Event and Participant Services (#31)
ayaanqui Nov 1, 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
46 changes: 46 additions & 0 deletions .air.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
root = "."
testdata_dir = "testdata"
tmp_dir = "tmp"

[build]
args_bin = []
bin = "./server"
cmd = "make build"
delay = 1000
exclude_dir = [".github", "src/database/migrations"]
exclude_file = ["src/database/*.sql.go", "src/database/db.go", "src/database/models.go"]
exclude_regex = ["_test.go"]
exclude_unchanged = false
follow_symlink = false
full_bin = ""
include_dir = []
include_ext = ["go", "sql"]
include_file = []
kill_delay = "0s"
log = "build-errors.log"
poll = false
poll_interval = 0
post_cmd = []
pre_cmd = []
rerun = false
rerun_delay = 500
send_interrupt = false
stop_on_error = false

[color]
app = ""
build = "yellow"
main = "magenta"
runner = "green"
watcher = "cyan"

[log]
main_only = false
time = false

[misc]
clean_on_exit = false

[screen]
clear_on_rebuild = false
keep_scroll = true
24 changes: 0 additions & 24 deletions .eslintrc.js

This file was deleted.

20 changes: 20 additions & 0 deletions .github/workflows/go-build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Build

on: push

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: set up go
uses: actions/setup-go@v2
with:
go-version: 1.21

- name: sqlc generate
run: make sqlc

- name: build
run: make build
41 changes: 41 additions & 0 deletions .github/workflows/go-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Unit Tests
on: push

jobs:
# Label of the runner job
runner-job:
# You must use a Linux environment when using service containers or container jobs
runs-on: ubuntu-latest

services:
postgres:
# Docker Hub image
image: postgres

env:
POSTGRES_PASSWORD: postgres
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 54322:5432

steps:
- uses: actions/checkout@v2

- name: set up go
uses: actions/setup-go@v2
with:
go-version: 1.21

- name: sqlc generate
run: make sqlc

- name: build
run: make build

- name: run tests
run: make test
43 changes: 6 additions & 37 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,39 +1,8 @@
# compiled output
/dist
/node_modules
main
server
db_config.json
*tokens.json

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
typescript

# OS
.DS_Store

# Tests
/coverage
/.nyc_output

# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json


ormconfig.json
uploads
auth-tokens.json
tmp
4 changes: 0 additions & 4 deletions .prettierrc

This file was deleted.

127 changes: 59 additions & 68 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<p align="center">
<a href="http://giftxtrade.com/" target="blank">
<!-- <img src="https://giftxtrade.com/logos/logo_profile_rounded.svg" width='50' alt="GiftTrade Logo" /> -->
<img src="https://giftxtrade.com/logos/logotype_rounded_color.svg" width='250' alt="GiftTrade Logo" />
<img src="https://raw.githubusercontent.com/giftxtrade/logos/master/logotype_rounded_color.svg" width='250' alt="GiftTrade Logo" />
</a>
</p>

Expand All @@ -11,88 +10,80 @@

<br />

## Description
The GiftTrade API repository serves as the REST API for the [giftxtrade.com](https://giftxtrade.com) web app. This repo is designed to work with a fully working MySQL database.

## API endpoints
| Endpoint | Request Method | Auth | Description |
| ------------------------------------------ | ------------------------ | ---- | -------------------------------- |
| `/` | `GET` | no | `n/a` |
| `/auth/google` | `GET` | no | Redirects to Google oauth endpoint |
| `/auth/google/redirect` | `GET` | no | Generates a token given the Google oauth callback |
| `/auth/profile` | `GET` | yes | Given a token, returns the profile details for the authenticated user |
| `/products` | `GET` | no | Returns a list of products with given a set of query parameters to tune the results |
| `/events` | `GET`, `POST` | yes | Create and fetch events for an authenticated user |
| `/events/:id` | `GET`, `PATCH`, `DELETE` | yes | Fetch, update, or delete a specific event for an authenticated user. Updating or deleting an event requires the user to be an event organizer |
| `/events/get-details/:linkCode` | `GET` | yes | Returns the name and description (if exists) for a specific event |
| `/events/invites` | `GET` | yes | Returns a list of all pending invites for an authenticated user |
| `/events/invites/accept/:eventId` | `GET` | yes | Accepts the event invite for an authenticated user |
| `/events/invites/decline/:eventId` | `GET` | yes | Declines the event invite for an authenticated user |
| `/events/get-link/:eventId` | `GET` | yes | Generates the invite link to a specific event |
| `/events/get-link/:eventId` | `GET` | yes | Generates the invite link to a specific event |
| `/events/verify-invite-code/:inviteCode` | `GET` | yes | Verify the invite code for a specific event |
| `/events/invite-code/:inviteCode` | `GET` | yes | Add the event to the user's pending invites list |
| `/participants/manage` | `PATCH`, `DELETE` | yes | Update participant details, or remove them from event. Requires that the participant is also an organizer |
| `/participants/:eventId/:participantId` | `GET` | yes | Fetch participant information, given the user is part of the same event |
| `/participants/:participantId` | `PATCH`, `DELETE` | yes | Allows user to manage their participant information, including leaving event, and updating address |
| `/wishes` | `POST`, `DELETE` | yes | Creates or removes a wishlist item |
| `/wishes/:id` | `GET` | yes | Fetch all wishlist items from the user participant given an event id |
| `/wishes/:eventId/:participantId` | `GET` | yes | Fetch all wishlist items from a participant given the participant's id and an event id |
| `/draws` | `POST` | yes | Creates randomized pairings from the active participants. Requires that user is an organizer |
| `/draws/confirm/:eventId` | `GET` | yes | Confirms the generated draws and sends emails to all the participants. Requires that user is an organizer |
| `/draws/:eventId` | `GET` | yes | Fetch all pairings for a given event. Requires that user is an organizer |
| `/me/:eventId` | `GET` | yes | Fetch user's draw for a given event |
| `/categories` | `GET` | no | Fetches all product categories |

## Set up

### Clone repository
```
git clone git@github.com:giftxtrade/api.git
```
## Tech stack
- [PostgreSQL](https://www.postgresql.org/) - Primary database
- [GORM](https://gorm.io) - ORM to interact with the database programmatically
- [Postgres for GORM](https://github.com/go-gorm/postgres) - Postgres Driver for GORM
- [Google UUID](https://pkg.go.dev/github.com/google/uuid@v1.3.0) - Generates UUID before inserts
- [Fiber](https://github.com/gofiber/fiber) - Express.js inspired framework for Go (uses [Fasthttp](https://github.com/valyala/fasthttp))
- [Goth](https://github.com/markbates/goth) - OAuth support for multiple platforms
- [Goth Fiber](https://github.com/Shareed2k/goth_fiber) - Goth implementation for Fiber

### Install dependencies
```
npm install
```
## Instructions

### Set up config files

### Configure database connection
This repo requires a working connection with a MySQL database and uses TypeORM to manage models and connections with the database.
#### `db_config.json`
This project also uses a PostgreSQL database in order to run. To start, create a file called `db_config.json` in the project root and place the following in the file, replacing all content within the `[]` with the correct database values:

To set up the config file with the connection details, create a file named `ormconfig.json` in the root of the project directory, then copy the code below, replacing all `<...>` with the appropriate values for you local database.
```json
{
"type": "mysql",
"host": "localhost",
"port": 3306,
"username": "<username>",
"password": "<password>",
"database": "<database>",
"entities": [
"dist/**/*.entity{.ts,.js}"
],
"synchronize": true
"dbName": "[database name]",
"username": "[database username]",
"password": "[database password]",
"port": 5432
}
```

***Note:*** All database table and column names are represented in `snake_case`. While all json field names are represented using `camelCase`.

#### `tokens.json`

In addition to the `db_config.json`, you will also need to create a `tokens.json` file which will hold the JWT secret, note that this token should be a randomly generated value and must not be made public. The `token.json` file should contain the following:
```json
{
"jwtKey": "[YOUR SECRET TOKEN]",
"twitter": {
"apiKey": "[Twitter OAuth 1.0 API Key]",
"apiKeySecret": "[Twitter OAuth 1.0 API Secret]",
"bearerToken": "[Twitter OAuth Bearer Token]",
"callbackUrl": "http://localhost:8080/auth/twitter/callback"
},
"google": {
"clientId": "[Google Client Id]",
"clientSecret": "[Google Secret Key]",
"callbackUrl": "http://localhost:8080/auth/google/callback"
}
}
```

### Configure API keys
GiftTrade API requires a number of API keys from Google, Sendgrid, (and possible from Amazon in the near future). To configure the authentication tokens file, copy `auth-tokens.sample.json` file from the root of the project, then rename the file to `auth-tokens.json`, or use the following command in the terminal:
### Generate Binary

```
cp auth-tokens.sample.json ./auth-tokens.json
$ make build
```
Once `auth-tokens.json` is present, make sure to replace all values with the appropriate values, if working locally, you can leave `FRONTEND_BASE` and `JWT.SECRET` as it is. However, it is essential that at the very least you create an account on [Google Console](https://console.cloud.google.com/) and set up an OAuth key and paste the appropriate keys on the `GOOGLE` section. Do the same for [SendGrid](https://sendgrid.com) and use the free tier to get access to the appropriate API tokens.

### Start server in watch-mode
or

```
npm start:dev
$ go build src/server.go
```

### Start server
Creates an executable binary file called `server`. To run this file call `./server`, like so:

```
npm start
$ ./server
```

### Build server
This should start the server on port `8080`.

### Run without Binary

Another way to run the server is by using the `make run` command.

```
npm build
```
$ make run
```

Running the command should also start the server on port `8080`. This command is equivalent to running `go run src/server.go`.
13 changes: 0 additions & 13 deletions auth-tokens.sample.json

This file was deleted.

34 changes: 34 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
version: '3.8'
services:
db:
image: postgres:14.1-alpine
restart: always
environment:
- POSTGRES_HOST=postgres
- POSTGRES_PORT=5432
- POSTGRES_DB=postgres
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
ports:
- '5433:5432'
volumes:
- giftxtrade-db:/var/lib/postgresql/data

db-test:
image: postgres:14.1-alpine
restart: always
environment:
- POSTGRES_HOST=postgres
- POSTGRES_PORT=5432
- POSTGRES_DB=postgres
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
ports:
- '54322:5432'
volumes:
- giftxtrade-db-test:/var/lib/postgresql/data
volumes:
giftxtrade-db:
driver: local
giftxtrade-db-test:
driver: local
Loading