Skip to content

Commit 801ca26

Browse files
CourtcircuitsTristan Radulescu
and
Tristan Radulescu
authored
feat(GIST-22): add organizations (#8)
* wip(GIST-22): add migration to create organization + trigger * wip(GIST-22): add tests for organization TDD * wip(GIST-22): add test for organization creation + CI * wip(GIST-22): fixed migrations * wip(GIST-22): changed trigger for workflow gha * wip(GIST-22): fix mr-test workflow syntax * wip(GIST-22): fix mr-test workflow syntax again * wip(GIST-22): added CRUD on orgs and linked gists to orgs * wip(GIST-22): fix tests imports * wip(GIST-22): fix org as optionnal attr * docs(GIST-22): updated openapi v3 doc --------- Co-authored-by: Tristan Radulescu <[email protected]>
1 parent 00e1432 commit 801ca26

27 files changed

+1064
-399
lines changed

.github/workflows/mr-test.yml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Continuous testing
2+
on:
3+
pull_request:
4+
branches:
5+
- main
6+
7+
jobs:
8+
test:
9+
name: Integration tests
10+
runs-on: ubuntu-latest
11+
services:
12+
postgres:
13+
image: postgres
14+
env:
15+
POSTGRES_PASSWORD: postgres
16+
POSTGRES_DB: gists
17+
POSTGRES_USER: postgres
18+
options: >-
19+
--health-cmd pg_isready
20+
--health-interval 10s
21+
--health-timeout 5s
22+
--health-retries 5
23+
ports:
24+
- 5432:5432
25+
steps:
26+
- uses: actions/checkout@v4
27+
- name: Install Go toolchain
28+
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
29+
with:
30+
go-version: 1.23.0
31+
- name: Run migrations
32+
run: go build -o main && chmod +x ./main && PORT="4000" PG_USER="postgres" PG_PASSWORD="postgres" PG_PORT="5432" PG_HOST="0.0.0.0" PG_DATABASE="gists" GOOGLE_KEY="" GOOGLE_SECRET="" GITHUB_KEY="" GITHUB_SECRET="" PUBLIC_URL="http://localhost:4000" APP_KEY="DUMP_APP_KEY_FOR_TEST" SMTP_HOST="" MAIL_SMTP="" MAIL_PASSWORD="" SMTP_PORT="" FRONTEND_URL="http://localhost:3000" ./main migrate
33+
- name: Run tests
34+
run: PORT="4000" PG_USER="postgres" PG_PASSWORD="postgres" PG_PORT="5432" PG_HOST="0.0.0.0" PG_DATABASE="gists" GOOGLE_KEY="" GOOGLE_SECRET="" GITHUB_KEY="" GITHUB_SECRET="" PUBLIC_URL="http://localhost:4000" APP_KEY="DUMP_APP_KEY_FOR_TEST" SMTP_HOST="" MAIL_SMTP="" MAIL_PASSWORD="" SMTP_PORT="" FRONTEND_URL="http://localhost:3000" go test ./tests/

.vscode/settings.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"ansible.python.interpreterPath": "/bin/python3"
3+
}

auth/controller.go

+14-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,16 @@ import (
55
"github.com/gofiber/fiber/v2"
66
)
77

8-
type AuthControllerImpl struct{}
8+
type IAuthController interface {
9+
Callback() fiber.Handler
10+
Authenticate() fiber.Handler
11+
LocalAuth() fiber.Handler
12+
VerifyAuthToken() fiber.Handler
13+
}
14+
15+
type AuthControllerImpl struct{
16+
AuthService IAuthService
17+
}
918

1019
type AuthLocalValidator struct {
1120
Email string `json:"email"`
@@ -18,7 +27,7 @@ type AuthLocalVerificationValidator struct {
1827

1928
func (a *AuthControllerImpl) Callback() fiber.Handler {
2029
return func(c *fiber.Ctx) error {
21-
token, err := AuthService.Callback(c)
30+
token, err := a.AuthService.Callback(c)
2231
if err != nil {
2332
return c.Status(400).SendString(err.Error())
2433
}
@@ -33,7 +42,7 @@ func (a *AuthControllerImpl) Callback() fiber.Handler {
3342

3443
func (a *AuthControllerImpl) Authenticate() fiber.Handler {
3544
return func(c *fiber.Ctx) error {
36-
return AuthService.Authenticate(c)
45+
return a.AuthService.Authenticate(c)
3746
}
3847
}
3948

@@ -44,7 +53,7 @@ func (a *AuthControllerImpl) LocalAuth() fiber.Handler {
4453
return c.Status(400).SendString("Request must be valid JSON with field email as text")
4554
}
4655

47-
if err := AuthService.LocalAuth(e.Email); err != nil {
56+
if _, err := a.AuthService.LocalAuth(e.Email); err != nil {
4857
return c.Status(400).SendString(err.Error())
4958
}
5059

@@ -63,7 +72,7 @@ func (a *AuthControllerImpl) VerifyAuthToken() fiber.Handler {
6372
token := e.Token
6473
email := e.Email
6574

66-
jwt_token, err := AuthService.VerifyLocalAuthToken(token, email)
75+
jwt_token, err := a.AuthService.VerifyLocalAuthToken(token, email)
6776

6877
if err != nil {
6978
return c.Status(400).SendString(err.Error())

auth/router.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package auth
33
import "github.com/gofiber/fiber/v2"
44

55
type AuthRouter struct {
6-
Controller AuthControllerImpl
6+
Controller IAuthController
77
}
88

99
func (r *AuthRouter) SubscribeRoutes(app *fiber.Router) {

auth/service.go

+14-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,17 @@ import (
1616
"github.com/shareed2k/goth_fiber"
1717
)
1818

19+
type IAuthService interface {
20+
Authenticate(c *fiber.Ctx) error
21+
LocalAuth(email string) (TokenSQL, error)
22+
VerifyLocalAuthToken(token string, email string) (string, error)
23+
Callback(c *fiber.Ctx) (string, error)
24+
GetUser(auth_user goth.User) (*user.User, *AuthIdentity, error)
25+
Register(auth_user goth.User) (*user.User, error)
26+
RegisterProviders()
27+
IsAuthenticated(token string) (*JWTClaim, error)
28+
}
29+
1930
type AuthServiceImpl struct{}
2031

2132
func (a *AuthServiceImpl) Authenticate(c *fiber.Ctx) error {
@@ -28,7 +39,7 @@ func (a *AuthServiceImpl) Authenticate(c *fiber.Ctx) error {
2839
}
2940

3041
// generates a token and sends it to the user by email
31-
func (a *AuthServiceImpl) LocalAuth(email string) error {
42+
func (a *AuthServiceImpl) LocalAuth(email string) (TokenSQL, error) {
3243
token_val := utils.GenToken(6)
3344
token_model := TokenSQL{
3445
Keyword: sql.NullString{String: email, Valid: true},
@@ -39,12 +50,12 @@ func (a *AuthServiceImpl) LocalAuth(email string) error {
3950
_, err := token_model.Save()
4051

4152
if err != nil {
42-
return err
53+
return token_model, err
4354
}
4455

4556
err = utils.SendEmail("Gistapp: Local Auth", "Your token is: "+token_val, email)
4657

47-
return err
58+
return token_model, err
4859
}
4960

5061
// verifies the token and finishes the registration

0 commit comments

Comments
 (0)