Skip to content

Commit

Permalink
Merge branch 'develop' into create-users
Browse files Browse the repository at this point in the history
  • Loading branch information
MTthoas committed Apr 24, 2024
2 parents ee9e1ac + d602e61 commit 75611aa
Show file tree
Hide file tree
Showing 81 changed files with 1,587 additions and 10,124 deletions.
26 changes: 14 additions & 12 deletions api/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,39 +1,41 @@
# Utilisation d'une image de builder Go avec Alpine pour un environnement minimal.
FROM golang:1.21-alpine AS builder

# Install git - required for fetching Go modules and Swaggo.
# Installation de git, nécessaire pour récupérer les modules Go et Swaggo.
RUN apk add --no-cache git

# Install Swag CLI.
# Installation de Swag CLI pour la documentation Swagger.
RUN go install github.com/swaggo/swag/cmd/swag@latest

# Move to the API directory where the Dockerfile and source code are.
# Définir le répertoire de travail où se trouve le code source.
WORKDIR /api

# Copy the go module files and download the dependencies.
# Copie des fichiers de module Go et téléchargement des dépendances.
COPY go.mod go.sum ./
RUN go mod download

# Copy the entire API directory and build it.
# Copie du reste de l'API dans l'image.
COPY . .

# Generate Swagger documentation.
# Génération de la documentation Swagger.
RUN swag init --generalInfo ./routes/swagger_routes.go --output ./docs

# Set necessary environment variables needed for our image.
# Configuration des variables d'environnement nécessaires pour la construction.
ENV CGO_ENABLED=0 GOOS=linux GOARCH=amd64

# Build the API server.
# Construction du serveur API.
RUN go build -ldflags="-s -w" -o apiserver .

# Utilisation d'une image scratch pour un environnement d'exécution minimal.
FROM scratch

# Copy binary, config files, and Swagger docs from /api to the root folder of the scratch container.
# Copie du binaire, des fichiers de configuration, et de la documentation Swagger.
COPY --from=builder /api/apiserver /
COPY --from=builder /api/.env /
COPY --from=builder /api/docs /docs

# Export necessary port.
# Exposition du port sur lequel le serveur API s'exécute.
EXPOSE 5000

# Command to run when starting the container.
ENTRYPOINT ["/apiserver"]
# Commande pour exécuter le serveur API lors du démarrage du conteneur.
CMD ["/apiserver"]
7 changes: 5 additions & 2 deletions api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ docker network create -d bridge dev-network

# PostgreSQL and initial Migration

docker run --rm -d --name dev-postgres --network dev-network -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=password -e POSTGRES_DB=postgres -v ${HOME}/dev-postgres/data/:/var/lib/postgresql/data -p 5432:5432 postgres
docker run --rm -d --name dev-postgres --network dev-network -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=password -e POSTGRES_DB=postgres -v \${HOME}/dev-postgres/data/:/var/lib/postgresql/data -p 5432:5432 postgres

docker run --rm -d \
--name dev-postgres \
--network dev-network \
-e POSTGRES_USER=postgres \
-e POSTGRES_PASSWORD=password \
-e POSTGRES_DB=postgres \
-v ${HOME}/dev-postgres/data/:/var/lib/postgresql/data \
-v \${HOME}/dev-postgres/data/:/var/lib/postgresql/data \
-p 5432:5432 \
postgres

Expand All @@ -30,5 +30,8 @@ docker run --rm -d --name dev-fiber --network dev-network -p 5000:5000 fiber

## IN LOCAL

docker build -t api-build .

go install github.com/swaggo/swag/cmd/swag@latest
swag init --generalInfo ./routes/swagger_routes.go --output ./docs
>> go run main.go
168 changes: 168 additions & 0 deletions api/controllers/pool.controller.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
package controllers

import (
"github.com/MTthoas/dex/api/models"
"github.com/MTthoas/dex/api/platform/database"
"github.com/MTthoas/dex/api/utils"
"github.com/gofiber/fiber/v2"
)

// GetPools function to get all pools
// @Summary Get all pools
// @Description Get all pools
// @Tags Pools
// @Accept json
// @Produce json
// @Success 200 {object} []models.Pool
// @Failure 500 {object} map[string]interface{}
// @Router /api/v1/pools [get]
func GetPools(c *fiber.Ctx) error {
db, err := database.OpenDBConnection()
if err != nil {
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
"error": err.Error(),
})
}
pools, err := db.PoolQueries.GetAllPools()
if err != nil {
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
"error": err.Error(),
})
}
return c.Status(fiber.StatusOK).JSON(fiber.Map{
"data": pools,
})
}

// GetPool function to get pool by ID
// @Summary Get pool by ID
// @Description Get pool by ID
// @Tags Pools
// @Accept json
// @Produce json
// @Param id path int true "ID of the pool"
// @Success 200 {object} models.Pool
// @Failure 404 {object} map[string]interface{}
// @Failure 500 {object} map[string]interface{}
// @Router /api/v1/pools/{id} [get]
func GetPool(c *fiber.Ctx) error {
db, err := database.OpenDBConnection()
if err != nil {
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
"error": err.Error(),
})
}
id := c.Params("id")
pool, err := db.PoolQueries.GetPoolByID(utils.StringToInt(id))
if err != nil {
return c.Status(fiber.StatusNotFound).JSON(fiber.Map{
"error": err.Error(),
})
}
return c.Status(fiber.StatusOK).JSON(fiber.Map{
"data": pool,
})
}

// CreatePool function to create a new pool
// @Summary Create a new pool
// @Description Create a new pool
// @Tags Pools
// @Accept json
// @Produce json
// @Param pool body models.Pool true "Pool object"
// @Success 200 {object} models.Pool
// @Failure 500 {object} map[string]interface{}
// @Router /api/v1/pools [post]
func CreatePool(c *fiber.Ctx) error {
db, err := database.OpenDBConnection()
if err != nil {
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
"error": err.Error(),
})
}
pool := new(models.Pool)
if err := c.BodyParser(pool); err != nil {
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
"error": err.Error(),
})
}

createdPool, err := db.PoolQueries.CreatePool(*pool)
if err != nil {
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
"error": err.Error(),
})
}
return c.Status(fiber.StatusOK).JSON(fiber.Map{
"data": createdPool,
})
}

// UpdatePool function to update a pool
// @Summary Update a pool
// @Description Update a pool
// @Tags Pools
// @Accept json
// @Produce json
// @Param pool body models.Pool true "Pool object"
// @Success 200 {object} models.Pool
// @Failure 500 {object} map[string]interface{}
// @Router /api/v1/pools [put]
func UpdatePool(c *fiber.Ctx) error {
db, err := database.OpenDBConnection()
if err != nil {
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
"error": err.Error(),
})
}
pool := new(models.Pool)
if err := c.BodyParser(pool); err != nil {
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
"error": err.Error(),
})
}

updatedPool, err := db.PoolQueries.UpdatePool(*pool)
if err != nil {
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
"error": err.Error(),
})
}
return c.Status(fiber.StatusOK).JSON(fiber.Map{
"data": updatedPool,
})
}

// DeletePool function to delete a pool
// @Summary Delete a pool
// @Description Delete a pool
// @Tags Pools
// @Accept json
// @Produce json
// @Param id path int true "ID of the pool"
// @Success 200 {object} map[string]interface{}
// @Failure 500 {object} map[string]interface{}
// @Router /api/v1/pools/{id} [delete]
func DeletePool(c *fiber.Ctx) error {
db, err := database.OpenDBConnection()
if err != nil {
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
"error": err.Error(),
})
}
id := c.Params("id")
if err := db.PoolQueries.DeletePool(utils.StringToInt(id)); err != nil {
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
"error": err.Error(),
})
}
return c.Status(fiber.StatusOK).JSON(fiber.Map{
"msg": "pool deleted",
})
}





12 changes: 6 additions & 6 deletions api/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ require (
github.com/valyala/tcplisten v1.0.0 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/mod v0.16.0 // indirect
golang.org/x/net v0.22.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.19.0 // indirect
golang.org/x/tools v0.20.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gorm.io/driver/postgres v1.5.7 // indirect
Expand Down
12 changes: 12 additions & 0 deletions api/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -252,13 +252,17 @@ golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5y
golang.org/x/crypto v0.0.0-20220214200702-86341886e292/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA=
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30=
golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M=
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.16.0 h1:QX4fJ0Rr5cPQCF7O9lh9Se4pmwfwskqZfq5moyldzic=
golang.org/x/mod v0.16.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA=
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
Expand All @@ -272,11 +276,15 @@ golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc=
golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w=
golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand All @@ -301,6 +309,8 @@ golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
Expand Down Expand Up @@ -328,6 +338,8 @@ golang.org/x/tools v0.1.7/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.19.0 h1:tfGCXNR1OsFG+sVdLAitlpjAvD/I6dHDKnYrpEZUHkw=
golang.org/x/tools v0.19.0/go.mod h1:qoJWxmGSIBmAeriMx19ogtrEPrGtDbPK634QFIcLAhc=
golang.org/x/tools v0.20.0 h1:hz/CVckiOxybQvFw6h7b/q80NTr9IUQb4s1IIzW7KNY=
golang.org/x/tools v0.20.0/go.mod h1:WvitBU7JJf6A4jOdg4S1tviW9bhUxkgeCui/0JHctQg=
golang.org/x/xerrors v0.0.0-20190410155217-1f06c39b4373/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
Loading

0 comments on commit 75611aa

Please sign in to comment.