-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into create-users
- Loading branch information
Showing
81 changed files
with
1,587 additions
and
10,124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
}) | ||
} | ||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.