Skip to content

Commit

Permalink
feat: api layout
Browse files Browse the repository at this point in the history
  • Loading branch information
lbennett-stacki committed Jul 9, 2024
1 parent 5c9621e commit 945856b
Show file tree
Hide file tree
Showing 20 changed files with 206 additions and 26 deletions.
2 changes: 2 additions & 0 deletions cloud/api/Justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dev:
go run .
21 changes: 0 additions & 21 deletions cloud/api/api.go

This file was deleted.

9 changes: 9 additions & 0 deletions cloud/api/authentication/routes/reset-password.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package authenticationRoutes

import "github.com/gofiber/fiber/v2"

func ResetPassword(c *fiber.Ctx) error {
return c.Status(200).JSON(&fiber.Map{
"todo": true,
})
}
9 changes: 9 additions & 0 deletions cloud/api/authentication/routes/sign-in.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package authenticationRoutes

import "github.com/gofiber/fiber/v2"

func SignIn(c *fiber.Ctx) error {
return c.Status(200).JSON(&fiber.Map{
"todo": true,
})
}
9 changes: 9 additions & 0 deletions cloud/api/authentication/routes/sign-out.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package authenticationRoutes

import "github.com/gofiber/fiber/v2"

func SignOut(c *fiber.Ctx) error {
return c.Status(200).JSON(&fiber.Map{
"todo": true,
})
}
9 changes: 9 additions & 0 deletions cloud/api/authentication/routes/verify-email.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package authenticationRoutes

import "github.com/gofiber/fiber/v2"

func VerifyEmail(c *fiber.Ctx) error {
return c.Status(200).JSON(&fiber.Map{
"todo": true,
})
}
3 changes: 2 additions & 1 deletion cloud/api/go.mod
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
module nv-api
module envy-api

go 1.22.3

require (
github.com/andybalholm/brotli v1.0.5 // indirect
github.com/gofiber/fiber/v2 v2.52.5 // indirect
github.com/google/uuid v1.5.0 // indirect
github.com/jmoiron/sqlx v1.4.0 // indirect
github.com/klauspost/compress v1.17.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
Expand Down
6 changes: 6 additions & 0 deletions cloud/api/go.sum
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs=
github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg=
github.com/gofiber/fiber/v2 v2.52.5 h1:tWoP1MJQjGEe4GB5TUGOi7P2E0ZMMRx5ZTG4rT+yGMo=
github.com/gofiber/fiber/v2 v2.52.5/go.mod h1:KEOE+cXMhXG0zHc9d8+E38hoX+ZN7bhOtgeF2oT6jrQ=
github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU=
github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/jmoiron/sqlx v1.4.0 h1:1PLqN7S1UYp5t4SrVVnt4nUVNemrDAtxlulVe+Qgm3o=
github.com/jmoiron/sqlx v1.4.0/go.mod h1:ZrZ7UsYB/weZdl2Bxg6jCRO9c3YHl8r3ahlKmRT4JLY=
github.com/klauspost/compress v1.17.0 h1:Rnbp4K9EjcDuVuHtd0dgA4qNuv9yKDYKK1ulpJwgrqM=
github.com/klauspost/compress v1.17.0/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
Expand Down
9 changes: 9 additions & 0 deletions cloud/api/health/routes/health.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package healthRoutes

import "github.com/gofiber/fiber/v2"

func CheckHealth(c *fiber.Ctx) error {
return c.Status(201).JSON(&fiber.Map{
"healthy": true,
})
}
37 changes: 37 additions & 0 deletions cloud/api/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package main

import (
authenticationRoutes "envy-api/authentication/routes"
healthRoutes "envy-api/health/routes"
organisationsRoutes "envy-api/organisations/routes"
projectsRoutes "envy-api/projects/routes"
usersRoutes "envy-api/users/routes"
"log"

"github.com/gofiber/fiber/v2"
)

func main() {
app := fiber.New()

app.Get("/health", healthRoutes.CheckHealth)

app.Post("/sign-in", authenticationRoutes.SignIn)
app.Post("/sign-out", authenticationRoutes.SignOut)
app.Post("/reset-password", authenticationRoutes.ResetPassword)
app.Post("/verify-email", authenticationRoutes.VerifyEmail)

app.Post("/users", usersRoutes.CreateUser)
app.Get("/me", usersRoutes.GetMe)
app.Patch("/me", usersRoutes.PatchMe)

app.Post("/organisations", organisationsRoutes.CreateOrganisation)
app.Get("/organisations/:id", organisationsRoutes.GetOrganisation)
app.Patch("/organisations/:id", organisationsRoutes.PatchOrganisation)

app.Post("/projects", projectsRoutes.CreateProject)
app.Get("/projects/:id", projectsRoutes.GetProject)
app.Patch("/projects/:id", projectsRoutes.PatchProject)

log.Fatal(app.Listen(":4000"))
}
20 changes: 20 additions & 0 deletions cloud/api/organisations/routes/create.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package organisationsRoutes

import "github.com/gofiber/fiber/v2"

type Organisation struct {
ID int `json:"id"`
}

func CreateOrganisation(c *fiber.Ctx) error {
organisation := CreateOrganisationLib()

return c.Status(201).JSON(&fiber.Map{
"success": true,
"organisation": organisation,
})
}

func CreateOrganisationLib() Organisation {
return Organisation{ID: 1}
}
9 changes: 9 additions & 0 deletions cloud/api/organisations/routes/get.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package organisationsRoutes

import "github.com/gofiber/fiber/v2"

func GetOrganisation(c *fiber.Ctx) error {
return c.Status(200).JSON(&fiber.Map{
"todo": true,
})
}
9 changes: 9 additions & 0 deletions cloud/api/organisations/routes/patch.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package organisationsRoutes

import "github.com/gofiber/fiber/v2"

func PatchOrganisation(c *fiber.Ctx) error {
return c.Status(201).JSON(&fiber.Map{
"todo": true,
})
}
20 changes: 20 additions & 0 deletions cloud/api/projects/routes/create.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package projectsRoutes

import "github.com/gofiber/fiber/v2"

type Project struct {
ID int `json:"id"`
}

func CreateProject(c *fiber.Ctx) error {
project := CreateProjectLib()

return c.Status(201).JSON(&fiber.Map{
"success": true,
"project": project,
})
}

func CreateProjectLib() Project {
return Project{ID: 1}
}
9 changes: 9 additions & 0 deletions cloud/api/projects/routes/get.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package projectsRoutes

import "github.com/gofiber/fiber/v2"

func GetProject(c *fiber.Ctx) error {
return c.Status(200).JSON(&fiber.Map{
"todo": true,
})
}
9 changes: 9 additions & 0 deletions cloud/api/projects/routes/patch.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package projectsRoutes

import "github.com/gofiber/fiber/v2"

func PatchProject(c *fiber.Ctx) error {
return c.Status(201).JSON(&fiber.Map{
"todo": true,
})
}
20 changes: 20 additions & 0 deletions cloud/api/users/routes/create.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package usersRoutes

import "github.com/gofiber/fiber/v2"

type User struct {
ID int `json:"id"`
}

func CreateUser(c *fiber.Ctx) error {
user := CreateUserLib()

return c.Status(201).JSON(&fiber.Map{
"success": true,
"user": user,
})
}

func CreateUserLib() User {
return User{ID: 1}
}
9 changes: 9 additions & 0 deletions cloud/api/users/routes/get-me.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package usersRoutes

import "github.com/gofiber/fiber/v2"

func GetMe(c *fiber.Ctx) error {
return c.Status(200).JSON(&fiber.Map{
"todo": true,
})
}
9 changes: 9 additions & 0 deletions cloud/api/users/routes/patch-me.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package usersRoutes

import "github.com/gofiber/fiber/v2"

func PatchMe(c *fiber.Ctx) error {
return c.Status(201).JSON(&fiber.Map{
"todo": true,
})
}
4 changes: 0 additions & 4 deletions cloud/Justfile → cloud/db/Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

NAME := "envy"
ENV := "development"
DATABASE_DIR := "db"
DATABASE_SCHEMA_DIR := "schema"

# Database
Expand All @@ -23,12 +22,9 @@ db-login:
turso auth login
atlas login
db-migrate:
cd {{DATABASE_DIR}} && \
atlas schema apply -u "$(just db-url)?authToken=$(just db-token)" \
--to file://{{DATABASE_SCHEMA_DIR}} --exclude '_litestream_seq,_litestream_lock'
db-lint:
cd {{DATABASE_DIR}} && \
atlas migrate lint --dev-url "sqlite://dev?mode=memory" -w
db-diff:
cd {{DATABASE_DIR}} && \
atlas migrate diff --to file://{{DATABASE_SCHEMA_DIR}} --dev-url "sqlite://dev?mode=memory"

0 comments on commit 945856b

Please sign in to comment.