diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..ad03ea4 --- /dev/null +++ b/.env.example @@ -0,0 +1,10 @@ +# Backend +PORT=8080 +DATABASE_DRIVER=sqlite3 +DATABASE_URL=file:./data/matosbox.db?_fk=1 +ATTACHMENTS_DIR=./data/pieces_jointes +BACKUP_DIR=./data/backups +MAX_UPLOAD_MB=50 + +# App +TIMEZONE=Europe/Paris diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a4ca67..b000b27 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ - Analyse detaillee des consignes. - Reference structure BDD. - TODO projet global. +- Migration SQL initiale. +- Handlers CRUD pour objets, categories, emplacements. ## [0.1.0] - 2026-01-21 - MVP core + DB SQLite (planifie). diff --git a/TODO.md b/TODO.md index 39ab0d6..a1c6b13 100644 --- a/TODO.md +++ b/TODO.md @@ -1,4 +1,6 @@ # TODO MatosBox +en suivant consigne: MatosBox Documentation.md + ## Priorite haute (MVP) - [ ] Creer schemas Ent en francais : Objet, Categorie, Emplacement. diff --git a/Taskfile.yml b/Taskfile.yml new file mode 100644 index 0000000..3be3f6e --- /dev/null +++ b/Taskfile.yml @@ -0,0 +1,12 @@ +version: '3' + +env: + GOPATH: /tmp/go + GOMODCACHE: /tmp/go/pkg/mod + GOCACHE: /tmp/go/cache + +includes: + backend: + taskfile: ./backend/Taskfile.yml + dir: ./backend + diff --git a/backend/Taskfile.yml b/backend/Taskfile.yml new file mode 100644 index 0000000..215de91 --- /dev/null +++ b/backend/Taskfile.yml @@ -0,0 +1,22 @@ +version: '3' + +tasks: + run: + desc: Lancer le backend en mode dev + cmds: + - go run ./cmd/app + + test: + desc: Lancer les tests Go + cmds: + - go test ./... + + ent: + desc: Generer le code Ent + cmds: + - go run -mod=mod entgo.io/ent/cmd/ent generate ./internal/data/ent/schema --target ./internal/data/ent + + swagger: + desc: Regenerer la doc Swagger + cmds: + - bash scripts/gen_swagger.sh diff --git a/backend/cmd/app/main.go b/backend/cmd/app/main.go index 68dd5a0..fd5899b 100644 --- a/backend/cmd/app/main.go +++ b/backend/cmd/app/main.go @@ -1,12 +1,25 @@ package main import ( + "context" + "log" "net/http" "os" "github.com/gin-gonic/gin" + _ "github.com/mattn/go-sqlite3" + swaggerFiles "github.com/swaggo/files" + ginSwagger "github.com/swaggo/gin-swagger" + + "gitea.maison43.duckdns.org/gilles/matosbox/docs" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/handlers" ) +// @title MatosBox API +// @version 0.1.0 +// @description API MatosBox pour la gestion d'inventaire. +// @BasePath /v1 func main() { // Config simple : port via PORT, defaut 8080. port := os.Getenv("PORT") @@ -16,10 +29,41 @@ func main() { r := gin.Default() + // Connexion base de donnees. + driver := os.Getenv("DATABASE_DRIVER") + if driver == "" { + driver = "sqlite3" + } + dsn := os.Getenv("DATABASE_URL") + if dsn == "" { + dsn = "file:./data/matosbox.db?_fk=1" + } + + client, err := ent.Open(driver, dsn) + if err != nil { + log.Fatalf("connexion base impossible: %v", err) + } + defer func() { + if err := client.Close(); err != nil { + log.Printf("fermeture base impossible: %v", err) + } + }() + + // Auto-creation du schema en dev. A remplacer par migrations en prod. + if err := client.Schema.Create(context.Background()); err != nil { + log.Fatalf("creation schema impossible: %v", err) + } + // Route de sante pour verifier que le backend repond. r.GET("/healthz", func(c *gin.Context) { c.JSON(http.StatusOK, gin.H{"status": "ok"}) }) + handlers.RegisterRoutes(r, client) + + // Swagger (doc API). + docs.SwaggerInfo.BasePath = "/v1" + r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler)) + _ = r.Run(":" + port) } diff --git a/backend/docs/docs.go b/backend/docs/docs.go new file mode 100644 index 0000000..256fb0d --- /dev/null +++ b/backend/docs/docs.go @@ -0,0 +1,2142 @@ +// Package docs Code generated by swaggo/swag. DO NOT EDIT +package docs + +import "github.com/swaggo/swag" + +const docTemplate = `{ + "schemes": {{ marshal .Schemes }}, + "swagger": "2.0", + "info": { + "description": "{{escape .Description}}", + "title": "{{.Title}}", + "contact": {}, + "version": "{{.Version}}" + }, + "host": "{{.Host}}", + "basePath": "{{.BasePath}}", + "paths": { + "/categories": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "Categories" + ], + "summary": "Lister les categories", + "parameters": [ + { + "type": "integer", + "description": "Page", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "description": "Limite", + "name": "limit", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + }, + "post": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Categories" + ], + "summary": "Creer une categorie", + "parameters": [ + { + "description": "Categorie a creer", + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/handlers.categorieRequest" + } + } + ], + "responses": { + "201": { + "description": "Created", + "schema": { + "$ref": "#/definitions/ent.Categorie" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + } + }, + "/categories/{id}": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "Categories" + ], + "summary": "Recuperer une categorie", + "parameters": [ + { + "type": "string", + "description": "ID categorie", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/ent.Categorie" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "404": { + "description": "Not Found", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + }, + "put": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Categories" + ], + "summary": "Mettre a jour une categorie", + "parameters": [ + { + "type": "string", + "description": "ID categorie", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "Categorie a mettre a jour", + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/handlers.categorieRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/ent.Categorie" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "404": { + "description": "Not Found", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + }, + "delete": { + "tags": [ + "Categories" + ], + "summary": "Supprimer une categorie", + "parameters": [ + { + "type": "string", + "description": "ID categorie", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "204": { + "description": "No Content", + "schema": { + "type": "string" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + } + }, + "/champs_personnalises/{id}": { + "put": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "ChampsPersonnalises" + ], + "summary": "Mettre a jour un champ personnalise", + "parameters": [ + { + "type": "string", + "description": "ID champ", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "Champ personnalise", + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/handlers.champPersonnaliseRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/ent.ChampPersonnalise" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "404": { + "description": "Not Found", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + }, + "delete": { + "tags": [ + "ChampsPersonnalises" + ], + "summary": "Supprimer un champ personnalise", + "parameters": [ + { + "type": "string", + "description": "ID champ", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "204": { + "description": "No Content", + "schema": { + "type": "string" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "404": { + "description": "Not Found", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + } + }, + "/emplacements": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "Emplacements" + ], + "summary": "Lister les emplacements", + "parameters": [ + { + "type": "integer", + "description": "Page", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "description": "Limite", + "name": "limit", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + }, + "post": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Emplacements" + ], + "summary": "Creer un emplacement", + "parameters": [ + { + "description": "Emplacement a creer", + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/handlers.emplacementRequest" + } + } + ], + "responses": { + "201": { + "description": "Created", + "schema": { + "$ref": "#/definitions/ent.Emplacement" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + } + }, + "/emplacements/{id}": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "Emplacements" + ], + "summary": "Recuperer un emplacement", + "parameters": [ + { + "type": "string", + "description": "ID emplacement", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/ent.Emplacement" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "404": { + "description": "Not Found", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + }, + "put": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Emplacements" + ], + "summary": "Mettre a jour un emplacement", + "parameters": [ + { + "type": "string", + "description": "ID emplacement", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "Emplacement a mettre a jour", + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/handlers.emplacementRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/ent.Emplacement" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "404": { + "description": "Not Found", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + }, + "delete": { + "tags": [ + "Emplacements" + ], + "summary": "Supprimer un emplacement", + "parameters": [ + { + "type": "string", + "description": "ID emplacement", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "204": { + "description": "No Content", + "schema": { + "type": "string" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + } + }, + "/liens_emplacements/{id}": { + "put": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "LiensEmplacements" + ], + "summary": "Mettre a jour un lien objet/emplacement", + "parameters": [ + { + "type": "string", + "description": "ID lien", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "Mise a jour", + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/handlers.lienObjetEmplacementUpdateRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/ent.LienObjetEmplacement" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "404": { + "description": "Not Found", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "409": { + "description": "Conflict", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + }, + "delete": { + "tags": [ + "LiensEmplacements" + ], + "summary": "Supprimer un lien objet/emplacement", + "parameters": [ + { + "type": "string", + "description": "ID lien", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "204": { + "description": "No Content", + "schema": { + "type": "string" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "404": { + "description": "Not Found", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + } + }, + "/objets": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "Objets" + ], + "summary": "Lister les objets", + "parameters": [ + { + "type": "integer", + "description": "Page", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "description": "Limite", + "name": "limit", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + }, + "post": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Objets" + ], + "summary": "Creer un objet", + "parameters": [ + { + "description": "Objet a creer", + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/handlers.objetRequest" + } + } + ], + "responses": { + "201": { + "description": "Created", + "schema": { + "$ref": "#/definitions/ent.Objet" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + } + }, + "/objets/{id}": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "Objets" + ], + "summary": "Recuperer un objet", + "parameters": [ + { + "type": "string", + "description": "ID objet", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/ent.Objet" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "404": { + "description": "Not Found", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + }, + "put": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Objets" + ], + "summary": "Mettre a jour un objet", + "parameters": [ + { + "type": "string", + "description": "ID objet", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "Objet a mettre a jour", + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/handlers.objetRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/ent.Objet" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "404": { + "description": "Not Found", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + }, + "delete": { + "tags": [ + "Objets" + ], + "summary": "Supprimer un objet", + "parameters": [ + { + "type": "string", + "description": "ID objet", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "204": { + "description": "No Content", + "schema": { + "type": "string" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + } + }, + "/objets/{id}/champs_personnalises": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "ChampsPersonnalises" + ], + "summary": "Lister les champs personnalises", + "parameters": [ + { + "type": "string", + "description": "ID objet", + "name": "id", + "in": "path", + "required": true + }, + { + "type": "integer", + "description": "Page", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "description": "Limite", + "name": "limit", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "400": { + "description": "Bad Request", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + }, + "post": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "ChampsPersonnalises" + ], + "summary": "Creer un champ personnalise", + "parameters": [ + { + "type": "string", + "description": "ID objet", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "Champ personnalise", + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/handlers.champPersonnaliseRequest" + } + } + ], + "responses": { + "201": { + "description": "Created", + "schema": { + "$ref": "#/definitions/ent.ChampPersonnalise" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + } + }, + "/objets/{id}/liens_emplacements": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "LiensEmplacements" + ], + "summary": "Lister les liens objet/emplacement", + "parameters": [ + { + "type": "string", + "description": "ID objet", + "name": "id", + "in": "path", + "required": true + }, + { + "type": "integer", + "description": "Page", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "description": "Limite", + "name": "limit", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "400": { + "description": "Bad Request", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + }, + "post": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "LiensEmplacements" + ], + "summary": "Creer un lien objet/emplacement", + "parameters": [ + { + "type": "string", + "description": "ID objet", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "Lien", + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/handlers.lienObjetEmplacementRequest" + } + } + ], + "responses": { + "201": { + "description": "Created", + "schema": { + "$ref": "#/definitions/ent.LienObjetEmplacement" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "404": { + "description": "Not Found", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "409": { + "description": "Conflict", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + } + }, + "/objets/{id}/pieces_jointes": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "PiecesJointes" + ], + "summary": "Lister les pieces jointes", + "parameters": [ + { + "type": "string", + "description": "ID objet", + "name": "id", + "in": "path", + "required": true + }, + { + "type": "integer", + "description": "Page", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "description": "Limite", + "name": "limit", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "400": { + "description": "Bad Request", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + }, + "post": { + "consumes": [ + "multipart/form-data" + ], + "produces": [ + "application/json" + ], + "tags": [ + "PiecesJointes" + ], + "summary": "Uploader des pieces jointes", + "parameters": [ + { + "type": "string", + "description": "ID objet", + "name": "id", + "in": "path", + "required": true + }, + { + "type": "file", + "description": "Fichiers (multi)", + "name": "fichiers", + "in": "formData", + "required": true + } + ], + "responses": { + "201": { + "description": "Created", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "400": { + "description": "Bad Request", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "404": { + "description": "Not Found", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "413": { + "description": "Request Entity Too Large", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + } + }, + "/pieces_jointes/{id}": { + "delete": { + "tags": [ + "PiecesJointes" + ], + "summary": "Supprimer une piece jointe", + "parameters": [ + { + "type": "string", + "description": "ID piece jointe", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "204": { + "description": "No Content", + "schema": { + "type": "string" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "404": { + "description": "Not Found", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + } + }, + "/pieces_jointes/{id}/principale": { + "put": { + "produces": [ + "application/json" + ], + "tags": [ + "PiecesJointes" + ], + "summary": "Definir la piece jointe principale", + "parameters": [ + { + "type": "string", + "description": "ID piece jointe", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/ent.PieceJointe" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "404": { + "description": "Not Found", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + } + } + }, + "definitions": { + "champpersonnalise.TypeChamp": { + "type": "string", + "enum": [ + "string", + "string", + "int", + "bool", + "date" + ], + "x-enum-varnames": [ + "DefaultTypeChamp", + "TypeChampString", + "TypeChampInt", + "TypeChampBool", + "TypeChampDate" + ] + }, + "ent.Categorie": { + "type": "object", + "properties": { + "created_at": { + "description": "Date de creation", + "type": "string" + }, + "edges": { + "description": "Edges holds the relations/edges for other nodes in the graph.\nThe values are being populated by the CategorieQuery when eager-loading is set.", + "allOf": [ + { + "$ref": "#/definitions/ent.CategorieEdges" + } + ] + }, + "icone": { + "description": "Nom ou code d'icone", + "type": "string" + }, + "id": { + "description": "ID of the ent.\nIdentifiant unique de la categorie", + "type": "string" + }, + "nom": { + "description": "Nom de la categorie", + "type": "string" + }, + "parent_id": { + "description": "Identifiant du parent", + "type": "string" + }, + "slug": { + "description": "Slug URL-friendly", + "type": "string" + }, + "updated_at": { + "description": "Date de derniere mise a jour", + "type": "string" + } + } + }, + "ent.CategorieEdges": { + "type": "object", + "properties": { + "enfants": { + "description": "Enfants holds the value of the enfants edge.", + "type": "array", + "items": { + "$ref": "#/definitions/ent.Categorie" + } + }, + "parent": { + "description": "Lien parent/enfants pour l'arbre des categories", + "allOf": [ + { + "$ref": "#/definitions/ent.Categorie" + } + ] + } + } + }, + "ent.ChampPersonnalise": { + "type": "object", + "properties": { + "created_at": { + "description": "Date de creation", + "type": "string" + }, + "edges": { + "description": "Edges holds the relations/edges for other nodes in the graph.\nThe values are being populated by the ChampPersonnaliseQuery when eager-loading is set.", + "allOf": [ + { + "$ref": "#/definitions/ent.ChampPersonnaliseEdges" + } + ] + }, + "id": { + "description": "ID of the ent.\nIdentifiant unique du champ", + "type": "string" + }, + "nom_champ": { + "description": "Nom du champ", + "type": "string" + }, + "objet_id": { + "description": "Identifiant de l'objet", + "type": "string" + }, + "type_champ": { + "description": "Type du champ", + "allOf": [ + { + "$ref": "#/definitions/champpersonnalise.TypeChamp" + } + ] + }, + "unite": { + "description": "Unite (si applicable)", + "type": "string" + }, + "updated_at": { + "description": "Date de derniere mise a jour", + "type": "string" + }, + "valeur": { + "description": "Valeur stockee en texte", + "type": "string" + } + } + }, + "ent.ChampPersonnaliseEdges": { + "type": "object", + "properties": { + "objet": { + "description": "Objet holds the value of the objet edge.", + "allOf": [ + { + "$ref": "#/definitions/ent.Objet" + } + ] + } + } + }, + "ent.Emplacement": { + "type": "object", + "properties": { + "created_at": { + "description": "Date de creation", + "type": "string" + }, + "edges": { + "description": "Edges holds the relations/edges for other nodes in the graph.\nThe values are being populated by the EmplacementQuery when eager-loading is set.", + "allOf": [ + { + "$ref": "#/definitions/ent.EmplacementEdges" + } + ] + }, + "icone": { + "description": "Nom ou code d'icone", + "type": "string" + }, + "id": { + "description": "ID of the ent.\nIdentifiant unique de l'emplacement", + "type": "string" + }, + "meuble": { + "description": "Meuble associe", + "type": "string" + }, + "nom": { + "description": "Nom de l'emplacement", + "type": "string" + }, + "numero_boite": { + "description": "Numero de boite", + "type": "string" + }, + "parent_id": { + "description": "Identifiant du parent", + "type": "string" + }, + "piece": { + "description": "Piece associee", + "type": "string" + }, + "slug": { + "description": "Slug URL-friendly", + "type": "string" + }, + "updated_at": { + "description": "Date de derniere mise a jour", + "type": "string" + } + } + }, + "ent.EmplacementEdges": { + "type": "object", + "properties": { + "enfants": { + "description": "Enfants holds the value of the enfants edge.", + "type": "array", + "items": { + "$ref": "#/definitions/ent.Emplacement" + } + }, + "liens_objets": { + "description": "Liens entre emplacements et objets", + "type": "array", + "items": { + "$ref": "#/definitions/ent.LienObjetEmplacement" + } + }, + "parent": { + "description": "Lien parent/enfants pour l'arbre des emplacements", + "allOf": [ + { + "$ref": "#/definitions/ent.Emplacement" + } + ] + } + } + }, + "ent.LienObjetEmplacement": { + "type": "object", + "properties": { + "created_at": { + "description": "Date de creation", + "type": "string" + }, + "edges": { + "description": "Edges holds the relations/edges for other nodes in the graph.\nThe values are being populated by the LienObjetEmplacementQuery when eager-loading is set.", + "allOf": [ + { + "$ref": "#/definitions/ent.LienObjetEmplacementEdges" + } + ] + }, + "emplacement_id": { + "description": "Identifiant de l'emplacement", + "type": "string" + }, + "id": { + "description": "ID of the ent.\nIdentifiant unique du lien", + "type": "string" + }, + "objet_id": { + "description": "Identifiant de l'objet", + "type": "string" + }, + "type": { + "description": "Type de relation", + "allOf": [ + { + "$ref": "#/definitions/lienobjetemplacement.Type" + } + ] + }, + "updated_at": { + "description": "Date de derniere mise a jour", + "type": "string" + } + } + }, + "ent.LienObjetEmplacementEdges": { + "type": "object", + "properties": { + "emplacement": { + "description": "Emplacement holds the value of the emplacement edge.", + "allOf": [ + { + "$ref": "#/definitions/ent.Emplacement" + } + ] + }, + "objet": { + "description": "Objet holds the value of the objet edge.", + "allOf": [ + { + "$ref": "#/definitions/ent.Objet" + } + ] + } + } + }, + "ent.Objet": { + "type": "object", + "properties": { + "boutique": { + "description": "Boutique ou fournisseur", + "type": "string" + }, + "caracteristiques": { + "description": "Caracteristiques personnalisees", + "type": "object", + "additionalProperties": true + }, + "created_at": { + "description": "Date de creation", + "type": "string" + }, + "date_achat": { + "description": "Date d'achat", + "type": "string" + }, + "description": { + "description": "Description libre", + "type": "string" + }, + "edges": { + "description": "Edges holds the relations/edges for other nodes in the graph.\nThe values are being populated by the ObjetQuery when eager-loading is set.", + "allOf": [ + { + "$ref": "#/definitions/ent.ObjetEdges" + } + ] + }, + "fabricant": { + "description": "Fabricant", + "type": "string" + }, + "id": { + "description": "ID of the ent.\nIdentifiant unique de l'objet", + "type": "string" + }, + "nom": { + "description": "Nom de l'objet", + "type": "string" + }, + "numero_modele": { + "description": "Numero de modele", + "type": "string" + }, + "numero_serie": { + "description": "Numero de serie", + "type": "string" + }, + "prix_achat": { + "description": "Prix d'achat", + "type": "number" + }, + "quantite": { + "description": "Quantite en stock", + "type": "integer" + }, + "statut": { + "description": "Statut de l'objet", + "allOf": [ + { + "$ref": "#/definitions/objet.Statut" + } + ] + }, + "updated_at": { + "description": "Date de derniere mise a jour", + "type": "string" + } + } + }, + "ent.ObjetEdges": { + "type": "object", + "properties": { + "champs_personnalises": { + "description": "ChampsPersonnalises holds the value of the champs_personnalises edge.", + "type": "array", + "items": { + "$ref": "#/definitions/ent.ChampPersonnalise" + } + }, + "liens_emplacements": { + "description": "LiensEmplacements holds the value of the liens_emplacements edge.", + "type": "array", + "items": { + "$ref": "#/definitions/ent.LienObjetEmplacement" + } + }, + "pieces_jointes": { + "description": "PiecesJointes holds the value of the pieces_jointes edge.", + "type": "array", + "items": { + "$ref": "#/definitions/ent.PieceJointe" + } + } + } + }, + "ent.PieceJointe": { + "type": "object", + "properties": { + "categorie": { + "description": "Categorie de la piece jointe", + "allOf": [ + { + "$ref": "#/definitions/piecejointe.Categorie" + } + ] + }, + "chemin": { + "description": "Chemin de stockage", + "type": "string" + }, + "created_at": { + "description": "Date de creation", + "type": "string" + }, + "edges": { + "description": "Edges holds the relations/edges for other nodes in the graph.\nThe values are being populated by the PieceJointeQuery when eager-loading is set.", + "allOf": [ + { + "$ref": "#/definitions/ent.PieceJointeEdges" + } + ] + }, + "est_principale": { + "description": "Piece jointe principale", + "type": "boolean" + }, + "id": { + "description": "ID of the ent.\nIdentifiant unique de la piece jointe", + "type": "string" + }, + "nom_fichier": { + "description": "Nom du fichier", + "type": "string" + }, + "objet_id": { + "description": "Identifiant de l'objet", + "type": "string" + }, + "type_mime": { + "description": "Type MIME", + "type": "string" + }, + "updated_at": { + "description": "Date de derniere mise a jour", + "type": "string" + } + } + }, + "ent.PieceJointeEdges": { + "type": "object", + "properties": { + "objet": { + "description": "Objet holds the value of the objet edge.", + "allOf": [ + { + "$ref": "#/definitions/ent.Objet" + } + ] + } + } + }, + "handlers.categorieRequest": { + "type": "object", + "properties": { + "icone": { + "type": "string" + }, + "nom": { + "type": "string" + }, + "parent_id": { + "type": "string" + }, + "slug": { + "type": "string" + } + } + }, + "handlers.champPersonnaliseRequest": { + "type": "object", + "properties": { + "nom_champ": { + "type": "string" + }, + "type_champ": { + "type": "string" + }, + "unite": { + "type": "string" + }, + "valeur": { + "type": "string" + } + } + }, + "handlers.emplacementRequest": { + "type": "object", + "properties": { + "icone": { + "type": "string" + }, + "meuble": { + "type": "string" + }, + "nom": { + "type": "string" + }, + "numero_boite": { + "type": "string" + }, + "parent_id": { + "type": "string" + }, + "piece": { + "type": "string" + }, + "slug": { + "type": "string" + } + } + }, + "handlers.lienObjetEmplacementRequest": { + "type": "object", + "properties": { + "emplacement_id": { + "type": "string" + }, + "type": { + "type": "string" + } + } + }, + "handlers.lienObjetEmplacementUpdateRequest": { + "type": "object", + "properties": { + "emplacement_id": { + "type": "string" + }, + "type": { + "type": "string" + } + } + }, + "handlers.objetRequest": { + "type": "object", + "properties": { + "boutique": { + "type": "string" + }, + "caracteristiques": { + "type": "object", + "additionalProperties": {} + }, + "date_achat": { + "type": "string" + }, + "description": { + "type": "string" + }, + "fabricant": { + "type": "string" + }, + "nom": { + "type": "string" + }, + "numero_modele": { + "type": "string" + }, + "numero_serie": { + "type": "string" + }, + "prix_achat": { + "type": "number" + }, + "quantite": { + "type": "integer" + }, + "statut": { + "type": "string" + } + } + }, + "lienobjetemplacement.Type": { + "type": "string", + "enum": [ + "stocke", + "stocke", + "utilise_dans" + ], + "x-enum-varnames": [ + "DefaultType", + "TypeStocke", + "TypeUtiliseDans" + ] + }, + "objet.Statut": { + "type": "string", + "enum": [ + "en_stock", + "en_stock", + "pret", + "hors_service", + "archive" + ], + "x-enum-varnames": [ + "DefaultStatut", + "StatutEnStock", + "StatutPret", + "StatutHorsService", + "StatutArchive" + ] + }, + "piecejointe.Categorie": { + "type": "string", + "enum": [ + "image", + "image", + "pdf_notice", + "markdown_tuto" + ], + "x-enum-varnames": [ + "DefaultCategorie", + "CategorieImage", + "CategoriePdfNotice", + "CategorieMarkdownTuto" + ] + } + } +}` + +// SwaggerInfo holds exported Swagger Info so clients can modify it +var SwaggerInfo = &swag.Spec{ + Version: "0.1.0", + Host: "", + BasePath: "/v1", + Schemes: []string{}, + Title: "MatosBox API", + Description: "API MatosBox pour la gestion d'inventaire.", + InfoInstanceName: "swagger", + SwaggerTemplate: docTemplate, + LeftDelim: "{{", + RightDelim: "}}", +} + +func init() { + swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo) +} diff --git a/backend/docs/swagger.json b/backend/docs/swagger.json new file mode 100644 index 0000000..e9e5ec7 --- /dev/null +++ b/backend/docs/swagger.json @@ -0,0 +1,2117 @@ +{ + "swagger": "2.0", + "info": { + "description": "API MatosBox pour la gestion d'inventaire.", + "title": "MatosBox API", + "contact": {}, + "version": "0.1.0" + }, + "basePath": "/v1", + "paths": { + "/categories": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "Categories" + ], + "summary": "Lister les categories", + "parameters": [ + { + "type": "integer", + "description": "Page", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "description": "Limite", + "name": "limit", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + }, + "post": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Categories" + ], + "summary": "Creer une categorie", + "parameters": [ + { + "description": "Categorie a creer", + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/handlers.categorieRequest" + } + } + ], + "responses": { + "201": { + "description": "Created", + "schema": { + "$ref": "#/definitions/ent.Categorie" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + } + }, + "/categories/{id}": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "Categories" + ], + "summary": "Recuperer une categorie", + "parameters": [ + { + "type": "string", + "description": "ID categorie", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/ent.Categorie" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "404": { + "description": "Not Found", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + }, + "put": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Categories" + ], + "summary": "Mettre a jour une categorie", + "parameters": [ + { + "type": "string", + "description": "ID categorie", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "Categorie a mettre a jour", + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/handlers.categorieRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/ent.Categorie" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "404": { + "description": "Not Found", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + }, + "delete": { + "tags": [ + "Categories" + ], + "summary": "Supprimer une categorie", + "parameters": [ + { + "type": "string", + "description": "ID categorie", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "204": { + "description": "No Content", + "schema": { + "type": "string" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + } + }, + "/champs_personnalises/{id}": { + "put": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "ChampsPersonnalises" + ], + "summary": "Mettre a jour un champ personnalise", + "parameters": [ + { + "type": "string", + "description": "ID champ", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "Champ personnalise", + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/handlers.champPersonnaliseRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/ent.ChampPersonnalise" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "404": { + "description": "Not Found", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + }, + "delete": { + "tags": [ + "ChampsPersonnalises" + ], + "summary": "Supprimer un champ personnalise", + "parameters": [ + { + "type": "string", + "description": "ID champ", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "204": { + "description": "No Content", + "schema": { + "type": "string" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "404": { + "description": "Not Found", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + } + }, + "/emplacements": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "Emplacements" + ], + "summary": "Lister les emplacements", + "parameters": [ + { + "type": "integer", + "description": "Page", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "description": "Limite", + "name": "limit", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + }, + "post": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Emplacements" + ], + "summary": "Creer un emplacement", + "parameters": [ + { + "description": "Emplacement a creer", + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/handlers.emplacementRequest" + } + } + ], + "responses": { + "201": { + "description": "Created", + "schema": { + "$ref": "#/definitions/ent.Emplacement" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + } + }, + "/emplacements/{id}": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "Emplacements" + ], + "summary": "Recuperer un emplacement", + "parameters": [ + { + "type": "string", + "description": "ID emplacement", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/ent.Emplacement" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "404": { + "description": "Not Found", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + }, + "put": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Emplacements" + ], + "summary": "Mettre a jour un emplacement", + "parameters": [ + { + "type": "string", + "description": "ID emplacement", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "Emplacement a mettre a jour", + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/handlers.emplacementRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/ent.Emplacement" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "404": { + "description": "Not Found", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + }, + "delete": { + "tags": [ + "Emplacements" + ], + "summary": "Supprimer un emplacement", + "parameters": [ + { + "type": "string", + "description": "ID emplacement", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "204": { + "description": "No Content", + "schema": { + "type": "string" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + } + }, + "/liens_emplacements/{id}": { + "put": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "LiensEmplacements" + ], + "summary": "Mettre a jour un lien objet/emplacement", + "parameters": [ + { + "type": "string", + "description": "ID lien", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "Mise a jour", + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/handlers.lienObjetEmplacementUpdateRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/ent.LienObjetEmplacement" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "404": { + "description": "Not Found", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "409": { + "description": "Conflict", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + }, + "delete": { + "tags": [ + "LiensEmplacements" + ], + "summary": "Supprimer un lien objet/emplacement", + "parameters": [ + { + "type": "string", + "description": "ID lien", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "204": { + "description": "No Content", + "schema": { + "type": "string" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "404": { + "description": "Not Found", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + } + }, + "/objets": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "Objets" + ], + "summary": "Lister les objets", + "parameters": [ + { + "type": "integer", + "description": "Page", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "description": "Limite", + "name": "limit", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + }, + "post": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Objets" + ], + "summary": "Creer un objet", + "parameters": [ + { + "description": "Objet a creer", + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/handlers.objetRequest" + } + } + ], + "responses": { + "201": { + "description": "Created", + "schema": { + "$ref": "#/definitions/ent.Objet" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + } + }, + "/objets/{id}": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "Objets" + ], + "summary": "Recuperer un objet", + "parameters": [ + { + "type": "string", + "description": "ID objet", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/ent.Objet" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "404": { + "description": "Not Found", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + }, + "put": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Objets" + ], + "summary": "Mettre a jour un objet", + "parameters": [ + { + "type": "string", + "description": "ID objet", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "Objet a mettre a jour", + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/handlers.objetRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/ent.Objet" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "404": { + "description": "Not Found", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + }, + "delete": { + "tags": [ + "Objets" + ], + "summary": "Supprimer un objet", + "parameters": [ + { + "type": "string", + "description": "ID objet", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "204": { + "description": "No Content", + "schema": { + "type": "string" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + } + }, + "/objets/{id}/champs_personnalises": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "ChampsPersonnalises" + ], + "summary": "Lister les champs personnalises", + "parameters": [ + { + "type": "string", + "description": "ID objet", + "name": "id", + "in": "path", + "required": true + }, + { + "type": "integer", + "description": "Page", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "description": "Limite", + "name": "limit", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "400": { + "description": "Bad Request", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + }, + "post": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "ChampsPersonnalises" + ], + "summary": "Creer un champ personnalise", + "parameters": [ + { + "type": "string", + "description": "ID objet", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "Champ personnalise", + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/handlers.champPersonnaliseRequest" + } + } + ], + "responses": { + "201": { + "description": "Created", + "schema": { + "$ref": "#/definitions/ent.ChampPersonnalise" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + } + }, + "/objets/{id}/liens_emplacements": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "LiensEmplacements" + ], + "summary": "Lister les liens objet/emplacement", + "parameters": [ + { + "type": "string", + "description": "ID objet", + "name": "id", + "in": "path", + "required": true + }, + { + "type": "integer", + "description": "Page", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "description": "Limite", + "name": "limit", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "400": { + "description": "Bad Request", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + }, + "post": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "LiensEmplacements" + ], + "summary": "Creer un lien objet/emplacement", + "parameters": [ + { + "type": "string", + "description": "ID objet", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "Lien", + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/handlers.lienObjetEmplacementRequest" + } + } + ], + "responses": { + "201": { + "description": "Created", + "schema": { + "$ref": "#/definitions/ent.LienObjetEmplacement" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "404": { + "description": "Not Found", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "409": { + "description": "Conflict", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + } + }, + "/objets/{id}/pieces_jointes": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "PiecesJointes" + ], + "summary": "Lister les pieces jointes", + "parameters": [ + { + "type": "string", + "description": "ID objet", + "name": "id", + "in": "path", + "required": true + }, + { + "type": "integer", + "description": "Page", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "description": "Limite", + "name": "limit", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "400": { + "description": "Bad Request", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + }, + "post": { + "consumes": [ + "multipart/form-data" + ], + "produces": [ + "application/json" + ], + "tags": [ + "PiecesJointes" + ], + "summary": "Uploader des pieces jointes", + "parameters": [ + { + "type": "string", + "description": "ID objet", + "name": "id", + "in": "path", + "required": true + }, + { + "type": "file", + "description": "Fichiers (multi)", + "name": "fichiers", + "in": "formData", + "required": true + } + ], + "responses": { + "201": { + "description": "Created", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "400": { + "description": "Bad Request", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "404": { + "description": "Not Found", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "413": { + "description": "Request Entity Too Large", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + } + }, + "/pieces_jointes/{id}": { + "delete": { + "tags": [ + "PiecesJointes" + ], + "summary": "Supprimer une piece jointe", + "parameters": [ + { + "type": "string", + "description": "ID piece jointe", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "204": { + "description": "No Content", + "schema": { + "type": "string" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "404": { + "description": "Not Found", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + } + }, + "/pieces_jointes/{id}/principale": { + "put": { + "produces": [ + "application/json" + ], + "tags": [ + "PiecesJointes" + ], + "summary": "Definir la piece jointe principale", + "parameters": [ + { + "type": "string", + "description": "ID piece jointe", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/ent.PieceJointe" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "404": { + "description": "Not Found", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + } + } + }, + "definitions": { + "champpersonnalise.TypeChamp": { + "type": "string", + "enum": [ + "string", + "string", + "int", + "bool", + "date" + ], + "x-enum-varnames": [ + "DefaultTypeChamp", + "TypeChampString", + "TypeChampInt", + "TypeChampBool", + "TypeChampDate" + ] + }, + "ent.Categorie": { + "type": "object", + "properties": { + "created_at": { + "description": "Date de creation", + "type": "string" + }, + "edges": { + "description": "Edges holds the relations/edges for other nodes in the graph.\nThe values are being populated by the CategorieQuery when eager-loading is set.", + "allOf": [ + { + "$ref": "#/definitions/ent.CategorieEdges" + } + ] + }, + "icone": { + "description": "Nom ou code d'icone", + "type": "string" + }, + "id": { + "description": "ID of the ent.\nIdentifiant unique de la categorie", + "type": "string" + }, + "nom": { + "description": "Nom de la categorie", + "type": "string" + }, + "parent_id": { + "description": "Identifiant du parent", + "type": "string" + }, + "slug": { + "description": "Slug URL-friendly", + "type": "string" + }, + "updated_at": { + "description": "Date de derniere mise a jour", + "type": "string" + } + } + }, + "ent.CategorieEdges": { + "type": "object", + "properties": { + "enfants": { + "description": "Enfants holds the value of the enfants edge.", + "type": "array", + "items": { + "$ref": "#/definitions/ent.Categorie" + } + }, + "parent": { + "description": "Lien parent/enfants pour l'arbre des categories", + "allOf": [ + { + "$ref": "#/definitions/ent.Categorie" + } + ] + } + } + }, + "ent.ChampPersonnalise": { + "type": "object", + "properties": { + "created_at": { + "description": "Date de creation", + "type": "string" + }, + "edges": { + "description": "Edges holds the relations/edges for other nodes in the graph.\nThe values are being populated by the ChampPersonnaliseQuery when eager-loading is set.", + "allOf": [ + { + "$ref": "#/definitions/ent.ChampPersonnaliseEdges" + } + ] + }, + "id": { + "description": "ID of the ent.\nIdentifiant unique du champ", + "type": "string" + }, + "nom_champ": { + "description": "Nom du champ", + "type": "string" + }, + "objet_id": { + "description": "Identifiant de l'objet", + "type": "string" + }, + "type_champ": { + "description": "Type du champ", + "allOf": [ + { + "$ref": "#/definitions/champpersonnalise.TypeChamp" + } + ] + }, + "unite": { + "description": "Unite (si applicable)", + "type": "string" + }, + "updated_at": { + "description": "Date de derniere mise a jour", + "type": "string" + }, + "valeur": { + "description": "Valeur stockee en texte", + "type": "string" + } + } + }, + "ent.ChampPersonnaliseEdges": { + "type": "object", + "properties": { + "objet": { + "description": "Objet holds the value of the objet edge.", + "allOf": [ + { + "$ref": "#/definitions/ent.Objet" + } + ] + } + } + }, + "ent.Emplacement": { + "type": "object", + "properties": { + "created_at": { + "description": "Date de creation", + "type": "string" + }, + "edges": { + "description": "Edges holds the relations/edges for other nodes in the graph.\nThe values are being populated by the EmplacementQuery when eager-loading is set.", + "allOf": [ + { + "$ref": "#/definitions/ent.EmplacementEdges" + } + ] + }, + "icone": { + "description": "Nom ou code d'icone", + "type": "string" + }, + "id": { + "description": "ID of the ent.\nIdentifiant unique de l'emplacement", + "type": "string" + }, + "meuble": { + "description": "Meuble associe", + "type": "string" + }, + "nom": { + "description": "Nom de l'emplacement", + "type": "string" + }, + "numero_boite": { + "description": "Numero de boite", + "type": "string" + }, + "parent_id": { + "description": "Identifiant du parent", + "type": "string" + }, + "piece": { + "description": "Piece associee", + "type": "string" + }, + "slug": { + "description": "Slug URL-friendly", + "type": "string" + }, + "updated_at": { + "description": "Date de derniere mise a jour", + "type": "string" + } + } + }, + "ent.EmplacementEdges": { + "type": "object", + "properties": { + "enfants": { + "description": "Enfants holds the value of the enfants edge.", + "type": "array", + "items": { + "$ref": "#/definitions/ent.Emplacement" + } + }, + "liens_objets": { + "description": "Liens entre emplacements et objets", + "type": "array", + "items": { + "$ref": "#/definitions/ent.LienObjetEmplacement" + } + }, + "parent": { + "description": "Lien parent/enfants pour l'arbre des emplacements", + "allOf": [ + { + "$ref": "#/definitions/ent.Emplacement" + } + ] + } + } + }, + "ent.LienObjetEmplacement": { + "type": "object", + "properties": { + "created_at": { + "description": "Date de creation", + "type": "string" + }, + "edges": { + "description": "Edges holds the relations/edges for other nodes in the graph.\nThe values are being populated by the LienObjetEmplacementQuery when eager-loading is set.", + "allOf": [ + { + "$ref": "#/definitions/ent.LienObjetEmplacementEdges" + } + ] + }, + "emplacement_id": { + "description": "Identifiant de l'emplacement", + "type": "string" + }, + "id": { + "description": "ID of the ent.\nIdentifiant unique du lien", + "type": "string" + }, + "objet_id": { + "description": "Identifiant de l'objet", + "type": "string" + }, + "type": { + "description": "Type de relation", + "allOf": [ + { + "$ref": "#/definitions/lienobjetemplacement.Type" + } + ] + }, + "updated_at": { + "description": "Date de derniere mise a jour", + "type": "string" + } + } + }, + "ent.LienObjetEmplacementEdges": { + "type": "object", + "properties": { + "emplacement": { + "description": "Emplacement holds the value of the emplacement edge.", + "allOf": [ + { + "$ref": "#/definitions/ent.Emplacement" + } + ] + }, + "objet": { + "description": "Objet holds the value of the objet edge.", + "allOf": [ + { + "$ref": "#/definitions/ent.Objet" + } + ] + } + } + }, + "ent.Objet": { + "type": "object", + "properties": { + "boutique": { + "description": "Boutique ou fournisseur", + "type": "string" + }, + "caracteristiques": { + "description": "Caracteristiques personnalisees", + "type": "object", + "additionalProperties": true + }, + "created_at": { + "description": "Date de creation", + "type": "string" + }, + "date_achat": { + "description": "Date d'achat", + "type": "string" + }, + "description": { + "description": "Description libre", + "type": "string" + }, + "edges": { + "description": "Edges holds the relations/edges for other nodes in the graph.\nThe values are being populated by the ObjetQuery when eager-loading is set.", + "allOf": [ + { + "$ref": "#/definitions/ent.ObjetEdges" + } + ] + }, + "fabricant": { + "description": "Fabricant", + "type": "string" + }, + "id": { + "description": "ID of the ent.\nIdentifiant unique de l'objet", + "type": "string" + }, + "nom": { + "description": "Nom de l'objet", + "type": "string" + }, + "numero_modele": { + "description": "Numero de modele", + "type": "string" + }, + "numero_serie": { + "description": "Numero de serie", + "type": "string" + }, + "prix_achat": { + "description": "Prix d'achat", + "type": "number" + }, + "quantite": { + "description": "Quantite en stock", + "type": "integer" + }, + "statut": { + "description": "Statut de l'objet", + "allOf": [ + { + "$ref": "#/definitions/objet.Statut" + } + ] + }, + "updated_at": { + "description": "Date de derniere mise a jour", + "type": "string" + } + } + }, + "ent.ObjetEdges": { + "type": "object", + "properties": { + "champs_personnalises": { + "description": "ChampsPersonnalises holds the value of the champs_personnalises edge.", + "type": "array", + "items": { + "$ref": "#/definitions/ent.ChampPersonnalise" + } + }, + "liens_emplacements": { + "description": "LiensEmplacements holds the value of the liens_emplacements edge.", + "type": "array", + "items": { + "$ref": "#/definitions/ent.LienObjetEmplacement" + } + }, + "pieces_jointes": { + "description": "PiecesJointes holds the value of the pieces_jointes edge.", + "type": "array", + "items": { + "$ref": "#/definitions/ent.PieceJointe" + } + } + } + }, + "ent.PieceJointe": { + "type": "object", + "properties": { + "categorie": { + "description": "Categorie de la piece jointe", + "allOf": [ + { + "$ref": "#/definitions/piecejointe.Categorie" + } + ] + }, + "chemin": { + "description": "Chemin de stockage", + "type": "string" + }, + "created_at": { + "description": "Date de creation", + "type": "string" + }, + "edges": { + "description": "Edges holds the relations/edges for other nodes in the graph.\nThe values are being populated by the PieceJointeQuery when eager-loading is set.", + "allOf": [ + { + "$ref": "#/definitions/ent.PieceJointeEdges" + } + ] + }, + "est_principale": { + "description": "Piece jointe principale", + "type": "boolean" + }, + "id": { + "description": "ID of the ent.\nIdentifiant unique de la piece jointe", + "type": "string" + }, + "nom_fichier": { + "description": "Nom du fichier", + "type": "string" + }, + "objet_id": { + "description": "Identifiant de l'objet", + "type": "string" + }, + "type_mime": { + "description": "Type MIME", + "type": "string" + }, + "updated_at": { + "description": "Date de derniere mise a jour", + "type": "string" + } + } + }, + "ent.PieceJointeEdges": { + "type": "object", + "properties": { + "objet": { + "description": "Objet holds the value of the objet edge.", + "allOf": [ + { + "$ref": "#/definitions/ent.Objet" + } + ] + } + } + }, + "handlers.categorieRequest": { + "type": "object", + "properties": { + "icone": { + "type": "string" + }, + "nom": { + "type": "string" + }, + "parent_id": { + "type": "string" + }, + "slug": { + "type": "string" + } + } + }, + "handlers.champPersonnaliseRequest": { + "type": "object", + "properties": { + "nom_champ": { + "type": "string" + }, + "type_champ": { + "type": "string" + }, + "unite": { + "type": "string" + }, + "valeur": { + "type": "string" + } + } + }, + "handlers.emplacementRequest": { + "type": "object", + "properties": { + "icone": { + "type": "string" + }, + "meuble": { + "type": "string" + }, + "nom": { + "type": "string" + }, + "numero_boite": { + "type": "string" + }, + "parent_id": { + "type": "string" + }, + "piece": { + "type": "string" + }, + "slug": { + "type": "string" + } + } + }, + "handlers.lienObjetEmplacementRequest": { + "type": "object", + "properties": { + "emplacement_id": { + "type": "string" + }, + "type": { + "type": "string" + } + } + }, + "handlers.lienObjetEmplacementUpdateRequest": { + "type": "object", + "properties": { + "emplacement_id": { + "type": "string" + }, + "type": { + "type": "string" + } + } + }, + "handlers.objetRequest": { + "type": "object", + "properties": { + "boutique": { + "type": "string" + }, + "caracteristiques": { + "type": "object", + "additionalProperties": {} + }, + "date_achat": { + "type": "string" + }, + "description": { + "type": "string" + }, + "fabricant": { + "type": "string" + }, + "nom": { + "type": "string" + }, + "numero_modele": { + "type": "string" + }, + "numero_serie": { + "type": "string" + }, + "prix_achat": { + "type": "number" + }, + "quantite": { + "type": "integer" + }, + "statut": { + "type": "string" + } + } + }, + "lienobjetemplacement.Type": { + "type": "string", + "enum": [ + "stocke", + "stocke", + "utilise_dans" + ], + "x-enum-varnames": [ + "DefaultType", + "TypeStocke", + "TypeUtiliseDans" + ] + }, + "objet.Statut": { + "type": "string", + "enum": [ + "en_stock", + "en_stock", + "pret", + "hors_service", + "archive" + ], + "x-enum-varnames": [ + "DefaultStatut", + "StatutEnStock", + "StatutPret", + "StatutHorsService", + "StatutArchive" + ] + }, + "piecejointe.Categorie": { + "type": "string", + "enum": [ + "image", + "image", + "pdf_notice", + "markdown_tuto" + ], + "x-enum-varnames": [ + "DefaultCategorie", + "CategorieImage", + "CategoriePdfNotice", + "CategorieMarkdownTuto" + ] + } + } +} \ No newline at end of file diff --git a/backend/docs/swagger.yaml b/backend/docs/swagger.yaml new file mode 100644 index 0000000..c29d796 --- /dev/null +++ b/backend/docs/swagger.yaml @@ -0,0 +1,1424 @@ +basePath: /v1 +definitions: + champpersonnalise.TypeChamp: + enum: + - string + - string + - int + - bool + - date + type: string + x-enum-varnames: + - DefaultTypeChamp + - TypeChampString + - TypeChampInt + - TypeChampBool + - TypeChampDate + ent.Categorie: + properties: + created_at: + description: Date de creation + type: string + edges: + allOf: + - $ref: '#/definitions/ent.CategorieEdges' + description: |- + Edges holds the relations/edges for other nodes in the graph. + The values are being populated by the CategorieQuery when eager-loading is set. + icone: + description: Nom ou code d'icone + type: string + id: + description: |- + ID of the ent. + Identifiant unique de la categorie + type: string + nom: + description: Nom de la categorie + type: string + parent_id: + description: Identifiant du parent + type: string + slug: + description: Slug URL-friendly + type: string + updated_at: + description: Date de derniere mise a jour + type: string + type: object + ent.CategorieEdges: + properties: + enfants: + description: Enfants holds the value of the enfants edge. + items: + $ref: '#/definitions/ent.Categorie' + type: array + parent: + allOf: + - $ref: '#/definitions/ent.Categorie' + description: Lien parent/enfants pour l'arbre des categories + type: object + ent.ChampPersonnalise: + properties: + created_at: + description: Date de creation + type: string + edges: + allOf: + - $ref: '#/definitions/ent.ChampPersonnaliseEdges' + description: |- + Edges holds the relations/edges for other nodes in the graph. + The values are being populated by the ChampPersonnaliseQuery when eager-loading is set. + id: + description: |- + ID of the ent. + Identifiant unique du champ + type: string + nom_champ: + description: Nom du champ + type: string + objet_id: + description: Identifiant de l'objet + type: string + type_champ: + allOf: + - $ref: '#/definitions/champpersonnalise.TypeChamp' + description: Type du champ + unite: + description: Unite (si applicable) + type: string + updated_at: + description: Date de derniere mise a jour + type: string + valeur: + description: Valeur stockee en texte + type: string + type: object + ent.ChampPersonnaliseEdges: + properties: + objet: + allOf: + - $ref: '#/definitions/ent.Objet' + description: Objet holds the value of the objet edge. + type: object + ent.Emplacement: + properties: + created_at: + description: Date de creation + type: string + edges: + allOf: + - $ref: '#/definitions/ent.EmplacementEdges' + description: |- + Edges holds the relations/edges for other nodes in the graph. + The values are being populated by the EmplacementQuery when eager-loading is set. + icone: + description: Nom ou code d'icone + type: string + id: + description: |- + ID of the ent. + Identifiant unique de l'emplacement + type: string + meuble: + description: Meuble associe + type: string + nom: + description: Nom de l'emplacement + type: string + numero_boite: + description: Numero de boite + type: string + parent_id: + description: Identifiant du parent + type: string + piece: + description: Piece associee + type: string + slug: + description: Slug URL-friendly + type: string + updated_at: + description: Date de derniere mise a jour + type: string + type: object + ent.EmplacementEdges: + properties: + enfants: + description: Enfants holds the value of the enfants edge. + items: + $ref: '#/definitions/ent.Emplacement' + type: array + liens_objets: + description: Liens entre emplacements et objets + items: + $ref: '#/definitions/ent.LienObjetEmplacement' + type: array + parent: + allOf: + - $ref: '#/definitions/ent.Emplacement' + description: Lien parent/enfants pour l'arbre des emplacements + type: object + ent.LienObjetEmplacement: + properties: + created_at: + description: Date de creation + type: string + edges: + allOf: + - $ref: '#/definitions/ent.LienObjetEmplacementEdges' + description: |- + Edges holds the relations/edges for other nodes in the graph. + The values are being populated by the LienObjetEmplacementQuery when eager-loading is set. + emplacement_id: + description: Identifiant de l'emplacement + type: string + id: + description: |- + ID of the ent. + Identifiant unique du lien + type: string + objet_id: + description: Identifiant de l'objet + type: string + type: + allOf: + - $ref: '#/definitions/lienobjetemplacement.Type' + description: Type de relation + updated_at: + description: Date de derniere mise a jour + type: string + type: object + ent.LienObjetEmplacementEdges: + properties: + emplacement: + allOf: + - $ref: '#/definitions/ent.Emplacement' + description: Emplacement holds the value of the emplacement edge. + objet: + allOf: + - $ref: '#/definitions/ent.Objet' + description: Objet holds the value of the objet edge. + type: object + ent.Objet: + properties: + boutique: + description: Boutique ou fournisseur + type: string + caracteristiques: + additionalProperties: true + description: Caracteristiques personnalisees + type: object + created_at: + description: Date de creation + type: string + date_achat: + description: Date d'achat + type: string + description: + description: Description libre + type: string + edges: + allOf: + - $ref: '#/definitions/ent.ObjetEdges' + description: |- + Edges holds the relations/edges for other nodes in the graph. + The values are being populated by the ObjetQuery when eager-loading is set. + fabricant: + description: Fabricant + type: string + id: + description: |- + ID of the ent. + Identifiant unique de l'objet + type: string + nom: + description: Nom de l'objet + type: string + numero_modele: + description: Numero de modele + type: string + numero_serie: + description: Numero de serie + type: string + prix_achat: + description: Prix d'achat + type: number + quantite: + description: Quantite en stock + type: integer + statut: + allOf: + - $ref: '#/definitions/objet.Statut' + description: Statut de l'objet + updated_at: + description: Date de derniere mise a jour + type: string + type: object + ent.ObjetEdges: + properties: + champs_personnalises: + description: ChampsPersonnalises holds the value of the champs_personnalises + edge. + items: + $ref: '#/definitions/ent.ChampPersonnalise' + type: array + liens_emplacements: + description: LiensEmplacements holds the value of the liens_emplacements edge. + items: + $ref: '#/definitions/ent.LienObjetEmplacement' + type: array + pieces_jointes: + description: PiecesJointes holds the value of the pieces_jointes edge. + items: + $ref: '#/definitions/ent.PieceJointe' + type: array + type: object + ent.PieceJointe: + properties: + categorie: + allOf: + - $ref: '#/definitions/piecejointe.Categorie' + description: Categorie de la piece jointe + chemin: + description: Chemin de stockage + type: string + created_at: + description: Date de creation + type: string + edges: + allOf: + - $ref: '#/definitions/ent.PieceJointeEdges' + description: |- + Edges holds the relations/edges for other nodes in the graph. + The values are being populated by the PieceJointeQuery when eager-loading is set. + est_principale: + description: Piece jointe principale + type: boolean + id: + description: |- + ID of the ent. + Identifiant unique de la piece jointe + type: string + nom_fichier: + description: Nom du fichier + type: string + objet_id: + description: Identifiant de l'objet + type: string + type_mime: + description: Type MIME + type: string + updated_at: + description: Date de derniere mise a jour + type: string + type: object + ent.PieceJointeEdges: + properties: + objet: + allOf: + - $ref: '#/definitions/ent.Objet' + description: Objet holds the value of the objet edge. + type: object + handlers.categorieRequest: + properties: + icone: + type: string + nom: + type: string + parent_id: + type: string + slug: + type: string + type: object + handlers.champPersonnaliseRequest: + properties: + nom_champ: + type: string + type_champ: + type: string + unite: + type: string + valeur: + type: string + type: object + handlers.emplacementRequest: + properties: + icone: + type: string + meuble: + type: string + nom: + type: string + numero_boite: + type: string + parent_id: + type: string + piece: + type: string + slug: + type: string + type: object + handlers.lienObjetEmplacementRequest: + properties: + emplacement_id: + type: string + type: + type: string + type: object + handlers.lienObjetEmplacementUpdateRequest: + properties: + emplacement_id: + type: string + type: + type: string + type: object + handlers.objetRequest: + properties: + boutique: + type: string + caracteristiques: + additionalProperties: {} + type: object + date_achat: + type: string + description: + type: string + fabricant: + type: string + nom: + type: string + numero_modele: + type: string + numero_serie: + type: string + prix_achat: + type: number + quantite: + type: integer + statut: + type: string + type: object + lienobjetemplacement.Type: + enum: + - stocke + - stocke + - utilise_dans + type: string + x-enum-varnames: + - DefaultType + - TypeStocke + - TypeUtiliseDans + objet.Statut: + enum: + - en_stock + - en_stock + - pret + - hors_service + - archive + type: string + x-enum-varnames: + - DefaultStatut + - StatutEnStock + - StatutPret + - StatutHorsService + - StatutArchive + piecejointe.Categorie: + enum: + - image + - image + - pdf_notice + - markdown_tuto + type: string + x-enum-varnames: + - DefaultCategorie + - CategorieImage + - CategoriePdfNotice + - CategorieMarkdownTuto +info: + contact: {} + description: API MatosBox pour la gestion d'inventaire. + title: MatosBox API + version: 0.1.0 +paths: + /categories: + get: + parameters: + - description: Page + in: query + name: page + type: integer + - description: Limite + in: query + name: limit + type: integer + produces: + - application/json + responses: + "200": + description: OK + schema: + additionalProperties: true + type: object + "500": + description: Internal Server Error + schema: + additionalProperties: + type: string + type: object + summary: Lister les categories + tags: + - Categories + post: + consumes: + - application/json + parameters: + - description: Categorie a creer + in: body + name: body + required: true + schema: + $ref: '#/definitions/handlers.categorieRequest' + produces: + - application/json + responses: + "201": + description: Created + schema: + $ref: '#/definitions/ent.Categorie' + "400": + description: Bad Request + schema: + additionalProperties: + type: string + type: object + "500": + description: Internal Server Error + schema: + additionalProperties: + type: string + type: object + summary: Creer une categorie + tags: + - Categories + /categories/{id}: + delete: + parameters: + - description: ID categorie + in: path + name: id + required: true + type: string + responses: + "204": + description: No Content + schema: + type: string + "400": + description: Bad Request + schema: + additionalProperties: + type: string + type: object + "500": + description: Internal Server Error + schema: + additionalProperties: + type: string + type: object + summary: Supprimer une categorie + tags: + - Categories + get: + parameters: + - description: ID categorie + in: path + name: id + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/ent.Categorie' + "400": + description: Bad Request + schema: + additionalProperties: + type: string + type: object + "404": + description: Not Found + schema: + additionalProperties: + type: string + type: object + "500": + description: Internal Server Error + schema: + additionalProperties: + type: string + type: object + summary: Recuperer une categorie + tags: + - Categories + put: + consumes: + - application/json + parameters: + - description: ID categorie + in: path + name: id + required: true + type: string + - description: Categorie a mettre a jour + in: body + name: body + required: true + schema: + $ref: '#/definitions/handlers.categorieRequest' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/ent.Categorie' + "400": + description: Bad Request + schema: + additionalProperties: + type: string + type: object + "404": + description: Not Found + schema: + additionalProperties: + type: string + type: object + "500": + description: Internal Server Error + schema: + additionalProperties: + type: string + type: object + summary: Mettre a jour une categorie + tags: + - Categories + /champs_personnalises/{id}: + delete: + parameters: + - description: ID champ + in: path + name: id + required: true + type: string + responses: + "204": + description: No Content + schema: + type: string + "400": + description: Bad Request + schema: + additionalProperties: + type: string + type: object + "404": + description: Not Found + schema: + additionalProperties: + type: string + type: object + "500": + description: Internal Server Error + schema: + additionalProperties: + type: string + type: object + summary: Supprimer un champ personnalise + tags: + - ChampsPersonnalises + put: + consumes: + - application/json + parameters: + - description: ID champ + in: path + name: id + required: true + type: string + - description: Champ personnalise + in: body + name: body + required: true + schema: + $ref: '#/definitions/handlers.champPersonnaliseRequest' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/ent.ChampPersonnalise' + "400": + description: Bad Request + schema: + additionalProperties: + type: string + type: object + "404": + description: Not Found + schema: + additionalProperties: + type: string + type: object + "500": + description: Internal Server Error + schema: + additionalProperties: + type: string + type: object + summary: Mettre a jour un champ personnalise + tags: + - ChampsPersonnalises + /emplacements: + get: + parameters: + - description: Page + in: query + name: page + type: integer + - description: Limite + in: query + name: limit + type: integer + produces: + - application/json + responses: + "200": + description: OK + schema: + additionalProperties: true + type: object + "500": + description: Internal Server Error + schema: + additionalProperties: + type: string + type: object + summary: Lister les emplacements + tags: + - Emplacements + post: + consumes: + - application/json + parameters: + - description: Emplacement a creer + in: body + name: body + required: true + schema: + $ref: '#/definitions/handlers.emplacementRequest' + produces: + - application/json + responses: + "201": + description: Created + schema: + $ref: '#/definitions/ent.Emplacement' + "400": + description: Bad Request + schema: + additionalProperties: + type: string + type: object + "500": + description: Internal Server Error + schema: + additionalProperties: + type: string + type: object + summary: Creer un emplacement + tags: + - Emplacements + /emplacements/{id}: + delete: + parameters: + - description: ID emplacement + in: path + name: id + required: true + type: string + responses: + "204": + description: No Content + schema: + type: string + "400": + description: Bad Request + schema: + additionalProperties: + type: string + type: object + "500": + description: Internal Server Error + schema: + additionalProperties: + type: string + type: object + summary: Supprimer un emplacement + tags: + - Emplacements + get: + parameters: + - description: ID emplacement + in: path + name: id + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/ent.Emplacement' + "400": + description: Bad Request + schema: + additionalProperties: + type: string + type: object + "404": + description: Not Found + schema: + additionalProperties: + type: string + type: object + "500": + description: Internal Server Error + schema: + additionalProperties: + type: string + type: object + summary: Recuperer un emplacement + tags: + - Emplacements + put: + consumes: + - application/json + parameters: + - description: ID emplacement + in: path + name: id + required: true + type: string + - description: Emplacement a mettre a jour + in: body + name: body + required: true + schema: + $ref: '#/definitions/handlers.emplacementRequest' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/ent.Emplacement' + "400": + description: Bad Request + schema: + additionalProperties: + type: string + type: object + "404": + description: Not Found + schema: + additionalProperties: + type: string + type: object + "500": + description: Internal Server Error + schema: + additionalProperties: + type: string + type: object + summary: Mettre a jour un emplacement + tags: + - Emplacements + /liens_emplacements/{id}: + delete: + parameters: + - description: ID lien + in: path + name: id + required: true + type: string + responses: + "204": + description: No Content + schema: + type: string + "400": + description: Bad Request + schema: + additionalProperties: + type: string + type: object + "404": + description: Not Found + schema: + additionalProperties: + type: string + type: object + "500": + description: Internal Server Error + schema: + additionalProperties: + type: string + type: object + summary: Supprimer un lien objet/emplacement + tags: + - LiensEmplacements + put: + consumes: + - application/json + parameters: + - description: ID lien + in: path + name: id + required: true + type: string + - description: Mise a jour + in: body + name: body + required: true + schema: + $ref: '#/definitions/handlers.lienObjetEmplacementUpdateRequest' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/ent.LienObjetEmplacement' + "400": + description: Bad Request + schema: + additionalProperties: + type: string + type: object + "404": + description: Not Found + schema: + additionalProperties: + type: string + type: object + "409": + description: Conflict + schema: + additionalProperties: + type: string + type: object + "500": + description: Internal Server Error + schema: + additionalProperties: + type: string + type: object + summary: Mettre a jour un lien objet/emplacement + tags: + - LiensEmplacements + /objets: + get: + parameters: + - description: Page + in: query + name: page + type: integer + - description: Limite + in: query + name: limit + type: integer + produces: + - application/json + responses: + "200": + description: OK + schema: + additionalProperties: true + type: object + "500": + description: Internal Server Error + schema: + additionalProperties: + type: string + type: object + summary: Lister les objets + tags: + - Objets + post: + consumes: + - application/json + parameters: + - description: Objet a creer + in: body + name: body + required: true + schema: + $ref: '#/definitions/handlers.objetRequest' + produces: + - application/json + responses: + "201": + description: Created + schema: + $ref: '#/definitions/ent.Objet' + "400": + description: Bad Request + schema: + additionalProperties: + type: string + type: object + "500": + description: Internal Server Error + schema: + additionalProperties: + type: string + type: object + summary: Creer un objet + tags: + - Objets + /objets/{id}: + delete: + parameters: + - description: ID objet + in: path + name: id + required: true + type: string + responses: + "204": + description: No Content + schema: + type: string + "400": + description: Bad Request + schema: + additionalProperties: + type: string + type: object + "500": + description: Internal Server Error + schema: + additionalProperties: + type: string + type: object + summary: Supprimer un objet + tags: + - Objets + get: + parameters: + - description: ID objet + in: path + name: id + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/ent.Objet' + "400": + description: Bad Request + schema: + additionalProperties: + type: string + type: object + "404": + description: Not Found + schema: + additionalProperties: + type: string + type: object + "500": + description: Internal Server Error + schema: + additionalProperties: + type: string + type: object + summary: Recuperer un objet + tags: + - Objets + put: + consumes: + - application/json + parameters: + - description: ID objet + in: path + name: id + required: true + type: string + - description: Objet a mettre a jour + in: body + name: body + required: true + schema: + $ref: '#/definitions/handlers.objetRequest' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/ent.Objet' + "400": + description: Bad Request + schema: + additionalProperties: + type: string + type: object + "404": + description: Not Found + schema: + additionalProperties: + type: string + type: object + "500": + description: Internal Server Error + schema: + additionalProperties: + type: string + type: object + summary: Mettre a jour un objet + tags: + - Objets + /objets/{id}/champs_personnalises: + get: + parameters: + - description: ID objet + in: path + name: id + required: true + type: string + - description: Page + in: query + name: page + type: integer + - description: Limite + in: query + name: limit + type: integer + produces: + - application/json + responses: + "200": + description: OK + schema: + additionalProperties: true + type: object + "400": + description: Bad Request + schema: + additionalProperties: + type: string + type: object + "500": + description: Internal Server Error + schema: + additionalProperties: + type: string + type: object + summary: Lister les champs personnalises + tags: + - ChampsPersonnalises + post: + consumes: + - application/json + parameters: + - description: ID objet + in: path + name: id + required: true + type: string + - description: Champ personnalise + in: body + name: body + required: true + schema: + $ref: '#/definitions/handlers.champPersonnaliseRequest' + produces: + - application/json + responses: + "201": + description: Created + schema: + $ref: '#/definitions/ent.ChampPersonnalise' + "400": + description: Bad Request + schema: + additionalProperties: + type: string + type: object + "500": + description: Internal Server Error + schema: + additionalProperties: + type: string + type: object + summary: Creer un champ personnalise + tags: + - ChampsPersonnalises + /objets/{id}/liens_emplacements: + get: + parameters: + - description: ID objet + in: path + name: id + required: true + type: string + - description: Page + in: query + name: page + type: integer + - description: Limite + in: query + name: limit + type: integer + produces: + - application/json + responses: + "200": + description: OK + schema: + additionalProperties: true + type: object + "400": + description: Bad Request + schema: + additionalProperties: + type: string + type: object + "500": + description: Internal Server Error + schema: + additionalProperties: + type: string + type: object + summary: Lister les liens objet/emplacement + tags: + - LiensEmplacements + post: + consumes: + - application/json + parameters: + - description: ID objet + in: path + name: id + required: true + type: string + - description: Lien + in: body + name: body + required: true + schema: + $ref: '#/definitions/handlers.lienObjetEmplacementRequest' + produces: + - application/json + responses: + "201": + description: Created + schema: + $ref: '#/definitions/ent.LienObjetEmplacement' + "400": + description: Bad Request + schema: + additionalProperties: + type: string + type: object + "404": + description: Not Found + schema: + additionalProperties: + type: string + type: object + "409": + description: Conflict + schema: + additionalProperties: + type: string + type: object + "500": + description: Internal Server Error + schema: + additionalProperties: + type: string + type: object + summary: Creer un lien objet/emplacement + tags: + - LiensEmplacements + /objets/{id}/pieces_jointes: + get: + parameters: + - description: ID objet + in: path + name: id + required: true + type: string + - description: Page + in: query + name: page + type: integer + - description: Limite + in: query + name: limit + type: integer + produces: + - application/json + responses: + "200": + description: OK + schema: + additionalProperties: true + type: object + "400": + description: Bad Request + schema: + additionalProperties: + type: string + type: object + "500": + description: Internal Server Error + schema: + additionalProperties: + type: string + type: object + summary: Lister les pieces jointes + tags: + - PiecesJointes + post: + consumes: + - multipart/form-data + parameters: + - description: ID objet + in: path + name: id + required: true + type: string + - description: Fichiers (multi) + in: formData + name: fichiers + required: true + type: file + produces: + - application/json + responses: + "201": + description: Created + schema: + additionalProperties: true + type: object + "400": + description: Bad Request + schema: + additionalProperties: + type: string + type: object + "404": + description: Not Found + schema: + additionalProperties: + type: string + type: object + "413": + description: Request Entity Too Large + schema: + additionalProperties: + type: string + type: object + "500": + description: Internal Server Error + schema: + additionalProperties: + type: string + type: object + summary: Uploader des pieces jointes + tags: + - PiecesJointes + /pieces_jointes/{id}: + delete: + parameters: + - description: ID piece jointe + in: path + name: id + required: true + type: string + responses: + "204": + description: No Content + schema: + type: string + "400": + description: Bad Request + schema: + additionalProperties: + type: string + type: object + "404": + description: Not Found + schema: + additionalProperties: + type: string + type: object + "500": + description: Internal Server Error + schema: + additionalProperties: + type: string + type: object + summary: Supprimer une piece jointe + tags: + - PiecesJointes + /pieces_jointes/{id}/principale: + put: + parameters: + - description: ID piece jointe + in: path + name: id + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/ent.PieceJointe' + "400": + description: Bad Request + schema: + additionalProperties: + type: string + type: object + "404": + description: Not Found + schema: + additionalProperties: + type: string + type: object + "500": + description: Internal Server Error + schema: + additionalProperties: + type: string + type: object + summary: Definir la piece jointe principale + tags: + - PiecesJointes +swagger: "2.0" diff --git a/backend/go.mod b/backend/go.mod index 24e8541..9e5f518 100644 --- a/backend/go.mod +++ b/backend/go.mod @@ -3,7 +3,63 @@ module gitea.maison43.duckdns.org/gilles/matosbox go 1.23 require ( - entgo.io/ent v0.13.1 + entgo.io/ent v0.14.5 github.com/gin-gonic/gin v1.10.0 github.com/google/uuid v1.6.0 + github.com/mattn/go-sqlite3 v1.14.22 + github.com/swaggo/files v1.0.1 + github.com/swaggo/gin-swagger v1.6.0 + github.com/swaggo/swag v1.8.12 +) + +require ( + ariga.io/atlas v0.32.1-0.20250325101103-175b25e1c1b9 // indirect + github.com/KyleBanks/depth v1.2.1 // indirect + github.com/PuerkitoBio/purell v1.1.1 // indirect + github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect + github.com/agext/levenshtein v1.2.3 // indirect + github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect + github.com/bmatcuk/doublestar v1.3.4 // indirect + github.com/bytedance/sonic v1.11.6 // indirect + github.com/bytedance/sonic/loader v0.1.1 // indirect + github.com/cloudwego/base64x v0.1.4 // indirect + github.com/cloudwego/iasm v0.2.0 // indirect + github.com/gabriel-vasile/mimetype v1.4.3 // indirect + github.com/gin-contrib/sse v0.1.0 // indirect + github.com/go-openapi/inflect v0.19.0 // indirect + github.com/go-openapi/jsonpointer v0.19.5 // indirect + github.com/go-openapi/jsonreference v0.19.6 // indirect + github.com/go-openapi/spec v0.20.4 // indirect + github.com/go-openapi/swag v0.19.15 // indirect + github.com/go-playground/locales v0.14.1 // indirect + github.com/go-playground/universal-translator v0.18.1 // indirect + github.com/go-playground/validator/v10 v10.20.0 // indirect + github.com/goccy/go-json v0.10.2 // indirect + github.com/google/go-cmp v0.6.0 // indirect + github.com/hashicorp/hcl/v2 v2.18.1 // indirect + github.com/josharian/intern v1.0.0 // indirect + github.com/json-iterator/go v1.1.12 // indirect + github.com/klauspost/cpuid/v2 v2.2.7 // indirect + github.com/leodido/go-urn v1.4.0 // indirect + github.com/mailru/easyjson v0.7.6 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect + github.com/mitchellh/go-wordwrap v1.0.1 // indirect + github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect + github.com/modern-go/reflect2 v1.0.2 // indirect + github.com/pelletier/go-toml/v2 v2.2.2 // indirect + github.com/rogpeppe/go-internal v1.14.1 // indirect + github.com/twitchyliquid64/golang-asm v0.15.1 // indirect + github.com/ugorji/go/codec v1.2.12 // indirect + github.com/zclconf/go-cty v1.14.4 // indirect + github.com/zclconf/go-cty-yaml v1.1.0 // indirect + golang.org/x/arch v0.8.0 // indirect + golang.org/x/crypto v0.33.0 // indirect + golang.org/x/mod v0.23.0 // indirect + golang.org/x/net v0.35.0 // indirect + golang.org/x/sys v0.30.0 // indirect + golang.org/x/text v0.22.0 // indirect + golang.org/x/tools v0.30.0 // indirect + google.golang.org/protobuf v1.34.1 // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/backend/go.sum b/backend/go.sum new file mode 100644 index 0000000..e71c978 --- /dev/null +++ b/backend/go.sum @@ -0,0 +1,203 @@ +ariga.io/atlas v0.32.1-0.20250325101103-175b25e1c1b9 h1:E0wvcUXTkgyN4wy4LGtNzMNGMytJN8afmIWXJVMi4cc= +ariga.io/atlas v0.32.1-0.20250325101103-175b25e1c1b9/go.mod h1:Oe1xWPuu5q9LzyrWfbZmEZxFYeu4BHTyzfjeW2aZp/w= +entgo.io/ent v0.14.5 h1:Rj2WOYJtCkWyFo6a+5wB3EfBRP0rnx1fMk6gGA0UUe4= +entgo.io/ent v0.14.5/go.mod h1:zTzLmWtPvGpmSwtkaayM2cm5m819NdM7z7tYPq3vN0U= +github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60= +github.com/DATA-DOG/go-sqlmock v1.5.0/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM= +github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc= +github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE= +github.com/PuerkitoBio/purell v1.1.1 h1:WEQqlqaGbrPkxLJWfBwQmfEAE1Z7ONdDLqrN38tNFfI= +github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= +github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M= +github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= +github.com/agext/levenshtein v1.2.3 h1:YB2fHEn0UJagG8T1rrWknE3ZQzWM06O8AMAatNn7lmo= +github.com/agext/levenshtein v1.2.3/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558= +github.com/apparentlymart/go-textseg/v15 v15.0.0 h1:uYvfpb3DyLSCGWnctWKGj857c6ew1u1fNQOlOtuGxQY= +github.com/apparentlymart/go-textseg/v15 v15.0.0/go.mod h1:K8XmNZdhEBkdlyDdvbmmsvpAG721bKi0joRfFdHIWJ4= +github.com/bmatcuk/doublestar v1.3.4 h1:gPypJ5xD31uhX6Tf54sDPUOBXTqKH4c9aPY66CyQrS0= +github.com/bmatcuk/doublestar v1.3.4/go.mod h1:wiQtGV+rzVYxB7WIlirSN++5HPtPlXEo9MEoZQC/PmE= +github.com/bytedance/sonic v1.11.6 h1:oUp34TzMlL+OY1OUWxHqsdkgC/Zfc85zGqw9siXjrc0= +github.com/bytedance/sonic v1.11.6/go.mod h1:LysEHSvpvDySVdC2f87zGWf6CIKJcAvqab1ZaiQtds4= +github.com/bytedance/sonic/loader v0.1.1 h1:c+e5Pt1k/cy5wMveRDyk2X4B9hF4g7an8N3zCYjJFNM= +github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU= +github.com/cloudwego/base64x v0.1.4 h1:jwCgWpFanWmN8xoIUHa2rtzmkd5J2plF/dnLS6Xd/0Y= +github.com/cloudwego/base64x v0.1.4/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w= +github.com/cloudwego/iasm v0.2.0 h1:1KNIy1I1H9hNNFEEH3DVnI4UujN+1zjpuk6gwHLTssg= +github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY= +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0= +github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk= +github.com/gin-contrib/gzip v0.0.6 h1:NjcunTcGAj5CO1gn4N8jHOSIeRFHIbn51z6K+xaN4d4= +github.com/gin-contrib/gzip v0.0.6/go.mod h1:QOJlmV2xmayAjkNS2Y8NQsMneuRShOU/kjovCXNuzzk= +github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= +github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= +github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU= +github.com/gin-gonic/gin v1.10.0/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y= +github.com/go-openapi/inflect v0.19.0 h1:9jCH9scKIbHeV9m12SmPilScz6krDxKRasNNSNPXu/4= +github.com/go-openapi/inflect v0.19.0/go.mod h1:lHpZVlpIQqLyKwJ4N+YSc9hchQy/i12fJykb83CRBH4= +github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= +github.com/go-openapi/jsonpointer v0.19.5 h1:gZr+CIYByUqjcgeLXnQu2gHYQC9o73G2XUeOFYEICuY= +github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= +github.com/go-openapi/jsonreference v0.19.6 h1:UBIxjkht+AWIgYzCDSv2GN+E/togfwXUJFRTWhl2Jjs= +github.com/go-openapi/jsonreference v0.19.6/go.mod h1:diGHMEHg2IqXZGKxqyvWdfWU/aim5Dprw5bqpKkTvns= +github.com/go-openapi/spec v0.20.4 h1:O8hJrt0UMnhHcluhIdUgCLRWyM2x7QkBXRvOs7m+O1M= +github.com/go-openapi/spec v0.20.4/go.mod h1:faYFR1CvsJZ0mNsmsphTMSoRrNV3TEDoAM7FOEWeq8I= +github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= +github.com/go-openapi/swag v0.19.15 h1:D2NRCBzS9/pEY3gP9Nl8aDqGUcPFrwG2p+CNFrLyrCM= +github.com/go-openapi/swag v0.19.15/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ= +github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= +github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= +github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= +github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= +github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= +github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= +github.com/go-playground/validator/v10 v10.20.0 h1:K9ISHbSaI0lyB2eWMPJo+kOS/FBExVwjEviJTixqxL8= +github.com/go-playground/validator/v10 v10.20.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= +github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68= +github.com/go-test/deep v1.0.3/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA= +github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= +github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/hashicorp/hcl/v2 v2.18.1 h1:6nxnOJFku1EuSawSD81fuviYUV8DxFr3fp2dUi3ZYSo= +github.com/hashicorp/hcl/v2 v2.18.1/go.mod h1:ThLC89FV4p9MPW804KVbe/cEXoQ8NZEh+JtMeeGErHE= +github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= +github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= +github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= +github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= +github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= +github.com/klauspost/cpuid/v2 v2.2.7 h1:ZWSB3igEs+d0qvnxR/ZBzXVmxkgt8DdzP6m9pfuVLDM= +github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= +github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= +github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= +github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= +github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ= +github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI= +github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= +github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= +github.com/mailru/easyjson v0.7.6 h1:8yTIVnZgCoiM1TgqoeTl+LfU5Jg6/xL3QhGQnimLYnA= +github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= +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-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU= +github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y= +github.com/mitchellh/go-wordwrap v1.0.1 h1:TLuKupo69TCn6TQSyGxwI1EblZZEsQ0vMlAFQflz0v0= +github.com/mitchellh/go-wordwrap v1.0.1/go.mod h1:R62XHJLzvMFRBbcrT7m7WgmE1eOyTSsCt+hzestvNj0= +github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= +github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= +github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= +github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= +github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM= +github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ= +github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc= +github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8= +github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/swaggo/files v1.0.1 h1:J1bVJ4XHZNq0I46UU90611i9/YzdrF7x92oX1ig5IdE= +github.com/swaggo/files v1.0.1/go.mod h1:0qXmMNH6sXNf+73t65aKeB+ApmgxdnkQzVTAj2uaMUg= +github.com/swaggo/gin-swagger v1.6.0 h1:y8sxvQ3E20/RCyrXeFfg60r6H0Z+SwpTjMYsMm+zy8M= +github.com/swaggo/gin-swagger v1.6.0/go.mod h1:BG00cCEy294xtVpyIAHG6+e2Qzj/xKlRdOqDkvq0uzo= +github.com/swaggo/swag v1.8.12 h1:pctzkNPu0AlQP2royqX3apjKCQonAnf7KGoxeO4y64w= +github.com/swaggo/swag v1.8.12/go.mod h1:lNfm6Gg+oAq3zRJQNEMBE66LIJKM44mxFqhEEgy2its= +github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= +github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= +github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE= +github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +github.com/zclconf/go-cty v1.14.4 h1:uXXczd9QDGsgu0i/QFR/hzI5NYCHLf6NQw/atrbnhq8= +github.com/zclconf/go-cty v1.14.4/go.mod h1:VvMs5i0vgZdhYawQNq5kePSpLAoz8u1xvZgrPIxfnZE= +github.com/zclconf/go-cty-yaml v1.1.0 h1:nP+jp0qPHv2IhUVqmQSzjvqAWcObN0KBkUl2rWBdig0= +github.com/zclconf/go-cty-yaml v1.1.0/go.mod h1:9YLUH4g7lOhVWqUbctnVlZ5KLpg7JAprQNgxSZ1Gyxs= +golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= +golang.org/x/arch v0.8.0 h1:3wRIsP3pM4yUptoR96otTUOXI367OS0+c9eeRi9doIc= +golang.org/x/arch v0.8.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.33.0 h1:IOBPskki6Lysi0lo9qQvbxiQ+FvsCC/YWOecCHAixus= +golang.org/x/crypto v0.33.0/go.mod h1:bVdXmD7IV/4GdElGPozy6U7lWdRXA4qyRVGJV57uQ5M= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/mod v0.23.0 h1:Zb7khfcRGKk+kqfxFaP5tZqCnDZMjC5VtUBs87Hr6QM= +golang.org/x/mod v0.23.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20210421230115-4e50805a0758/go.mod h1:72T/g9IO56b78aLF+1Kcs5dz7/ng1VjMUvfKvpfy+jM= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/net v0.35.0 h1:T5GQRQb2y08kTAByq9L4/bz8cipCdA8FbRTXewonqY8= +golang.org/x/net v0.35.0/go.mod h1:EglIi67kWsHKlRzzVMUD93VMSWGFOMSZgxFjparz1Qk= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/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.11.0 h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w= +golang.org/x/sync v0.11.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210420072515-93ed5bcd2bfe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +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.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc= +golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +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= +golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM= +golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/tools v0.30.0 h1:BgcpHewrV5AUp2G9MebG4XPFI1E2W41zU1SaqVA9vJY= +golang.org/x/tools v0.30.0/go.mod h1:c347cR/OJfw5TI+GfX7RUPNMdDRRbjvYTS0jPyvsVtY= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg= +google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU= +gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50= +rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= diff --git a/backend/internal/data/ent/categorie.go b/backend/internal/data/ent/categorie.go new file mode 100644 index 0000000..7e043d7 --- /dev/null +++ b/backend/internal/data/ent/categorie.go @@ -0,0 +1,218 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "fmt" + "strings" + "time" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/categorie" + "github.com/google/uuid" +) + +// Categorie is the model entity for the Categorie schema. +type Categorie struct { + config `json:"-"` + // ID of the ent. + // Identifiant unique de la categorie + ID uuid.UUID `json:"id,omitempty"` + // Nom de la categorie + Nom string `json:"nom,omitempty"` + // Identifiant du parent + ParentID *uuid.UUID `json:"parent_id,omitempty"` + // Slug URL-friendly + Slug *string `json:"slug,omitempty"` + // Nom ou code d'icone + Icone *string `json:"icone,omitempty"` + // Date de creation + CreatedAt time.Time `json:"created_at,omitempty"` + // Date de derniere mise a jour + UpdatedAt time.Time `json:"updated_at,omitempty"` + // Edges holds the relations/edges for other nodes in the graph. + // The values are being populated by the CategorieQuery when eager-loading is set. + Edges CategorieEdges `json:"edges"` + selectValues sql.SelectValues +} + +// CategorieEdges holds the relations/edges for other nodes in the graph. +type CategorieEdges struct { + // Lien parent/enfants pour l'arbre des categories + Parent *Categorie `json:"parent,omitempty"` + // Enfants holds the value of the enfants edge. + Enfants []*Categorie `json:"enfants,omitempty"` + // loadedTypes holds the information for reporting if a + // type was loaded (or requested) in eager-loading or not. + loadedTypes [2]bool +} + +// ParentOrErr returns the Parent value or an error if the edge +// was not loaded in eager-loading, or loaded but was not found. +func (e CategorieEdges) ParentOrErr() (*Categorie, error) { + if e.Parent != nil { + return e.Parent, nil + } else if e.loadedTypes[0] { + return nil, &NotFoundError{label: categorie.Label} + } + return nil, &NotLoadedError{edge: "parent"} +} + +// EnfantsOrErr returns the Enfants value or an error if the edge +// was not loaded in eager-loading. +func (e CategorieEdges) EnfantsOrErr() ([]*Categorie, error) { + if e.loadedTypes[1] { + return e.Enfants, nil + } + return nil, &NotLoadedError{edge: "enfants"} +} + +// scanValues returns the types for scanning values from sql.Rows. +func (*Categorie) scanValues(columns []string) ([]any, error) { + values := make([]any, len(columns)) + for i := range columns { + switch columns[i] { + case categorie.FieldParentID: + values[i] = &sql.NullScanner{S: new(uuid.UUID)} + case categorie.FieldNom, categorie.FieldSlug, categorie.FieldIcone: + values[i] = new(sql.NullString) + case categorie.FieldCreatedAt, categorie.FieldUpdatedAt: + values[i] = new(sql.NullTime) + case categorie.FieldID: + values[i] = new(uuid.UUID) + default: + values[i] = new(sql.UnknownType) + } + } + return values, nil +} + +// assignValues assigns the values that were returned from sql.Rows (after scanning) +// to the Categorie fields. +func (_m *Categorie) assignValues(columns []string, values []any) error { + if m, n := len(values), len(columns); m < n { + return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) + } + for i := range columns { + switch columns[i] { + case categorie.FieldID: + if value, ok := values[i].(*uuid.UUID); !ok { + return fmt.Errorf("unexpected type %T for field id", values[i]) + } else if value != nil { + _m.ID = *value + } + case categorie.FieldNom: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field nom", values[i]) + } else if value.Valid { + _m.Nom = value.String + } + case categorie.FieldParentID: + if value, ok := values[i].(*sql.NullScanner); !ok { + return fmt.Errorf("unexpected type %T for field parent_id", values[i]) + } else if value.Valid { + _m.ParentID = new(uuid.UUID) + *_m.ParentID = *value.S.(*uuid.UUID) + } + case categorie.FieldSlug: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field slug", values[i]) + } else if value.Valid { + _m.Slug = new(string) + *_m.Slug = value.String + } + case categorie.FieldIcone: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field icone", values[i]) + } else if value.Valid { + _m.Icone = new(string) + *_m.Icone = value.String + } + case categorie.FieldCreatedAt: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field created_at", values[i]) + } else if value.Valid { + _m.CreatedAt = value.Time + } + case categorie.FieldUpdatedAt: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field updated_at", values[i]) + } else if value.Valid { + _m.UpdatedAt = value.Time + } + default: + _m.selectValues.Set(columns[i], values[i]) + } + } + return nil +} + +// Value returns the ent.Value that was dynamically selected and assigned to the Categorie. +// This includes values selected through modifiers, order, etc. +func (_m *Categorie) Value(name string) (ent.Value, error) { + return _m.selectValues.Get(name) +} + +// QueryParent queries the "parent" edge of the Categorie entity. +func (_m *Categorie) QueryParent() *CategorieQuery { + return NewCategorieClient(_m.config).QueryParent(_m) +} + +// QueryEnfants queries the "enfants" edge of the Categorie entity. +func (_m *Categorie) QueryEnfants() *CategorieQuery { + return NewCategorieClient(_m.config).QueryEnfants(_m) +} + +// Update returns a builder for updating this Categorie. +// Note that you need to call Categorie.Unwrap() before calling this method if this Categorie +// was returned from a transaction, and the transaction was committed or rolled back. +func (_m *Categorie) Update() *CategorieUpdateOne { + return NewCategorieClient(_m.config).UpdateOne(_m) +} + +// Unwrap unwraps the Categorie entity that was returned from a transaction after it was closed, +// so that all future queries will be executed through the driver which created the transaction. +func (_m *Categorie) Unwrap() *Categorie { + _tx, ok := _m.config.driver.(*txDriver) + if !ok { + panic("ent: Categorie is not a transactional entity") + } + _m.config.driver = _tx.drv + return _m +} + +// String implements the fmt.Stringer. +func (_m *Categorie) String() string { + var builder strings.Builder + builder.WriteString("Categorie(") + builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID)) + builder.WriteString("nom=") + builder.WriteString(_m.Nom) + builder.WriteString(", ") + if v := _m.ParentID; v != nil { + builder.WriteString("parent_id=") + builder.WriteString(fmt.Sprintf("%v", *v)) + } + builder.WriteString(", ") + if v := _m.Slug; v != nil { + builder.WriteString("slug=") + builder.WriteString(*v) + } + builder.WriteString(", ") + if v := _m.Icone; v != nil { + builder.WriteString("icone=") + builder.WriteString(*v) + } + builder.WriteString(", ") + builder.WriteString("created_at=") + builder.WriteString(_m.CreatedAt.Format(time.ANSIC)) + builder.WriteString(", ") + builder.WriteString("updated_at=") + builder.WriteString(_m.UpdatedAt.Format(time.ANSIC)) + builder.WriteByte(')') + return builder.String() +} + +// Categories is a parsable slice of Categorie. +type Categories []*Categorie diff --git a/backend/internal/data/ent/categorie/categorie.go b/backend/internal/data/ent/categorie/categorie.go new file mode 100644 index 0000000..b386ebe --- /dev/null +++ b/backend/internal/data/ent/categorie/categorie.go @@ -0,0 +1,151 @@ +// Code generated by ent, DO NOT EDIT. + +package categorie + +import ( + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "github.com/google/uuid" +) + +const ( + // Label holds the string label denoting the categorie type in the database. + Label = "categorie" + // FieldID holds the string denoting the id field in the database. + FieldID = "id" + // FieldNom holds the string denoting the nom field in the database. + FieldNom = "nom" + // FieldParentID holds the string denoting the parent_id field in the database. + FieldParentID = "parent_id" + // FieldSlug holds the string denoting the slug field in the database. + FieldSlug = "slug" + // FieldIcone holds the string denoting the icone field in the database. + FieldIcone = "icone" + // FieldCreatedAt holds the string denoting the created_at field in the database. + FieldCreatedAt = "created_at" + // FieldUpdatedAt holds the string denoting the updated_at field in the database. + FieldUpdatedAt = "updated_at" + // EdgeParent holds the string denoting the parent edge name in mutations. + EdgeParent = "parent" + // EdgeEnfants holds the string denoting the enfants edge name in mutations. + EdgeEnfants = "enfants" + // Table holds the table name of the categorie in the database. + Table = "categorie" + // ParentTable is the table that holds the parent relation/edge. + ParentTable = "categorie" + // ParentColumn is the table column denoting the parent relation/edge. + ParentColumn = "parent_id" + // EnfantsTable is the table that holds the enfants relation/edge. + EnfantsTable = "categorie" + // EnfantsColumn is the table column denoting the enfants relation/edge. + EnfantsColumn = "parent_id" +) + +// Columns holds all SQL columns for categorie fields. +var Columns = []string{ + FieldID, + FieldNom, + FieldParentID, + FieldSlug, + FieldIcone, + FieldCreatedAt, + FieldUpdatedAt, +} + +// ValidColumn reports if the column name is valid (part of the table columns). +func ValidColumn(column string) bool { + for i := range Columns { + if column == Columns[i] { + return true + } + } + return false +} + +var ( + // NomValidator is a validator for the "nom" field. It is called by the builders before save. + NomValidator func(string) error + // DefaultCreatedAt holds the default value on creation for the "created_at" field. + DefaultCreatedAt func() time.Time + // DefaultUpdatedAt holds the default value on creation for the "updated_at" field. + DefaultUpdatedAt func() time.Time + // UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field. + UpdateDefaultUpdatedAt func() time.Time + // DefaultID holds the default value on creation for the "id" field. + DefaultID func() uuid.UUID +) + +// OrderOption defines the ordering options for the Categorie queries. +type OrderOption func(*sql.Selector) + +// ByID orders the results by the id field. +func ByID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldID, opts...).ToFunc() +} + +// ByNom orders the results by the nom field. +func ByNom(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldNom, opts...).ToFunc() +} + +// ByParentID orders the results by the parent_id field. +func ByParentID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldParentID, opts...).ToFunc() +} + +// BySlug orders the results by the slug field. +func BySlug(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldSlug, opts...).ToFunc() +} + +// ByIcone orders the results by the icone field. +func ByIcone(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldIcone, opts...).ToFunc() +} + +// ByCreatedAt orders the results by the created_at field. +func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() +} + +// ByUpdatedAt orders the results by the updated_at field. +func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc() +} + +// ByParentField orders the results by parent field. +func ByParentField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newParentStep(), sql.OrderByField(field, opts...)) + } +} + +// ByEnfantsCount orders the results by enfants count. +func ByEnfantsCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newEnfantsStep(), opts...) + } +} + +// ByEnfants orders the results by enfants terms. +func ByEnfants(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newEnfantsStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} +func newParentStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(Table, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, ParentTable, ParentColumn), + ) +} +func newEnfantsStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(Table, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, EnfantsTable, EnfantsColumn), + ) +} diff --git a/backend/internal/data/ent/categorie/where.go b/backend/internal/data/ent/categorie/where.go new file mode 100644 index 0000000..10c2b51 --- /dev/null +++ b/backend/internal/data/ent/categorie/where.go @@ -0,0 +1,473 @@ +// Code generated by ent, DO NOT EDIT. + +package categorie + +import ( + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/predicate" + "github.com/google/uuid" +) + +// ID filters vertices based on their ID field. +func ID(id uuid.UUID) predicate.Categorie { + return predicate.Categorie(sql.FieldEQ(FieldID, id)) +} + +// IDEQ applies the EQ predicate on the ID field. +func IDEQ(id uuid.UUID) predicate.Categorie { + return predicate.Categorie(sql.FieldEQ(FieldID, id)) +} + +// IDNEQ applies the NEQ predicate on the ID field. +func IDNEQ(id uuid.UUID) predicate.Categorie { + return predicate.Categorie(sql.FieldNEQ(FieldID, id)) +} + +// IDIn applies the In predicate on the ID field. +func IDIn(ids ...uuid.UUID) predicate.Categorie { + return predicate.Categorie(sql.FieldIn(FieldID, ids...)) +} + +// IDNotIn applies the NotIn predicate on the ID field. +func IDNotIn(ids ...uuid.UUID) predicate.Categorie { + return predicate.Categorie(sql.FieldNotIn(FieldID, ids...)) +} + +// IDGT applies the GT predicate on the ID field. +func IDGT(id uuid.UUID) predicate.Categorie { + return predicate.Categorie(sql.FieldGT(FieldID, id)) +} + +// IDGTE applies the GTE predicate on the ID field. +func IDGTE(id uuid.UUID) predicate.Categorie { + return predicate.Categorie(sql.FieldGTE(FieldID, id)) +} + +// IDLT applies the LT predicate on the ID field. +func IDLT(id uuid.UUID) predicate.Categorie { + return predicate.Categorie(sql.FieldLT(FieldID, id)) +} + +// IDLTE applies the LTE predicate on the ID field. +func IDLTE(id uuid.UUID) predicate.Categorie { + return predicate.Categorie(sql.FieldLTE(FieldID, id)) +} + +// Nom applies equality check predicate on the "nom" field. It's identical to NomEQ. +func Nom(v string) predicate.Categorie { + return predicate.Categorie(sql.FieldEQ(FieldNom, v)) +} + +// ParentID applies equality check predicate on the "parent_id" field. It's identical to ParentIDEQ. +func ParentID(v uuid.UUID) predicate.Categorie { + return predicate.Categorie(sql.FieldEQ(FieldParentID, v)) +} + +// Slug applies equality check predicate on the "slug" field. It's identical to SlugEQ. +func Slug(v string) predicate.Categorie { + return predicate.Categorie(sql.FieldEQ(FieldSlug, v)) +} + +// Icone applies equality check predicate on the "icone" field. It's identical to IconeEQ. +func Icone(v string) predicate.Categorie { + return predicate.Categorie(sql.FieldEQ(FieldIcone, v)) +} + +// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. +func CreatedAt(v time.Time) predicate.Categorie { + return predicate.Categorie(sql.FieldEQ(FieldCreatedAt, v)) +} + +// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ. +func UpdatedAt(v time.Time) predicate.Categorie { + return predicate.Categorie(sql.FieldEQ(FieldUpdatedAt, v)) +} + +// NomEQ applies the EQ predicate on the "nom" field. +func NomEQ(v string) predicate.Categorie { + return predicate.Categorie(sql.FieldEQ(FieldNom, v)) +} + +// NomNEQ applies the NEQ predicate on the "nom" field. +func NomNEQ(v string) predicate.Categorie { + return predicate.Categorie(sql.FieldNEQ(FieldNom, v)) +} + +// NomIn applies the In predicate on the "nom" field. +func NomIn(vs ...string) predicate.Categorie { + return predicate.Categorie(sql.FieldIn(FieldNom, vs...)) +} + +// NomNotIn applies the NotIn predicate on the "nom" field. +func NomNotIn(vs ...string) predicate.Categorie { + return predicate.Categorie(sql.FieldNotIn(FieldNom, vs...)) +} + +// NomGT applies the GT predicate on the "nom" field. +func NomGT(v string) predicate.Categorie { + return predicate.Categorie(sql.FieldGT(FieldNom, v)) +} + +// NomGTE applies the GTE predicate on the "nom" field. +func NomGTE(v string) predicate.Categorie { + return predicate.Categorie(sql.FieldGTE(FieldNom, v)) +} + +// NomLT applies the LT predicate on the "nom" field. +func NomLT(v string) predicate.Categorie { + return predicate.Categorie(sql.FieldLT(FieldNom, v)) +} + +// NomLTE applies the LTE predicate on the "nom" field. +func NomLTE(v string) predicate.Categorie { + return predicate.Categorie(sql.FieldLTE(FieldNom, v)) +} + +// NomContains applies the Contains predicate on the "nom" field. +func NomContains(v string) predicate.Categorie { + return predicate.Categorie(sql.FieldContains(FieldNom, v)) +} + +// NomHasPrefix applies the HasPrefix predicate on the "nom" field. +func NomHasPrefix(v string) predicate.Categorie { + return predicate.Categorie(sql.FieldHasPrefix(FieldNom, v)) +} + +// NomHasSuffix applies the HasSuffix predicate on the "nom" field. +func NomHasSuffix(v string) predicate.Categorie { + return predicate.Categorie(sql.FieldHasSuffix(FieldNom, v)) +} + +// NomEqualFold applies the EqualFold predicate on the "nom" field. +func NomEqualFold(v string) predicate.Categorie { + return predicate.Categorie(sql.FieldEqualFold(FieldNom, v)) +} + +// NomContainsFold applies the ContainsFold predicate on the "nom" field. +func NomContainsFold(v string) predicate.Categorie { + return predicate.Categorie(sql.FieldContainsFold(FieldNom, v)) +} + +// ParentIDEQ applies the EQ predicate on the "parent_id" field. +func ParentIDEQ(v uuid.UUID) predicate.Categorie { + return predicate.Categorie(sql.FieldEQ(FieldParentID, v)) +} + +// ParentIDNEQ applies the NEQ predicate on the "parent_id" field. +func ParentIDNEQ(v uuid.UUID) predicate.Categorie { + return predicate.Categorie(sql.FieldNEQ(FieldParentID, v)) +} + +// ParentIDIn applies the In predicate on the "parent_id" field. +func ParentIDIn(vs ...uuid.UUID) predicate.Categorie { + return predicate.Categorie(sql.FieldIn(FieldParentID, vs...)) +} + +// ParentIDNotIn applies the NotIn predicate on the "parent_id" field. +func ParentIDNotIn(vs ...uuid.UUID) predicate.Categorie { + return predicate.Categorie(sql.FieldNotIn(FieldParentID, vs...)) +} + +// ParentIDIsNil applies the IsNil predicate on the "parent_id" field. +func ParentIDIsNil() predicate.Categorie { + return predicate.Categorie(sql.FieldIsNull(FieldParentID)) +} + +// ParentIDNotNil applies the NotNil predicate on the "parent_id" field. +func ParentIDNotNil() predicate.Categorie { + return predicate.Categorie(sql.FieldNotNull(FieldParentID)) +} + +// SlugEQ applies the EQ predicate on the "slug" field. +func SlugEQ(v string) predicate.Categorie { + return predicate.Categorie(sql.FieldEQ(FieldSlug, v)) +} + +// SlugNEQ applies the NEQ predicate on the "slug" field. +func SlugNEQ(v string) predicate.Categorie { + return predicate.Categorie(sql.FieldNEQ(FieldSlug, v)) +} + +// SlugIn applies the In predicate on the "slug" field. +func SlugIn(vs ...string) predicate.Categorie { + return predicate.Categorie(sql.FieldIn(FieldSlug, vs...)) +} + +// SlugNotIn applies the NotIn predicate on the "slug" field. +func SlugNotIn(vs ...string) predicate.Categorie { + return predicate.Categorie(sql.FieldNotIn(FieldSlug, vs...)) +} + +// SlugGT applies the GT predicate on the "slug" field. +func SlugGT(v string) predicate.Categorie { + return predicate.Categorie(sql.FieldGT(FieldSlug, v)) +} + +// SlugGTE applies the GTE predicate on the "slug" field. +func SlugGTE(v string) predicate.Categorie { + return predicate.Categorie(sql.FieldGTE(FieldSlug, v)) +} + +// SlugLT applies the LT predicate on the "slug" field. +func SlugLT(v string) predicate.Categorie { + return predicate.Categorie(sql.FieldLT(FieldSlug, v)) +} + +// SlugLTE applies the LTE predicate on the "slug" field. +func SlugLTE(v string) predicate.Categorie { + return predicate.Categorie(sql.FieldLTE(FieldSlug, v)) +} + +// SlugContains applies the Contains predicate on the "slug" field. +func SlugContains(v string) predicate.Categorie { + return predicate.Categorie(sql.FieldContains(FieldSlug, v)) +} + +// SlugHasPrefix applies the HasPrefix predicate on the "slug" field. +func SlugHasPrefix(v string) predicate.Categorie { + return predicate.Categorie(sql.FieldHasPrefix(FieldSlug, v)) +} + +// SlugHasSuffix applies the HasSuffix predicate on the "slug" field. +func SlugHasSuffix(v string) predicate.Categorie { + return predicate.Categorie(sql.FieldHasSuffix(FieldSlug, v)) +} + +// SlugIsNil applies the IsNil predicate on the "slug" field. +func SlugIsNil() predicate.Categorie { + return predicate.Categorie(sql.FieldIsNull(FieldSlug)) +} + +// SlugNotNil applies the NotNil predicate on the "slug" field. +func SlugNotNil() predicate.Categorie { + return predicate.Categorie(sql.FieldNotNull(FieldSlug)) +} + +// SlugEqualFold applies the EqualFold predicate on the "slug" field. +func SlugEqualFold(v string) predicate.Categorie { + return predicate.Categorie(sql.FieldEqualFold(FieldSlug, v)) +} + +// SlugContainsFold applies the ContainsFold predicate on the "slug" field. +func SlugContainsFold(v string) predicate.Categorie { + return predicate.Categorie(sql.FieldContainsFold(FieldSlug, v)) +} + +// IconeEQ applies the EQ predicate on the "icone" field. +func IconeEQ(v string) predicate.Categorie { + return predicate.Categorie(sql.FieldEQ(FieldIcone, v)) +} + +// IconeNEQ applies the NEQ predicate on the "icone" field. +func IconeNEQ(v string) predicate.Categorie { + return predicate.Categorie(sql.FieldNEQ(FieldIcone, v)) +} + +// IconeIn applies the In predicate on the "icone" field. +func IconeIn(vs ...string) predicate.Categorie { + return predicate.Categorie(sql.FieldIn(FieldIcone, vs...)) +} + +// IconeNotIn applies the NotIn predicate on the "icone" field. +func IconeNotIn(vs ...string) predicate.Categorie { + return predicate.Categorie(sql.FieldNotIn(FieldIcone, vs...)) +} + +// IconeGT applies the GT predicate on the "icone" field. +func IconeGT(v string) predicate.Categorie { + return predicate.Categorie(sql.FieldGT(FieldIcone, v)) +} + +// IconeGTE applies the GTE predicate on the "icone" field. +func IconeGTE(v string) predicate.Categorie { + return predicate.Categorie(sql.FieldGTE(FieldIcone, v)) +} + +// IconeLT applies the LT predicate on the "icone" field. +func IconeLT(v string) predicate.Categorie { + return predicate.Categorie(sql.FieldLT(FieldIcone, v)) +} + +// IconeLTE applies the LTE predicate on the "icone" field. +func IconeLTE(v string) predicate.Categorie { + return predicate.Categorie(sql.FieldLTE(FieldIcone, v)) +} + +// IconeContains applies the Contains predicate on the "icone" field. +func IconeContains(v string) predicate.Categorie { + return predicate.Categorie(sql.FieldContains(FieldIcone, v)) +} + +// IconeHasPrefix applies the HasPrefix predicate on the "icone" field. +func IconeHasPrefix(v string) predicate.Categorie { + return predicate.Categorie(sql.FieldHasPrefix(FieldIcone, v)) +} + +// IconeHasSuffix applies the HasSuffix predicate on the "icone" field. +func IconeHasSuffix(v string) predicate.Categorie { + return predicate.Categorie(sql.FieldHasSuffix(FieldIcone, v)) +} + +// IconeIsNil applies the IsNil predicate on the "icone" field. +func IconeIsNil() predicate.Categorie { + return predicate.Categorie(sql.FieldIsNull(FieldIcone)) +} + +// IconeNotNil applies the NotNil predicate on the "icone" field. +func IconeNotNil() predicate.Categorie { + return predicate.Categorie(sql.FieldNotNull(FieldIcone)) +} + +// IconeEqualFold applies the EqualFold predicate on the "icone" field. +func IconeEqualFold(v string) predicate.Categorie { + return predicate.Categorie(sql.FieldEqualFold(FieldIcone, v)) +} + +// IconeContainsFold applies the ContainsFold predicate on the "icone" field. +func IconeContainsFold(v string) predicate.Categorie { + return predicate.Categorie(sql.FieldContainsFold(FieldIcone, v)) +} + +// CreatedAtEQ applies the EQ predicate on the "created_at" field. +func CreatedAtEQ(v time.Time) predicate.Categorie { + return predicate.Categorie(sql.FieldEQ(FieldCreatedAt, v)) +} + +// CreatedAtNEQ applies the NEQ predicate on the "created_at" field. +func CreatedAtNEQ(v time.Time) predicate.Categorie { + return predicate.Categorie(sql.FieldNEQ(FieldCreatedAt, v)) +} + +// CreatedAtIn applies the In predicate on the "created_at" field. +func CreatedAtIn(vs ...time.Time) predicate.Categorie { + return predicate.Categorie(sql.FieldIn(FieldCreatedAt, vs...)) +} + +// CreatedAtNotIn applies the NotIn predicate on the "created_at" field. +func CreatedAtNotIn(vs ...time.Time) predicate.Categorie { + return predicate.Categorie(sql.FieldNotIn(FieldCreatedAt, vs...)) +} + +// CreatedAtGT applies the GT predicate on the "created_at" field. +func CreatedAtGT(v time.Time) predicate.Categorie { + return predicate.Categorie(sql.FieldGT(FieldCreatedAt, v)) +} + +// CreatedAtGTE applies the GTE predicate on the "created_at" field. +func CreatedAtGTE(v time.Time) predicate.Categorie { + return predicate.Categorie(sql.FieldGTE(FieldCreatedAt, v)) +} + +// CreatedAtLT applies the LT predicate on the "created_at" field. +func CreatedAtLT(v time.Time) predicate.Categorie { + return predicate.Categorie(sql.FieldLT(FieldCreatedAt, v)) +} + +// CreatedAtLTE applies the LTE predicate on the "created_at" field. +func CreatedAtLTE(v time.Time) predicate.Categorie { + return predicate.Categorie(sql.FieldLTE(FieldCreatedAt, v)) +} + +// UpdatedAtEQ applies the EQ predicate on the "updated_at" field. +func UpdatedAtEQ(v time.Time) predicate.Categorie { + return predicate.Categorie(sql.FieldEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field. +func UpdatedAtNEQ(v time.Time) predicate.Categorie { + return predicate.Categorie(sql.FieldNEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtIn applies the In predicate on the "updated_at" field. +func UpdatedAtIn(vs ...time.Time) predicate.Categorie { + return predicate.Categorie(sql.FieldIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field. +func UpdatedAtNotIn(vs ...time.Time) predicate.Categorie { + return predicate.Categorie(sql.FieldNotIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtGT applies the GT predicate on the "updated_at" field. +func UpdatedAtGT(v time.Time) predicate.Categorie { + return predicate.Categorie(sql.FieldGT(FieldUpdatedAt, v)) +} + +// UpdatedAtGTE applies the GTE predicate on the "updated_at" field. +func UpdatedAtGTE(v time.Time) predicate.Categorie { + return predicate.Categorie(sql.FieldGTE(FieldUpdatedAt, v)) +} + +// UpdatedAtLT applies the LT predicate on the "updated_at" field. +func UpdatedAtLT(v time.Time) predicate.Categorie { + return predicate.Categorie(sql.FieldLT(FieldUpdatedAt, v)) +} + +// UpdatedAtLTE applies the LTE predicate on the "updated_at" field. +func UpdatedAtLTE(v time.Time) predicate.Categorie { + return predicate.Categorie(sql.FieldLTE(FieldUpdatedAt, v)) +} + +// HasParent applies the HasEdge predicate on the "parent" edge. +func HasParent() predicate.Categorie { + return predicate.Categorie(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, ParentTable, ParentColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasParentWith applies the HasEdge predicate on the "parent" edge with a given conditions (other predicates). +func HasParentWith(preds ...predicate.Categorie) predicate.Categorie { + return predicate.Categorie(func(s *sql.Selector) { + step := newParentStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + +// HasEnfants applies the HasEdge predicate on the "enfants" edge. +func HasEnfants() predicate.Categorie { + return predicate.Categorie(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, EnfantsTable, EnfantsColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasEnfantsWith applies the HasEdge predicate on the "enfants" edge with a given conditions (other predicates). +func HasEnfantsWith(preds ...predicate.Categorie) predicate.Categorie { + return predicate.Categorie(func(s *sql.Selector) { + step := newEnfantsStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + +// And groups predicates with the AND operator between them. +func And(predicates ...predicate.Categorie) predicate.Categorie { + return predicate.Categorie(sql.AndPredicates(predicates...)) +} + +// Or groups predicates with the OR operator between them. +func Or(predicates ...predicate.Categorie) predicate.Categorie { + return predicate.Categorie(sql.OrPredicates(predicates...)) +} + +// Not applies the not operator on the given predicate. +func Not(p predicate.Categorie) predicate.Categorie { + return predicate.Categorie(sql.NotPredicates(p)) +} diff --git a/backend/internal/data/ent/categorie_create.go b/backend/internal/data/ent/categorie_create.go new file mode 100644 index 0000000..76738b6 --- /dev/null +++ b/backend/internal/data/ent/categorie_create.go @@ -0,0 +1,372 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + "time" + + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/categorie" + "github.com/google/uuid" +) + +// CategorieCreate is the builder for creating a Categorie entity. +type CategorieCreate struct { + config + mutation *CategorieMutation + hooks []Hook +} + +// SetNom sets the "nom" field. +func (_c *CategorieCreate) SetNom(v string) *CategorieCreate { + _c.mutation.SetNom(v) + return _c +} + +// SetParentID sets the "parent_id" field. +func (_c *CategorieCreate) SetParentID(v uuid.UUID) *CategorieCreate { + _c.mutation.SetParentID(v) + return _c +} + +// SetNillableParentID sets the "parent_id" field if the given value is not nil. +func (_c *CategorieCreate) SetNillableParentID(v *uuid.UUID) *CategorieCreate { + if v != nil { + _c.SetParentID(*v) + } + return _c +} + +// SetSlug sets the "slug" field. +func (_c *CategorieCreate) SetSlug(v string) *CategorieCreate { + _c.mutation.SetSlug(v) + return _c +} + +// SetNillableSlug sets the "slug" field if the given value is not nil. +func (_c *CategorieCreate) SetNillableSlug(v *string) *CategorieCreate { + if v != nil { + _c.SetSlug(*v) + } + return _c +} + +// SetIcone sets the "icone" field. +func (_c *CategorieCreate) SetIcone(v string) *CategorieCreate { + _c.mutation.SetIcone(v) + return _c +} + +// SetNillableIcone sets the "icone" field if the given value is not nil. +func (_c *CategorieCreate) SetNillableIcone(v *string) *CategorieCreate { + if v != nil { + _c.SetIcone(*v) + } + return _c +} + +// SetCreatedAt sets the "created_at" field. +func (_c *CategorieCreate) SetCreatedAt(v time.Time) *CategorieCreate { + _c.mutation.SetCreatedAt(v) + return _c +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (_c *CategorieCreate) SetNillableCreatedAt(v *time.Time) *CategorieCreate { + if v != nil { + _c.SetCreatedAt(*v) + } + return _c +} + +// SetUpdatedAt sets the "updated_at" field. +func (_c *CategorieCreate) SetUpdatedAt(v time.Time) *CategorieCreate { + _c.mutation.SetUpdatedAt(v) + return _c +} + +// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. +func (_c *CategorieCreate) SetNillableUpdatedAt(v *time.Time) *CategorieCreate { + if v != nil { + _c.SetUpdatedAt(*v) + } + return _c +} + +// SetID sets the "id" field. +func (_c *CategorieCreate) SetID(v uuid.UUID) *CategorieCreate { + _c.mutation.SetID(v) + return _c +} + +// SetNillableID sets the "id" field if the given value is not nil. +func (_c *CategorieCreate) SetNillableID(v *uuid.UUID) *CategorieCreate { + if v != nil { + _c.SetID(*v) + } + return _c +} + +// SetParent sets the "parent" edge to the Categorie entity. +func (_c *CategorieCreate) SetParent(v *Categorie) *CategorieCreate { + return _c.SetParentID(v.ID) +} + +// AddEnfantIDs adds the "enfants" edge to the Categorie entity by IDs. +func (_c *CategorieCreate) AddEnfantIDs(ids ...uuid.UUID) *CategorieCreate { + _c.mutation.AddEnfantIDs(ids...) + return _c +} + +// AddEnfants adds the "enfants" edges to the Categorie entity. +func (_c *CategorieCreate) AddEnfants(v ...*Categorie) *CategorieCreate { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _c.AddEnfantIDs(ids...) +} + +// Mutation returns the CategorieMutation object of the builder. +func (_c *CategorieCreate) Mutation() *CategorieMutation { + return _c.mutation +} + +// Save creates the Categorie in the database. +func (_c *CategorieCreate) Save(ctx context.Context) (*Categorie, error) { + _c.defaults() + return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks) +} + +// SaveX calls Save and panics if Save returns an error. +func (_c *CategorieCreate) SaveX(ctx context.Context) *Categorie { + v, err := _c.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (_c *CategorieCreate) Exec(ctx context.Context) error { + _, err := _c.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_c *CategorieCreate) ExecX(ctx context.Context) { + if err := _c.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (_c *CategorieCreate) defaults() { + if _, ok := _c.mutation.CreatedAt(); !ok { + v := categorie.DefaultCreatedAt() + _c.mutation.SetCreatedAt(v) + } + if _, ok := _c.mutation.UpdatedAt(); !ok { + v := categorie.DefaultUpdatedAt() + _c.mutation.SetUpdatedAt(v) + } + if _, ok := _c.mutation.ID(); !ok { + v := categorie.DefaultID() + _c.mutation.SetID(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_c *CategorieCreate) check() error { + if _, ok := _c.mutation.Nom(); !ok { + return &ValidationError{Name: "nom", err: errors.New(`ent: missing required field "Categorie.nom"`)} + } + if v, ok := _c.mutation.Nom(); ok { + if err := categorie.NomValidator(v); err != nil { + return &ValidationError{Name: "nom", err: fmt.Errorf(`ent: validator failed for field "Categorie.nom": %w`, err)} + } + } + if _, ok := _c.mutation.CreatedAt(); !ok { + return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Categorie.created_at"`)} + } + if _, ok := _c.mutation.UpdatedAt(); !ok { + return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "Categorie.updated_at"`)} + } + return nil +} + +func (_c *CategorieCreate) sqlSave(ctx context.Context) (*Categorie, error) { + if err := _c.check(); err != nil { + return nil, err + } + _node, _spec := _c.createSpec() + if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + if _spec.ID.Value != nil { + if id, ok := _spec.ID.Value.(*uuid.UUID); ok { + _node.ID = *id + } else if err := _node.ID.Scan(_spec.ID.Value); err != nil { + return nil, err + } + } + _c.mutation.id = &_node.ID + _c.mutation.done = true + return _node, nil +} + +func (_c *CategorieCreate) createSpec() (*Categorie, *sqlgraph.CreateSpec) { + var ( + _node = &Categorie{config: _c.config} + _spec = sqlgraph.NewCreateSpec(categorie.Table, sqlgraph.NewFieldSpec(categorie.FieldID, field.TypeUUID)) + ) + if id, ok := _c.mutation.ID(); ok { + _node.ID = id + _spec.ID.Value = &id + } + if value, ok := _c.mutation.Nom(); ok { + _spec.SetField(categorie.FieldNom, field.TypeString, value) + _node.Nom = value + } + if value, ok := _c.mutation.Slug(); ok { + _spec.SetField(categorie.FieldSlug, field.TypeString, value) + _node.Slug = &value + } + if value, ok := _c.mutation.Icone(); ok { + _spec.SetField(categorie.FieldIcone, field.TypeString, value) + _node.Icone = &value + } + if value, ok := _c.mutation.CreatedAt(); ok { + _spec.SetField(categorie.FieldCreatedAt, field.TypeTime, value) + _node.CreatedAt = value + } + if value, ok := _c.mutation.UpdatedAt(); ok { + _spec.SetField(categorie.FieldUpdatedAt, field.TypeTime, value) + _node.UpdatedAt = value + } + if nodes := _c.mutation.ParentIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: categorie.ParentTable, + Columns: []string{categorie.ParentColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(categorie.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _node.ParentID = &nodes[0] + _spec.Edges = append(_spec.Edges, edge) + } + if nodes := _c.mutation.EnfantsIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: categorie.EnfantsTable, + Columns: []string{categorie.EnfantsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(categorie.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges = append(_spec.Edges, edge) + } + return _node, _spec +} + +// CategorieCreateBulk is the builder for creating many Categorie entities in bulk. +type CategorieCreateBulk struct { + config + err error + builders []*CategorieCreate +} + +// Save creates the Categorie entities in the database. +func (_c *CategorieCreateBulk) Save(ctx context.Context) ([]*Categorie, error) { + if _c.err != nil { + return nil, _c.err + } + specs := make([]*sqlgraph.CreateSpec, len(_c.builders)) + nodes := make([]*Categorie, len(_c.builders)) + mutators := make([]Mutator, len(_c.builders)) + for i := range _c.builders { + func(i int, root context.Context) { + builder := _c.builders[i] + builder.defaults() + var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { + mutation, ok := m.(*CategorieMutation) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T", m) + } + if err := builder.check(); err != nil { + return nil, err + } + builder.mutation = mutation + var err error + nodes[i], specs[i] = builder.createSpec() + if i < len(mutators)-1 { + _, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation) + } else { + spec := &sqlgraph.BatchCreateSpec{Nodes: specs} + // Invoke the actual operation on the latest mutation in the chain. + if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + } + } + if err != nil { + return nil, err + } + mutation.id = &nodes[i].ID + mutation.done = true + return nodes[i], nil + }) + for i := len(builder.hooks) - 1; i >= 0; i-- { + mut = builder.hooks[i](mut) + } + mutators[i] = mut + }(i, ctx) + } + if len(mutators) > 0 { + if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil { + return nil, err + } + } + return nodes, nil +} + +// SaveX is like Save, but panics if an error occurs. +func (_c *CategorieCreateBulk) SaveX(ctx context.Context) []*Categorie { + v, err := _c.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (_c *CategorieCreateBulk) Exec(ctx context.Context) error { + _, err := _c.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_c *CategorieCreateBulk) ExecX(ctx context.Context) { + if err := _c.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/backend/internal/data/ent/categorie_delete.go b/backend/internal/data/ent/categorie_delete.go new file mode 100644 index 0000000..3f82272 --- /dev/null +++ b/backend/internal/data/ent/categorie_delete.go @@ -0,0 +1,88 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/categorie" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/predicate" +) + +// CategorieDelete is the builder for deleting a Categorie entity. +type CategorieDelete struct { + config + hooks []Hook + mutation *CategorieMutation +} + +// Where appends a list predicates to the CategorieDelete builder. +func (_d *CategorieDelete) Where(ps ...predicate.Categorie) *CategorieDelete { + _d.mutation.Where(ps...) + return _d +} + +// Exec executes the deletion query and returns how many vertices were deleted. +func (_d *CategorieDelete) Exec(ctx context.Context) (int, error) { + return withHooks(ctx, _d.sqlExec, _d.mutation, _d.hooks) +} + +// ExecX is like Exec, but panics if an error occurs. +func (_d *CategorieDelete) ExecX(ctx context.Context) int { + n, err := _d.Exec(ctx) + if err != nil { + panic(err) + } + return n +} + +func (_d *CategorieDelete) sqlExec(ctx context.Context) (int, error) { + _spec := sqlgraph.NewDeleteSpec(categorie.Table, sqlgraph.NewFieldSpec(categorie.FieldID, field.TypeUUID)) + if ps := _d.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + affected, err := sqlgraph.DeleteNodes(ctx, _d.driver, _spec) + if err != nil && sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + _d.mutation.done = true + return affected, err +} + +// CategorieDeleteOne is the builder for deleting a single Categorie entity. +type CategorieDeleteOne struct { + _d *CategorieDelete +} + +// Where appends a list predicates to the CategorieDelete builder. +func (_d *CategorieDeleteOne) Where(ps ...predicate.Categorie) *CategorieDeleteOne { + _d._d.mutation.Where(ps...) + return _d +} + +// Exec executes the deletion query. +func (_d *CategorieDeleteOne) Exec(ctx context.Context) error { + n, err := _d._d.Exec(ctx) + switch { + case err != nil: + return err + case n == 0: + return &NotFoundError{categorie.Label} + default: + return nil + } +} + +// ExecX is like Exec, but panics if an error occurs. +func (_d *CategorieDeleteOne) ExecX(ctx context.Context) { + if err := _d.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/backend/internal/data/ent/categorie_query.go b/backend/internal/data/ent/categorie_query.go new file mode 100644 index 0000000..cd3633d --- /dev/null +++ b/backend/internal/data/ent/categorie_query.go @@ -0,0 +1,686 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "database/sql/driver" + "fmt" + "math" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/categorie" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/predicate" + "github.com/google/uuid" +) + +// CategorieQuery is the builder for querying Categorie entities. +type CategorieQuery struct { + config + ctx *QueryContext + order []categorie.OrderOption + inters []Interceptor + predicates []predicate.Categorie + withParent *CategorieQuery + withEnfants *CategorieQuery + // intermediate query (i.e. traversal path). + sql *sql.Selector + path func(context.Context) (*sql.Selector, error) +} + +// Where adds a new predicate for the CategorieQuery builder. +func (_q *CategorieQuery) Where(ps ...predicate.Categorie) *CategorieQuery { + _q.predicates = append(_q.predicates, ps...) + return _q +} + +// Limit the number of records to be returned by this query. +func (_q *CategorieQuery) Limit(limit int) *CategorieQuery { + _q.ctx.Limit = &limit + return _q +} + +// Offset to start from. +func (_q *CategorieQuery) Offset(offset int) *CategorieQuery { + _q.ctx.Offset = &offset + return _q +} + +// Unique configures the query builder to filter duplicate records on query. +// By default, unique is set to true, and can be disabled using this method. +func (_q *CategorieQuery) Unique(unique bool) *CategorieQuery { + _q.ctx.Unique = &unique + return _q +} + +// Order specifies how the records should be ordered. +func (_q *CategorieQuery) Order(o ...categorie.OrderOption) *CategorieQuery { + _q.order = append(_q.order, o...) + return _q +} + +// QueryParent chains the current query on the "parent" edge. +func (_q *CategorieQuery) QueryParent() *CategorieQuery { + query := (&CategorieClient{config: _q.config}).Query() + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + selector := _q.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(categorie.Table, categorie.FieldID, selector), + sqlgraph.To(categorie.Table, categorie.FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, categorie.ParentTable, categorie.ParentColumn), + ) + fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) + return fromU, nil + } + return query +} + +// QueryEnfants chains the current query on the "enfants" edge. +func (_q *CategorieQuery) QueryEnfants() *CategorieQuery { + query := (&CategorieClient{config: _q.config}).Query() + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + selector := _q.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(categorie.Table, categorie.FieldID, selector), + sqlgraph.To(categorie.Table, categorie.FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, categorie.EnfantsTable, categorie.EnfantsColumn), + ) + fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) + return fromU, nil + } + return query +} + +// First returns the first Categorie entity from the query. +// Returns a *NotFoundError when no Categorie was found. +func (_q *CategorieQuery) First(ctx context.Context) (*Categorie, error) { + nodes, err := _q.Limit(1).All(setContextOp(ctx, _q.ctx, ent.OpQueryFirst)) + if err != nil { + return nil, err + } + if len(nodes) == 0 { + return nil, &NotFoundError{categorie.Label} + } + return nodes[0], nil +} + +// FirstX is like First, but panics if an error occurs. +func (_q *CategorieQuery) FirstX(ctx context.Context) *Categorie { + node, err := _q.First(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return node +} + +// FirstID returns the first Categorie ID from the query. +// Returns a *NotFoundError when no Categorie ID was found. +func (_q *CategorieQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { + var ids []uuid.UUID + if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil { + return + } + if len(ids) == 0 { + err = &NotFoundError{categorie.Label} + return + } + return ids[0], nil +} + +// FirstIDX is like FirstID, but panics if an error occurs. +func (_q *CategorieQuery) FirstIDX(ctx context.Context) uuid.UUID { + id, err := _q.FirstID(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return id +} + +// Only returns a single Categorie entity found by the query, ensuring it only returns one. +// Returns a *NotSingularError when more than one Categorie entity is found. +// Returns a *NotFoundError when no Categorie entities are found. +func (_q *CategorieQuery) Only(ctx context.Context) (*Categorie, error) { + nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly)) + if err != nil { + return nil, err + } + switch len(nodes) { + case 1: + return nodes[0], nil + case 0: + return nil, &NotFoundError{categorie.Label} + default: + return nil, &NotSingularError{categorie.Label} + } +} + +// OnlyX is like Only, but panics if an error occurs. +func (_q *CategorieQuery) OnlyX(ctx context.Context) *Categorie { + node, err := _q.Only(ctx) + if err != nil { + panic(err) + } + return node +} + +// OnlyID is like Only, but returns the only Categorie ID in the query. +// Returns a *NotSingularError when more than one Categorie ID is found. +// Returns a *NotFoundError when no entities are found. +func (_q *CategorieQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { + var ids []uuid.UUID + if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryOnlyID)); err != nil { + return + } + switch len(ids) { + case 1: + id = ids[0] + case 0: + err = &NotFoundError{categorie.Label} + default: + err = &NotSingularError{categorie.Label} + } + return +} + +// OnlyIDX is like OnlyID, but panics if an error occurs. +func (_q *CategorieQuery) OnlyIDX(ctx context.Context) uuid.UUID { + id, err := _q.OnlyID(ctx) + if err != nil { + panic(err) + } + return id +} + +// All executes the query and returns a list of Categories. +func (_q *CategorieQuery) All(ctx context.Context) ([]*Categorie, error) { + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll) + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + qr := querierAll[[]*Categorie, *CategorieQuery]() + return withInterceptors[[]*Categorie](ctx, _q, qr, _q.inters) +} + +// AllX is like All, but panics if an error occurs. +func (_q *CategorieQuery) AllX(ctx context.Context) []*Categorie { + nodes, err := _q.All(ctx) + if err != nil { + panic(err) + } + return nodes +} + +// IDs executes the query and returns a list of Categorie IDs. +func (_q *CategorieQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) { + if _q.ctx.Unique == nil && _q.path != nil { + _q.Unique(true) + } + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryIDs) + if err = _q.Select(categorie.FieldID).Scan(ctx, &ids); err != nil { + return nil, err + } + return ids, nil +} + +// IDsX is like IDs, but panics if an error occurs. +func (_q *CategorieQuery) IDsX(ctx context.Context) []uuid.UUID { + ids, err := _q.IDs(ctx) + if err != nil { + panic(err) + } + return ids +} + +// Count returns the count of the given query. +func (_q *CategorieQuery) Count(ctx context.Context) (int, error) { + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryCount) + if err := _q.prepareQuery(ctx); err != nil { + return 0, err + } + return withInterceptors[int](ctx, _q, querierCount[*CategorieQuery](), _q.inters) +} + +// CountX is like Count, but panics if an error occurs. +func (_q *CategorieQuery) CountX(ctx context.Context) int { + count, err := _q.Count(ctx) + if err != nil { + panic(err) + } + return count +} + +// Exist returns true if the query has elements in the graph. +func (_q *CategorieQuery) Exist(ctx context.Context) (bool, error) { + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryExist) + switch _, err := _q.FirstID(ctx); { + case IsNotFound(err): + return false, nil + case err != nil: + return false, fmt.Errorf("ent: check existence: %w", err) + default: + return true, nil + } +} + +// ExistX is like Exist, but panics if an error occurs. +func (_q *CategorieQuery) ExistX(ctx context.Context) bool { + exist, err := _q.Exist(ctx) + if err != nil { + panic(err) + } + return exist +} + +// Clone returns a duplicate of the CategorieQuery builder, including all associated steps. It can be +// used to prepare common query builders and use them differently after the clone is made. +func (_q *CategorieQuery) Clone() *CategorieQuery { + if _q == nil { + return nil + } + return &CategorieQuery{ + config: _q.config, + ctx: _q.ctx.Clone(), + order: append([]categorie.OrderOption{}, _q.order...), + inters: append([]Interceptor{}, _q.inters...), + predicates: append([]predicate.Categorie{}, _q.predicates...), + withParent: _q.withParent.Clone(), + withEnfants: _q.withEnfants.Clone(), + // clone intermediate query. + sql: _q.sql.Clone(), + path: _q.path, + } +} + +// WithParent tells the query-builder to eager-load the nodes that are connected to +// the "parent" edge. The optional arguments are used to configure the query builder of the edge. +func (_q *CategorieQuery) WithParent(opts ...func(*CategorieQuery)) *CategorieQuery { + query := (&CategorieClient{config: _q.config}).Query() + for _, opt := range opts { + opt(query) + } + _q.withParent = query + return _q +} + +// WithEnfants tells the query-builder to eager-load the nodes that are connected to +// the "enfants" edge. The optional arguments are used to configure the query builder of the edge. +func (_q *CategorieQuery) WithEnfants(opts ...func(*CategorieQuery)) *CategorieQuery { + query := (&CategorieClient{config: _q.config}).Query() + for _, opt := range opts { + opt(query) + } + _q.withEnfants = query + return _q +} + +// GroupBy is used to group vertices by one or more fields/columns. +// It is often used with aggregate functions, like: count, max, mean, min, sum. +// +// Example: +// +// var v []struct { +// Nom string `json:"nom,omitempty"` +// Count int `json:"count,omitempty"` +// } +// +// client.Categorie.Query(). +// GroupBy(categorie.FieldNom). +// Aggregate(ent.Count()). +// Scan(ctx, &v) +func (_q *CategorieQuery) GroupBy(field string, fields ...string) *CategorieGroupBy { + _q.ctx.Fields = append([]string{field}, fields...) + grbuild := &CategorieGroupBy{build: _q} + grbuild.flds = &_q.ctx.Fields + grbuild.label = categorie.Label + grbuild.scan = grbuild.Scan + return grbuild +} + +// Select allows the selection one or more fields/columns for the given query, +// instead of selecting all fields in the entity. +// +// Example: +// +// var v []struct { +// Nom string `json:"nom,omitempty"` +// } +// +// client.Categorie.Query(). +// Select(categorie.FieldNom). +// Scan(ctx, &v) +func (_q *CategorieQuery) Select(fields ...string) *CategorieSelect { + _q.ctx.Fields = append(_q.ctx.Fields, fields...) + sbuild := &CategorieSelect{CategorieQuery: _q} + sbuild.label = categorie.Label + sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan + return sbuild +} + +// Aggregate returns a CategorieSelect configured with the given aggregations. +func (_q *CategorieQuery) Aggregate(fns ...AggregateFunc) *CategorieSelect { + return _q.Select().Aggregate(fns...) +} + +func (_q *CategorieQuery) prepareQuery(ctx context.Context) error { + for _, inter := range _q.inters { + if inter == nil { + return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)") + } + if trv, ok := inter.(Traverser); ok { + if err := trv.Traverse(ctx, _q); err != nil { + return err + } + } + } + for _, f := range _q.ctx.Fields { + if !categorie.ValidColumn(f) { + return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + } + if _q.path != nil { + prev, err := _q.path(ctx) + if err != nil { + return err + } + _q.sql = prev + } + return nil +} + +func (_q *CategorieQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Categorie, error) { + var ( + nodes = []*Categorie{} + _spec = _q.querySpec() + loadedTypes = [2]bool{ + _q.withParent != nil, + _q.withEnfants != nil, + } + ) + _spec.ScanValues = func(columns []string) ([]any, error) { + return (*Categorie).scanValues(nil, columns) + } + _spec.Assign = func(columns []string, values []any) error { + node := &Categorie{config: _q.config} + nodes = append(nodes, node) + node.Edges.loadedTypes = loadedTypes + return node.assignValues(columns, values) + } + for i := range hooks { + hooks[i](ctx, _spec) + } + if err := sqlgraph.QueryNodes(ctx, _q.driver, _spec); err != nil { + return nil, err + } + if len(nodes) == 0 { + return nodes, nil + } + if query := _q.withParent; query != nil { + if err := _q.loadParent(ctx, query, nodes, nil, + func(n *Categorie, e *Categorie) { n.Edges.Parent = e }); err != nil { + return nil, err + } + } + if query := _q.withEnfants; query != nil { + if err := _q.loadEnfants(ctx, query, nodes, + func(n *Categorie) { n.Edges.Enfants = []*Categorie{} }, + func(n *Categorie, e *Categorie) { n.Edges.Enfants = append(n.Edges.Enfants, e) }); err != nil { + return nil, err + } + } + return nodes, nil +} + +func (_q *CategorieQuery) loadParent(ctx context.Context, query *CategorieQuery, nodes []*Categorie, init func(*Categorie), assign func(*Categorie, *Categorie)) error { + ids := make([]uuid.UUID, 0, len(nodes)) + nodeids := make(map[uuid.UUID][]*Categorie) + for i := range nodes { + if nodes[i].ParentID == nil { + continue + } + fk := *nodes[i].ParentID + if _, ok := nodeids[fk]; !ok { + ids = append(ids, fk) + } + nodeids[fk] = append(nodeids[fk], nodes[i]) + } + if len(ids) == 0 { + return nil + } + query.Where(categorie.IDIn(ids...)) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + nodes, ok := nodeids[n.ID] + if !ok { + return fmt.Errorf(`unexpected foreign-key "parent_id" returned %v`, n.ID) + } + for i := range nodes { + assign(nodes[i], n) + } + } + return nil +} +func (_q *CategorieQuery) loadEnfants(ctx context.Context, query *CategorieQuery, nodes []*Categorie, init func(*Categorie), assign func(*Categorie, *Categorie)) error { + fks := make([]driver.Value, 0, len(nodes)) + nodeids := make(map[uuid.UUID]*Categorie) + for i := range nodes { + fks = append(fks, nodes[i].ID) + nodeids[nodes[i].ID] = nodes[i] + if init != nil { + init(nodes[i]) + } + } + if len(query.ctx.Fields) > 0 { + query.ctx.AppendFieldOnce(categorie.FieldParentID) + } + query.Where(predicate.Categorie(func(s *sql.Selector) { + s.Where(sql.InValues(s.C(categorie.EnfantsColumn), fks...)) + })) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + fk := n.ParentID + if fk == nil { + return fmt.Errorf(`foreign-key "parent_id" is nil for node %v`, n.ID) + } + node, ok := nodeids[*fk] + if !ok { + return fmt.Errorf(`unexpected referenced foreign-key "parent_id" returned %v for node %v`, *fk, n.ID) + } + assign(node, n) + } + return nil +} + +func (_q *CategorieQuery) sqlCount(ctx context.Context) (int, error) { + _spec := _q.querySpec() + _spec.Node.Columns = _q.ctx.Fields + if len(_q.ctx.Fields) > 0 { + _spec.Unique = _q.ctx.Unique != nil && *_q.ctx.Unique + } + return sqlgraph.CountNodes(ctx, _q.driver, _spec) +} + +func (_q *CategorieQuery) querySpec() *sqlgraph.QuerySpec { + _spec := sqlgraph.NewQuerySpec(categorie.Table, categorie.Columns, sqlgraph.NewFieldSpec(categorie.FieldID, field.TypeUUID)) + _spec.From = _q.sql + if unique := _q.ctx.Unique; unique != nil { + _spec.Unique = *unique + } else if _q.path != nil { + _spec.Unique = true + } + if fields := _q.ctx.Fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, categorie.FieldID) + for i := range fields { + if fields[i] != categorie.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) + } + } + if _q.withParent != nil { + _spec.Node.AddColumnOnce(categorie.FieldParentID) + } + } + if ps := _q.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if limit := _q.ctx.Limit; limit != nil { + _spec.Limit = *limit + } + if offset := _q.ctx.Offset; offset != nil { + _spec.Offset = *offset + } + if ps := _q.order; len(ps) > 0 { + _spec.Order = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + return _spec +} + +func (_q *CategorieQuery) sqlQuery(ctx context.Context) *sql.Selector { + builder := sql.Dialect(_q.driver.Dialect()) + t1 := builder.Table(categorie.Table) + columns := _q.ctx.Fields + if len(columns) == 0 { + columns = categorie.Columns + } + selector := builder.Select(t1.Columns(columns...)...).From(t1) + if _q.sql != nil { + selector = _q.sql + selector.Select(selector.Columns(columns...)...) + } + if _q.ctx.Unique != nil && *_q.ctx.Unique { + selector.Distinct() + } + for _, p := range _q.predicates { + p(selector) + } + for _, p := range _q.order { + p(selector) + } + if offset := _q.ctx.Offset; offset != nil { + // limit is mandatory for offset clause. We start + // with default value, and override it below if needed. + selector.Offset(*offset).Limit(math.MaxInt32) + } + if limit := _q.ctx.Limit; limit != nil { + selector.Limit(*limit) + } + return selector +} + +// CategorieGroupBy is the group-by builder for Categorie entities. +type CategorieGroupBy struct { + selector + build *CategorieQuery +} + +// Aggregate adds the given aggregation functions to the group-by query. +func (_g *CategorieGroupBy) Aggregate(fns ...AggregateFunc) *CategorieGroupBy { + _g.fns = append(_g.fns, fns...) + return _g +} + +// Scan applies the selector query and scans the result into the given value. +func (_g *CategorieGroupBy) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, _g.build.ctx, ent.OpQueryGroupBy) + if err := _g.build.prepareQuery(ctx); err != nil { + return err + } + return scanWithInterceptors[*CategorieQuery, *CategorieGroupBy](ctx, _g.build, _g, _g.build.inters, v) +} + +func (_g *CategorieGroupBy) sqlScan(ctx context.Context, root *CategorieQuery, v any) error { + selector := root.sqlQuery(ctx).Select() + aggregation := make([]string, 0, len(_g.fns)) + for _, fn := range _g.fns { + aggregation = append(aggregation, fn(selector)) + } + if len(selector.SelectedColumns()) == 0 { + columns := make([]string, 0, len(*_g.flds)+len(_g.fns)) + for _, f := range *_g.flds { + columns = append(columns, selector.C(f)) + } + columns = append(columns, aggregation...) + selector.Select(columns...) + } + selector.GroupBy(selector.Columns(*_g.flds...)...) + if err := selector.Err(); err != nil { + return err + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := _g.build.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} + +// CategorieSelect is the builder for selecting fields of Categorie entities. +type CategorieSelect struct { + *CategorieQuery + selector +} + +// Aggregate adds the given aggregation functions to the selector query. +func (_s *CategorieSelect) Aggregate(fns ...AggregateFunc) *CategorieSelect { + _s.fns = append(_s.fns, fns...) + return _s +} + +// Scan applies the selector query and scans the result into the given value. +func (_s *CategorieSelect) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, _s.ctx, ent.OpQuerySelect) + if err := _s.prepareQuery(ctx); err != nil { + return err + } + return scanWithInterceptors[*CategorieQuery, *CategorieSelect](ctx, _s.CategorieQuery, _s, _s.inters, v) +} + +func (_s *CategorieSelect) sqlScan(ctx context.Context, root *CategorieQuery, v any) error { + selector := root.sqlQuery(ctx) + aggregation := make([]string, 0, len(_s.fns)) + for _, fn := range _s.fns { + aggregation = append(aggregation, fn(selector)) + } + switch n := len(*_s.selector.flds); { + case n == 0 && len(aggregation) > 0: + selector.Select(aggregation...) + case n != 0 && len(aggregation) > 0: + selector.AppendSelect(aggregation...) + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := _s.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} diff --git a/backend/internal/data/ent/categorie_update.go b/backend/internal/data/ent/categorie_update.go new file mode 100644 index 0000000..6ed05cf --- /dev/null +++ b/backend/internal/data/ent/categorie_update.go @@ -0,0 +1,693 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/categorie" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/predicate" + "github.com/google/uuid" +) + +// CategorieUpdate is the builder for updating Categorie entities. +type CategorieUpdate struct { + config + hooks []Hook + mutation *CategorieMutation +} + +// Where appends a list predicates to the CategorieUpdate builder. +func (_u *CategorieUpdate) Where(ps ...predicate.Categorie) *CategorieUpdate { + _u.mutation.Where(ps...) + return _u +} + +// SetNom sets the "nom" field. +func (_u *CategorieUpdate) SetNom(v string) *CategorieUpdate { + _u.mutation.SetNom(v) + return _u +} + +// SetNillableNom sets the "nom" field if the given value is not nil. +func (_u *CategorieUpdate) SetNillableNom(v *string) *CategorieUpdate { + if v != nil { + _u.SetNom(*v) + } + return _u +} + +// SetParentID sets the "parent_id" field. +func (_u *CategorieUpdate) SetParentID(v uuid.UUID) *CategorieUpdate { + _u.mutation.SetParentID(v) + return _u +} + +// SetNillableParentID sets the "parent_id" field if the given value is not nil. +func (_u *CategorieUpdate) SetNillableParentID(v *uuid.UUID) *CategorieUpdate { + if v != nil { + _u.SetParentID(*v) + } + return _u +} + +// ClearParentID clears the value of the "parent_id" field. +func (_u *CategorieUpdate) ClearParentID() *CategorieUpdate { + _u.mutation.ClearParentID() + return _u +} + +// SetSlug sets the "slug" field. +func (_u *CategorieUpdate) SetSlug(v string) *CategorieUpdate { + _u.mutation.SetSlug(v) + return _u +} + +// SetNillableSlug sets the "slug" field if the given value is not nil. +func (_u *CategorieUpdate) SetNillableSlug(v *string) *CategorieUpdate { + if v != nil { + _u.SetSlug(*v) + } + return _u +} + +// ClearSlug clears the value of the "slug" field. +func (_u *CategorieUpdate) ClearSlug() *CategorieUpdate { + _u.mutation.ClearSlug() + return _u +} + +// SetIcone sets the "icone" field. +func (_u *CategorieUpdate) SetIcone(v string) *CategorieUpdate { + _u.mutation.SetIcone(v) + return _u +} + +// SetNillableIcone sets the "icone" field if the given value is not nil. +func (_u *CategorieUpdate) SetNillableIcone(v *string) *CategorieUpdate { + if v != nil { + _u.SetIcone(*v) + } + return _u +} + +// ClearIcone clears the value of the "icone" field. +func (_u *CategorieUpdate) ClearIcone() *CategorieUpdate { + _u.mutation.ClearIcone() + return _u +} + +// SetCreatedAt sets the "created_at" field. +func (_u *CategorieUpdate) SetCreatedAt(v time.Time) *CategorieUpdate { + _u.mutation.SetCreatedAt(v) + return _u +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (_u *CategorieUpdate) SetNillableCreatedAt(v *time.Time) *CategorieUpdate { + if v != nil { + _u.SetCreatedAt(*v) + } + return _u +} + +// SetUpdatedAt sets the "updated_at" field. +func (_u *CategorieUpdate) SetUpdatedAt(v time.Time) *CategorieUpdate { + _u.mutation.SetUpdatedAt(v) + return _u +} + +// SetParent sets the "parent" edge to the Categorie entity. +func (_u *CategorieUpdate) SetParent(v *Categorie) *CategorieUpdate { + return _u.SetParentID(v.ID) +} + +// AddEnfantIDs adds the "enfants" edge to the Categorie entity by IDs. +func (_u *CategorieUpdate) AddEnfantIDs(ids ...uuid.UUID) *CategorieUpdate { + _u.mutation.AddEnfantIDs(ids...) + return _u +} + +// AddEnfants adds the "enfants" edges to the Categorie entity. +func (_u *CategorieUpdate) AddEnfants(v ...*Categorie) *CategorieUpdate { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.AddEnfantIDs(ids...) +} + +// Mutation returns the CategorieMutation object of the builder. +func (_u *CategorieUpdate) Mutation() *CategorieMutation { + return _u.mutation +} + +// ClearParent clears the "parent" edge to the Categorie entity. +func (_u *CategorieUpdate) ClearParent() *CategorieUpdate { + _u.mutation.ClearParent() + return _u +} + +// ClearEnfants clears all "enfants" edges to the Categorie entity. +func (_u *CategorieUpdate) ClearEnfants() *CategorieUpdate { + _u.mutation.ClearEnfants() + return _u +} + +// RemoveEnfantIDs removes the "enfants" edge to Categorie entities by IDs. +func (_u *CategorieUpdate) RemoveEnfantIDs(ids ...uuid.UUID) *CategorieUpdate { + _u.mutation.RemoveEnfantIDs(ids...) + return _u +} + +// RemoveEnfants removes "enfants" edges to Categorie entities. +func (_u *CategorieUpdate) RemoveEnfants(v ...*Categorie) *CategorieUpdate { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.RemoveEnfantIDs(ids...) +} + +// Save executes the query and returns the number of nodes affected by the update operation. +func (_u *CategorieUpdate) Save(ctx context.Context) (int, error) { + _u.defaults() + return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (_u *CategorieUpdate) SaveX(ctx context.Context) int { + affected, err := _u.Save(ctx) + if err != nil { + panic(err) + } + return affected +} + +// Exec executes the query. +func (_u *CategorieUpdate) Exec(ctx context.Context) error { + _, err := _u.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_u *CategorieUpdate) ExecX(ctx context.Context) { + if err := _u.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (_u *CategorieUpdate) defaults() { + if _, ok := _u.mutation.UpdatedAt(); !ok { + v := categorie.UpdateDefaultUpdatedAt() + _u.mutation.SetUpdatedAt(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_u *CategorieUpdate) check() error { + if v, ok := _u.mutation.Nom(); ok { + if err := categorie.NomValidator(v); err != nil { + return &ValidationError{Name: "nom", err: fmt.Errorf(`ent: validator failed for field "Categorie.nom": %w`, err)} + } + } + return nil +} + +func (_u *CategorieUpdate) sqlSave(ctx context.Context) (_node int, err error) { + if err := _u.check(); err != nil { + return _node, err + } + _spec := sqlgraph.NewUpdateSpec(categorie.Table, categorie.Columns, sqlgraph.NewFieldSpec(categorie.FieldID, field.TypeUUID)) + if ps := _u.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := _u.mutation.Nom(); ok { + _spec.SetField(categorie.FieldNom, field.TypeString, value) + } + if value, ok := _u.mutation.Slug(); ok { + _spec.SetField(categorie.FieldSlug, field.TypeString, value) + } + if _u.mutation.SlugCleared() { + _spec.ClearField(categorie.FieldSlug, field.TypeString) + } + if value, ok := _u.mutation.Icone(); ok { + _spec.SetField(categorie.FieldIcone, field.TypeString, value) + } + if _u.mutation.IconeCleared() { + _spec.ClearField(categorie.FieldIcone, field.TypeString) + } + if value, ok := _u.mutation.CreatedAt(); ok { + _spec.SetField(categorie.FieldCreatedAt, field.TypeTime, value) + } + if value, ok := _u.mutation.UpdatedAt(); ok { + _spec.SetField(categorie.FieldUpdatedAt, field.TypeTime, value) + } + if _u.mutation.ParentCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: categorie.ParentTable, + Columns: []string{categorie.ParentColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(categorie.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.ParentIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: categorie.ParentTable, + Columns: []string{categorie.ParentColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(categorie.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if _u.mutation.EnfantsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: categorie.EnfantsTable, + Columns: []string{categorie.EnfantsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(categorie.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.RemovedEnfantsIDs(); len(nodes) > 0 && !_u.mutation.EnfantsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: categorie.EnfantsTable, + Columns: []string{categorie.EnfantsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(categorie.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.EnfantsIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: categorie.EnfantsTable, + Columns: []string{categorie.EnfantsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(categorie.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{categorie.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return 0, err + } + _u.mutation.done = true + return _node, nil +} + +// CategorieUpdateOne is the builder for updating a single Categorie entity. +type CategorieUpdateOne struct { + config + fields []string + hooks []Hook + mutation *CategorieMutation +} + +// SetNom sets the "nom" field. +func (_u *CategorieUpdateOne) SetNom(v string) *CategorieUpdateOne { + _u.mutation.SetNom(v) + return _u +} + +// SetNillableNom sets the "nom" field if the given value is not nil. +func (_u *CategorieUpdateOne) SetNillableNom(v *string) *CategorieUpdateOne { + if v != nil { + _u.SetNom(*v) + } + return _u +} + +// SetParentID sets the "parent_id" field. +func (_u *CategorieUpdateOne) SetParentID(v uuid.UUID) *CategorieUpdateOne { + _u.mutation.SetParentID(v) + return _u +} + +// SetNillableParentID sets the "parent_id" field if the given value is not nil. +func (_u *CategorieUpdateOne) SetNillableParentID(v *uuid.UUID) *CategorieUpdateOne { + if v != nil { + _u.SetParentID(*v) + } + return _u +} + +// ClearParentID clears the value of the "parent_id" field. +func (_u *CategorieUpdateOne) ClearParentID() *CategorieUpdateOne { + _u.mutation.ClearParentID() + return _u +} + +// SetSlug sets the "slug" field. +func (_u *CategorieUpdateOne) SetSlug(v string) *CategorieUpdateOne { + _u.mutation.SetSlug(v) + return _u +} + +// SetNillableSlug sets the "slug" field if the given value is not nil. +func (_u *CategorieUpdateOne) SetNillableSlug(v *string) *CategorieUpdateOne { + if v != nil { + _u.SetSlug(*v) + } + return _u +} + +// ClearSlug clears the value of the "slug" field. +func (_u *CategorieUpdateOne) ClearSlug() *CategorieUpdateOne { + _u.mutation.ClearSlug() + return _u +} + +// SetIcone sets the "icone" field. +func (_u *CategorieUpdateOne) SetIcone(v string) *CategorieUpdateOne { + _u.mutation.SetIcone(v) + return _u +} + +// SetNillableIcone sets the "icone" field if the given value is not nil. +func (_u *CategorieUpdateOne) SetNillableIcone(v *string) *CategorieUpdateOne { + if v != nil { + _u.SetIcone(*v) + } + return _u +} + +// ClearIcone clears the value of the "icone" field. +func (_u *CategorieUpdateOne) ClearIcone() *CategorieUpdateOne { + _u.mutation.ClearIcone() + return _u +} + +// SetCreatedAt sets the "created_at" field. +func (_u *CategorieUpdateOne) SetCreatedAt(v time.Time) *CategorieUpdateOne { + _u.mutation.SetCreatedAt(v) + return _u +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (_u *CategorieUpdateOne) SetNillableCreatedAt(v *time.Time) *CategorieUpdateOne { + if v != nil { + _u.SetCreatedAt(*v) + } + return _u +} + +// SetUpdatedAt sets the "updated_at" field. +func (_u *CategorieUpdateOne) SetUpdatedAt(v time.Time) *CategorieUpdateOne { + _u.mutation.SetUpdatedAt(v) + return _u +} + +// SetParent sets the "parent" edge to the Categorie entity. +func (_u *CategorieUpdateOne) SetParent(v *Categorie) *CategorieUpdateOne { + return _u.SetParentID(v.ID) +} + +// AddEnfantIDs adds the "enfants" edge to the Categorie entity by IDs. +func (_u *CategorieUpdateOne) AddEnfantIDs(ids ...uuid.UUID) *CategorieUpdateOne { + _u.mutation.AddEnfantIDs(ids...) + return _u +} + +// AddEnfants adds the "enfants" edges to the Categorie entity. +func (_u *CategorieUpdateOne) AddEnfants(v ...*Categorie) *CategorieUpdateOne { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.AddEnfantIDs(ids...) +} + +// Mutation returns the CategorieMutation object of the builder. +func (_u *CategorieUpdateOne) Mutation() *CategorieMutation { + return _u.mutation +} + +// ClearParent clears the "parent" edge to the Categorie entity. +func (_u *CategorieUpdateOne) ClearParent() *CategorieUpdateOne { + _u.mutation.ClearParent() + return _u +} + +// ClearEnfants clears all "enfants" edges to the Categorie entity. +func (_u *CategorieUpdateOne) ClearEnfants() *CategorieUpdateOne { + _u.mutation.ClearEnfants() + return _u +} + +// RemoveEnfantIDs removes the "enfants" edge to Categorie entities by IDs. +func (_u *CategorieUpdateOne) RemoveEnfantIDs(ids ...uuid.UUID) *CategorieUpdateOne { + _u.mutation.RemoveEnfantIDs(ids...) + return _u +} + +// RemoveEnfants removes "enfants" edges to Categorie entities. +func (_u *CategorieUpdateOne) RemoveEnfants(v ...*Categorie) *CategorieUpdateOne { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.RemoveEnfantIDs(ids...) +} + +// Where appends a list predicates to the CategorieUpdate builder. +func (_u *CategorieUpdateOne) Where(ps ...predicate.Categorie) *CategorieUpdateOne { + _u.mutation.Where(ps...) + return _u +} + +// Select allows selecting one or more fields (columns) of the returned entity. +// The default is selecting all fields defined in the entity schema. +func (_u *CategorieUpdateOne) Select(field string, fields ...string) *CategorieUpdateOne { + _u.fields = append([]string{field}, fields...) + return _u +} + +// Save executes the query and returns the updated Categorie entity. +func (_u *CategorieUpdateOne) Save(ctx context.Context) (*Categorie, error) { + _u.defaults() + return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (_u *CategorieUpdateOne) SaveX(ctx context.Context) *Categorie { + node, err := _u.Save(ctx) + if err != nil { + panic(err) + } + return node +} + +// Exec executes the query on the entity. +func (_u *CategorieUpdateOne) Exec(ctx context.Context) error { + _, err := _u.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_u *CategorieUpdateOne) ExecX(ctx context.Context) { + if err := _u.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (_u *CategorieUpdateOne) defaults() { + if _, ok := _u.mutation.UpdatedAt(); !ok { + v := categorie.UpdateDefaultUpdatedAt() + _u.mutation.SetUpdatedAt(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_u *CategorieUpdateOne) check() error { + if v, ok := _u.mutation.Nom(); ok { + if err := categorie.NomValidator(v); err != nil { + return &ValidationError{Name: "nom", err: fmt.Errorf(`ent: validator failed for field "Categorie.nom": %w`, err)} + } + } + return nil +} + +func (_u *CategorieUpdateOne) sqlSave(ctx context.Context) (_node *Categorie, err error) { + if err := _u.check(); err != nil { + return _node, err + } + _spec := sqlgraph.NewUpdateSpec(categorie.Table, categorie.Columns, sqlgraph.NewFieldSpec(categorie.FieldID, field.TypeUUID)) + id, ok := _u.mutation.ID() + if !ok { + return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Categorie.id" for update`)} + } + _spec.Node.ID.Value = id + if fields := _u.fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, categorie.FieldID) + for _, f := range fields { + if !categorie.ValidColumn(f) { + return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + if f != categorie.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, f) + } + } + } + if ps := _u.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := _u.mutation.Nom(); ok { + _spec.SetField(categorie.FieldNom, field.TypeString, value) + } + if value, ok := _u.mutation.Slug(); ok { + _spec.SetField(categorie.FieldSlug, field.TypeString, value) + } + if _u.mutation.SlugCleared() { + _spec.ClearField(categorie.FieldSlug, field.TypeString) + } + if value, ok := _u.mutation.Icone(); ok { + _spec.SetField(categorie.FieldIcone, field.TypeString, value) + } + if _u.mutation.IconeCleared() { + _spec.ClearField(categorie.FieldIcone, field.TypeString) + } + if value, ok := _u.mutation.CreatedAt(); ok { + _spec.SetField(categorie.FieldCreatedAt, field.TypeTime, value) + } + if value, ok := _u.mutation.UpdatedAt(); ok { + _spec.SetField(categorie.FieldUpdatedAt, field.TypeTime, value) + } + if _u.mutation.ParentCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: categorie.ParentTable, + Columns: []string{categorie.ParentColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(categorie.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.ParentIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: categorie.ParentTable, + Columns: []string{categorie.ParentColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(categorie.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if _u.mutation.EnfantsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: categorie.EnfantsTable, + Columns: []string{categorie.EnfantsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(categorie.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.RemovedEnfantsIDs(); len(nodes) > 0 && !_u.mutation.EnfantsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: categorie.EnfantsTable, + Columns: []string{categorie.EnfantsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(categorie.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.EnfantsIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: categorie.EnfantsTable, + Columns: []string{categorie.EnfantsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(categorie.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + _node = &Categorie{config: _u.config} + _spec.Assign = _node.assignValues + _spec.ScanValues = _node.scanValues + if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{categorie.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + _u.mutation.done = true + return _node, nil +} diff --git a/backend/internal/data/ent/champpersonnalise.go b/backend/internal/data/ent/champpersonnalise.go new file mode 100644 index 0000000..df4f1c3 --- /dev/null +++ b/backend/internal/data/ent/champpersonnalise.go @@ -0,0 +1,209 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "fmt" + "strings" + "time" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/champpersonnalise" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/objet" + "github.com/google/uuid" +) + +// ChampPersonnalise is the model entity for the ChampPersonnalise schema. +type ChampPersonnalise struct { + config `json:"-"` + // ID of the ent. + // Identifiant unique du champ + ID uuid.UUID `json:"id,omitempty"` + // Identifiant de l'objet + ObjetID uuid.UUID `json:"objet_id,omitempty"` + // Nom du champ + NomChamp string `json:"nom_champ,omitempty"` + // Type du champ + TypeChamp champpersonnalise.TypeChamp `json:"type_champ,omitempty"` + // Valeur stockee en texte + Valeur *string `json:"valeur,omitempty"` + // Unite (si applicable) + Unite *string `json:"unite,omitempty"` + // Date de creation + CreatedAt time.Time `json:"created_at,omitempty"` + // Date de derniere mise a jour + UpdatedAt time.Time `json:"updated_at,omitempty"` + // Edges holds the relations/edges for other nodes in the graph. + // The values are being populated by the ChampPersonnaliseQuery when eager-loading is set. + Edges ChampPersonnaliseEdges `json:"edges"` + selectValues sql.SelectValues +} + +// ChampPersonnaliseEdges holds the relations/edges for other nodes in the graph. +type ChampPersonnaliseEdges struct { + // Objet holds the value of the objet edge. + Objet *Objet `json:"objet,omitempty"` + // loadedTypes holds the information for reporting if a + // type was loaded (or requested) in eager-loading or not. + loadedTypes [1]bool +} + +// ObjetOrErr returns the Objet value or an error if the edge +// was not loaded in eager-loading, or loaded but was not found. +func (e ChampPersonnaliseEdges) ObjetOrErr() (*Objet, error) { + if e.Objet != nil { + return e.Objet, nil + } else if e.loadedTypes[0] { + return nil, &NotFoundError{label: objet.Label} + } + return nil, &NotLoadedError{edge: "objet"} +} + +// scanValues returns the types for scanning values from sql.Rows. +func (*ChampPersonnalise) scanValues(columns []string) ([]any, error) { + values := make([]any, len(columns)) + for i := range columns { + switch columns[i] { + case champpersonnalise.FieldNomChamp, champpersonnalise.FieldTypeChamp, champpersonnalise.FieldValeur, champpersonnalise.FieldUnite: + values[i] = new(sql.NullString) + case champpersonnalise.FieldCreatedAt, champpersonnalise.FieldUpdatedAt: + values[i] = new(sql.NullTime) + case champpersonnalise.FieldID, champpersonnalise.FieldObjetID: + values[i] = new(uuid.UUID) + default: + values[i] = new(sql.UnknownType) + } + } + return values, nil +} + +// assignValues assigns the values that were returned from sql.Rows (after scanning) +// to the ChampPersonnalise fields. +func (_m *ChampPersonnalise) assignValues(columns []string, values []any) error { + if m, n := len(values), len(columns); m < n { + return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) + } + for i := range columns { + switch columns[i] { + case champpersonnalise.FieldID: + if value, ok := values[i].(*uuid.UUID); !ok { + return fmt.Errorf("unexpected type %T for field id", values[i]) + } else if value != nil { + _m.ID = *value + } + case champpersonnalise.FieldObjetID: + if value, ok := values[i].(*uuid.UUID); !ok { + return fmt.Errorf("unexpected type %T for field objet_id", values[i]) + } else if value != nil { + _m.ObjetID = *value + } + case champpersonnalise.FieldNomChamp: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field nom_champ", values[i]) + } else if value.Valid { + _m.NomChamp = value.String + } + case champpersonnalise.FieldTypeChamp: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field type_champ", values[i]) + } else if value.Valid { + _m.TypeChamp = champpersonnalise.TypeChamp(value.String) + } + case champpersonnalise.FieldValeur: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field valeur", values[i]) + } else if value.Valid { + _m.Valeur = new(string) + *_m.Valeur = value.String + } + case champpersonnalise.FieldUnite: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field unite", values[i]) + } else if value.Valid { + _m.Unite = new(string) + *_m.Unite = value.String + } + case champpersonnalise.FieldCreatedAt: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field created_at", values[i]) + } else if value.Valid { + _m.CreatedAt = value.Time + } + case champpersonnalise.FieldUpdatedAt: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field updated_at", values[i]) + } else if value.Valid { + _m.UpdatedAt = value.Time + } + default: + _m.selectValues.Set(columns[i], values[i]) + } + } + return nil +} + +// Value returns the ent.Value that was dynamically selected and assigned to the ChampPersonnalise. +// This includes values selected through modifiers, order, etc. +func (_m *ChampPersonnalise) Value(name string) (ent.Value, error) { + return _m.selectValues.Get(name) +} + +// QueryObjet queries the "objet" edge of the ChampPersonnalise entity. +func (_m *ChampPersonnalise) QueryObjet() *ObjetQuery { + return NewChampPersonnaliseClient(_m.config).QueryObjet(_m) +} + +// Update returns a builder for updating this ChampPersonnalise. +// Note that you need to call ChampPersonnalise.Unwrap() before calling this method if this ChampPersonnalise +// was returned from a transaction, and the transaction was committed or rolled back. +func (_m *ChampPersonnalise) Update() *ChampPersonnaliseUpdateOne { + return NewChampPersonnaliseClient(_m.config).UpdateOne(_m) +} + +// Unwrap unwraps the ChampPersonnalise entity that was returned from a transaction after it was closed, +// so that all future queries will be executed through the driver which created the transaction. +func (_m *ChampPersonnalise) Unwrap() *ChampPersonnalise { + _tx, ok := _m.config.driver.(*txDriver) + if !ok { + panic("ent: ChampPersonnalise is not a transactional entity") + } + _m.config.driver = _tx.drv + return _m +} + +// String implements the fmt.Stringer. +func (_m *ChampPersonnalise) String() string { + var builder strings.Builder + builder.WriteString("ChampPersonnalise(") + builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID)) + builder.WriteString("objet_id=") + builder.WriteString(fmt.Sprintf("%v", _m.ObjetID)) + builder.WriteString(", ") + builder.WriteString("nom_champ=") + builder.WriteString(_m.NomChamp) + builder.WriteString(", ") + builder.WriteString("type_champ=") + builder.WriteString(fmt.Sprintf("%v", _m.TypeChamp)) + builder.WriteString(", ") + if v := _m.Valeur; v != nil { + builder.WriteString("valeur=") + builder.WriteString(*v) + } + builder.WriteString(", ") + if v := _m.Unite; v != nil { + builder.WriteString("unite=") + builder.WriteString(*v) + } + builder.WriteString(", ") + builder.WriteString("created_at=") + builder.WriteString(_m.CreatedAt.Format(time.ANSIC)) + builder.WriteString(", ") + builder.WriteString("updated_at=") + builder.WriteString(_m.UpdatedAt.Format(time.ANSIC)) + builder.WriteByte(')') + return builder.String() +} + +// ChampPersonnalises is a parsable slice of ChampPersonnalise. +type ChampPersonnalises []*ChampPersonnalise diff --git a/backend/internal/data/ent/champpersonnalise/champpersonnalise.go b/backend/internal/data/ent/champpersonnalise/champpersonnalise.go new file mode 100644 index 0000000..79df2dc --- /dev/null +++ b/backend/internal/data/ent/champpersonnalise/champpersonnalise.go @@ -0,0 +1,164 @@ +// Code generated by ent, DO NOT EDIT. + +package champpersonnalise + +import ( + "fmt" + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "github.com/google/uuid" +) + +const ( + // Label holds the string label denoting the champpersonnalise type in the database. + Label = "champ_personnalise" + // FieldID holds the string denoting the id field in the database. + FieldID = "id" + // FieldObjetID holds the string denoting the objet_id field in the database. + FieldObjetID = "objet_id" + // FieldNomChamp holds the string denoting the nom_champ field in the database. + FieldNomChamp = "nom_champ" + // FieldTypeChamp holds the string denoting the type_champ field in the database. + FieldTypeChamp = "type_champ" + // FieldValeur holds the string denoting the valeur field in the database. + FieldValeur = "valeur" + // FieldUnite holds the string denoting the unite field in the database. + FieldUnite = "unite" + // FieldCreatedAt holds the string denoting the created_at field in the database. + FieldCreatedAt = "created_at" + // FieldUpdatedAt holds the string denoting the updated_at field in the database. + FieldUpdatedAt = "updated_at" + // EdgeObjet holds the string denoting the objet edge name in mutations. + EdgeObjet = "objet" + // Table holds the table name of the champpersonnalise in the database. + Table = "champ_personnalise" + // ObjetTable is the table that holds the objet relation/edge. + ObjetTable = "champ_personnalise" + // ObjetInverseTable is the table name for the Objet entity. + // It exists in this package in order to avoid circular dependency with the "objet" package. + ObjetInverseTable = "objet" + // ObjetColumn is the table column denoting the objet relation/edge. + ObjetColumn = "objet_id" +) + +// Columns holds all SQL columns for champpersonnalise fields. +var Columns = []string{ + FieldID, + FieldObjetID, + FieldNomChamp, + FieldTypeChamp, + FieldValeur, + FieldUnite, + FieldCreatedAt, + FieldUpdatedAt, +} + +// ValidColumn reports if the column name is valid (part of the table columns). +func ValidColumn(column string) bool { + for i := range Columns { + if column == Columns[i] { + return true + } + } + return false +} + +var ( + // NomChampValidator is a validator for the "nom_champ" field. It is called by the builders before save. + NomChampValidator func(string) error + // DefaultCreatedAt holds the default value on creation for the "created_at" field. + DefaultCreatedAt func() time.Time + // DefaultUpdatedAt holds the default value on creation for the "updated_at" field. + DefaultUpdatedAt func() time.Time + // UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field. + UpdateDefaultUpdatedAt func() time.Time + // DefaultID holds the default value on creation for the "id" field. + DefaultID func() uuid.UUID +) + +// TypeChamp defines the type for the "type_champ" enum field. +type TypeChamp string + +// TypeChampString is the default value of the TypeChamp enum. +const DefaultTypeChamp = TypeChampString + +// TypeChamp values. +const ( + TypeChampString TypeChamp = "string" + TypeChampInt TypeChamp = "int" + TypeChampBool TypeChamp = "bool" + TypeChampDate TypeChamp = "date" +) + +func (tc TypeChamp) String() string { + return string(tc) +} + +// TypeChampValidator is a validator for the "type_champ" field enum values. It is called by the builders before save. +func TypeChampValidator(tc TypeChamp) error { + switch tc { + case TypeChampString, TypeChampInt, TypeChampBool, TypeChampDate: + return nil + default: + return fmt.Errorf("champpersonnalise: invalid enum value for type_champ field: %q", tc) + } +} + +// OrderOption defines the ordering options for the ChampPersonnalise queries. +type OrderOption func(*sql.Selector) + +// ByID orders the results by the id field. +func ByID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldID, opts...).ToFunc() +} + +// ByObjetID orders the results by the objet_id field. +func ByObjetID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldObjetID, opts...).ToFunc() +} + +// ByNomChamp orders the results by the nom_champ field. +func ByNomChamp(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldNomChamp, opts...).ToFunc() +} + +// ByTypeChamp orders the results by the type_champ field. +func ByTypeChamp(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldTypeChamp, opts...).ToFunc() +} + +// ByValeur orders the results by the valeur field. +func ByValeur(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldValeur, opts...).ToFunc() +} + +// ByUnite orders the results by the unite field. +func ByUnite(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldUnite, opts...).ToFunc() +} + +// ByCreatedAt orders the results by the created_at field. +func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() +} + +// ByUpdatedAt orders the results by the updated_at field. +func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc() +} + +// ByObjetField orders the results by objet field. +func ByObjetField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newObjetStep(), sql.OrderByField(field, opts...)) + } +} +func newObjetStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(ObjetInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, ObjetTable, ObjetColumn), + ) +} diff --git a/backend/internal/data/ent/champpersonnalise/where.go b/backend/internal/data/ent/champpersonnalise/where.go new file mode 100644 index 0000000..02f9f6e --- /dev/null +++ b/backend/internal/data/ent/champpersonnalise/where.go @@ -0,0 +1,460 @@ +// Code generated by ent, DO NOT EDIT. + +package champpersonnalise + +import ( + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/predicate" + "github.com/google/uuid" +) + +// ID filters vertices based on their ID field. +func ID(id uuid.UUID) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldEQ(FieldID, id)) +} + +// IDEQ applies the EQ predicate on the ID field. +func IDEQ(id uuid.UUID) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldEQ(FieldID, id)) +} + +// IDNEQ applies the NEQ predicate on the ID field. +func IDNEQ(id uuid.UUID) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldNEQ(FieldID, id)) +} + +// IDIn applies the In predicate on the ID field. +func IDIn(ids ...uuid.UUID) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldIn(FieldID, ids...)) +} + +// IDNotIn applies the NotIn predicate on the ID field. +func IDNotIn(ids ...uuid.UUID) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldNotIn(FieldID, ids...)) +} + +// IDGT applies the GT predicate on the ID field. +func IDGT(id uuid.UUID) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldGT(FieldID, id)) +} + +// IDGTE applies the GTE predicate on the ID field. +func IDGTE(id uuid.UUID) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldGTE(FieldID, id)) +} + +// IDLT applies the LT predicate on the ID field. +func IDLT(id uuid.UUID) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldLT(FieldID, id)) +} + +// IDLTE applies the LTE predicate on the ID field. +func IDLTE(id uuid.UUID) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldLTE(FieldID, id)) +} + +// ObjetID applies equality check predicate on the "objet_id" field. It's identical to ObjetIDEQ. +func ObjetID(v uuid.UUID) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldEQ(FieldObjetID, v)) +} + +// NomChamp applies equality check predicate on the "nom_champ" field. It's identical to NomChampEQ. +func NomChamp(v string) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldEQ(FieldNomChamp, v)) +} + +// Valeur applies equality check predicate on the "valeur" field. It's identical to ValeurEQ. +func Valeur(v string) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldEQ(FieldValeur, v)) +} + +// Unite applies equality check predicate on the "unite" field. It's identical to UniteEQ. +func Unite(v string) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldEQ(FieldUnite, v)) +} + +// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. +func CreatedAt(v time.Time) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldEQ(FieldCreatedAt, v)) +} + +// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ. +func UpdatedAt(v time.Time) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldEQ(FieldUpdatedAt, v)) +} + +// ObjetIDEQ applies the EQ predicate on the "objet_id" field. +func ObjetIDEQ(v uuid.UUID) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldEQ(FieldObjetID, v)) +} + +// ObjetIDNEQ applies the NEQ predicate on the "objet_id" field. +func ObjetIDNEQ(v uuid.UUID) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldNEQ(FieldObjetID, v)) +} + +// ObjetIDIn applies the In predicate on the "objet_id" field. +func ObjetIDIn(vs ...uuid.UUID) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldIn(FieldObjetID, vs...)) +} + +// ObjetIDNotIn applies the NotIn predicate on the "objet_id" field. +func ObjetIDNotIn(vs ...uuid.UUID) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldNotIn(FieldObjetID, vs...)) +} + +// NomChampEQ applies the EQ predicate on the "nom_champ" field. +func NomChampEQ(v string) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldEQ(FieldNomChamp, v)) +} + +// NomChampNEQ applies the NEQ predicate on the "nom_champ" field. +func NomChampNEQ(v string) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldNEQ(FieldNomChamp, v)) +} + +// NomChampIn applies the In predicate on the "nom_champ" field. +func NomChampIn(vs ...string) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldIn(FieldNomChamp, vs...)) +} + +// NomChampNotIn applies the NotIn predicate on the "nom_champ" field. +func NomChampNotIn(vs ...string) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldNotIn(FieldNomChamp, vs...)) +} + +// NomChampGT applies the GT predicate on the "nom_champ" field. +func NomChampGT(v string) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldGT(FieldNomChamp, v)) +} + +// NomChampGTE applies the GTE predicate on the "nom_champ" field. +func NomChampGTE(v string) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldGTE(FieldNomChamp, v)) +} + +// NomChampLT applies the LT predicate on the "nom_champ" field. +func NomChampLT(v string) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldLT(FieldNomChamp, v)) +} + +// NomChampLTE applies the LTE predicate on the "nom_champ" field. +func NomChampLTE(v string) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldLTE(FieldNomChamp, v)) +} + +// NomChampContains applies the Contains predicate on the "nom_champ" field. +func NomChampContains(v string) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldContains(FieldNomChamp, v)) +} + +// NomChampHasPrefix applies the HasPrefix predicate on the "nom_champ" field. +func NomChampHasPrefix(v string) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldHasPrefix(FieldNomChamp, v)) +} + +// NomChampHasSuffix applies the HasSuffix predicate on the "nom_champ" field. +func NomChampHasSuffix(v string) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldHasSuffix(FieldNomChamp, v)) +} + +// NomChampEqualFold applies the EqualFold predicate on the "nom_champ" field. +func NomChampEqualFold(v string) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldEqualFold(FieldNomChamp, v)) +} + +// NomChampContainsFold applies the ContainsFold predicate on the "nom_champ" field. +func NomChampContainsFold(v string) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldContainsFold(FieldNomChamp, v)) +} + +// TypeChampEQ applies the EQ predicate on the "type_champ" field. +func TypeChampEQ(v TypeChamp) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldEQ(FieldTypeChamp, v)) +} + +// TypeChampNEQ applies the NEQ predicate on the "type_champ" field. +func TypeChampNEQ(v TypeChamp) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldNEQ(FieldTypeChamp, v)) +} + +// TypeChampIn applies the In predicate on the "type_champ" field. +func TypeChampIn(vs ...TypeChamp) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldIn(FieldTypeChamp, vs...)) +} + +// TypeChampNotIn applies the NotIn predicate on the "type_champ" field. +func TypeChampNotIn(vs ...TypeChamp) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldNotIn(FieldTypeChamp, vs...)) +} + +// ValeurEQ applies the EQ predicate on the "valeur" field. +func ValeurEQ(v string) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldEQ(FieldValeur, v)) +} + +// ValeurNEQ applies the NEQ predicate on the "valeur" field. +func ValeurNEQ(v string) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldNEQ(FieldValeur, v)) +} + +// ValeurIn applies the In predicate on the "valeur" field. +func ValeurIn(vs ...string) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldIn(FieldValeur, vs...)) +} + +// ValeurNotIn applies the NotIn predicate on the "valeur" field. +func ValeurNotIn(vs ...string) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldNotIn(FieldValeur, vs...)) +} + +// ValeurGT applies the GT predicate on the "valeur" field. +func ValeurGT(v string) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldGT(FieldValeur, v)) +} + +// ValeurGTE applies the GTE predicate on the "valeur" field. +func ValeurGTE(v string) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldGTE(FieldValeur, v)) +} + +// ValeurLT applies the LT predicate on the "valeur" field. +func ValeurLT(v string) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldLT(FieldValeur, v)) +} + +// ValeurLTE applies the LTE predicate on the "valeur" field. +func ValeurLTE(v string) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldLTE(FieldValeur, v)) +} + +// ValeurContains applies the Contains predicate on the "valeur" field. +func ValeurContains(v string) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldContains(FieldValeur, v)) +} + +// ValeurHasPrefix applies the HasPrefix predicate on the "valeur" field. +func ValeurHasPrefix(v string) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldHasPrefix(FieldValeur, v)) +} + +// ValeurHasSuffix applies the HasSuffix predicate on the "valeur" field. +func ValeurHasSuffix(v string) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldHasSuffix(FieldValeur, v)) +} + +// ValeurIsNil applies the IsNil predicate on the "valeur" field. +func ValeurIsNil() predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldIsNull(FieldValeur)) +} + +// ValeurNotNil applies the NotNil predicate on the "valeur" field. +func ValeurNotNil() predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldNotNull(FieldValeur)) +} + +// ValeurEqualFold applies the EqualFold predicate on the "valeur" field. +func ValeurEqualFold(v string) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldEqualFold(FieldValeur, v)) +} + +// ValeurContainsFold applies the ContainsFold predicate on the "valeur" field. +func ValeurContainsFold(v string) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldContainsFold(FieldValeur, v)) +} + +// UniteEQ applies the EQ predicate on the "unite" field. +func UniteEQ(v string) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldEQ(FieldUnite, v)) +} + +// UniteNEQ applies the NEQ predicate on the "unite" field. +func UniteNEQ(v string) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldNEQ(FieldUnite, v)) +} + +// UniteIn applies the In predicate on the "unite" field. +func UniteIn(vs ...string) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldIn(FieldUnite, vs...)) +} + +// UniteNotIn applies the NotIn predicate on the "unite" field. +func UniteNotIn(vs ...string) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldNotIn(FieldUnite, vs...)) +} + +// UniteGT applies the GT predicate on the "unite" field. +func UniteGT(v string) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldGT(FieldUnite, v)) +} + +// UniteGTE applies the GTE predicate on the "unite" field. +func UniteGTE(v string) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldGTE(FieldUnite, v)) +} + +// UniteLT applies the LT predicate on the "unite" field. +func UniteLT(v string) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldLT(FieldUnite, v)) +} + +// UniteLTE applies the LTE predicate on the "unite" field. +func UniteLTE(v string) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldLTE(FieldUnite, v)) +} + +// UniteContains applies the Contains predicate on the "unite" field. +func UniteContains(v string) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldContains(FieldUnite, v)) +} + +// UniteHasPrefix applies the HasPrefix predicate on the "unite" field. +func UniteHasPrefix(v string) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldHasPrefix(FieldUnite, v)) +} + +// UniteHasSuffix applies the HasSuffix predicate on the "unite" field. +func UniteHasSuffix(v string) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldHasSuffix(FieldUnite, v)) +} + +// UniteIsNil applies the IsNil predicate on the "unite" field. +func UniteIsNil() predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldIsNull(FieldUnite)) +} + +// UniteNotNil applies the NotNil predicate on the "unite" field. +func UniteNotNil() predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldNotNull(FieldUnite)) +} + +// UniteEqualFold applies the EqualFold predicate on the "unite" field. +func UniteEqualFold(v string) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldEqualFold(FieldUnite, v)) +} + +// UniteContainsFold applies the ContainsFold predicate on the "unite" field. +func UniteContainsFold(v string) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldContainsFold(FieldUnite, v)) +} + +// CreatedAtEQ applies the EQ predicate on the "created_at" field. +func CreatedAtEQ(v time.Time) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldEQ(FieldCreatedAt, v)) +} + +// CreatedAtNEQ applies the NEQ predicate on the "created_at" field. +func CreatedAtNEQ(v time.Time) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldNEQ(FieldCreatedAt, v)) +} + +// CreatedAtIn applies the In predicate on the "created_at" field. +func CreatedAtIn(vs ...time.Time) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldIn(FieldCreatedAt, vs...)) +} + +// CreatedAtNotIn applies the NotIn predicate on the "created_at" field. +func CreatedAtNotIn(vs ...time.Time) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldNotIn(FieldCreatedAt, vs...)) +} + +// CreatedAtGT applies the GT predicate on the "created_at" field. +func CreatedAtGT(v time.Time) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldGT(FieldCreatedAt, v)) +} + +// CreatedAtGTE applies the GTE predicate on the "created_at" field. +func CreatedAtGTE(v time.Time) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldGTE(FieldCreatedAt, v)) +} + +// CreatedAtLT applies the LT predicate on the "created_at" field. +func CreatedAtLT(v time.Time) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldLT(FieldCreatedAt, v)) +} + +// CreatedAtLTE applies the LTE predicate on the "created_at" field. +func CreatedAtLTE(v time.Time) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldLTE(FieldCreatedAt, v)) +} + +// UpdatedAtEQ applies the EQ predicate on the "updated_at" field. +func UpdatedAtEQ(v time.Time) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field. +func UpdatedAtNEQ(v time.Time) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldNEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtIn applies the In predicate on the "updated_at" field. +func UpdatedAtIn(vs ...time.Time) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field. +func UpdatedAtNotIn(vs ...time.Time) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldNotIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtGT applies the GT predicate on the "updated_at" field. +func UpdatedAtGT(v time.Time) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldGT(FieldUpdatedAt, v)) +} + +// UpdatedAtGTE applies the GTE predicate on the "updated_at" field. +func UpdatedAtGTE(v time.Time) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldGTE(FieldUpdatedAt, v)) +} + +// UpdatedAtLT applies the LT predicate on the "updated_at" field. +func UpdatedAtLT(v time.Time) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldLT(FieldUpdatedAt, v)) +} + +// UpdatedAtLTE applies the LTE predicate on the "updated_at" field. +func UpdatedAtLTE(v time.Time) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.FieldLTE(FieldUpdatedAt, v)) +} + +// HasObjet applies the HasEdge predicate on the "objet" edge. +func HasObjet() predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, ObjetTable, ObjetColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasObjetWith applies the HasEdge predicate on the "objet" edge with a given conditions (other predicates). +func HasObjetWith(preds ...predicate.Objet) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(func(s *sql.Selector) { + step := newObjetStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + +// And groups predicates with the AND operator between them. +func And(predicates ...predicate.ChampPersonnalise) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.AndPredicates(predicates...)) +} + +// Or groups predicates with the OR operator between them. +func Or(predicates ...predicate.ChampPersonnalise) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.OrPredicates(predicates...)) +} + +// Not applies the not operator on the given predicate. +func Not(p predicate.ChampPersonnalise) predicate.ChampPersonnalise { + return predicate.ChampPersonnalise(sql.NotPredicates(p)) +} diff --git a/backend/internal/data/ent/champpersonnalise_create.go b/backend/internal/data/ent/champpersonnalise_create.go new file mode 100644 index 0000000..d88f46c --- /dev/null +++ b/backend/internal/data/ent/champpersonnalise_create.go @@ -0,0 +1,370 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + "time" + + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/champpersonnalise" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/objet" + "github.com/google/uuid" +) + +// ChampPersonnaliseCreate is the builder for creating a ChampPersonnalise entity. +type ChampPersonnaliseCreate struct { + config + mutation *ChampPersonnaliseMutation + hooks []Hook +} + +// SetObjetID sets the "objet_id" field. +func (_c *ChampPersonnaliseCreate) SetObjetID(v uuid.UUID) *ChampPersonnaliseCreate { + _c.mutation.SetObjetID(v) + return _c +} + +// SetNomChamp sets the "nom_champ" field. +func (_c *ChampPersonnaliseCreate) SetNomChamp(v string) *ChampPersonnaliseCreate { + _c.mutation.SetNomChamp(v) + return _c +} + +// SetTypeChamp sets the "type_champ" field. +func (_c *ChampPersonnaliseCreate) SetTypeChamp(v champpersonnalise.TypeChamp) *ChampPersonnaliseCreate { + _c.mutation.SetTypeChamp(v) + return _c +} + +// SetNillableTypeChamp sets the "type_champ" field if the given value is not nil. +func (_c *ChampPersonnaliseCreate) SetNillableTypeChamp(v *champpersonnalise.TypeChamp) *ChampPersonnaliseCreate { + if v != nil { + _c.SetTypeChamp(*v) + } + return _c +} + +// SetValeur sets the "valeur" field. +func (_c *ChampPersonnaliseCreate) SetValeur(v string) *ChampPersonnaliseCreate { + _c.mutation.SetValeur(v) + return _c +} + +// SetNillableValeur sets the "valeur" field if the given value is not nil. +func (_c *ChampPersonnaliseCreate) SetNillableValeur(v *string) *ChampPersonnaliseCreate { + if v != nil { + _c.SetValeur(*v) + } + return _c +} + +// SetUnite sets the "unite" field. +func (_c *ChampPersonnaliseCreate) SetUnite(v string) *ChampPersonnaliseCreate { + _c.mutation.SetUnite(v) + return _c +} + +// SetNillableUnite sets the "unite" field if the given value is not nil. +func (_c *ChampPersonnaliseCreate) SetNillableUnite(v *string) *ChampPersonnaliseCreate { + if v != nil { + _c.SetUnite(*v) + } + return _c +} + +// SetCreatedAt sets the "created_at" field. +func (_c *ChampPersonnaliseCreate) SetCreatedAt(v time.Time) *ChampPersonnaliseCreate { + _c.mutation.SetCreatedAt(v) + return _c +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (_c *ChampPersonnaliseCreate) SetNillableCreatedAt(v *time.Time) *ChampPersonnaliseCreate { + if v != nil { + _c.SetCreatedAt(*v) + } + return _c +} + +// SetUpdatedAt sets the "updated_at" field. +func (_c *ChampPersonnaliseCreate) SetUpdatedAt(v time.Time) *ChampPersonnaliseCreate { + _c.mutation.SetUpdatedAt(v) + return _c +} + +// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. +func (_c *ChampPersonnaliseCreate) SetNillableUpdatedAt(v *time.Time) *ChampPersonnaliseCreate { + if v != nil { + _c.SetUpdatedAt(*v) + } + return _c +} + +// SetID sets the "id" field. +func (_c *ChampPersonnaliseCreate) SetID(v uuid.UUID) *ChampPersonnaliseCreate { + _c.mutation.SetID(v) + return _c +} + +// SetNillableID sets the "id" field if the given value is not nil. +func (_c *ChampPersonnaliseCreate) SetNillableID(v *uuid.UUID) *ChampPersonnaliseCreate { + if v != nil { + _c.SetID(*v) + } + return _c +} + +// SetObjet sets the "objet" edge to the Objet entity. +func (_c *ChampPersonnaliseCreate) SetObjet(v *Objet) *ChampPersonnaliseCreate { + return _c.SetObjetID(v.ID) +} + +// Mutation returns the ChampPersonnaliseMutation object of the builder. +func (_c *ChampPersonnaliseCreate) Mutation() *ChampPersonnaliseMutation { + return _c.mutation +} + +// Save creates the ChampPersonnalise in the database. +func (_c *ChampPersonnaliseCreate) Save(ctx context.Context) (*ChampPersonnalise, error) { + _c.defaults() + return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks) +} + +// SaveX calls Save and panics if Save returns an error. +func (_c *ChampPersonnaliseCreate) SaveX(ctx context.Context) *ChampPersonnalise { + v, err := _c.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (_c *ChampPersonnaliseCreate) Exec(ctx context.Context) error { + _, err := _c.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_c *ChampPersonnaliseCreate) ExecX(ctx context.Context) { + if err := _c.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (_c *ChampPersonnaliseCreate) defaults() { + if _, ok := _c.mutation.TypeChamp(); !ok { + v := champpersonnalise.DefaultTypeChamp + _c.mutation.SetTypeChamp(v) + } + if _, ok := _c.mutation.CreatedAt(); !ok { + v := champpersonnalise.DefaultCreatedAt() + _c.mutation.SetCreatedAt(v) + } + if _, ok := _c.mutation.UpdatedAt(); !ok { + v := champpersonnalise.DefaultUpdatedAt() + _c.mutation.SetUpdatedAt(v) + } + if _, ok := _c.mutation.ID(); !ok { + v := champpersonnalise.DefaultID() + _c.mutation.SetID(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_c *ChampPersonnaliseCreate) check() error { + if _, ok := _c.mutation.ObjetID(); !ok { + return &ValidationError{Name: "objet_id", err: errors.New(`ent: missing required field "ChampPersonnalise.objet_id"`)} + } + if _, ok := _c.mutation.NomChamp(); !ok { + return &ValidationError{Name: "nom_champ", err: errors.New(`ent: missing required field "ChampPersonnalise.nom_champ"`)} + } + if v, ok := _c.mutation.NomChamp(); ok { + if err := champpersonnalise.NomChampValidator(v); err != nil { + return &ValidationError{Name: "nom_champ", err: fmt.Errorf(`ent: validator failed for field "ChampPersonnalise.nom_champ": %w`, err)} + } + } + if _, ok := _c.mutation.TypeChamp(); !ok { + return &ValidationError{Name: "type_champ", err: errors.New(`ent: missing required field "ChampPersonnalise.type_champ"`)} + } + if v, ok := _c.mutation.TypeChamp(); ok { + if err := champpersonnalise.TypeChampValidator(v); err != nil { + return &ValidationError{Name: "type_champ", err: fmt.Errorf(`ent: validator failed for field "ChampPersonnalise.type_champ": %w`, err)} + } + } + if _, ok := _c.mutation.CreatedAt(); !ok { + return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "ChampPersonnalise.created_at"`)} + } + if _, ok := _c.mutation.UpdatedAt(); !ok { + return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "ChampPersonnalise.updated_at"`)} + } + if len(_c.mutation.ObjetIDs()) == 0 { + return &ValidationError{Name: "objet", err: errors.New(`ent: missing required edge "ChampPersonnalise.objet"`)} + } + return nil +} + +func (_c *ChampPersonnaliseCreate) sqlSave(ctx context.Context) (*ChampPersonnalise, error) { + if err := _c.check(); err != nil { + return nil, err + } + _node, _spec := _c.createSpec() + if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + if _spec.ID.Value != nil { + if id, ok := _spec.ID.Value.(*uuid.UUID); ok { + _node.ID = *id + } else if err := _node.ID.Scan(_spec.ID.Value); err != nil { + return nil, err + } + } + _c.mutation.id = &_node.ID + _c.mutation.done = true + return _node, nil +} + +func (_c *ChampPersonnaliseCreate) createSpec() (*ChampPersonnalise, *sqlgraph.CreateSpec) { + var ( + _node = &ChampPersonnalise{config: _c.config} + _spec = sqlgraph.NewCreateSpec(champpersonnalise.Table, sqlgraph.NewFieldSpec(champpersonnalise.FieldID, field.TypeUUID)) + ) + if id, ok := _c.mutation.ID(); ok { + _node.ID = id + _spec.ID.Value = &id + } + if value, ok := _c.mutation.NomChamp(); ok { + _spec.SetField(champpersonnalise.FieldNomChamp, field.TypeString, value) + _node.NomChamp = value + } + if value, ok := _c.mutation.TypeChamp(); ok { + _spec.SetField(champpersonnalise.FieldTypeChamp, field.TypeEnum, value) + _node.TypeChamp = value + } + if value, ok := _c.mutation.Valeur(); ok { + _spec.SetField(champpersonnalise.FieldValeur, field.TypeString, value) + _node.Valeur = &value + } + if value, ok := _c.mutation.Unite(); ok { + _spec.SetField(champpersonnalise.FieldUnite, field.TypeString, value) + _node.Unite = &value + } + if value, ok := _c.mutation.CreatedAt(); ok { + _spec.SetField(champpersonnalise.FieldCreatedAt, field.TypeTime, value) + _node.CreatedAt = value + } + if value, ok := _c.mutation.UpdatedAt(); ok { + _spec.SetField(champpersonnalise.FieldUpdatedAt, field.TypeTime, value) + _node.UpdatedAt = value + } + if nodes := _c.mutation.ObjetIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: champpersonnalise.ObjetTable, + Columns: []string{champpersonnalise.ObjetColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(objet.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _node.ObjetID = nodes[0] + _spec.Edges = append(_spec.Edges, edge) + } + return _node, _spec +} + +// ChampPersonnaliseCreateBulk is the builder for creating many ChampPersonnalise entities in bulk. +type ChampPersonnaliseCreateBulk struct { + config + err error + builders []*ChampPersonnaliseCreate +} + +// Save creates the ChampPersonnalise entities in the database. +func (_c *ChampPersonnaliseCreateBulk) Save(ctx context.Context) ([]*ChampPersonnalise, error) { + if _c.err != nil { + return nil, _c.err + } + specs := make([]*sqlgraph.CreateSpec, len(_c.builders)) + nodes := make([]*ChampPersonnalise, len(_c.builders)) + mutators := make([]Mutator, len(_c.builders)) + for i := range _c.builders { + func(i int, root context.Context) { + builder := _c.builders[i] + builder.defaults() + var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { + mutation, ok := m.(*ChampPersonnaliseMutation) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T", m) + } + if err := builder.check(); err != nil { + return nil, err + } + builder.mutation = mutation + var err error + nodes[i], specs[i] = builder.createSpec() + if i < len(mutators)-1 { + _, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation) + } else { + spec := &sqlgraph.BatchCreateSpec{Nodes: specs} + // Invoke the actual operation on the latest mutation in the chain. + if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + } + } + if err != nil { + return nil, err + } + mutation.id = &nodes[i].ID + mutation.done = true + return nodes[i], nil + }) + for i := len(builder.hooks) - 1; i >= 0; i-- { + mut = builder.hooks[i](mut) + } + mutators[i] = mut + }(i, ctx) + } + if len(mutators) > 0 { + if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil { + return nil, err + } + } + return nodes, nil +} + +// SaveX is like Save, but panics if an error occurs. +func (_c *ChampPersonnaliseCreateBulk) SaveX(ctx context.Context) []*ChampPersonnalise { + v, err := _c.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (_c *ChampPersonnaliseCreateBulk) Exec(ctx context.Context) error { + _, err := _c.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_c *ChampPersonnaliseCreateBulk) ExecX(ctx context.Context) { + if err := _c.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/backend/internal/data/ent/champpersonnalise_delete.go b/backend/internal/data/ent/champpersonnalise_delete.go new file mode 100644 index 0000000..f85cf77 --- /dev/null +++ b/backend/internal/data/ent/champpersonnalise_delete.go @@ -0,0 +1,88 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/champpersonnalise" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/predicate" +) + +// ChampPersonnaliseDelete is the builder for deleting a ChampPersonnalise entity. +type ChampPersonnaliseDelete struct { + config + hooks []Hook + mutation *ChampPersonnaliseMutation +} + +// Where appends a list predicates to the ChampPersonnaliseDelete builder. +func (_d *ChampPersonnaliseDelete) Where(ps ...predicate.ChampPersonnalise) *ChampPersonnaliseDelete { + _d.mutation.Where(ps...) + return _d +} + +// Exec executes the deletion query and returns how many vertices were deleted. +func (_d *ChampPersonnaliseDelete) Exec(ctx context.Context) (int, error) { + return withHooks(ctx, _d.sqlExec, _d.mutation, _d.hooks) +} + +// ExecX is like Exec, but panics if an error occurs. +func (_d *ChampPersonnaliseDelete) ExecX(ctx context.Context) int { + n, err := _d.Exec(ctx) + if err != nil { + panic(err) + } + return n +} + +func (_d *ChampPersonnaliseDelete) sqlExec(ctx context.Context) (int, error) { + _spec := sqlgraph.NewDeleteSpec(champpersonnalise.Table, sqlgraph.NewFieldSpec(champpersonnalise.FieldID, field.TypeUUID)) + if ps := _d.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + affected, err := sqlgraph.DeleteNodes(ctx, _d.driver, _spec) + if err != nil && sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + _d.mutation.done = true + return affected, err +} + +// ChampPersonnaliseDeleteOne is the builder for deleting a single ChampPersonnalise entity. +type ChampPersonnaliseDeleteOne struct { + _d *ChampPersonnaliseDelete +} + +// Where appends a list predicates to the ChampPersonnaliseDelete builder. +func (_d *ChampPersonnaliseDeleteOne) Where(ps ...predicate.ChampPersonnalise) *ChampPersonnaliseDeleteOne { + _d._d.mutation.Where(ps...) + return _d +} + +// Exec executes the deletion query. +func (_d *ChampPersonnaliseDeleteOne) Exec(ctx context.Context) error { + n, err := _d._d.Exec(ctx) + switch { + case err != nil: + return err + case n == 0: + return &NotFoundError{champpersonnalise.Label} + default: + return nil + } +} + +// ExecX is like Exec, but panics if an error occurs. +func (_d *ChampPersonnaliseDeleteOne) ExecX(ctx context.Context) { + if err := _d.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/backend/internal/data/ent/champpersonnalise_query.go b/backend/internal/data/ent/champpersonnalise_query.go new file mode 100644 index 0000000..d7c8002 --- /dev/null +++ b/backend/internal/data/ent/champpersonnalise_query.go @@ -0,0 +1,607 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "fmt" + "math" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/champpersonnalise" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/objet" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/predicate" + "github.com/google/uuid" +) + +// ChampPersonnaliseQuery is the builder for querying ChampPersonnalise entities. +type ChampPersonnaliseQuery struct { + config + ctx *QueryContext + order []champpersonnalise.OrderOption + inters []Interceptor + predicates []predicate.ChampPersonnalise + withObjet *ObjetQuery + // intermediate query (i.e. traversal path). + sql *sql.Selector + path func(context.Context) (*sql.Selector, error) +} + +// Where adds a new predicate for the ChampPersonnaliseQuery builder. +func (_q *ChampPersonnaliseQuery) Where(ps ...predicate.ChampPersonnalise) *ChampPersonnaliseQuery { + _q.predicates = append(_q.predicates, ps...) + return _q +} + +// Limit the number of records to be returned by this query. +func (_q *ChampPersonnaliseQuery) Limit(limit int) *ChampPersonnaliseQuery { + _q.ctx.Limit = &limit + return _q +} + +// Offset to start from. +func (_q *ChampPersonnaliseQuery) Offset(offset int) *ChampPersonnaliseQuery { + _q.ctx.Offset = &offset + return _q +} + +// Unique configures the query builder to filter duplicate records on query. +// By default, unique is set to true, and can be disabled using this method. +func (_q *ChampPersonnaliseQuery) Unique(unique bool) *ChampPersonnaliseQuery { + _q.ctx.Unique = &unique + return _q +} + +// Order specifies how the records should be ordered. +func (_q *ChampPersonnaliseQuery) Order(o ...champpersonnalise.OrderOption) *ChampPersonnaliseQuery { + _q.order = append(_q.order, o...) + return _q +} + +// QueryObjet chains the current query on the "objet" edge. +func (_q *ChampPersonnaliseQuery) QueryObjet() *ObjetQuery { + query := (&ObjetClient{config: _q.config}).Query() + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + selector := _q.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(champpersonnalise.Table, champpersonnalise.FieldID, selector), + sqlgraph.To(objet.Table, objet.FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, champpersonnalise.ObjetTable, champpersonnalise.ObjetColumn), + ) + fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) + return fromU, nil + } + return query +} + +// First returns the first ChampPersonnalise entity from the query. +// Returns a *NotFoundError when no ChampPersonnalise was found. +func (_q *ChampPersonnaliseQuery) First(ctx context.Context) (*ChampPersonnalise, error) { + nodes, err := _q.Limit(1).All(setContextOp(ctx, _q.ctx, ent.OpQueryFirst)) + if err != nil { + return nil, err + } + if len(nodes) == 0 { + return nil, &NotFoundError{champpersonnalise.Label} + } + return nodes[0], nil +} + +// FirstX is like First, but panics if an error occurs. +func (_q *ChampPersonnaliseQuery) FirstX(ctx context.Context) *ChampPersonnalise { + node, err := _q.First(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return node +} + +// FirstID returns the first ChampPersonnalise ID from the query. +// Returns a *NotFoundError when no ChampPersonnalise ID was found. +func (_q *ChampPersonnaliseQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { + var ids []uuid.UUID + if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil { + return + } + if len(ids) == 0 { + err = &NotFoundError{champpersonnalise.Label} + return + } + return ids[0], nil +} + +// FirstIDX is like FirstID, but panics if an error occurs. +func (_q *ChampPersonnaliseQuery) FirstIDX(ctx context.Context) uuid.UUID { + id, err := _q.FirstID(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return id +} + +// Only returns a single ChampPersonnalise entity found by the query, ensuring it only returns one. +// Returns a *NotSingularError when more than one ChampPersonnalise entity is found. +// Returns a *NotFoundError when no ChampPersonnalise entities are found. +func (_q *ChampPersonnaliseQuery) Only(ctx context.Context) (*ChampPersonnalise, error) { + nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly)) + if err != nil { + return nil, err + } + switch len(nodes) { + case 1: + return nodes[0], nil + case 0: + return nil, &NotFoundError{champpersonnalise.Label} + default: + return nil, &NotSingularError{champpersonnalise.Label} + } +} + +// OnlyX is like Only, but panics if an error occurs. +func (_q *ChampPersonnaliseQuery) OnlyX(ctx context.Context) *ChampPersonnalise { + node, err := _q.Only(ctx) + if err != nil { + panic(err) + } + return node +} + +// OnlyID is like Only, but returns the only ChampPersonnalise ID in the query. +// Returns a *NotSingularError when more than one ChampPersonnalise ID is found. +// Returns a *NotFoundError when no entities are found. +func (_q *ChampPersonnaliseQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { + var ids []uuid.UUID + if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryOnlyID)); err != nil { + return + } + switch len(ids) { + case 1: + id = ids[0] + case 0: + err = &NotFoundError{champpersonnalise.Label} + default: + err = &NotSingularError{champpersonnalise.Label} + } + return +} + +// OnlyIDX is like OnlyID, but panics if an error occurs. +func (_q *ChampPersonnaliseQuery) OnlyIDX(ctx context.Context) uuid.UUID { + id, err := _q.OnlyID(ctx) + if err != nil { + panic(err) + } + return id +} + +// All executes the query and returns a list of ChampPersonnalises. +func (_q *ChampPersonnaliseQuery) All(ctx context.Context) ([]*ChampPersonnalise, error) { + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll) + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + qr := querierAll[[]*ChampPersonnalise, *ChampPersonnaliseQuery]() + return withInterceptors[[]*ChampPersonnalise](ctx, _q, qr, _q.inters) +} + +// AllX is like All, but panics if an error occurs. +func (_q *ChampPersonnaliseQuery) AllX(ctx context.Context) []*ChampPersonnalise { + nodes, err := _q.All(ctx) + if err != nil { + panic(err) + } + return nodes +} + +// IDs executes the query and returns a list of ChampPersonnalise IDs. +func (_q *ChampPersonnaliseQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) { + if _q.ctx.Unique == nil && _q.path != nil { + _q.Unique(true) + } + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryIDs) + if err = _q.Select(champpersonnalise.FieldID).Scan(ctx, &ids); err != nil { + return nil, err + } + return ids, nil +} + +// IDsX is like IDs, but panics if an error occurs. +func (_q *ChampPersonnaliseQuery) IDsX(ctx context.Context) []uuid.UUID { + ids, err := _q.IDs(ctx) + if err != nil { + panic(err) + } + return ids +} + +// Count returns the count of the given query. +func (_q *ChampPersonnaliseQuery) Count(ctx context.Context) (int, error) { + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryCount) + if err := _q.prepareQuery(ctx); err != nil { + return 0, err + } + return withInterceptors[int](ctx, _q, querierCount[*ChampPersonnaliseQuery](), _q.inters) +} + +// CountX is like Count, but panics if an error occurs. +func (_q *ChampPersonnaliseQuery) CountX(ctx context.Context) int { + count, err := _q.Count(ctx) + if err != nil { + panic(err) + } + return count +} + +// Exist returns true if the query has elements in the graph. +func (_q *ChampPersonnaliseQuery) Exist(ctx context.Context) (bool, error) { + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryExist) + switch _, err := _q.FirstID(ctx); { + case IsNotFound(err): + return false, nil + case err != nil: + return false, fmt.Errorf("ent: check existence: %w", err) + default: + return true, nil + } +} + +// ExistX is like Exist, but panics if an error occurs. +func (_q *ChampPersonnaliseQuery) ExistX(ctx context.Context) bool { + exist, err := _q.Exist(ctx) + if err != nil { + panic(err) + } + return exist +} + +// Clone returns a duplicate of the ChampPersonnaliseQuery builder, including all associated steps. It can be +// used to prepare common query builders and use them differently after the clone is made. +func (_q *ChampPersonnaliseQuery) Clone() *ChampPersonnaliseQuery { + if _q == nil { + return nil + } + return &ChampPersonnaliseQuery{ + config: _q.config, + ctx: _q.ctx.Clone(), + order: append([]champpersonnalise.OrderOption{}, _q.order...), + inters: append([]Interceptor{}, _q.inters...), + predicates: append([]predicate.ChampPersonnalise{}, _q.predicates...), + withObjet: _q.withObjet.Clone(), + // clone intermediate query. + sql: _q.sql.Clone(), + path: _q.path, + } +} + +// WithObjet tells the query-builder to eager-load the nodes that are connected to +// the "objet" edge. The optional arguments are used to configure the query builder of the edge. +func (_q *ChampPersonnaliseQuery) WithObjet(opts ...func(*ObjetQuery)) *ChampPersonnaliseQuery { + query := (&ObjetClient{config: _q.config}).Query() + for _, opt := range opts { + opt(query) + } + _q.withObjet = query + return _q +} + +// GroupBy is used to group vertices by one or more fields/columns. +// It is often used with aggregate functions, like: count, max, mean, min, sum. +// +// Example: +// +// var v []struct { +// ObjetID uuid.UUID `json:"objet_id,omitempty"` +// Count int `json:"count,omitempty"` +// } +// +// client.ChampPersonnalise.Query(). +// GroupBy(champpersonnalise.FieldObjetID). +// Aggregate(ent.Count()). +// Scan(ctx, &v) +func (_q *ChampPersonnaliseQuery) GroupBy(field string, fields ...string) *ChampPersonnaliseGroupBy { + _q.ctx.Fields = append([]string{field}, fields...) + grbuild := &ChampPersonnaliseGroupBy{build: _q} + grbuild.flds = &_q.ctx.Fields + grbuild.label = champpersonnalise.Label + grbuild.scan = grbuild.Scan + return grbuild +} + +// Select allows the selection one or more fields/columns for the given query, +// instead of selecting all fields in the entity. +// +// Example: +// +// var v []struct { +// ObjetID uuid.UUID `json:"objet_id,omitempty"` +// } +// +// client.ChampPersonnalise.Query(). +// Select(champpersonnalise.FieldObjetID). +// Scan(ctx, &v) +func (_q *ChampPersonnaliseQuery) Select(fields ...string) *ChampPersonnaliseSelect { + _q.ctx.Fields = append(_q.ctx.Fields, fields...) + sbuild := &ChampPersonnaliseSelect{ChampPersonnaliseQuery: _q} + sbuild.label = champpersonnalise.Label + sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan + return sbuild +} + +// Aggregate returns a ChampPersonnaliseSelect configured with the given aggregations. +func (_q *ChampPersonnaliseQuery) Aggregate(fns ...AggregateFunc) *ChampPersonnaliseSelect { + return _q.Select().Aggregate(fns...) +} + +func (_q *ChampPersonnaliseQuery) prepareQuery(ctx context.Context) error { + for _, inter := range _q.inters { + if inter == nil { + return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)") + } + if trv, ok := inter.(Traverser); ok { + if err := trv.Traverse(ctx, _q); err != nil { + return err + } + } + } + for _, f := range _q.ctx.Fields { + if !champpersonnalise.ValidColumn(f) { + return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + } + if _q.path != nil { + prev, err := _q.path(ctx) + if err != nil { + return err + } + _q.sql = prev + } + return nil +} + +func (_q *ChampPersonnaliseQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*ChampPersonnalise, error) { + var ( + nodes = []*ChampPersonnalise{} + _spec = _q.querySpec() + loadedTypes = [1]bool{ + _q.withObjet != nil, + } + ) + _spec.ScanValues = func(columns []string) ([]any, error) { + return (*ChampPersonnalise).scanValues(nil, columns) + } + _spec.Assign = func(columns []string, values []any) error { + node := &ChampPersonnalise{config: _q.config} + nodes = append(nodes, node) + node.Edges.loadedTypes = loadedTypes + return node.assignValues(columns, values) + } + for i := range hooks { + hooks[i](ctx, _spec) + } + if err := sqlgraph.QueryNodes(ctx, _q.driver, _spec); err != nil { + return nil, err + } + if len(nodes) == 0 { + return nodes, nil + } + if query := _q.withObjet; query != nil { + if err := _q.loadObjet(ctx, query, nodes, nil, + func(n *ChampPersonnalise, e *Objet) { n.Edges.Objet = e }); err != nil { + return nil, err + } + } + return nodes, nil +} + +func (_q *ChampPersonnaliseQuery) loadObjet(ctx context.Context, query *ObjetQuery, nodes []*ChampPersonnalise, init func(*ChampPersonnalise), assign func(*ChampPersonnalise, *Objet)) error { + ids := make([]uuid.UUID, 0, len(nodes)) + nodeids := make(map[uuid.UUID][]*ChampPersonnalise) + for i := range nodes { + fk := nodes[i].ObjetID + if _, ok := nodeids[fk]; !ok { + ids = append(ids, fk) + } + nodeids[fk] = append(nodeids[fk], nodes[i]) + } + if len(ids) == 0 { + return nil + } + query.Where(objet.IDIn(ids...)) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + nodes, ok := nodeids[n.ID] + if !ok { + return fmt.Errorf(`unexpected foreign-key "objet_id" returned %v`, n.ID) + } + for i := range nodes { + assign(nodes[i], n) + } + } + return nil +} + +func (_q *ChampPersonnaliseQuery) sqlCount(ctx context.Context) (int, error) { + _spec := _q.querySpec() + _spec.Node.Columns = _q.ctx.Fields + if len(_q.ctx.Fields) > 0 { + _spec.Unique = _q.ctx.Unique != nil && *_q.ctx.Unique + } + return sqlgraph.CountNodes(ctx, _q.driver, _spec) +} + +func (_q *ChampPersonnaliseQuery) querySpec() *sqlgraph.QuerySpec { + _spec := sqlgraph.NewQuerySpec(champpersonnalise.Table, champpersonnalise.Columns, sqlgraph.NewFieldSpec(champpersonnalise.FieldID, field.TypeUUID)) + _spec.From = _q.sql + if unique := _q.ctx.Unique; unique != nil { + _spec.Unique = *unique + } else if _q.path != nil { + _spec.Unique = true + } + if fields := _q.ctx.Fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, champpersonnalise.FieldID) + for i := range fields { + if fields[i] != champpersonnalise.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) + } + } + if _q.withObjet != nil { + _spec.Node.AddColumnOnce(champpersonnalise.FieldObjetID) + } + } + if ps := _q.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if limit := _q.ctx.Limit; limit != nil { + _spec.Limit = *limit + } + if offset := _q.ctx.Offset; offset != nil { + _spec.Offset = *offset + } + if ps := _q.order; len(ps) > 0 { + _spec.Order = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + return _spec +} + +func (_q *ChampPersonnaliseQuery) sqlQuery(ctx context.Context) *sql.Selector { + builder := sql.Dialect(_q.driver.Dialect()) + t1 := builder.Table(champpersonnalise.Table) + columns := _q.ctx.Fields + if len(columns) == 0 { + columns = champpersonnalise.Columns + } + selector := builder.Select(t1.Columns(columns...)...).From(t1) + if _q.sql != nil { + selector = _q.sql + selector.Select(selector.Columns(columns...)...) + } + if _q.ctx.Unique != nil && *_q.ctx.Unique { + selector.Distinct() + } + for _, p := range _q.predicates { + p(selector) + } + for _, p := range _q.order { + p(selector) + } + if offset := _q.ctx.Offset; offset != nil { + // limit is mandatory for offset clause. We start + // with default value, and override it below if needed. + selector.Offset(*offset).Limit(math.MaxInt32) + } + if limit := _q.ctx.Limit; limit != nil { + selector.Limit(*limit) + } + return selector +} + +// ChampPersonnaliseGroupBy is the group-by builder for ChampPersonnalise entities. +type ChampPersonnaliseGroupBy struct { + selector + build *ChampPersonnaliseQuery +} + +// Aggregate adds the given aggregation functions to the group-by query. +func (_g *ChampPersonnaliseGroupBy) Aggregate(fns ...AggregateFunc) *ChampPersonnaliseGroupBy { + _g.fns = append(_g.fns, fns...) + return _g +} + +// Scan applies the selector query and scans the result into the given value. +func (_g *ChampPersonnaliseGroupBy) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, _g.build.ctx, ent.OpQueryGroupBy) + if err := _g.build.prepareQuery(ctx); err != nil { + return err + } + return scanWithInterceptors[*ChampPersonnaliseQuery, *ChampPersonnaliseGroupBy](ctx, _g.build, _g, _g.build.inters, v) +} + +func (_g *ChampPersonnaliseGroupBy) sqlScan(ctx context.Context, root *ChampPersonnaliseQuery, v any) error { + selector := root.sqlQuery(ctx).Select() + aggregation := make([]string, 0, len(_g.fns)) + for _, fn := range _g.fns { + aggregation = append(aggregation, fn(selector)) + } + if len(selector.SelectedColumns()) == 0 { + columns := make([]string, 0, len(*_g.flds)+len(_g.fns)) + for _, f := range *_g.flds { + columns = append(columns, selector.C(f)) + } + columns = append(columns, aggregation...) + selector.Select(columns...) + } + selector.GroupBy(selector.Columns(*_g.flds...)...) + if err := selector.Err(); err != nil { + return err + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := _g.build.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} + +// ChampPersonnaliseSelect is the builder for selecting fields of ChampPersonnalise entities. +type ChampPersonnaliseSelect struct { + *ChampPersonnaliseQuery + selector +} + +// Aggregate adds the given aggregation functions to the selector query. +func (_s *ChampPersonnaliseSelect) Aggregate(fns ...AggregateFunc) *ChampPersonnaliseSelect { + _s.fns = append(_s.fns, fns...) + return _s +} + +// Scan applies the selector query and scans the result into the given value. +func (_s *ChampPersonnaliseSelect) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, _s.ctx, ent.OpQuerySelect) + if err := _s.prepareQuery(ctx); err != nil { + return err + } + return scanWithInterceptors[*ChampPersonnaliseQuery, *ChampPersonnaliseSelect](ctx, _s.ChampPersonnaliseQuery, _s, _s.inters, v) +} + +func (_s *ChampPersonnaliseSelect) sqlScan(ctx context.Context, root *ChampPersonnaliseQuery, v any) error { + selector := root.sqlQuery(ctx) + aggregation := make([]string, 0, len(_s.fns)) + for _, fn := range _s.fns { + aggregation = append(aggregation, fn(selector)) + } + switch n := len(*_s.selector.flds); { + case n == 0 && len(aggregation) > 0: + selector.Select(aggregation...) + case n != 0 && len(aggregation) > 0: + selector.AppendSelect(aggregation...) + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := _s.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} diff --git a/backend/internal/data/ent/champpersonnalise_update.go b/backend/internal/data/ent/champpersonnalise_update.go new file mode 100644 index 0000000..b6c3e50 --- /dev/null +++ b/backend/internal/data/ent/champpersonnalise_update.go @@ -0,0 +1,570 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/champpersonnalise" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/objet" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/predicate" + "github.com/google/uuid" +) + +// ChampPersonnaliseUpdate is the builder for updating ChampPersonnalise entities. +type ChampPersonnaliseUpdate struct { + config + hooks []Hook + mutation *ChampPersonnaliseMutation +} + +// Where appends a list predicates to the ChampPersonnaliseUpdate builder. +func (_u *ChampPersonnaliseUpdate) Where(ps ...predicate.ChampPersonnalise) *ChampPersonnaliseUpdate { + _u.mutation.Where(ps...) + return _u +} + +// SetObjetID sets the "objet_id" field. +func (_u *ChampPersonnaliseUpdate) SetObjetID(v uuid.UUID) *ChampPersonnaliseUpdate { + _u.mutation.SetObjetID(v) + return _u +} + +// SetNillableObjetID sets the "objet_id" field if the given value is not nil. +func (_u *ChampPersonnaliseUpdate) SetNillableObjetID(v *uuid.UUID) *ChampPersonnaliseUpdate { + if v != nil { + _u.SetObjetID(*v) + } + return _u +} + +// SetNomChamp sets the "nom_champ" field. +func (_u *ChampPersonnaliseUpdate) SetNomChamp(v string) *ChampPersonnaliseUpdate { + _u.mutation.SetNomChamp(v) + return _u +} + +// SetNillableNomChamp sets the "nom_champ" field if the given value is not nil. +func (_u *ChampPersonnaliseUpdate) SetNillableNomChamp(v *string) *ChampPersonnaliseUpdate { + if v != nil { + _u.SetNomChamp(*v) + } + return _u +} + +// SetTypeChamp sets the "type_champ" field. +func (_u *ChampPersonnaliseUpdate) SetTypeChamp(v champpersonnalise.TypeChamp) *ChampPersonnaliseUpdate { + _u.mutation.SetTypeChamp(v) + return _u +} + +// SetNillableTypeChamp sets the "type_champ" field if the given value is not nil. +func (_u *ChampPersonnaliseUpdate) SetNillableTypeChamp(v *champpersonnalise.TypeChamp) *ChampPersonnaliseUpdate { + if v != nil { + _u.SetTypeChamp(*v) + } + return _u +} + +// SetValeur sets the "valeur" field. +func (_u *ChampPersonnaliseUpdate) SetValeur(v string) *ChampPersonnaliseUpdate { + _u.mutation.SetValeur(v) + return _u +} + +// SetNillableValeur sets the "valeur" field if the given value is not nil. +func (_u *ChampPersonnaliseUpdate) SetNillableValeur(v *string) *ChampPersonnaliseUpdate { + if v != nil { + _u.SetValeur(*v) + } + return _u +} + +// ClearValeur clears the value of the "valeur" field. +func (_u *ChampPersonnaliseUpdate) ClearValeur() *ChampPersonnaliseUpdate { + _u.mutation.ClearValeur() + return _u +} + +// SetUnite sets the "unite" field. +func (_u *ChampPersonnaliseUpdate) SetUnite(v string) *ChampPersonnaliseUpdate { + _u.mutation.SetUnite(v) + return _u +} + +// SetNillableUnite sets the "unite" field if the given value is not nil. +func (_u *ChampPersonnaliseUpdate) SetNillableUnite(v *string) *ChampPersonnaliseUpdate { + if v != nil { + _u.SetUnite(*v) + } + return _u +} + +// ClearUnite clears the value of the "unite" field. +func (_u *ChampPersonnaliseUpdate) ClearUnite() *ChampPersonnaliseUpdate { + _u.mutation.ClearUnite() + return _u +} + +// SetCreatedAt sets the "created_at" field. +func (_u *ChampPersonnaliseUpdate) SetCreatedAt(v time.Time) *ChampPersonnaliseUpdate { + _u.mutation.SetCreatedAt(v) + return _u +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (_u *ChampPersonnaliseUpdate) SetNillableCreatedAt(v *time.Time) *ChampPersonnaliseUpdate { + if v != nil { + _u.SetCreatedAt(*v) + } + return _u +} + +// SetUpdatedAt sets the "updated_at" field. +func (_u *ChampPersonnaliseUpdate) SetUpdatedAt(v time.Time) *ChampPersonnaliseUpdate { + _u.mutation.SetUpdatedAt(v) + return _u +} + +// SetObjet sets the "objet" edge to the Objet entity. +func (_u *ChampPersonnaliseUpdate) SetObjet(v *Objet) *ChampPersonnaliseUpdate { + return _u.SetObjetID(v.ID) +} + +// Mutation returns the ChampPersonnaliseMutation object of the builder. +func (_u *ChampPersonnaliseUpdate) Mutation() *ChampPersonnaliseMutation { + return _u.mutation +} + +// ClearObjet clears the "objet" edge to the Objet entity. +func (_u *ChampPersonnaliseUpdate) ClearObjet() *ChampPersonnaliseUpdate { + _u.mutation.ClearObjet() + return _u +} + +// Save executes the query and returns the number of nodes affected by the update operation. +func (_u *ChampPersonnaliseUpdate) Save(ctx context.Context) (int, error) { + _u.defaults() + return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (_u *ChampPersonnaliseUpdate) SaveX(ctx context.Context) int { + affected, err := _u.Save(ctx) + if err != nil { + panic(err) + } + return affected +} + +// Exec executes the query. +func (_u *ChampPersonnaliseUpdate) Exec(ctx context.Context) error { + _, err := _u.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_u *ChampPersonnaliseUpdate) ExecX(ctx context.Context) { + if err := _u.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (_u *ChampPersonnaliseUpdate) defaults() { + if _, ok := _u.mutation.UpdatedAt(); !ok { + v := champpersonnalise.UpdateDefaultUpdatedAt() + _u.mutation.SetUpdatedAt(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_u *ChampPersonnaliseUpdate) check() error { + if v, ok := _u.mutation.NomChamp(); ok { + if err := champpersonnalise.NomChampValidator(v); err != nil { + return &ValidationError{Name: "nom_champ", err: fmt.Errorf(`ent: validator failed for field "ChampPersonnalise.nom_champ": %w`, err)} + } + } + if v, ok := _u.mutation.TypeChamp(); ok { + if err := champpersonnalise.TypeChampValidator(v); err != nil { + return &ValidationError{Name: "type_champ", err: fmt.Errorf(`ent: validator failed for field "ChampPersonnalise.type_champ": %w`, err)} + } + } + if _u.mutation.ObjetCleared() && len(_u.mutation.ObjetIDs()) > 0 { + return errors.New(`ent: clearing a required unique edge "ChampPersonnalise.objet"`) + } + return nil +} + +func (_u *ChampPersonnaliseUpdate) sqlSave(ctx context.Context) (_node int, err error) { + if err := _u.check(); err != nil { + return _node, err + } + _spec := sqlgraph.NewUpdateSpec(champpersonnalise.Table, champpersonnalise.Columns, sqlgraph.NewFieldSpec(champpersonnalise.FieldID, field.TypeUUID)) + if ps := _u.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := _u.mutation.NomChamp(); ok { + _spec.SetField(champpersonnalise.FieldNomChamp, field.TypeString, value) + } + if value, ok := _u.mutation.TypeChamp(); ok { + _spec.SetField(champpersonnalise.FieldTypeChamp, field.TypeEnum, value) + } + if value, ok := _u.mutation.Valeur(); ok { + _spec.SetField(champpersonnalise.FieldValeur, field.TypeString, value) + } + if _u.mutation.ValeurCleared() { + _spec.ClearField(champpersonnalise.FieldValeur, field.TypeString) + } + if value, ok := _u.mutation.Unite(); ok { + _spec.SetField(champpersonnalise.FieldUnite, field.TypeString, value) + } + if _u.mutation.UniteCleared() { + _spec.ClearField(champpersonnalise.FieldUnite, field.TypeString) + } + if value, ok := _u.mutation.CreatedAt(); ok { + _spec.SetField(champpersonnalise.FieldCreatedAt, field.TypeTime, value) + } + if value, ok := _u.mutation.UpdatedAt(); ok { + _spec.SetField(champpersonnalise.FieldUpdatedAt, field.TypeTime, value) + } + if _u.mutation.ObjetCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: champpersonnalise.ObjetTable, + Columns: []string{champpersonnalise.ObjetColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(objet.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.ObjetIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: champpersonnalise.ObjetTable, + Columns: []string{champpersonnalise.ObjetColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(objet.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{champpersonnalise.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return 0, err + } + _u.mutation.done = true + return _node, nil +} + +// ChampPersonnaliseUpdateOne is the builder for updating a single ChampPersonnalise entity. +type ChampPersonnaliseUpdateOne struct { + config + fields []string + hooks []Hook + mutation *ChampPersonnaliseMutation +} + +// SetObjetID sets the "objet_id" field. +func (_u *ChampPersonnaliseUpdateOne) SetObjetID(v uuid.UUID) *ChampPersonnaliseUpdateOne { + _u.mutation.SetObjetID(v) + return _u +} + +// SetNillableObjetID sets the "objet_id" field if the given value is not nil. +func (_u *ChampPersonnaliseUpdateOne) SetNillableObjetID(v *uuid.UUID) *ChampPersonnaliseUpdateOne { + if v != nil { + _u.SetObjetID(*v) + } + return _u +} + +// SetNomChamp sets the "nom_champ" field. +func (_u *ChampPersonnaliseUpdateOne) SetNomChamp(v string) *ChampPersonnaliseUpdateOne { + _u.mutation.SetNomChamp(v) + return _u +} + +// SetNillableNomChamp sets the "nom_champ" field if the given value is not nil. +func (_u *ChampPersonnaliseUpdateOne) SetNillableNomChamp(v *string) *ChampPersonnaliseUpdateOne { + if v != nil { + _u.SetNomChamp(*v) + } + return _u +} + +// SetTypeChamp sets the "type_champ" field. +func (_u *ChampPersonnaliseUpdateOne) SetTypeChamp(v champpersonnalise.TypeChamp) *ChampPersonnaliseUpdateOne { + _u.mutation.SetTypeChamp(v) + return _u +} + +// SetNillableTypeChamp sets the "type_champ" field if the given value is not nil. +func (_u *ChampPersonnaliseUpdateOne) SetNillableTypeChamp(v *champpersonnalise.TypeChamp) *ChampPersonnaliseUpdateOne { + if v != nil { + _u.SetTypeChamp(*v) + } + return _u +} + +// SetValeur sets the "valeur" field. +func (_u *ChampPersonnaliseUpdateOne) SetValeur(v string) *ChampPersonnaliseUpdateOne { + _u.mutation.SetValeur(v) + return _u +} + +// SetNillableValeur sets the "valeur" field if the given value is not nil. +func (_u *ChampPersonnaliseUpdateOne) SetNillableValeur(v *string) *ChampPersonnaliseUpdateOne { + if v != nil { + _u.SetValeur(*v) + } + return _u +} + +// ClearValeur clears the value of the "valeur" field. +func (_u *ChampPersonnaliseUpdateOne) ClearValeur() *ChampPersonnaliseUpdateOne { + _u.mutation.ClearValeur() + return _u +} + +// SetUnite sets the "unite" field. +func (_u *ChampPersonnaliseUpdateOne) SetUnite(v string) *ChampPersonnaliseUpdateOne { + _u.mutation.SetUnite(v) + return _u +} + +// SetNillableUnite sets the "unite" field if the given value is not nil. +func (_u *ChampPersonnaliseUpdateOne) SetNillableUnite(v *string) *ChampPersonnaliseUpdateOne { + if v != nil { + _u.SetUnite(*v) + } + return _u +} + +// ClearUnite clears the value of the "unite" field. +func (_u *ChampPersonnaliseUpdateOne) ClearUnite() *ChampPersonnaliseUpdateOne { + _u.mutation.ClearUnite() + return _u +} + +// SetCreatedAt sets the "created_at" field. +func (_u *ChampPersonnaliseUpdateOne) SetCreatedAt(v time.Time) *ChampPersonnaliseUpdateOne { + _u.mutation.SetCreatedAt(v) + return _u +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (_u *ChampPersonnaliseUpdateOne) SetNillableCreatedAt(v *time.Time) *ChampPersonnaliseUpdateOne { + if v != nil { + _u.SetCreatedAt(*v) + } + return _u +} + +// SetUpdatedAt sets the "updated_at" field. +func (_u *ChampPersonnaliseUpdateOne) SetUpdatedAt(v time.Time) *ChampPersonnaliseUpdateOne { + _u.mutation.SetUpdatedAt(v) + return _u +} + +// SetObjet sets the "objet" edge to the Objet entity. +func (_u *ChampPersonnaliseUpdateOne) SetObjet(v *Objet) *ChampPersonnaliseUpdateOne { + return _u.SetObjetID(v.ID) +} + +// Mutation returns the ChampPersonnaliseMutation object of the builder. +func (_u *ChampPersonnaliseUpdateOne) Mutation() *ChampPersonnaliseMutation { + return _u.mutation +} + +// ClearObjet clears the "objet" edge to the Objet entity. +func (_u *ChampPersonnaliseUpdateOne) ClearObjet() *ChampPersonnaliseUpdateOne { + _u.mutation.ClearObjet() + return _u +} + +// Where appends a list predicates to the ChampPersonnaliseUpdate builder. +func (_u *ChampPersonnaliseUpdateOne) Where(ps ...predicate.ChampPersonnalise) *ChampPersonnaliseUpdateOne { + _u.mutation.Where(ps...) + return _u +} + +// Select allows selecting one or more fields (columns) of the returned entity. +// The default is selecting all fields defined in the entity schema. +func (_u *ChampPersonnaliseUpdateOne) Select(field string, fields ...string) *ChampPersonnaliseUpdateOne { + _u.fields = append([]string{field}, fields...) + return _u +} + +// Save executes the query and returns the updated ChampPersonnalise entity. +func (_u *ChampPersonnaliseUpdateOne) Save(ctx context.Context) (*ChampPersonnalise, error) { + _u.defaults() + return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (_u *ChampPersonnaliseUpdateOne) SaveX(ctx context.Context) *ChampPersonnalise { + node, err := _u.Save(ctx) + if err != nil { + panic(err) + } + return node +} + +// Exec executes the query on the entity. +func (_u *ChampPersonnaliseUpdateOne) Exec(ctx context.Context) error { + _, err := _u.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_u *ChampPersonnaliseUpdateOne) ExecX(ctx context.Context) { + if err := _u.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (_u *ChampPersonnaliseUpdateOne) defaults() { + if _, ok := _u.mutation.UpdatedAt(); !ok { + v := champpersonnalise.UpdateDefaultUpdatedAt() + _u.mutation.SetUpdatedAt(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_u *ChampPersonnaliseUpdateOne) check() error { + if v, ok := _u.mutation.NomChamp(); ok { + if err := champpersonnalise.NomChampValidator(v); err != nil { + return &ValidationError{Name: "nom_champ", err: fmt.Errorf(`ent: validator failed for field "ChampPersonnalise.nom_champ": %w`, err)} + } + } + if v, ok := _u.mutation.TypeChamp(); ok { + if err := champpersonnalise.TypeChampValidator(v); err != nil { + return &ValidationError{Name: "type_champ", err: fmt.Errorf(`ent: validator failed for field "ChampPersonnalise.type_champ": %w`, err)} + } + } + if _u.mutation.ObjetCleared() && len(_u.mutation.ObjetIDs()) > 0 { + return errors.New(`ent: clearing a required unique edge "ChampPersonnalise.objet"`) + } + return nil +} + +func (_u *ChampPersonnaliseUpdateOne) sqlSave(ctx context.Context) (_node *ChampPersonnalise, err error) { + if err := _u.check(); err != nil { + return _node, err + } + _spec := sqlgraph.NewUpdateSpec(champpersonnalise.Table, champpersonnalise.Columns, sqlgraph.NewFieldSpec(champpersonnalise.FieldID, field.TypeUUID)) + id, ok := _u.mutation.ID() + if !ok { + return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "ChampPersonnalise.id" for update`)} + } + _spec.Node.ID.Value = id + if fields := _u.fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, champpersonnalise.FieldID) + for _, f := range fields { + if !champpersonnalise.ValidColumn(f) { + return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + if f != champpersonnalise.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, f) + } + } + } + if ps := _u.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := _u.mutation.NomChamp(); ok { + _spec.SetField(champpersonnalise.FieldNomChamp, field.TypeString, value) + } + if value, ok := _u.mutation.TypeChamp(); ok { + _spec.SetField(champpersonnalise.FieldTypeChamp, field.TypeEnum, value) + } + if value, ok := _u.mutation.Valeur(); ok { + _spec.SetField(champpersonnalise.FieldValeur, field.TypeString, value) + } + if _u.mutation.ValeurCleared() { + _spec.ClearField(champpersonnalise.FieldValeur, field.TypeString) + } + if value, ok := _u.mutation.Unite(); ok { + _spec.SetField(champpersonnalise.FieldUnite, field.TypeString, value) + } + if _u.mutation.UniteCleared() { + _spec.ClearField(champpersonnalise.FieldUnite, field.TypeString) + } + if value, ok := _u.mutation.CreatedAt(); ok { + _spec.SetField(champpersonnalise.FieldCreatedAt, field.TypeTime, value) + } + if value, ok := _u.mutation.UpdatedAt(); ok { + _spec.SetField(champpersonnalise.FieldUpdatedAt, field.TypeTime, value) + } + if _u.mutation.ObjetCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: champpersonnalise.ObjetTable, + Columns: []string{champpersonnalise.ObjetColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(objet.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.ObjetIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: champpersonnalise.ObjetTable, + Columns: []string{champpersonnalise.ObjetColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(objet.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + _node = &ChampPersonnalise{config: _u.config} + _spec.Assign = _node.assignValues + _spec.ScanValues = _node.scanValues + if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{champpersonnalise.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + _u.mutation.done = true + return _node, nil +} diff --git a/backend/internal/data/ent/client.go b/backend/internal/data/ent/client.go new file mode 100644 index 0000000..9bd59d2 --- /dev/null +++ b/backend/internal/data/ent/client.go @@ -0,0 +1,1251 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + "log" + "reflect" + + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/migrate" + "github.com/google/uuid" + + "entgo.io/ent" + "entgo.io/ent/dialect" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/categorie" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/champpersonnalise" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/emplacement" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/lienobjetemplacement" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/objet" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/piecejointe" +) + +// Client is the client that holds all ent builders. +type Client struct { + config + // Schema is the client for creating, migrating and dropping schema. + Schema *migrate.Schema + // Categorie is the client for interacting with the Categorie builders. + Categorie *CategorieClient + // ChampPersonnalise is the client for interacting with the ChampPersonnalise builders. + ChampPersonnalise *ChampPersonnaliseClient + // Emplacement is the client for interacting with the Emplacement builders. + Emplacement *EmplacementClient + // LienObjetEmplacement is the client for interacting with the LienObjetEmplacement builders. + LienObjetEmplacement *LienObjetEmplacementClient + // Objet is the client for interacting with the Objet builders. + Objet *ObjetClient + // PieceJointe is the client for interacting with the PieceJointe builders. + PieceJointe *PieceJointeClient +} + +// NewClient creates a new client configured with the given options. +func NewClient(opts ...Option) *Client { + client := &Client{config: newConfig(opts...)} + client.init() + return client +} + +func (c *Client) init() { + c.Schema = migrate.NewSchema(c.driver) + c.Categorie = NewCategorieClient(c.config) + c.ChampPersonnalise = NewChampPersonnaliseClient(c.config) + c.Emplacement = NewEmplacementClient(c.config) + c.LienObjetEmplacement = NewLienObjetEmplacementClient(c.config) + c.Objet = NewObjetClient(c.config) + c.PieceJointe = NewPieceJointeClient(c.config) +} + +type ( + // config is the configuration for the client and its builder. + config struct { + // driver used for executing database requests. + driver dialect.Driver + // debug enable a debug logging. + debug bool + // log used for logging on debug mode. + log func(...any) + // hooks to execute on mutations. + hooks *hooks + // interceptors to execute on queries. + inters *inters + } + // Option function to configure the client. + Option func(*config) +) + +// newConfig creates a new config for the client. +func newConfig(opts ...Option) config { + cfg := config{log: log.Println, hooks: &hooks{}, inters: &inters{}} + cfg.options(opts...) + return cfg +} + +// options applies the options on the config object. +func (c *config) options(opts ...Option) { + for _, opt := range opts { + opt(c) + } + if c.debug { + c.driver = dialect.Debug(c.driver, c.log) + } +} + +// Debug enables debug logging on the ent.Driver. +func Debug() Option { + return func(c *config) { + c.debug = true + } +} + +// Log sets the logging function for debug mode. +func Log(fn func(...any)) Option { + return func(c *config) { + c.log = fn + } +} + +// Driver configures the client driver. +func Driver(driver dialect.Driver) Option { + return func(c *config) { + c.driver = driver + } +} + +// Open opens a database/sql.DB specified by the driver name and +// the data source name, and returns a new client attached to it. +// Optional parameters can be added for configuring the client. +func Open(driverName, dataSourceName string, options ...Option) (*Client, error) { + switch driverName { + case dialect.MySQL, dialect.Postgres, dialect.SQLite: + drv, err := sql.Open(driverName, dataSourceName) + if err != nil { + return nil, err + } + return NewClient(append(options, Driver(drv))...), nil + default: + return nil, fmt.Errorf("unsupported driver: %q", driverName) + } +} + +// ErrTxStarted is returned when trying to start a new transaction from a transactional client. +var ErrTxStarted = errors.New("ent: cannot start a transaction within a transaction") + +// Tx returns a new transactional client. The provided context +// is used until the transaction is committed or rolled back. +func (c *Client) Tx(ctx context.Context) (*Tx, error) { + if _, ok := c.driver.(*txDriver); ok { + return nil, ErrTxStarted + } + tx, err := newTx(ctx, c.driver) + if err != nil { + return nil, fmt.Errorf("ent: starting a transaction: %w", err) + } + cfg := c.config + cfg.driver = tx + return &Tx{ + ctx: ctx, + config: cfg, + Categorie: NewCategorieClient(cfg), + ChampPersonnalise: NewChampPersonnaliseClient(cfg), + Emplacement: NewEmplacementClient(cfg), + LienObjetEmplacement: NewLienObjetEmplacementClient(cfg), + Objet: NewObjetClient(cfg), + PieceJointe: NewPieceJointeClient(cfg), + }, nil +} + +// BeginTx returns a transactional client with specified options. +func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) { + if _, ok := c.driver.(*txDriver); ok { + return nil, errors.New("ent: cannot start a transaction within a transaction") + } + tx, err := c.driver.(interface { + BeginTx(context.Context, *sql.TxOptions) (dialect.Tx, error) + }).BeginTx(ctx, opts) + if err != nil { + return nil, fmt.Errorf("ent: starting a transaction: %w", err) + } + cfg := c.config + cfg.driver = &txDriver{tx: tx, drv: c.driver} + return &Tx{ + ctx: ctx, + config: cfg, + Categorie: NewCategorieClient(cfg), + ChampPersonnalise: NewChampPersonnaliseClient(cfg), + Emplacement: NewEmplacementClient(cfg), + LienObjetEmplacement: NewLienObjetEmplacementClient(cfg), + Objet: NewObjetClient(cfg), + PieceJointe: NewPieceJointeClient(cfg), + }, nil +} + +// Debug returns a new debug-client. It's used to get verbose logging on specific operations. +// +// client.Debug(). +// Categorie. +// Query(). +// Count(ctx) +func (c *Client) Debug() *Client { + if c.debug { + return c + } + cfg := c.config + cfg.driver = dialect.Debug(c.driver, c.log) + client := &Client{config: cfg} + client.init() + return client +} + +// Close closes the database connection and prevents new queries from starting. +func (c *Client) Close() error { + return c.driver.Close() +} + +// Use adds the mutation hooks to all the entity clients. +// In order to add hooks to a specific client, call: `client.Node.Use(...)`. +func (c *Client) Use(hooks ...Hook) { + for _, n := range []interface{ Use(...Hook) }{ + c.Categorie, c.ChampPersonnalise, c.Emplacement, c.LienObjetEmplacement, + c.Objet, c.PieceJointe, + } { + n.Use(hooks...) + } +} + +// Intercept adds the query interceptors to all the entity clients. +// In order to add interceptors to a specific client, call: `client.Node.Intercept(...)`. +func (c *Client) Intercept(interceptors ...Interceptor) { + for _, n := range []interface{ Intercept(...Interceptor) }{ + c.Categorie, c.ChampPersonnalise, c.Emplacement, c.LienObjetEmplacement, + c.Objet, c.PieceJointe, + } { + n.Intercept(interceptors...) + } +} + +// Mutate implements the ent.Mutator interface. +func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { + switch m := m.(type) { + case *CategorieMutation: + return c.Categorie.mutate(ctx, m) + case *ChampPersonnaliseMutation: + return c.ChampPersonnalise.mutate(ctx, m) + case *EmplacementMutation: + return c.Emplacement.mutate(ctx, m) + case *LienObjetEmplacementMutation: + return c.LienObjetEmplacement.mutate(ctx, m) + case *ObjetMutation: + return c.Objet.mutate(ctx, m) + case *PieceJointeMutation: + return c.PieceJointe.mutate(ctx, m) + default: + return nil, fmt.Errorf("ent: unknown mutation type %T", m) + } +} + +// CategorieClient is a client for the Categorie schema. +type CategorieClient struct { + config +} + +// NewCategorieClient returns a client for the Categorie from the given config. +func NewCategorieClient(c config) *CategorieClient { + return &CategorieClient{config: c} +} + +// Use adds a list of mutation hooks to the hooks stack. +// A call to `Use(f, g, h)` equals to `categorie.Hooks(f(g(h())))`. +func (c *CategorieClient) Use(hooks ...Hook) { + c.hooks.Categorie = append(c.hooks.Categorie, hooks...) +} + +// Intercept adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `categorie.Intercept(f(g(h())))`. +func (c *CategorieClient) Intercept(interceptors ...Interceptor) { + c.inters.Categorie = append(c.inters.Categorie, interceptors...) +} + +// Create returns a builder for creating a Categorie entity. +func (c *CategorieClient) Create() *CategorieCreate { + mutation := newCategorieMutation(c.config, OpCreate) + return &CategorieCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// CreateBulk returns a builder for creating a bulk of Categorie entities. +func (c *CategorieClient) CreateBulk(builders ...*CategorieCreate) *CategorieCreateBulk { + return &CategorieCreateBulk{config: c.config, builders: builders} +} + +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *CategorieClient) MapCreateBulk(slice any, setFunc func(*CategorieCreate, int)) *CategorieCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &CategorieCreateBulk{err: fmt.Errorf("calling to CategorieClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*CategorieCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &CategorieCreateBulk{config: c.config, builders: builders} +} + +// Update returns an update builder for Categorie. +func (c *CategorieClient) Update() *CategorieUpdate { + mutation := newCategorieMutation(c.config, OpUpdate) + return &CategorieUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOne returns an update builder for the given entity. +func (c *CategorieClient) UpdateOne(_m *Categorie) *CategorieUpdateOne { + mutation := newCategorieMutation(c.config, OpUpdateOne, withCategorie(_m)) + return &CategorieUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOneID returns an update builder for the given id. +func (c *CategorieClient) UpdateOneID(id uuid.UUID) *CategorieUpdateOne { + mutation := newCategorieMutation(c.config, OpUpdateOne, withCategorieID(id)) + return &CategorieUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// Delete returns a delete builder for Categorie. +func (c *CategorieClient) Delete() *CategorieDelete { + mutation := newCategorieMutation(c.config, OpDelete) + return &CategorieDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// DeleteOne returns a builder for deleting the given entity. +func (c *CategorieClient) DeleteOne(_m *Categorie) *CategorieDeleteOne { + return c.DeleteOneID(_m.ID) +} + +// DeleteOneID returns a builder for deleting the given entity by its id. +func (c *CategorieClient) DeleteOneID(id uuid.UUID) *CategorieDeleteOne { + builder := c.Delete().Where(categorie.ID(id)) + builder.mutation.id = &id + builder.mutation.op = OpDeleteOne + return &CategorieDeleteOne{builder} +} + +// Query returns a query builder for Categorie. +func (c *CategorieClient) Query() *CategorieQuery { + return &CategorieQuery{ + config: c.config, + ctx: &QueryContext{Type: TypeCategorie}, + inters: c.Interceptors(), + } +} + +// Get returns a Categorie entity by its id. +func (c *CategorieClient) Get(ctx context.Context, id uuid.UUID) (*Categorie, error) { + return c.Query().Where(categorie.ID(id)).Only(ctx) +} + +// GetX is like Get, but panics if an error occurs. +func (c *CategorieClient) GetX(ctx context.Context, id uuid.UUID) *Categorie { + obj, err := c.Get(ctx, id) + if err != nil { + panic(err) + } + return obj +} + +// QueryParent queries the parent edge of a Categorie. +func (c *CategorieClient) QueryParent(_m *Categorie) *CategorieQuery { + query := (&CategorieClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := _m.ID + step := sqlgraph.NewStep( + sqlgraph.From(categorie.Table, categorie.FieldID, id), + sqlgraph.To(categorie.Table, categorie.FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, categorie.ParentTable, categorie.ParentColumn), + ) + fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// QueryEnfants queries the enfants edge of a Categorie. +func (c *CategorieClient) QueryEnfants(_m *Categorie) *CategorieQuery { + query := (&CategorieClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := _m.ID + step := sqlgraph.NewStep( + sqlgraph.From(categorie.Table, categorie.FieldID, id), + sqlgraph.To(categorie.Table, categorie.FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, categorie.EnfantsTable, categorie.EnfantsColumn), + ) + fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// Hooks returns the client hooks. +func (c *CategorieClient) Hooks() []Hook { + return c.hooks.Categorie +} + +// Interceptors returns the client interceptors. +func (c *CategorieClient) Interceptors() []Interceptor { + return c.inters.Categorie +} + +func (c *CategorieClient) mutate(ctx context.Context, m *CategorieMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&CategorieCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&CategorieUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&CategorieUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&CategorieDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Categorie mutation op: %q", m.Op()) + } +} + +// ChampPersonnaliseClient is a client for the ChampPersonnalise schema. +type ChampPersonnaliseClient struct { + config +} + +// NewChampPersonnaliseClient returns a client for the ChampPersonnalise from the given config. +func NewChampPersonnaliseClient(c config) *ChampPersonnaliseClient { + return &ChampPersonnaliseClient{config: c} +} + +// Use adds a list of mutation hooks to the hooks stack. +// A call to `Use(f, g, h)` equals to `champpersonnalise.Hooks(f(g(h())))`. +func (c *ChampPersonnaliseClient) Use(hooks ...Hook) { + c.hooks.ChampPersonnalise = append(c.hooks.ChampPersonnalise, hooks...) +} + +// Intercept adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `champpersonnalise.Intercept(f(g(h())))`. +func (c *ChampPersonnaliseClient) Intercept(interceptors ...Interceptor) { + c.inters.ChampPersonnalise = append(c.inters.ChampPersonnalise, interceptors...) +} + +// Create returns a builder for creating a ChampPersonnalise entity. +func (c *ChampPersonnaliseClient) Create() *ChampPersonnaliseCreate { + mutation := newChampPersonnaliseMutation(c.config, OpCreate) + return &ChampPersonnaliseCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// CreateBulk returns a builder for creating a bulk of ChampPersonnalise entities. +func (c *ChampPersonnaliseClient) CreateBulk(builders ...*ChampPersonnaliseCreate) *ChampPersonnaliseCreateBulk { + return &ChampPersonnaliseCreateBulk{config: c.config, builders: builders} +} + +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *ChampPersonnaliseClient) MapCreateBulk(slice any, setFunc func(*ChampPersonnaliseCreate, int)) *ChampPersonnaliseCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &ChampPersonnaliseCreateBulk{err: fmt.Errorf("calling to ChampPersonnaliseClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*ChampPersonnaliseCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &ChampPersonnaliseCreateBulk{config: c.config, builders: builders} +} + +// Update returns an update builder for ChampPersonnalise. +func (c *ChampPersonnaliseClient) Update() *ChampPersonnaliseUpdate { + mutation := newChampPersonnaliseMutation(c.config, OpUpdate) + return &ChampPersonnaliseUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOne returns an update builder for the given entity. +func (c *ChampPersonnaliseClient) UpdateOne(_m *ChampPersonnalise) *ChampPersonnaliseUpdateOne { + mutation := newChampPersonnaliseMutation(c.config, OpUpdateOne, withChampPersonnalise(_m)) + return &ChampPersonnaliseUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOneID returns an update builder for the given id. +func (c *ChampPersonnaliseClient) UpdateOneID(id uuid.UUID) *ChampPersonnaliseUpdateOne { + mutation := newChampPersonnaliseMutation(c.config, OpUpdateOne, withChampPersonnaliseID(id)) + return &ChampPersonnaliseUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// Delete returns a delete builder for ChampPersonnalise. +func (c *ChampPersonnaliseClient) Delete() *ChampPersonnaliseDelete { + mutation := newChampPersonnaliseMutation(c.config, OpDelete) + return &ChampPersonnaliseDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// DeleteOne returns a builder for deleting the given entity. +func (c *ChampPersonnaliseClient) DeleteOne(_m *ChampPersonnalise) *ChampPersonnaliseDeleteOne { + return c.DeleteOneID(_m.ID) +} + +// DeleteOneID returns a builder for deleting the given entity by its id. +func (c *ChampPersonnaliseClient) DeleteOneID(id uuid.UUID) *ChampPersonnaliseDeleteOne { + builder := c.Delete().Where(champpersonnalise.ID(id)) + builder.mutation.id = &id + builder.mutation.op = OpDeleteOne + return &ChampPersonnaliseDeleteOne{builder} +} + +// Query returns a query builder for ChampPersonnalise. +func (c *ChampPersonnaliseClient) Query() *ChampPersonnaliseQuery { + return &ChampPersonnaliseQuery{ + config: c.config, + ctx: &QueryContext{Type: TypeChampPersonnalise}, + inters: c.Interceptors(), + } +} + +// Get returns a ChampPersonnalise entity by its id. +func (c *ChampPersonnaliseClient) Get(ctx context.Context, id uuid.UUID) (*ChampPersonnalise, error) { + return c.Query().Where(champpersonnalise.ID(id)).Only(ctx) +} + +// GetX is like Get, but panics if an error occurs. +func (c *ChampPersonnaliseClient) GetX(ctx context.Context, id uuid.UUID) *ChampPersonnalise { + obj, err := c.Get(ctx, id) + if err != nil { + panic(err) + } + return obj +} + +// QueryObjet queries the objet edge of a ChampPersonnalise. +func (c *ChampPersonnaliseClient) QueryObjet(_m *ChampPersonnalise) *ObjetQuery { + query := (&ObjetClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := _m.ID + step := sqlgraph.NewStep( + sqlgraph.From(champpersonnalise.Table, champpersonnalise.FieldID, id), + sqlgraph.To(objet.Table, objet.FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, champpersonnalise.ObjetTable, champpersonnalise.ObjetColumn), + ) + fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// Hooks returns the client hooks. +func (c *ChampPersonnaliseClient) Hooks() []Hook { + return c.hooks.ChampPersonnalise +} + +// Interceptors returns the client interceptors. +func (c *ChampPersonnaliseClient) Interceptors() []Interceptor { + return c.inters.ChampPersonnalise +} + +func (c *ChampPersonnaliseClient) mutate(ctx context.Context, m *ChampPersonnaliseMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&ChampPersonnaliseCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&ChampPersonnaliseUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&ChampPersonnaliseUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&ChampPersonnaliseDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown ChampPersonnalise mutation op: %q", m.Op()) + } +} + +// EmplacementClient is a client for the Emplacement schema. +type EmplacementClient struct { + config +} + +// NewEmplacementClient returns a client for the Emplacement from the given config. +func NewEmplacementClient(c config) *EmplacementClient { + return &EmplacementClient{config: c} +} + +// Use adds a list of mutation hooks to the hooks stack. +// A call to `Use(f, g, h)` equals to `emplacement.Hooks(f(g(h())))`. +func (c *EmplacementClient) Use(hooks ...Hook) { + c.hooks.Emplacement = append(c.hooks.Emplacement, hooks...) +} + +// Intercept adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `emplacement.Intercept(f(g(h())))`. +func (c *EmplacementClient) Intercept(interceptors ...Interceptor) { + c.inters.Emplacement = append(c.inters.Emplacement, interceptors...) +} + +// Create returns a builder for creating a Emplacement entity. +func (c *EmplacementClient) Create() *EmplacementCreate { + mutation := newEmplacementMutation(c.config, OpCreate) + return &EmplacementCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// CreateBulk returns a builder for creating a bulk of Emplacement entities. +func (c *EmplacementClient) CreateBulk(builders ...*EmplacementCreate) *EmplacementCreateBulk { + return &EmplacementCreateBulk{config: c.config, builders: builders} +} + +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *EmplacementClient) MapCreateBulk(slice any, setFunc func(*EmplacementCreate, int)) *EmplacementCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &EmplacementCreateBulk{err: fmt.Errorf("calling to EmplacementClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*EmplacementCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &EmplacementCreateBulk{config: c.config, builders: builders} +} + +// Update returns an update builder for Emplacement. +func (c *EmplacementClient) Update() *EmplacementUpdate { + mutation := newEmplacementMutation(c.config, OpUpdate) + return &EmplacementUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOne returns an update builder for the given entity. +func (c *EmplacementClient) UpdateOne(_m *Emplacement) *EmplacementUpdateOne { + mutation := newEmplacementMutation(c.config, OpUpdateOne, withEmplacement(_m)) + return &EmplacementUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOneID returns an update builder for the given id. +func (c *EmplacementClient) UpdateOneID(id uuid.UUID) *EmplacementUpdateOne { + mutation := newEmplacementMutation(c.config, OpUpdateOne, withEmplacementID(id)) + return &EmplacementUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// Delete returns a delete builder for Emplacement. +func (c *EmplacementClient) Delete() *EmplacementDelete { + mutation := newEmplacementMutation(c.config, OpDelete) + return &EmplacementDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// DeleteOne returns a builder for deleting the given entity. +func (c *EmplacementClient) DeleteOne(_m *Emplacement) *EmplacementDeleteOne { + return c.DeleteOneID(_m.ID) +} + +// DeleteOneID returns a builder for deleting the given entity by its id. +func (c *EmplacementClient) DeleteOneID(id uuid.UUID) *EmplacementDeleteOne { + builder := c.Delete().Where(emplacement.ID(id)) + builder.mutation.id = &id + builder.mutation.op = OpDeleteOne + return &EmplacementDeleteOne{builder} +} + +// Query returns a query builder for Emplacement. +func (c *EmplacementClient) Query() *EmplacementQuery { + return &EmplacementQuery{ + config: c.config, + ctx: &QueryContext{Type: TypeEmplacement}, + inters: c.Interceptors(), + } +} + +// Get returns a Emplacement entity by its id. +func (c *EmplacementClient) Get(ctx context.Context, id uuid.UUID) (*Emplacement, error) { + return c.Query().Where(emplacement.ID(id)).Only(ctx) +} + +// GetX is like Get, but panics if an error occurs. +func (c *EmplacementClient) GetX(ctx context.Context, id uuid.UUID) *Emplacement { + obj, err := c.Get(ctx, id) + if err != nil { + panic(err) + } + return obj +} + +// QueryParent queries the parent edge of a Emplacement. +func (c *EmplacementClient) QueryParent(_m *Emplacement) *EmplacementQuery { + query := (&EmplacementClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := _m.ID + step := sqlgraph.NewStep( + sqlgraph.From(emplacement.Table, emplacement.FieldID, id), + sqlgraph.To(emplacement.Table, emplacement.FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, emplacement.ParentTable, emplacement.ParentColumn), + ) + fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// QueryEnfants queries the enfants edge of a Emplacement. +func (c *EmplacementClient) QueryEnfants(_m *Emplacement) *EmplacementQuery { + query := (&EmplacementClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := _m.ID + step := sqlgraph.NewStep( + sqlgraph.From(emplacement.Table, emplacement.FieldID, id), + sqlgraph.To(emplacement.Table, emplacement.FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, emplacement.EnfantsTable, emplacement.EnfantsColumn), + ) + fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// QueryLiensObjets queries the liens_objets edge of a Emplacement. +func (c *EmplacementClient) QueryLiensObjets(_m *Emplacement) *LienObjetEmplacementQuery { + query := (&LienObjetEmplacementClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := _m.ID + step := sqlgraph.NewStep( + sqlgraph.From(emplacement.Table, emplacement.FieldID, id), + sqlgraph.To(lienobjetemplacement.Table, lienobjetemplacement.FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, emplacement.LiensObjetsTable, emplacement.LiensObjetsColumn), + ) + fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// Hooks returns the client hooks. +func (c *EmplacementClient) Hooks() []Hook { + return c.hooks.Emplacement +} + +// Interceptors returns the client interceptors. +func (c *EmplacementClient) Interceptors() []Interceptor { + return c.inters.Emplacement +} + +func (c *EmplacementClient) mutate(ctx context.Context, m *EmplacementMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&EmplacementCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&EmplacementUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&EmplacementUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&EmplacementDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Emplacement mutation op: %q", m.Op()) + } +} + +// LienObjetEmplacementClient is a client for the LienObjetEmplacement schema. +type LienObjetEmplacementClient struct { + config +} + +// NewLienObjetEmplacementClient returns a client for the LienObjetEmplacement from the given config. +func NewLienObjetEmplacementClient(c config) *LienObjetEmplacementClient { + return &LienObjetEmplacementClient{config: c} +} + +// Use adds a list of mutation hooks to the hooks stack. +// A call to `Use(f, g, h)` equals to `lienobjetemplacement.Hooks(f(g(h())))`. +func (c *LienObjetEmplacementClient) Use(hooks ...Hook) { + c.hooks.LienObjetEmplacement = append(c.hooks.LienObjetEmplacement, hooks...) +} + +// Intercept adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `lienobjetemplacement.Intercept(f(g(h())))`. +func (c *LienObjetEmplacementClient) Intercept(interceptors ...Interceptor) { + c.inters.LienObjetEmplacement = append(c.inters.LienObjetEmplacement, interceptors...) +} + +// Create returns a builder for creating a LienObjetEmplacement entity. +func (c *LienObjetEmplacementClient) Create() *LienObjetEmplacementCreate { + mutation := newLienObjetEmplacementMutation(c.config, OpCreate) + return &LienObjetEmplacementCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// CreateBulk returns a builder for creating a bulk of LienObjetEmplacement entities. +func (c *LienObjetEmplacementClient) CreateBulk(builders ...*LienObjetEmplacementCreate) *LienObjetEmplacementCreateBulk { + return &LienObjetEmplacementCreateBulk{config: c.config, builders: builders} +} + +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *LienObjetEmplacementClient) MapCreateBulk(slice any, setFunc func(*LienObjetEmplacementCreate, int)) *LienObjetEmplacementCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &LienObjetEmplacementCreateBulk{err: fmt.Errorf("calling to LienObjetEmplacementClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*LienObjetEmplacementCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &LienObjetEmplacementCreateBulk{config: c.config, builders: builders} +} + +// Update returns an update builder for LienObjetEmplacement. +func (c *LienObjetEmplacementClient) Update() *LienObjetEmplacementUpdate { + mutation := newLienObjetEmplacementMutation(c.config, OpUpdate) + return &LienObjetEmplacementUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOne returns an update builder for the given entity. +func (c *LienObjetEmplacementClient) UpdateOne(_m *LienObjetEmplacement) *LienObjetEmplacementUpdateOne { + mutation := newLienObjetEmplacementMutation(c.config, OpUpdateOne, withLienObjetEmplacement(_m)) + return &LienObjetEmplacementUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOneID returns an update builder for the given id. +func (c *LienObjetEmplacementClient) UpdateOneID(id uuid.UUID) *LienObjetEmplacementUpdateOne { + mutation := newLienObjetEmplacementMutation(c.config, OpUpdateOne, withLienObjetEmplacementID(id)) + return &LienObjetEmplacementUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// Delete returns a delete builder for LienObjetEmplacement. +func (c *LienObjetEmplacementClient) Delete() *LienObjetEmplacementDelete { + mutation := newLienObjetEmplacementMutation(c.config, OpDelete) + return &LienObjetEmplacementDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// DeleteOne returns a builder for deleting the given entity. +func (c *LienObjetEmplacementClient) DeleteOne(_m *LienObjetEmplacement) *LienObjetEmplacementDeleteOne { + return c.DeleteOneID(_m.ID) +} + +// DeleteOneID returns a builder for deleting the given entity by its id. +func (c *LienObjetEmplacementClient) DeleteOneID(id uuid.UUID) *LienObjetEmplacementDeleteOne { + builder := c.Delete().Where(lienobjetemplacement.ID(id)) + builder.mutation.id = &id + builder.mutation.op = OpDeleteOne + return &LienObjetEmplacementDeleteOne{builder} +} + +// Query returns a query builder for LienObjetEmplacement. +func (c *LienObjetEmplacementClient) Query() *LienObjetEmplacementQuery { + return &LienObjetEmplacementQuery{ + config: c.config, + ctx: &QueryContext{Type: TypeLienObjetEmplacement}, + inters: c.Interceptors(), + } +} + +// Get returns a LienObjetEmplacement entity by its id. +func (c *LienObjetEmplacementClient) Get(ctx context.Context, id uuid.UUID) (*LienObjetEmplacement, error) { + return c.Query().Where(lienobjetemplacement.ID(id)).Only(ctx) +} + +// GetX is like Get, but panics if an error occurs. +func (c *LienObjetEmplacementClient) GetX(ctx context.Context, id uuid.UUID) *LienObjetEmplacement { + obj, err := c.Get(ctx, id) + if err != nil { + panic(err) + } + return obj +} + +// QueryObjet queries the objet edge of a LienObjetEmplacement. +func (c *LienObjetEmplacementClient) QueryObjet(_m *LienObjetEmplacement) *ObjetQuery { + query := (&ObjetClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := _m.ID + step := sqlgraph.NewStep( + sqlgraph.From(lienobjetemplacement.Table, lienobjetemplacement.FieldID, id), + sqlgraph.To(objet.Table, objet.FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, lienobjetemplacement.ObjetTable, lienobjetemplacement.ObjetColumn), + ) + fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// QueryEmplacement queries the emplacement edge of a LienObjetEmplacement. +func (c *LienObjetEmplacementClient) QueryEmplacement(_m *LienObjetEmplacement) *EmplacementQuery { + query := (&EmplacementClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := _m.ID + step := sqlgraph.NewStep( + sqlgraph.From(lienobjetemplacement.Table, lienobjetemplacement.FieldID, id), + sqlgraph.To(emplacement.Table, emplacement.FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, lienobjetemplacement.EmplacementTable, lienobjetemplacement.EmplacementColumn), + ) + fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// Hooks returns the client hooks. +func (c *LienObjetEmplacementClient) Hooks() []Hook { + return c.hooks.LienObjetEmplacement +} + +// Interceptors returns the client interceptors. +func (c *LienObjetEmplacementClient) Interceptors() []Interceptor { + return c.inters.LienObjetEmplacement +} + +func (c *LienObjetEmplacementClient) mutate(ctx context.Context, m *LienObjetEmplacementMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&LienObjetEmplacementCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&LienObjetEmplacementUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&LienObjetEmplacementUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&LienObjetEmplacementDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown LienObjetEmplacement mutation op: %q", m.Op()) + } +} + +// ObjetClient is a client for the Objet schema. +type ObjetClient struct { + config +} + +// NewObjetClient returns a client for the Objet from the given config. +func NewObjetClient(c config) *ObjetClient { + return &ObjetClient{config: c} +} + +// Use adds a list of mutation hooks to the hooks stack. +// A call to `Use(f, g, h)` equals to `objet.Hooks(f(g(h())))`. +func (c *ObjetClient) Use(hooks ...Hook) { + c.hooks.Objet = append(c.hooks.Objet, hooks...) +} + +// Intercept adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `objet.Intercept(f(g(h())))`. +func (c *ObjetClient) Intercept(interceptors ...Interceptor) { + c.inters.Objet = append(c.inters.Objet, interceptors...) +} + +// Create returns a builder for creating a Objet entity. +func (c *ObjetClient) Create() *ObjetCreate { + mutation := newObjetMutation(c.config, OpCreate) + return &ObjetCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// CreateBulk returns a builder for creating a bulk of Objet entities. +func (c *ObjetClient) CreateBulk(builders ...*ObjetCreate) *ObjetCreateBulk { + return &ObjetCreateBulk{config: c.config, builders: builders} +} + +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *ObjetClient) MapCreateBulk(slice any, setFunc func(*ObjetCreate, int)) *ObjetCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &ObjetCreateBulk{err: fmt.Errorf("calling to ObjetClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*ObjetCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &ObjetCreateBulk{config: c.config, builders: builders} +} + +// Update returns an update builder for Objet. +func (c *ObjetClient) Update() *ObjetUpdate { + mutation := newObjetMutation(c.config, OpUpdate) + return &ObjetUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOne returns an update builder for the given entity. +func (c *ObjetClient) UpdateOne(_m *Objet) *ObjetUpdateOne { + mutation := newObjetMutation(c.config, OpUpdateOne, withObjet(_m)) + return &ObjetUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOneID returns an update builder for the given id. +func (c *ObjetClient) UpdateOneID(id uuid.UUID) *ObjetUpdateOne { + mutation := newObjetMutation(c.config, OpUpdateOne, withObjetID(id)) + return &ObjetUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// Delete returns a delete builder for Objet. +func (c *ObjetClient) Delete() *ObjetDelete { + mutation := newObjetMutation(c.config, OpDelete) + return &ObjetDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// DeleteOne returns a builder for deleting the given entity. +func (c *ObjetClient) DeleteOne(_m *Objet) *ObjetDeleteOne { + return c.DeleteOneID(_m.ID) +} + +// DeleteOneID returns a builder for deleting the given entity by its id. +func (c *ObjetClient) DeleteOneID(id uuid.UUID) *ObjetDeleteOne { + builder := c.Delete().Where(objet.ID(id)) + builder.mutation.id = &id + builder.mutation.op = OpDeleteOne + return &ObjetDeleteOne{builder} +} + +// Query returns a query builder for Objet. +func (c *ObjetClient) Query() *ObjetQuery { + return &ObjetQuery{ + config: c.config, + ctx: &QueryContext{Type: TypeObjet}, + inters: c.Interceptors(), + } +} + +// Get returns a Objet entity by its id. +func (c *ObjetClient) Get(ctx context.Context, id uuid.UUID) (*Objet, error) { + return c.Query().Where(objet.ID(id)).Only(ctx) +} + +// GetX is like Get, but panics if an error occurs. +func (c *ObjetClient) GetX(ctx context.Context, id uuid.UUID) *Objet { + obj, err := c.Get(ctx, id) + if err != nil { + panic(err) + } + return obj +} + +// QueryLiensEmplacements queries the liens_emplacements edge of a Objet. +func (c *ObjetClient) QueryLiensEmplacements(_m *Objet) *LienObjetEmplacementQuery { + query := (&LienObjetEmplacementClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := _m.ID + step := sqlgraph.NewStep( + sqlgraph.From(objet.Table, objet.FieldID, id), + sqlgraph.To(lienobjetemplacement.Table, lienobjetemplacement.FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, objet.LiensEmplacementsTable, objet.LiensEmplacementsColumn), + ) + fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// QueryChampsPersonnalises queries the champs_personnalises edge of a Objet. +func (c *ObjetClient) QueryChampsPersonnalises(_m *Objet) *ChampPersonnaliseQuery { + query := (&ChampPersonnaliseClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := _m.ID + step := sqlgraph.NewStep( + sqlgraph.From(objet.Table, objet.FieldID, id), + sqlgraph.To(champpersonnalise.Table, champpersonnalise.FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, objet.ChampsPersonnalisesTable, objet.ChampsPersonnalisesColumn), + ) + fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// QueryPiecesJointes queries the pieces_jointes edge of a Objet. +func (c *ObjetClient) QueryPiecesJointes(_m *Objet) *PieceJointeQuery { + query := (&PieceJointeClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := _m.ID + step := sqlgraph.NewStep( + sqlgraph.From(objet.Table, objet.FieldID, id), + sqlgraph.To(piecejointe.Table, piecejointe.FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, objet.PiecesJointesTable, objet.PiecesJointesColumn), + ) + fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// Hooks returns the client hooks. +func (c *ObjetClient) Hooks() []Hook { + return c.hooks.Objet +} + +// Interceptors returns the client interceptors. +func (c *ObjetClient) Interceptors() []Interceptor { + return c.inters.Objet +} + +func (c *ObjetClient) mutate(ctx context.Context, m *ObjetMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&ObjetCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&ObjetUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&ObjetUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&ObjetDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Objet mutation op: %q", m.Op()) + } +} + +// PieceJointeClient is a client for the PieceJointe schema. +type PieceJointeClient struct { + config +} + +// NewPieceJointeClient returns a client for the PieceJointe from the given config. +func NewPieceJointeClient(c config) *PieceJointeClient { + return &PieceJointeClient{config: c} +} + +// Use adds a list of mutation hooks to the hooks stack. +// A call to `Use(f, g, h)` equals to `piecejointe.Hooks(f(g(h())))`. +func (c *PieceJointeClient) Use(hooks ...Hook) { + c.hooks.PieceJointe = append(c.hooks.PieceJointe, hooks...) +} + +// Intercept adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `piecejointe.Intercept(f(g(h())))`. +func (c *PieceJointeClient) Intercept(interceptors ...Interceptor) { + c.inters.PieceJointe = append(c.inters.PieceJointe, interceptors...) +} + +// Create returns a builder for creating a PieceJointe entity. +func (c *PieceJointeClient) Create() *PieceJointeCreate { + mutation := newPieceJointeMutation(c.config, OpCreate) + return &PieceJointeCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// CreateBulk returns a builder for creating a bulk of PieceJointe entities. +func (c *PieceJointeClient) CreateBulk(builders ...*PieceJointeCreate) *PieceJointeCreateBulk { + return &PieceJointeCreateBulk{config: c.config, builders: builders} +} + +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *PieceJointeClient) MapCreateBulk(slice any, setFunc func(*PieceJointeCreate, int)) *PieceJointeCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &PieceJointeCreateBulk{err: fmt.Errorf("calling to PieceJointeClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*PieceJointeCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &PieceJointeCreateBulk{config: c.config, builders: builders} +} + +// Update returns an update builder for PieceJointe. +func (c *PieceJointeClient) Update() *PieceJointeUpdate { + mutation := newPieceJointeMutation(c.config, OpUpdate) + return &PieceJointeUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOne returns an update builder for the given entity. +func (c *PieceJointeClient) UpdateOne(_m *PieceJointe) *PieceJointeUpdateOne { + mutation := newPieceJointeMutation(c.config, OpUpdateOne, withPieceJointe(_m)) + return &PieceJointeUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOneID returns an update builder for the given id. +func (c *PieceJointeClient) UpdateOneID(id uuid.UUID) *PieceJointeUpdateOne { + mutation := newPieceJointeMutation(c.config, OpUpdateOne, withPieceJointeID(id)) + return &PieceJointeUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// Delete returns a delete builder for PieceJointe. +func (c *PieceJointeClient) Delete() *PieceJointeDelete { + mutation := newPieceJointeMutation(c.config, OpDelete) + return &PieceJointeDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// DeleteOne returns a builder for deleting the given entity. +func (c *PieceJointeClient) DeleteOne(_m *PieceJointe) *PieceJointeDeleteOne { + return c.DeleteOneID(_m.ID) +} + +// DeleteOneID returns a builder for deleting the given entity by its id. +func (c *PieceJointeClient) DeleteOneID(id uuid.UUID) *PieceJointeDeleteOne { + builder := c.Delete().Where(piecejointe.ID(id)) + builder.mutation.id = &id + builder.mutation.op = OpDeleteOne + return &PieceJointeDeleteOne{builder} +} + +// Query returns a query builder for PieceJointe. +func (c *PieceJointeClient) Query() *PieceJointeQuery { + return &PieceJointeQuery{ + config: c.config, + ctx: &QueryContext{Type: TypePieceJointe}, + inters: c.Interceptors(), + } +} + +// Get returns a PieceJointe entity by its id. +func (c *PieceJointeClient) Get(ctx context.Context, id uuid.UUID) (*PieceJointe, error) { + return c.Query().Where(piecejointe.ID(id)).Only(ctx) +} + +// GetX is like Get, but panics if an error occurs. +func (c *PieceJointeClient) GetX(ctx context.Context, id uuid.UUID) *PieceJointe { + obj, err := c.Get(ctx, id) + if err != nil { + panic(err) + } + return obj +} + +// QueryObjet queries the objet edge of a PieceJointe. +func (c *PieceJointeClient) QueryObjet(_m *PieceJointe) *ObjetQuery { + query := (&ObjetClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := _m.ID + step := sqlgraph.NewStep( + sqlgraph.From(piecejointe.Table, piecejointe.FieldID, id), + sqlgraph.To(objet.Table, objet.FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, piecejointe.ObjetTable, piecejointe.ObjetColumn), + ) + fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// Hooks returns the client hooks. +func (c *PieceJointeClient) Hooks() []Hook { + return c.hooks.PieceJointe +} + +// Interceptors returns the client interceptors. +func (c *PieceJointeClient) Interceptors() []Interceptor { + return c.inters.PieceJointe +} + +func (c *PieceJointeClient) mutate(ctx context.Context, m *PieceJointeMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&PieceJointeCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&PieceJointeUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&PieceJointeUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&PieceJointeDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown PieceJointe mutation op: %q", m.Op()) + } +} + +// hooks and interceptors per client, for fast access. +type ( + hooks struct { + Categorie, ChampPersonnalise, Emplacement, LienObjetEmplacement, Objet, + PieceJointe []ent.Hook + } + inters struct { + Categorie, ChampPersonnalise, Emplacement, LienObjetEmplacement, Objet, + PieceJointe []ent.Interceptor + } +) diff --git a/backend/internal/data/ent/doc.go b/backend/internal/data/ent/doc.go new file mode 100644 index 0000000..4d46e99 --- /dev/null +++ b/backend/internal/data/ent/doc.go @@ -0,0 +1,3 @@ +package ent + +// Package ent contient le code genere par Ent. diff --git a/backend/internal/data/ent/emplacement.go b/backend/internal/data/ent/emplacement.go new file mode 100644 index 0000000..8b35de5 --- /dev/null +++ b/backend/internal/data/ent/emplacement.go @@ -0,0 +1,276 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "fmt" + "strings" + "time" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/emplacement" + "github.com/google/uuid" +) + +// Emplacement is the model entity for the Emplacement schema. +type Emplacement struct { + config `json:"-"` + // ID of the ent. + // Identifiant unique de l'emplacement + ID uuid.UUID `json:"id,omitempty"` + // Nom de l'emplacement + Nom string `json:"nom,omitempty"` + // Identifiant du parent + ParentID *uuid.UUID `json:"parent_id,omitempty"` + // Slug URL-friendly + Slug *string `json:"slug,omitempty"` + // Piece associee + Piece *string `json:"piece,omitempty"` + // Meuble associe + Meuble *string `json:"meuble,omitempty"` + // Numero de boite + NumeroBoite *string `json:"numero_boite,omitempty"` + // Nom ou code d'icone + Icone *string `json:"icone,omitempty"` + // Date de creation + CreatedAt time.Time `json:"created_at,omitempty"` + // Date de derniere mise a jour + UpdatedAt time.Time `json:"updated_at,omitempty"` + // Edges holds the relations/edges for other nodes in the graph. + // The values are being populated by the EmplacementQuery when eager-loading is set. + Edges EmplacementEdges `json:"edges"` + selectValues sql.SelectValues +} + +// EmplacementEdges holds the relations/edges for other nodes in the graph. +type EmplacementEdges struct { + // Lien parent/enfants pour l'arbre des emplacements + Parent *Emplacement `json:"parent,omitempty"` + // Enfants holds the value of the enfants edge. + Enfants []*Emplacement `json:"enfants,omitempty"` + // Liens entre emplacements et objets + LiensObjets []*LienObjetEmplacement `json:"liens_objets,omitempty"` + // loadedTypes holds the information for reporting if a + // type was loaded (or requested) in eager-loading or not. + loadedTypes [3]bool +} + +// ParentOrErr returns the Parent value or an error if the edge +// was not loaded in eager-loading, or loaded but was not found. +func (e EmplacementEdges) ParentOrErr() (*Emplacement, error) { + if e.Parent != nil { + return e.Parent, nil + } else if e.loadedTypes[0] { + return nil, &NotFoundError{label: emplacement.Label} + } + return nil, &NotLoadedError{edge: "parent"} +} + +// EnfantsOrErr returns the Enfants value or an error if the edge +// was not loaded in eager-loading. +func (e EmplacementEdges) EnfantsOrErr() ([]*Emplacement, error) { + if e.loadedTypes[1] { + return e.Enfants, nil + } + return nil, &NotLoadedError{edge: "enfants"} +} + +// LiensObjetsOrErr returns the LiensObjets value or an error if the edge +// was not loaded in eager-loading. +func (e EmplacementEdges) LiensObjetsOrErr() ([]*LienObjetEmplacement, error) { + if e.loadedTypes[2] { + return e.LiensObjets, nil + } + return nil, &NotLoadedError{edge: "liens_objets"} +} + +// scanValues returns the types for scanning values from sql.Rows. +func (*Emplacement) scanValues(columns []string) ([]any, error) { + values := make([]any, len(columns)) + for i := range columns { + switch columns[i] { + case emplacement.FieldParentID: + values[i] = &sql.NullScanner{S: new(uuid.UUID)} + case emplacement.FieldNom, emplacement.FieldSlug, emplacement.FieldPiece, emplacement.FieldMeuble, emplacement.FieldNumeroBoite, emplacement.FieldIcone: + values[i] = new(sql.NullString) + case emplacement.FieldCreatedAt, emplacement.FieldUpdatedAt: + values[i] = new(sql.NullTime) + case emplacement.FieldID: + values[i] = new(uuid.UUID) + default: + values[i] = new(sql.UnknownType) + } + } + return values, nil +} + +// assignValues assigns the values that were returned from sql.Rows (after scanning) +// to the Emplacement fields. +func (_m *Emplacement) assignValues(columns []string, values []any) error { + if m, n := len(values), len(columns); m < n { + return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) + } + for i := range columns { + switch columns[i] { + case emplacement.FieldID: + if value, ok := values[i].(*uuid.UUID); !ok { + return fmt.Errorf("unexpected type %T for field id", values[i]) + } else if value != nil { + _m.ID = *value + } + case emplacement.FieldNom: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field nom", values[i]) + } else if value.Valid { + _m.Nom = value.String + } + case emplacement.FieldParentID: + if value, ok := values[i].(*sql.NullScanner); !ok { + return fmt.Errorf("unexpected type %T for field parent_id", values[i]) + } else if value.Valid { + _m.ParentID = new(uuid.UUID) + *_m.ParentID = *value.S.(*uuid.UUID) + } + case emplacement.FieldSlug: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field slug", values[i]) + } else if value.Valid { + _m.Slug = new(string) + *_m.Slug = value.String + } + case emplacement.FieldPiece: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field piece", values[i]) + } else if value.Valid { + _m.Piece = new(string) + *_m.Piece = value.String + } + case emplacement.FieldMeuble: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field meuble", values[i]) + } else if value.Valid { + _m.Meuble = new(string) + *_m.Meuble = value.String + } + case emplacement.FieldNumeroBoite: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field numero_boite", values[i]) + } else if value.Valid { + _m.NumeroBoite = new(string) + *_m.NumeroBoite = value.String + } + case emplacement.FieldIcone: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field icone", values[i]) + } else if value.Valid { + _m.Icone = new(string) + *_m.Icone = value.String + } + case emplacement.FieldCreatedAt: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field created_at", values[i]) + } else if value.Valid { + _m.CreatedAt = value.Time + } + case emplacement.FieldUpdatedAt: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field updated_at", values[i]) + } else if value.Valid { + _m.UpdatedAt = value.Time + } + default: + _m.selectValues.Set(columns[i], values[i]) + } + } + return nil +} + +// Value returns the ent.Value that was dynamically selected and assigned to the Emplacement. +// This includes values selected through modifiers, order, etc. +func (_m *Emplacement) Value(name string) (ent.Value, error) { + return _m.selectValues.Get(name) +} + +// QueryParent queries the "parent" edge of the Emplacement entity. +func (_m *Emplacement) QueryParent() *EmplacementQuery { + return NewEmplacementClient(_m.config).QueryParent(_m) +} + +// QueryEnfants queries the "enfants" edge of the Emplacement entity. +func (_m *Emplacement) QueryEnfants() *EmplacementQuery { + return NewEmplacementClient(_m.config).QueryEnfants(_m) +} + +// QueryLiensObjets queries the "liens_objets" edge of the Emplacement entity. +func (_m *Emplacement) QueryLiensObjets() *LienObjetEmplacementQuery { + return NewEmplacementClient(_m.config).QueryLiensObjets(_m) +} + +// Update returns a builder for updating this Emplacement. +// Note that you need to call Emplacement.Unwrap() before calling this method if this Emplacement +// was returned from a transaction, and the transaction was committed or rolled back. +func (_m *Emplacement) Update() *EmplacementUpdateOne { + return NewEmplacementClient(_m.config).UpdateOne(_m) +} + +// Unwrap unwraps the Emplacement entity that was returned from a transaction after it was closed, +// so that all future queries will be executed through the driver which created the transaction. +func (_m *Emplacement) Unwrap() *Emplacement { + _tx, ok := _m.config.driver.(*txDriver) + if !ok { + panic("ent: Emplacement is not a transactional entity") + } + _m.config.driver = _tx.drv + return _m +} + +// String implements the fmt.Stringer. +func (_m *Emplacement) String() string { + var builder strings.Builder + builder.WriteString("Emplacement(") + builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID)) + builder.WriteString("nom=") + builder.WriteString(_m.Nom) + builder.WriteString(", ") + if v := _m.ParentID; v != nil { + builder.WriteString("parent_id=") + builder.WriteString(fmt.Sprintf("%v", *v)) + } + builder.WriteString(", ") + if v := _m.Slug; v != nil { + builder.WriteString("slug=") + builder.WriteString(*v) + } + builder.WriteString(", ") + if v := _m.Piece; v != nil { + builder.WriteString("piece=") + builder.WriteString(*v) + } + builder.WriteString(", ") + if v := _m.Meuble; v != nil { + builder.WriteString("meuble=") + builder.WriteString(*v) + } + builder.WriteString(", ") + if v := _m.NumeroBoite; v != nil { + builder.WriteString("numero_boite=") + builder.WriteString(*v) + } + builder.WriteString(", ") + if v := _m.Icone; v != nil { + builder.WriteString("icone=") + builder.WriteString(*v) + } + builder.WriteString(", ") + builder.WriteString("created_at=") + builder.WriteString(_m.CreatedAt.Format(time.ANSIC)) + builder.WriteString(", ") + builder.WriteString("updated_at=") + builder.WriteString(_m.UpdatedAt.Format(time.ANSIC)) + builder.WriteByte(')') + return builder.String() +} + +// Emplacements is a parsable slice of Emplacement. +type Emplacements []*Emplacement diff --git a/backend/internal/data/ent/emplacement/emplacement.go b/backend/internal/data/ent/emplacement/emplacement.go new file mode 100644 index 0000000..ba16ac3 --- /dev/null +++ b/backend/internal/data/ent/emplacement/emplacement.go @@ -0,0 +1,205 @@ +// Code generated by ent, DO NOT EDIT. + +package emplacement + +import ( + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "github.com/google/uuid" +) + +const ( + // Label holds the string label denoting the emplacement type in the database. + Label = "emplacement" + // FieldID holds the string denoting the id field in the database. + FieldID = "id" + // FieldNom holds the string denoting the nom field in the database. + FieldNom = "nom" + // FieldParentID holds the string denoting the parent_id field in the database. + FieldParentID = "parent_id" + // FieldSlug holds the string denoting the slug field in the database. + FieldSlug = "slug" + // FieldPiece holds the string denoting the piece field in the database. + FieldPiece = "piece" + // FieldMeuble holds the string denoting the meuble field in the database. + FieldMeuble = "meuble" + // FieldNumeroBoite holds the string denoting the numero_boite field in the database. + FieldNumeroBoite = "numero_boite" + // FieldIcone holds the string denoting the icone field in the database. + FieldIcone = "icone" + // FieldCreatedAt holds the string denoting the created_at field in the database. + FieldCreatedAt = "created_at" + // FieldUpdatedAt holds the string denoting the updated_at field in the database. + FieldUpdatedAt = "updated_at" + // EdgeParent holds the string denoting the parent edge name in mutations. + EdgeParent = "parent" + // EdgeEnfants holds the string denoting the enfants edge name in mutations. + EdgeEnfants = "enfants" + // EdgeLiensObjets holds the string denoting the liens_objets edge name in mutations. + EdgeLiensObjets = "liens_objets" + // Table holds the table name of the emplacement in the database. + Table = "emplacement" + // ParentTable is the table that holds the parent relation/edge. + ParentTable = "emplacement" + // ParentColumn is the table column denoting the parent relation/edge. + ParentColumn = "parent_id" + // EnfantsTable is the table that holds the enfants relation/edge. + EnfantsTable = "emplacement" + // EnfantsColumn is the table column denoting the enfants relation/edge. + EnfantsColumn = "parent_id" + // LiensObjetsTable is the table that holds the liens_objets relation/edge. + LiensObjetsTable = "lien_objet_emplacement" + // LiensObjetsInverseTable is the table name for the LienObjetEmplacement entity. + // It exists in this package in order to avoid circular dependency with the "lienobjetemplacement" package. + LiensObjetsInverseTable = "lien_objet_emplacement" + // LiensObjetsColumn is the table column denoting the liens_objets relation/edge. + LiensObjetsColumn = "emplacement_id" +) + +// Columns holds all SQL columns for emplacement fields. +var Columns = []string{ + FieldID, + FieldNom, + FieldParentID, + FieldSlug, + FieldPiece, + FieldMeuble, + FieldNumeroBoite, + FieldIcone, + FieldCreatedAt, + FieldUpdatedAt, +} + +// ValidColumn reports if the column name is valid (part of the table columns). +func ValidColumn(column string) bool { + for i := range Columns { + if column == Columns[i] { + return true + } + } + return false +} + +var ( + // NomValidator is a validator for the "nom" field. It is called by the builders before save. + NomValidator func(string) error + // DefaultCreatedAt holds the default value on creation for the "created_at" field. + DefaultCreatedAt func() time.Time + // DefaultUpdatedAt holds the default value on creation for the "updated_at" field. + DefaultUpdatedAt func() time.Time + // UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field. + UpdateDefaultUpdatedAt func() time.Time + // DefaultID holds the default value on creation for the "id" field. + DefaultID func() uuid.UUID +) + +// OrderOption defines the ordering options for the Emplacement queries. +type OrderOption func(*sql.Selector) + +// ByID orders the results by the id field. +func ByID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldID, opts...).ToFunc() +} + +// ByNom orders the results by the nom field. +func ByNom(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldNom, opts...).ToFunc() +} + +// ByParentID orders the results by the parent_id field. +func ByParentID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldParentID, opts...).ToFunc() +} + +// BySlug orders the results by the slug field. +func BySlug(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldSlug, opts...).ToFunc() +} + +// ByPiece orders the results by the piece field. +func ByPiece(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldPiece, opts...).ToFunc() +} + +// ByMeuble orders the results by the meuble field. +func ByMeuble(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldMeuble, opts...).ToFunc() +} + +// ByNumeroBoite orders the results by the numero_boite field. +func ByNumeroBoite(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldNumeroBoite, opts...).ToFunc() +} + +// ByIcone orders the results by the icone field. +func ByIcone(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldIcone, opts...).ToFunc() +} + +// ByCreatedAt orders the results by the created_at field. +func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() +} + +// ByUpdatedAt orders the results by the updated_at field. +func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc() +} + +// ByParentField orders the results by parent field. +func ByParentField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newParentStep(), sql.OrderByField(field, opts...)) + } +} + +// ByEnfantsCount orders the results by enfants count. +func ByEnfantsCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newEnfantsStep(), opts...) + } +} + +// ByEnfants orders the results by enfants terms. +func ByEnfants(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newEnfantsStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} + +// ByLiensObjetsCount orders the results by liens_objets count. +func ByLiensObjetsCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newLiensObjetsStep(), opts...) + } +} + +// ByLiensObjets orders the results by liens_objets terms. +func ByLiensObjets(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newLiensObjetsStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} +func newParentStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(Table, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, ParentTable, ParentColumn), + ) +} +func newEnfantsStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(Table, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, EnfantsTable, EnfantsColumn), + ) +} +func newLiensObjetsStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(LiensObjetsInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, LiensObjetsTable, LiensObjetsColumn), + ) +} diff --git a/backend/internal/data/ent/emplacement/where.go b/backend/internal/data/ent/emplacement/where.go new file mode 100644 index 0000000..7d4e9c0 --- /dev/null +++ b/backend/internal/data/ent/emplacement/where.go @@ -0,0 +1,736 @@ +// Code generated by ent, DO NOT EDIT. + +package emplacement + +import ( + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/predicate" + "github.com/google/uuid" +) + +// ID filters vertices based on their ID field. +func ID(id uuid.UUID) predicate.Emplacement { + return predicate.Emplacement(sql.FieldEQ(FieldID, id)) +} + +// IDEQ applies the EQ predicate on the ID field. +func IDEQ(id uuid.UUID) predicate.Emplacement { + return predicate.Emplacement(sql.FieldEQ(FieldID, id)) +} + +// IDNEQ applies the NEQ predicate on the ID field. +func IDNEQ(id uuid.UUID) predicate.Emplacement { + return predicate.Emplacement(sql.FieldNEQ(FieldID, id)) +} + +// IDIn applies the In predicate on the ID field. +func IDIn(ids ...uuid.UUID) predicate.Emplacement { + return predicate.Emplacement(sql.FieldIn(FieldID, ids...)) +} + +// IDNotIn applies the NotIn predicate on the ID field. +func IDNotIn(ids ...uuid.UUID) predicate.Emplacement { + return predicate.Emplacement(sql.FieldNotIn(FieldID, ids...)) +} + +// IDGT applies the GT predicate on the ID field. +func IDGT(id uuid.UUID) predicate.Emplacement { + return predicate.Emplacement(sql.FieldGT(FieldID, id)) +} + +// IDGTE applies the GTE predicate on the ID field. +func IDGTE(id uuid.UUID) predicate.Emplacement { + return predicate.Emplacement(sql.FieldGTE(FieldID, id)) +} + +// IDLT applies the LT predicate on the ID field. +func IDLT(id uuid.UUID) predicate.Emplacement { + return predicate.Emplacement(sql.FieldLT(FieldID, id)) +} + +// IDLTE applies the LTE predicate on the ID field. +func IDLTE(id uuid.UUID) predicate.Emplacement { + return predicate.Emplacement(sql.FieldLTE(FieldID, id)) +} + +// Nom applies equality check predicate on the "nom" field. It's identical to NomEQ. +func Nom(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldEQ(FieldNom, v)) +} + +// ParentID applies equality check predicate on the "parent_id" field. It's identical to ParentIDEQ. +func ParentID(v uuid.UUID) predicate.Emplacement { + return predicate.Emplacement(sql.FieldEQ(FieldParentID, v)) +} + +// Slug applies equality check predicate on the "slug" field. It's identical to SlugEQ. +func Slug(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldEQ(FieldSlug, v)) +} + +// Piece applies equality check predicate on the "piece" field. It's identical to PieceEQ. +func Piece(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldEQ(FieldPiece, v)) +} + +// Meuble applies equality check predicate on the "meuble" field. It's identical to MeubleEQ. +func Meuble(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldEQ(FieldMeuble, v)) +} + +// NumeroBoite applies equality check predicate on the "numero_boite" field. It's identical to NumeroBoiteEQ. +func NumeroBoite(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldEQ(FieldNumeroBoite, v)) +} + +// Icone applies equality check predicate on the "icone" field. It's identical to IconeEQ. +func Icone(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldEQ(FieldIcone, v)) +} + +// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. +func CreatedAt(v time.Time) predicate.Emplacement { + return predicate.Emplacement(sql.FieldEQ(FieldCreatedAt, v)) +} + +// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ. +func UpdatedAt(v time.Time) predicate.Emplacement { + return predicate.Emplacement(sql.FieldEQ(FieldUpdatedAt, v)) +} + +// NomEQ applies the EQ predicate on the "nom" field. +func NomEQ(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldEQ(FieldNom, v)) +} + +// NomNEQ applies the NEQ predicate on the "nom" field. +func NomNEQ(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldNEQ(FieldNom, v)) +} + +// NomIn applies the In predicate on the "nom" field. +func NomIn(vs ...string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldIn(FieldNom, vs...)) +} + +// NomNotIn applies the NotIn predicate on the "nom" field. +func NomNotIn(vs ...string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldNotIn(FieldNom, vs...)) +} + +// NomGT applies the GT predicate on the "nom" field. +func NomGT(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldGT(FieldNom, v)) +} + +// NomGTE applies the GTE predicate on the "nom" field. +func NomGTE(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldGTE(FieldNom, v)) +} + +// NomLT applies the LT predicate on the "nom" field. +func NomLT(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldLT(FieldNom, v)) +} + +// NomLTE applies the LTE predicate on the "nom" field. +func NomLTE(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldLTE(FieldNom, v)) +} + +// NomContains applies the Contains predicate on the "nom" field. +func NomContains(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldContains(FieldNom, v)) +} + +// NomHasPrefix applies the HasPrefix predicate on the "nom" field. +func NomHasPrefix(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldHasPrefix(FieldNom, v)) +} + +// NomHasSuffix applies the HasSuffix predicate on the "nom" field. +func NomHasSuffix(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldHasSuffix(FieldNom, v)) +} + +// NomEqualFold applies the EqualFold predicate on the "nom" field. +func NomEqualFold(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldEqualFold(FieldNom, v)) +} + +// NomContainsFold applies the ContainsFold predicate on the "nom" field. +func NomContainsFold(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldContainsFold(FieldNom, v)) +} + +// ParentIDEQ applies the EQ predicate on the "parent_id" field. +func ParentIDEQ(v uuid.UUID) predicate.Emplacement { + return predicate.Emplacement(sql.FieldEQ(FieldParentID, v)) +} + +// ParentIDNEQ applies the NEQ predicate on the "parent_id" field. +func ParentIDNEQ(v uuid.UUID) predicate.Emplacement { + return predicate.Emplacement(sql.FieldNEQ(FieldParentID, v)) +} + +// ParentIDIn applies the In predicate on the "parent_id" field. +func ParentIDIn(vs ...uuid.UUID) predicate.Emplacement { + return predicate.Emplacement(sql.FieldIn(FieldParentID, vs...)) +} + +// ParentIDNotIn applies the NotIn predicate on the "parent_id" field. +func ParentIDNotIn(vs ...uuid.UUID) predicate.Emplacement { + return predicate.Emplacement(sql.FieldNotIn(FieldParentID, vs...)) +} + +// ParentIDIsNil applies the IsNil predicate on the "parent_id" field. +func ParentIDIsNil() predicate.Emplacement { + return predicate.Emplacement(sql.FieldIsNull(FieldParentID)) +} + +// ParentIDNotNil applies the NotNil predicate on the "parent_id" field. +func ParentIDNotNil() predicate.Emplacement { + return predicate.Emplacement(sql.FieldNotNull(FieldParentID)) +} + +// SlugEQ applies the EQ predicate on the "slug" field. +func SlugEQ(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldEQ(FieldSlug, v)) +} + +// SlugNEQ applies the NEQ predicate on the "slug" field. +func SlugNEQ(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldNEQ(FieldSlug, v)) +} + +// SlugIn applies the In predicate on the "slug" field. +func SlugIn(vs ...string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldIn(FieldSlug, vs...)) +} + +// SlugNotIn applies the NotIn predicate on the "slug" field. +func SlugNotIn(vs ...string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldNotIn(FieldSlug, vs...)) +} + +// SlugGT applies the GT predicate on the "slug" field. +func SlugGT(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldGT(FieldSlug, v)) +} + +// SlugGTE applies the GTE predicate on the "slug" field. +func SlugGTE(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldGTE(FieldSlug, v)) +} + +// SlugLT applies the LT predicate on the "slug" field. +func SlugLT(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldLT(FieldSlug, v)) +} + +// SlugLTE applies the LTE predicate on the "slug" field. +func SlugLTE(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldLTE(FieldSlug, v)) +} + +// SlugContains applies the Contains predicate on the "slug" field. +func SlugContains(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldContains(FieldSlug, v)) +} + +// SlugHasPrefix applies the HasPrefix predicate on the "slug" field. +func SlugHasPrefix(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldHasPrefix(FieldSlug, v)) +} + +// SlugHasSuffix applies the HasSuffix predicate on the "slug" field. +func SlugHasSuffix(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldHasSuffix(FieldSlug, v)) +} + +// SlugIsNil applies the IsNil predicate on the "slug" field. +func SlugIsNil() predicate.Emplacement { + return predicate.Emplacement(sql.FieldIsNull(FieldSlug)) +} + +// SlugNotNil applies the NotNil predicate on the "slug" field. +func SlugNotNil() predicate.Emplacement { + return predicate.Emplacement(sql.FieldNotNull(FieldSlug)) +} + +// SlugEqualFold applies the EqualFold predicate on the "slug" field. +func SlugEqualFold(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldEqualFold(FieldSlug, v)) +} + +// SlugContainsFold applies the ContainsFold predicate on the "slug" field. +func SlugContainsFold(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldContainsFold(FieldSlug, v)) +} + +// PieceEQ applies the EQ predicate on the "piece" field. +func PieceEQ(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldEQ(FieldPiece, v)) +} + +// PieceNEQ applies the NEQ predicate on the "piece" field. +func PieceNEQ(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldNEQ(FieldPiece, v)) +} + +// PieceIn applies the In predicate on the "piece" field. +func PieceIn(vs ...string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldIn(FieldPiece, vs...)) +} + +// PieceNotIn applies the NotIn predicate on the "piece" field. +func PieceNotIn(vs ...string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldNotIn(FieldPiece, vs...)) +} + +// PieceGT applies the GT predicate on the "piece" field. +func PieceGT(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldGT(FieldPiece, v)) +} + +// PieceGTE applies the GTE predicate on the "piece" field. +func PieceGTE(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldGTE(FieldPiece, v)) +} + +// PieceLT applies the LT predicate on the "piece" field. +func PieceLT(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldLT(FieldPiece, v)) +} + +// PieceLTE applies the LTE predicate on the "piece" field. +func PieceLTE(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldLTE(FieldPiece, v)) +} + +// PieceContains applies the Contains predicate on the "piece" field. +func PieceContains(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldContains(FieldPiece, v)) +} + +// PieceHasPrefix applies the HasPrefix predicate on the "piece" field. +func PieceHasPrefix(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldHasPrefix(FieldPiece, v)) +} + +// PieceHasSuffix applies the HasSuffix predicate on the "piece" field. +func PieceHasSuffix(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldHasSuffix(FieldPiece, v)) +} + +// PieceIsNil applies the IsNil predicate on the "piece" field. +func PieceIsNil() predicate.Emplacement { + return predicate.Emplacement(sql.FieldIsNull(FieldPiece)) +} + +// PieceNotNil applies the NotNil predicate on the "piece" field. +func PieceNotNil() predicate.Emplacement { + return predicate.Emplacement(sql.FieldNotNull(FieldPiece)) +} + +// PieceEqualFold applies the EqualFold predicate on the "piece" field. +func PieceEqualFold(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldEqualFold(FieldPiece, v)) +} + +// PieceContainsFold applies the ContainsFold predicate on the "piece" field. +func PieceContainsFold(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldContainsFold(FieldPiece, v)) +} + +// MeubleEQ applies the EQ predicate on the "meuble" field. +func MeubleEQ(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldEQ(FieldMeuble, v)) +} + +// MeubleNEQ applies the NEQ predicate on the "meuble" field. +func MeubleNEQ(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldNEQ(FieldMeuble, v)) +} + +// MeubleIn applies the In predicate on the "meuble" field. +func MeubleIn(vs ...string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldIn(FieldMeuble, vs...)) +} + +// MeubleNotIn applies the NotIn predicate on the "meuble" field. +func MeubleNotIn(vs ...string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldNotIn(FieldMeuble, vs...)) +} + +// MeubleGT applies the GT predicate on the "meuble" field. +func MeubleGT(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldGT(FieldMeuble, v)) +} + +// MeubleGTE applies the GTE predicate on the "meuble" field. +func MeubleGTE(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldGTE(FieldMeuble, v)) +} + +// MeubleLT applies the LT predicate on the "meuble" field. +func MeubleLT(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldLT(FieldMeuble, v)) +} + +// MeubleLTE applies the LTE predicate on the "meuble" field. +func MeubleLTE(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldLTE(FieldMeuble, v)) +} + +// MeubleContains applies the Contains predicate on the "meuble" field. +func MeubleContains(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldContains(FieldMeuble, v)) +} + +// MeubleHasPrefix applies the HasPrefix predicate on the "meuble" field. +func MeubleHasPrefix(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldHasPrefix(FieldMeuble, v)) +} + +// MeubleHasSuffix applies the HasSuffix predicate on the "meuble" field. +func MeubleHasSuffix(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldHasSuffix(FieldMeuble, v)) +} + +// MeubleIsNil applies the IsNil predicate on the "meuble" field. +func MeubleIsNil() predicate.Emplacement { + return predicate.Emplacement(sql.FieldIsNull(FieldMeuble)) +} + +// MeubleNotNil applies the NotNil predicate on the "meuble" field. +func MeubleNotNil() predicate.Emplacement { + return predicate.Emplacement(sql.FieldNotNull(FieldMeuble)) +} + +// MeubleEqualFold applies the EqualFold predicate on the "meuble" field. +func MeubleEqualFold(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldEqualFold(FieldMeuble, v)) +} + +// MeubleContainsFold applies the ContainsFold predicate on the "meuble" field. +func MeubleContainsFold(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldContainsFold(FieldMeuble, v)) +} + +// NumeroBoiteEQ applies the EQ predicate on the "numero_boite" field. +func NumeroBoiteEQ(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldEQ(FieldNumeroBoite, v)) +} + +// NumeroBoiteNEQ applies the NEQ predicate on the "numero_boite" field. +func NumeroBoiteNEQ(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldNEQ(FieldNumeroBoite, v)) +} + +// NumeroBoiteIn applies the In predicate on the "numero_boite" field. +func NumeroBoiteIn(vs ...string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldIn(FieldNumeroBoite, vs...)) +} + +// NumeroBoiteNotIn applies the NotIn predicate on the "numero_boite" field. +func NumeroBoiteNotIn(vs ...string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldNotIn(FieldNumeroBoite, vs...)) +} + +// NumeroBoiteGT applies the GT predicate on the "numero_boite" field. +func NumeroBoiteGT(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldGT(FieldNumeroBoite, v)) +} + +// NumeroBoiteGTE applies the GTE predicate on the "numero_boite" field. +func NumeroBoiteGTE(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldGTE(FieldNumeroBoite, v)) +} + +// NumeroBoiteLT applies the LT predicate on the "numero_boite" field. +func NumeroBoiteLT(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldLT(FieldNumeroBoite, v)) +} + +// NumeroBoiteLTE applies the LTE predicate on the "numero_boite" field. +func NumeroBoiteLTE(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldLTE(FieldNumeroBoite, v)) +} + +// NumeroBoiteContains applies the Contains predicate on the "numero_boite" field. +func NumeroBoiteContains(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldContains(FieldNumeroBoite, v)) +} + +// NumeroBoiteHasPrefix applies the HasPrefix predicate on the "numero_boite" field. +func NumeroBoiteHasPrefix(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldHasPrefix(FieldNumeroBoite, v)) +} + +// NumeroBoiteHasSuffix applies the HasSuffix predicate on the "numero_boite" field. +func NumeroBoiteHasSuffix(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldHasSuffix(FieldNumeroBoite, v)) +} + +// NumeroBoiteIsNil applies the IsNil predicate on the "numero_boite" field. +func NumeroBoiteIsNil() predicate.Emplacement { + return predicate.Emplacement(sql.FieldIsNull(FieldNumeroBoite)) +} + +// NumeroBoiteNotNil applies the NotNil predicate on the "numero_boite" field. +func NumeroBoiteNotNil() predicate.Emplacement { + return predicate.Emplacement(sql.FieldNotNull(FieldNumeroBoite)) +} + +// NumeroBoiteEqualFold applies the EqualFold predicate on the "numero_boite" field. +func NumeroBoiteEqualFold(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldEqualFold(FieldNumeroBoite, v)) +} + +// NumeroBoiteContainsFold applies the ContainsFold predicate on the "numero_boite" field. +func NumeroBoiteContainsFold(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldContainsFold(FieldNumeroBoite, v)) +} + +// IconeEQ applies the EQ predicate on the "icone" field. +func IconeEQ(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldEQ(FieldIcone, v)) +} + +// IconeNEQ applies the NEQ predicate on the "icone" field. +func IconeNEQ(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldNEQ(FieldIcone, v)) +} + +// IconeIn applies the In predicate on the "icone" field. +func IconeIn(vs ...string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldIn(FieldIcone, vs...)) +} + +// IconeNotIn applies the NotIn predicate on the "icone" field. +func IconeNotIn(vs ...string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldNotIn(FieldIcone, vs...)) +} + +// IconeGT applies the GT predicate on the "icone" field. +func IconeGT(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldGT(FieldIcone, v)) +} + +// IconeGTE applies the GTE predicate on the "icone" field. +func IconeGTE(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldGTE(FieldIcone, v)) +} + +// IconeLT applies the LT predicate on the "icone" field. +func IconeLT(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldLT(FieldIcone, v)) +} + +// IconeLTE applies the LTE predicate on the "icone" field. +func IconeLTE(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldLTE(FieldIcone, v)) +} + +// IconeContains applies the Contains predicate on the "icone" field. +func IconeContains(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldContains(FieldIcone, v)) +} + +// IconeHasPrefix applies the HasPrefix predicate on the "icone" field. +func IconeHasPrefix(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldHasPrefix(FieldIcone, v)) +} + +// IconeHasSuffix applies the HasSuffix predicate on the "icone" field. +func IconeHasSuffix(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldHasSuffix(FieldIcone, v)) +} + +// IconeIsNil applies the IsNil predicate on the "icone" field. +func IconeIsNil() predicate.Emplacement { + return predicate.Emplacement(sql.FieldIsNull(FieldIcone)) +} + +// IconeNotNil applies the NotNil predicate on the "icone" field. +func IconeNotNil() predicate.Emplacement { + return predicate.Emplacement(sql.FieldNotNull(FieldIcone)) +} + +// IconeEqualFold applies the EqualFold predicate on the "icone" field. +func IconeEqualFold(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldEqualFold(FieldIcone, v)) +} + +// IconeContainsFold applies the ContainsFold predicate on the "icone" field. +func IconeContainsFold(v string) predicate.Emplacement { + return predicate.Emplacement(sql.FieldContainsFold(FieldIcone, v)) +} + +// CreatedAtEQ applies the EQ predicate on the "created_at" field. +func CreatedAtEQ(v time.Time) predicate.Emplacement { + return predicate.Emplacement(sql.FieldEQ(FieldCreatedAt, v)) +} + +// CreatedAtNEQ applies the NEQ predicate on the "created_at" field. +func CreatedAtNEQ(v time.Time) predicate.Emplacement { + return predicate.Emplacement(sql.FieldNEQ(FieldCreatedAt, v)) +} + +// CreatedAtIn applies the In predicate on the "created_at" field. +func CreatedAtIn(vs ...time.Time) predicate.Emplacement { + return predicate.Emplacement(sql.FieldIn(FieldCreatedAt, vs...)) +} + +// CreatedAtNotIn applies the NotIn predicate on the "created_at" field. +func CreatedAtNotIn(vs ...time.Time) predicate.Emplacement { + return predicate.Emplacement(sql.FieldNotIn(FieldCreatedAt, vs...)) +} + +// CreatedAtGT applies the GT predicate on the "created_at" field. +func CreatedAtGT(v time.Time) predicate.Emplacement { + return predicate.Emplacement(sql.FieldGT(FieldCreatedAt, v)) +} + +// CreatedAtGTE applies the GTE predicate on the "created_at" field. +func CreatedAtGTE(v time.Time) predicate.Emplacement { + return predicate.Emplacement(sql.FieldGTE(FieldCreatedAt, v)) +} + +// CreatedAtLT applies the LT predicate on the "created_at" field. +func CreatedAtLT(v time.Time) predicate.Emplacement { + return predicate.Emplacement(sql.FieldLT(FieldCreatedAt, v)) +} + +// CreatedAtLTE applies the LTE predicate on the "created_at" field. +func CreatedAtLTE(v time.Time) predicate.Emplacement { + return predicate.Emplacement(sql.FieldLTE(FieldCreatedAt, v)) +} + +// UpdatedAtEQ applies the EQ predicate on the "updated_at" field. +func UpdatedAtEQ(v time.Time) predicate.Emplacement { + return predicate.Emplacement(sql.FieldEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field. +func UpdatedAtNEQ(v time.Time) predicate.Emplacement { + return predicate.Emplacement(sql.FieldNEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtIn applies the In predicate on the "updated_at" field. +func UpdatedAtIn(vs ...time.Time) predicate.Emplacement { + return predicate.Emplacement(sql.FieldIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field. +func UpdatedAtNotIn(vs ...time.Time) predicate.Emplacement { + return predicate.Emplacement(sql.FieldNotIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtGT applies the GT predicate on the "updated_at" field. +func UpdatedAtGT(v time.Time) predicate.Emplacement { + return predicate.Emplacement(sql.FieldGT(FieldUpdatedAt, v)) +} + +// UpdatedAtGTE applies the GTE predicate on the "updated_at" field. +func UpdatedAtGTE(v time.Time) predicate.Emplacement { + return predicate.Emplacement(sql.FieldGTE(FieldUpdatedAt, v)) +} + +// UpdatedAtLT applies the LT predicate on the "updated_at" field. +func UpdatedAtLT(v time.Time) predicate.Emplacement { + return predicate.Emplacement(sql.FieldLT(FieldUpdatedAt, v)) +} + +// UpdatedAtLTE applies the LTE predicate on the "updated_at" field. +func UpdatedAtLTE(v time.Time) predicate.Emplacement { + return predicate.Emplacement(sql.FieldLTE(FieldUpdatedAt, v)) +} + +// HasParent applies the HasEdge predicate on the "parent" edge. +func HasParent() predicate.Emplacement { + return predicate.Emplacement(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, ParentTable, ParentColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasParentWith applies the HasEdge predicate on the "parent" edge with a given conditions (other predicates). +func HasParentWith(preds ...predicate.Emplacement) predicate.Emplacement { + return predicate.Emplacement(func(s *sql.Selector) { + step := newParentStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + +// HasEnfants applies the HasEdge predicate on the "enfants" edge. +func HasEnfants() predicate.Emplacement { + return predicate.Emplacement(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, EnfantsTable, EnfantsColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasEnfantsWith applies the HasEdge predicate on the "enfants" edge with a given conditions (other predicates). +func HasEnfantsWith(preds ...predicate.Emplacement) predicate.Emplacement { + return predicate.Emplacement(func(s *sql.Selector) { + step := newEnfantsStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + +// HasLiensObjets applies the HasEdge predicate on the "liens_objets" edge. +func HasLiensObjets() predicate.Emplacement { + return predicate.Emplacement(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, LiensObjetsTable, LiensObjetsColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasLiensObjetsWith applies the HasEdge predicate on the "liens_objets" edge with a given conditions (other predicates). +func HasLiensObjetsWith(preds ...predicate.LienObjetEmplacement) predicate.Emplacement { + return predicate.Emplacement(func(s *sql.Selector) { + step := newLiensObjetsStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + +// And groups predicates with the AND operator between them. +func And(predicates ...predicate.Emplacement) predicate.Emplacement { + return predicate.Emplacement(sql.AndPredicates(predicates...)) +} + +// Or groups predicates with the OR operator between them. +func Or(predicates ...predicate.Emplacement) predicate.Emplacement { + return predicate.Emplacement(sql.OrPredicates(predicates...)) +} + +// Not applies the not operator on the given predicate. +func Not(p predicate.Emplacement) predicate.Emplacement { + return predicate.Emplacement(sql.NotPredicates(p)) +} diff --git a/backend/internal/data/ent/emplacement_create.go b/backend/internal/data/ent/emplacement_create.go new file mode 100644 index 0000000..66de5b2 --- /dev/null +++ b/backend/internal/data/ent/emplacement_create.go @@ -0,0 +1,458 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + "time" + + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/emplacement" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/lienobjetemplacement" + "github.com/google/uuid" +) + +// EmplacementCreate is the builder for creating a Emplacement entity. +type EmplacementCreate struct { + config + mutation *EmplacementMutation + hooks []Hook +} + +// SetNom sets the "nom" field. +func (_c *EmplacementCreate) SetNom(v string) *EmplacementCreate { + _c.mutation.SetNom(v) + return _c +} + +// SetParentID sets the "parent_id" field. +func (_c *EmplacementCreate) SetParentID(v uuid.UUID) *EmplacementCreate { + _c.mutation.SetParentID(v) + return _c +} + +// SetNillableParentID sets the "parent_id" field if the given value is not nil. +func (_c *EmplacementCreate) SetNillableParentID(v *uuid.UUID) *EmplacementCreate { + if v != nil { + _c.SetParentID(*v) + } + return _c +} + +// SetSlug sets the "slug" field. +func (_c *EmplacementCreate) SetSlug(v string) *EmplacementCreate { + _c.mutation.SetSlug(v) + return _c +} + +// SetNillableSlug sets the "slug" field if the given value is not nil. +func (_c *EmplacementCreate) SetNillableSlug(v *string) *EmplacementCreate { + if v != nil { + _c.SetSlug(*v) + } + return _c +} + +// SetPiece sets the "piece" field. +func (_c *EmplacementCreate) SetPiece(v string) *EmplacementCreate { + _c.mutation.SetPiece(v) + return _c +} + +// SetNillablePiece sets the "piece" field if the given value is not nil. +func (_c *EmplacementCreate) SetNillablePiece(v *string) *EmplacementCreate { + if v != nil { + _c.SetPiece(*v) + } + return _c +} + +// SetMeuble sets the "meuble" field. +func (_c *EmplacementCreate) SetMeuble(v string) *EmplacementCreate { + _c.mutation.SetMeuble(v) + return _c +} + +// SetNillableMeuble sets the "meuble" field if the given value is not nil. +func (_c *EmplacementCreate) SetNillableMeuble(v *string) *EmplacementCreate { + if v != nil { + _c.SetMeuble(*v) + } + return _c +} + +// SetNumeroBoite sets the "numero_boite" field. +func (_c *EmplacementCreate) SetNumeroBoite(v string) *EmplacementCreate { + _c.mutation.SetNumeroBoite(v) + return _c +} + +// SetNillableNumeroBoite sets the "numero_boite" field if the given value is not nil. +func (_c *EmplacementCreate) SetNillableNumeroBoite(v *string) *EmplacementCreate { + if v != nil { + _c.SetNumeroBoite(*v) + } + return _c +} + +// SetIcone sets the "icone" field. +func (_c *EmplacementCreate) SetIcone(v string) *EmplacementCreate { + _c.mutation.SetIcone(v) + return _c +} + +// SetNillableIcone sets the "icone" field if the given value is not nil. +func (_c *EmplacementCreate) SetNillableIcone(v *string) *EmplacementCreate { + if v != nil { + _c.SetIcone(*v) + } + return _c +} + +// SetCreatedAt sets the "created_at" field. +func (_c *EmplacementCreate) SetCreatedAt(v time.Time) *EmplacementCreate { + _c.mutation.SetCreatedAt(v) + return _c +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (_c *EmplacementCreate) SetNillableCreatedAt(v *time.Time) *EmplacementCreate { + if v != nil { + _c.SetCreatedAt(*v) + } + return _c +} + +// SetUpdatedAt sets the "updated_at" field. +func (_c *EmplacementCreate) SetUpdatedAt(v time.Time) *EmplacementCreate { + _c.mutation.SetUpdatedAt(v) + return _c +} + +// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. +func (_c *EmplacementCreate) SetNillableUpdatedAt(v *time.Time) *EmplacementCreate { + if v != nil { + _c.SetUpdatedAt(*v) + } + return _c +} + +// SetID sets the "id" field. +func (_c *EmplacementCreate) SetID(v uuid.UUID) *EmplacementCreate { + _c.mutation.SetID(v) + return _c +} + +// SetNillableID sets the "id" field if the given value is not nil. +func (_c *EmplacementCreate) SetNillableID(v *uuid.UUID) *EmplacementCreate { + if v != nil { + _c.SetID(*v) + } + return _c +} + +// SetParent sets the "parent" edge to the Emplacement entity. +func (_c *EmplacementCreate) SetParent(v *Emplacement) *EmplacementCreate { + return _c.SetParentID(v.ID) +} + +// AddEnfantIDs adds the "enfants" edge to the Emplacement entity by IDs. +func (_c *EmplacementCreate) AddEnfantIDs(ids ...uuid.UUID) *EmplacementCreate { + _c.mutation.AddEnfantIDs(ids...) + return _c +} + +// AddEnfants adds the "enfants" edges to the Emplacement entity. +func (_c *EmplacementCreate) AddEnfants(v ...*Emplacement) *EmplacementCreate { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _c.AddEnfantIDs(ids...) +} + +// AddLiensObjetIDs adds the "liens_objets" edge to the LienObjetEmplacement entity by IDs. +func (_c *EmplacementCreate) AddLiensObjetIDs(ids ...uuid.UUID) *EmplacementCreate { + _c.mutation.AddLiensObjetIDs(ids...) + return _c +} + +// AddLiensObjets adds the "liens_objets" edges to the LienObjetEmplacement entity. +func (_c *EmplacementCreate) AddLiensObjets(v ...*LienObjetEmplacement) *EmplacementCreate { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _c.AddLiensObjetIDs(ids...) +} + +// Mutation returns the EmplacementMutation object of the builder. +func (_c *EmplacementCreate) Mutation() *EmplacementMutation { + return _c.mutation +} + +// Save creates the Emplacement in the database. +func (_c *EmplacementCreate) Save(ctx context.Context) (*Emplacement, error) { + _c.defaults() + return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks) +} + +// SaveX calls Save and panics if Save returns an error. +func (_c *EmplacementCreate) SaveX(ctx context.Context) *Emplacement { + v, err := _c.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (_c *EmplacementCreate) Exec(ctx context.Context) error { + _, err := _c.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_c *EmplacementCreate) ExecX(ctx context.Context) { + if err := _c.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (_c *EmplacementCreate) defaults() { + if _, ok := _c.mutation.CreatedAt(); !ok { + v := emplacement.DefaultCreatedAt() + _c.mutation.SetCreatedAt(v) + } + if _, ok := _c.mutation.UpdatedAt(); !ok { + v := emplacement.DefaultUpdatedAt() + _c.mutation.SetUpdatedAt(v) + } + if _, ok := _c.mutation.ID(); !ok { + v := emplacement.DefaultID() + _c.mutation.SetID(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_c *EmplacementCreate) check() error { + if _, ok := _c.mutation.Nom(); !ok { + return &ValidationError{Name: "nom", err: errors.New(`ent: missing required field "Emplacement.nom"`)} + } + if v, ok := _c.mutation.Nom(); ok { + if err := emplacement.NomValidator(v); err != nil { + return &ValidationError{Name: "nom", err: fmt.Errorf(`ent: validator failed for field "Emplacement.nom": %w`, err)} + } + } + if _, ok := _c.mutation.CreatedAt(); !ok { + return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Emplacement.created_at"`)} + } + if _, ok := _c.mutation.UpdatedAt(); !ok { + return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "Emplacement.updated_at"`)} + } + return nil +} + +func (_c *EmplacementCreate) sqlSave(ctx context.Context) (*Emplacement, error) { + if err := _c.check(); err != nil { + return nil, err + } + _node, _spec := _c.createSpec() + if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + if _spec.ID.Value != nil { + if id, ok := _spec.ID.Value.(*uuid.UUID); ok { + _node.ID = *id + } else if err := _node.ID.Scan(_spec.ID.Value); err != nil { + return nil, err + } + } + _c.mutation.id = &_node.ID + _c.mutation.done = true + return _node, nil +} + +func (_c *EmplacementCreate) createSpec() (*Emplacement, *sqlgraph.CreateSpec) { + var ( + _node = &Emplacement{config: _c.config} + _spec = sqlgraph.NewCreateSpec(emplacement.Table, sqlgraph.NewFieldSpec(emplacement.FieldID, field.TypeUUID)) + ) + if id, ok := _c.mutation.ID(); ok { + _node.ID = id + _spec.ID.Value = &id + } + if value, ok := _c.mutation.Nom(); ok { + _spec.SetField(emplacement.FieldNom, field.TypeString, value) + _node.Nom = value + } + if value, ok := _c.mutation.Slug(); ok { + _spec.SetField(emplacement.FieldSlug, field.TypeString, value) + _node.Slug = &value + } + if value, ok := _c.mutation.Piece(); ok { + _spec.SetField(emplacement.FieldPiece, field.TypeString, value) + _node.Piece = &value + } + if value, ok := _c.mutation.Meuble(); ok { + _spec.SetField(emplacement.FieldMeuble, field.TypeString, value) + _node.Meuble = &value + } + if value, ok := _c.mutation.NumeroBoite(); ok { + _spec.SetField(emplacement.FieldNumeroBoite, field.TypeString, value) + _node.NumeroBoite = &value + } + if value, ok := _c.mutation.Icone(); ok { + _spec.SetField(emplacement.FieldIcone, field.TypeString, value) + _node.Icone = &value + } + if value, ok := _c.mutation.CreatedAt(); ok { + _spec.SetField(emplacement.FieldCreatedAt, field.TypeTime, value) + _node.CreatedAt = value + } + if value, ok := _c.mutation.UpdatedAt(); ok { + _spec.SetField(emplacement.FieldUpdatedAt, field.TypeTime, value) + _node.UpdatedAt = value + } + if nodes := _c.mutation.ParentIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: emplacement.ParentTable, + Columns: []string{emplacement.ParentColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(emplacement.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _node.ParentID = &nodes[0] + _spec.Edges = append(_spec.Edges, edge) + } + if nodes := _c.mutation.EnfantsIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: emplacement.EnfantsTable, + Columns: []string{emplacement.EnfantsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(emplacement.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges = append(_spec.Edges, edge) + } + if nodes := _c.mutation.LiensObjetsIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: emplacement.LiensObjetsTable, + Columns: []string{emplacement.LiensObjetsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(lienobjetemplacement.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges = append(_spec.Edges, edge) + } + return _node, _spec +} + +// EmplacementCreateBulk is the builder for creating many Emplacement entities in bulk. +type EmplacementCreateBulk struct { + config + err error + builders []*EmplacementCreate +} + +// Save creates the Emplacement entities in the database. +func (_c *EmplacementCreateBulk) Save(ctx context.Context) ([]*Emplacement, error) { + if _c.err != nil { + return nil, _c.err + } + specs := make([]*sqlgraph.CreateSpec, len(_c.builders)) + nodes := make([]*Emplacement, len(_c.builders)) + mutators := make([]Mutator, len(_c.builders)) + for i := range _c.builders { + func(i int, root context.Context) { + builder := _c.builders[i] + builder.defaults() + var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { + mutation, ok := m.(*EmplacementMutation) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T", m) + } + if err := builder.check(); err != nil { + return nil, err + } + builder.mutation = mutation + var err error + nodes[i], specs[i] = builder.createSpec() + if i < len(mutators)-1 { + _, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation) + } else { + spec := &sqlgraph.BatchCreateSpec{Nodes: specs} + // Invoke the actual operation on the latest mutation in the chain. + if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + } + } + if err != nil { + return nil, err + } + mutation.id = &nodes[i].ID + mutation.done = true + return nodes[i], nil + }) + for i := len(builder.hooks) - 1; i >= 0; i-- { + mut = builder.hooks[i](mut) + } + mutators[i] = mut + }(i, ctx) + } + if len(mutators) > 0 { + if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil { + return nil, err + } + } + return nodes, nil +} + +// SaveX is like Save, but panics if an error occurs. +func (_c *EmplacementCreateBulk) SaveX(ctx context.Context) []*Emplacement { + v, err := _c.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (_c *EmplacementCreateBulk) Exec(ctx context.Context) error { + _, err := _c.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_c *EmplacementCreateBulk) ExecX(ctx context.Context) { + if err := _c.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/backend/internal/data/ent/emplacement_delete.go b/backend/internal/data/ent/emplacement_delete.go new file mode 100644 index 0000000..46fee29 --- /dev/null +++ b/backend/internal/data/ent/emplacement_delete.go @@ -0,0 +1,88 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/emplacement" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/predicate" +) + +// EmplacementDelete is the builder for deleting a Emplacement entity. +type EmplacementDelete struct { + config + hooks []Hook + mutation *EmplacementMutation +} + +// Where appends a list predicates to the EmplacementDelete builder. +func (_d *EmplacementDelete) Where(ps ...predicate.Emplacement) *EmplacementDelete { + _d.mutation.Where(ps...) + return _d +} + +// Exec executes the deletion query and returns how many vertices were deleted. +func (_d *EmplacementDelete) Exec(ctx context.Context) (int, error) { + return withHooks(ctx, _d.sqlExec, _d.mutation, _d.hooks) +} + +// ExecX is like Exec, but panics if an error occurs. +func (_d *EmplacementDelete) ExecX(ctx context.Context) int { + n, err := _d.Exec(ctx) + if err != nil { + panic(err) + } + return n +} + +func (_d *EmplacementDelete) sqlExec(ctx context.Context) (int, error) { + _spec := sqlgraph.NewDeleteSpec(emplacement.Table, sqlgraph.NewFieldSpec(emplacement.FieldID, field.TypeUUID)) + if ps := _d.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + affected, err := sqlgraph.DeleteNodes(ctx, _d.driver, _spec) + if err != nil && sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + _d.mutation.done = true + return affected, err +} + +// EmplacementDeleteOne is the builder for deleting a single Emplacement entity. +type EmplacementDeleteOne struct { + _d *EmplacementDelete +} + +// Where appends a list predicates to the EmplacementDelete builder. +func (_d *EmplacementDeleteOne) Where(ps ...predicate.Emplacement) *EmplacementDeleteOne { + _d._d.mutation.Where(ps...) + return _d +} + +// Exec executes the deletion query. +func (_d *EmplacementDeleteOne) Exec(ctx context.Context) error { + n, err := _d._d.Exec(ctx) + switch { + case err != nil: + return err + case n == 0: + return &NotFoundError{emplacement.Label} + default: + return nil + } +} + +// ExecX is like Exec, but panics if an error occurs. +func (_d *EmplacementDeleteOne) ExecX(ctx context.Context) { + if err := _d.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/backend/internal/data/ent/emplacement_query.go b/backend/internal/data/ent/emplacement_query.go new file mode 100644 index 0000000..5a1d6e3 --- /dev/null +++ b/backend/internal/data/ent/emplacement_query.go @@ -0,0 +1,760 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "database/sql/driver" + "fmt" + "math" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/emplacement" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/lienobjetemplacement" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/predicate" + "github.com/google/uuid" +) + +// EmplacementQuery is the builder for querying Emplacement entities. +type EmplacementQuery struct { + config + ctx *QueryContext + order []emplacement.OrderOption + inters []Interceptor + predicates []predicate.Emplacement + withParent *EmplacementQuery + withEnfants *EmplacementQuery + withLiensObjets *LienObjetEmplacementQuery + // intermediate query (i.e. traversal path). + sql *sql.Selector + path func(context.Context) (*sql.Selector, error) +} + +// Where adds a new predicate for the EmplacementQuery builder. +func (_q *EmplacementQuery) Where(ps ...predicate.Emplacement) *EmplacementQuery { + _q.predicates = append(_q.predicates, ps...) + return _q +} + +// Limit the number of records to be returned by this query. +func (_q *EmplacementQuery) Limit(limit int) *EmplacementQuery { + _q.ctx.Limit = &limit + return _q +} + +// Offset to start from. +func (_q *EmplacementQuery) Offset(offset int) *EmplacementQuery { + _q.ctx.Offset = &offset + return _q +} + +// Unique configures the query builder to filter duplicate records on query. +// By default, unique is set to true, and can be disabled using this method. +func (_q *EmplacementQuery) Unique(unique bool) *EmplacementQuery { + _q.ctx.Unique = &unique + return _q +} + +// Order specifies how the records should be ordered. +func (_q *EmplacementQuery) Order(o ...emplacement.OrderOption) *EmplacementQuery { + _q.order = append(_q.order, o...) + return _q +} + +// QueryParent chains the current query on the "parent" edge. +func (_q *EmplacementQuery) QueryParent() *EmplacementQuery { + query := (&EmplacementClient{config: _q.config}).Query() + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + selector := _q.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(emplacement.Table, emplacement.FieldID, selector), + sqlgraph.To(emplacement.Table, emplacement.FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, emplacement.ParentTable, emplacement.ParentColumn), + ) + fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) + return fromU, nil + } + return query +} + +// QueryEnfants chains the current query on the "enfants" edge. +func (_q *EmplacementQuery) QueryEnfants() *EmplacementQuery { + query := (&EmplacementClient{config: _q.config}).Query() + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + selector := _q.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(emplacement.Table, emplacement.FieldID, selector), + sqlgraph.To(emplacement.Table, emplacement.FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, emplacement.EnfantsTable, emplacement.EnfantsColumn), + ) + fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) + return fromU, nil + } + return query +} + +// QueryLiensObjets chains the current query on the "liens_objets" edge. +func (_q *EmplacementQuery) QueryLiensObjets() *LienObjetEmplacementQuery { + query := (&LienObjetEmplacementClient{config: _q.config}).Query() + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + selector := _q.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(emplacement.Table, emplacement.FieldID, selector), + sqlgraph.To(lienobjetemplacement.Table, lienobjetemplacement.FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, emplacement.LiensObjetsTable, emplacement.LiensObjetsColumn), + ) + fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) + return fromU, nil + } + return query +} + +// First returns the first Emplacement entity from the query. +// Returns a *NotFoundError when no Emplacement was found. +func (_q *EmplacementQuery) First(ctx context.Context) (*Emplacement, error) { + nodes, err := _q.Limit(1).All(setContextOp(ctx, _q.ctx, ent.OpQueryFirst)) + if err != nil { + return nil, err + } + if len(nodes) == 0 { + return nil, &NotFoundError{emplacement.Label} + } + return nodes[0], nil +} + +// FirstX is like First, but panics if an error occurs. +func (_q *EmplacementQuery) FirstX(ctx context.Context) *Emplacement { + node, err := _q.First(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return node +} + +// FirstID returns the first Emplacement ID from the query. +// Returns a *NotFoundError when no Emplacement ID was found. +func (_q *EmplacementQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { + var ids []uuid.UUID + if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil { + return + } + if len(ids) == 0 { + err = &NotFoundError{emplacement.Label} + return + } + return ids[0], nil +} + +// FirstIDX is like FirstID, but panics if an error occurs. +func (_q *EmplacementQuery) FirstIDX(ctx context.Context) uuid.UUID { + id, err := _q.FirstID(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return id +} + +// Only returns a single Emplacement entity found by the query, ensuring it only returns one. +// Returns a *NotSingularError when more than one Emplacement entity is found. +// Returns a *NotFoundError when no Emplacement entities are found. +func (_q *EmplacementQuery) Only(ctx context.Context) (*Emplacement, error) { + nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly)) + if err != nil { + return nil, err + } + switch len(nodes) { + case 1: + return nodes[0], nil + case 0: + return nil, &NotFoundError{emplacement.Label} + default: + return nil, &NotSingularError{emplacement.Label} + } +} + +// OnlyX is like Only, but panics if an error occurs. +func (_q *EmplacementQuery) OnlyX(ctx context.Context) *Emplacement { + node, err := _q.Only(ctx) + if err != nil { + panic(err) + } + return node +} + +// OnlyID is like Only, but returns the only Emplacement ID in the query. +// Returns a *NotSingularError when more than one Emplacement ID is found. +// Returns a *NotFoundError when no entities are found. +func (_q *EmplacementQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { + var ids []uuid.UUID + if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryOnlyID)); err != nil { + return + } + switch len(ids) { + case 1: + id = ids[0] + case 0: + err = &NotFoundError{emplacement.Label} + default: + err = &NotSingularError{emplacement.Label} + } + return +} + +// OnlyIDX is like OnlyID, but panics if an error occurs. +func (_q *EmplacementQuery) OnlyIDX(ctx context.Context) uuid.UUID { + id, err := _q.OnlyID(ctx) + if err != nil { + panic(err) + } + return id +} + +// All executes the query and returns a list of Emplacements. +func (_q *EmplacementQuery) All(ctx context.Context) ([]*Emplacement, error) { + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll) + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + qr := querierAll[[]*Emplacement, *EmplacementQuery]() + return withInterceptors[[]*Emplacement](ctx, _q, qr, _q.inters) +} + +// AllX is like All, but panics if an error occurs. +func (_q *EmplacementQuery) AllX(ctx context.Context) []*Emplacement { + nodes, err := _q.All(ctx) + if err != nil { + panic(err) + } + return nodes +} + +// IDs executes the query and returns a list of Emplacement IDs. +func (_q *EmplacementQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) { + if _q.ctx.Unique == nil && _q.path != nil { + _q.Unique(true) + } + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryIDs) + if err = _q.Select(emplacement.FieldID).Scan(ctx, &ids); err != nil { + return nil, err + } + return ids, nil +} + +// IDsX is like IDs, but panics if an error occurs. +func (_q *EmplacementQuery) IDsX(ctx context.Context) []uuid.UUID { + ids, err := _q.IDs(ctx) + if err != nil { + panic(err) + } + return ids +} + +// Count returns the count of the given query. +func (_q *EmplacementQuery) Count(ctx context.Context) (int, error) { + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryCount) + if err := _q.prepareQuery(ctx); err != nil { + return 0, err + } + return withInterceptors[int](ctx, _q, querierCount[*EmplacementQuery](), _q.inters) +} + +// CountX is like Count, but panics if an error occurs. +func (_q *EmplacementQuery) CountX(ctx context.Context) int { + count, err := _q.Count(ctx) + if err != nil { + panic(err) + } + return count +} + +// Exist returns true if the query has elements in the graph. +func (_q *EmplacementQuery) Exist(ctx context.Context) (bool, error) { + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryExist) + switch _, err := _q.FirstID(ctx); { + case IsNotFound(err): + return false, nil + case err != nil: + return false, fmt.Errorf("ent: check existence: %w", err) + default: + return true, nil + } +} + +// ExistX is like Exist, but panics if an error occurs. +func (_q *EmplacementQuery) ExistX(ctx context.Context) bool { + exist, err := _q.Exist(ctx) + if err != nil { + panic(err) + } + return exist +} + +// Clone returns a duplicate of the EmplacementQuery builder, including all associated steps. It can be +// used to prepare common query builders and use them differently after the clone is made. +func (_q *EmplacementQuery) Clone() *EmplacementQuery { + if _q == nil { + return nil + } + return &EmplacementQuery{ + config: _q.config, + ctx: _q.ctx.Clone(), + order: append([]emplacement.OrderOption{}, _q.order...), + inters: append([]Interceptor{}, _q.inters...), + predicates: append([]predicate.Emplacement{}, _q.predicates...), + withParent: _q.withParent.Clone(), + withEnfants: _q.withEnfants.Clone(), + withLiensObjets: _q.withLiensObjets.Clone(), + // clone intermediate query. + sql: _q.sql.Clone(), + path: _q.path, + } +} + +// WithParent tells the query-builder to eager-load the nodes that are connected to +// the "parent" edge. The optional arguments are used to configure the query builder of the edge. +func (_q *EmplacementQuery) WithParent(opts ...func(*EmplacementQuery)) *EmplacementQuery { + query := (&EmplacementClient{config: _q.config}).Query() + for _, opt := range opts { + opt(query) + } + _q.withParent = query + return _q +} + +// WithEnfants tells the query-builder to eager-load the nodes that are connected to +// the "enfants" edge. The optional arguments are used to configure the query builder of the edge. +func (_q *EmplacementQuery) WithEnfants(opts ...func(*EmplacementQuery)) *EmplacementQuery { + query := (&EmplacementClient{config: _q.config}).Query() + for _, opt := range opts { + opt(query) + } + _q.withEnfants = query + return _q +} + +// WithLiensObjets tells the query-builder to eager-load the nodes that are connected to +// the "liens_objets" edge. The optional arguments are used to configure the query builder of the edge. +func (_q *EmplacementQuery) WithLiensObjets(opts ...func(*LienObjetEmplacementQuery)) *EmplacementQuery { + query := (&LienObjetEmplacementClient{config: _q.config}).Query() + for _, opt := range opts { + opt(query) + } + _q.withLiensObjets = query + return _q +} + +// GroupBy is used to group vertices by one or more fields/columns. +// It is often used with aggregate functions, like: count, max, mean, min, sum. +// +// Example: +// +// var v []struct { +// Nom string `json:"nom,omitempty"` +// Count int `json:"count,omitempty"` +// } +// +// client.Emplacement.Query(). +// GroupBy(emplacement.FieldNom). +// Aggregate(ent.Count()). +// Scan(ctx, &v) +func (_q *EmplacementQuery) GroupBy(field string, fields ...string) *EmplacementGroupBy { + _q.ctx.Fields = append([]string{field}, fields...) + grbuild := &EmplacementGroupBy{build: _q} + grbuild.flds = &_q.ctx.Fields + grbuild.label = emplacement.Label + grbuild.scan = grbuild.Scan + return grbuild +} + +// Select allows the selection one or more fields/columns for the given query, +// instead of selecting all fields in the entity. +// +// Example: +// +// var v []struct { +// Nom string `json:"nom,omitempty"` +// } +// +// client.Emplacement.Query(). +// Select(emplacement.FieldNom). +// Scan(ctx, &v) +func (_q *EmplacementQuery) Select(fields ...string) *EmplacementSelect { + _q.ctx.Fields = append(_q.ctx.Fields, fields...) + sbuild := &EmplacementSelect{EmplacementQuery: _q} + sbuild.label = emplacement.Label + sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan + return sbuild +} + +// Aggregate returns a EmplacementSelect configured with the given aggregations. +func (_q *EmplacementQuery) Aggregate(fns ...AggregateFunc) *EmplacementSelect { + return _q.Select().Aggregate(fns...) +} + +func (_q *EmplacementQuery) prepareQuery(ctx context.Context) error { + for _, inter := range _q.inters { + if inter == nil { + return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)") + } + if trv, ok := inter.(Traverser); ok { + if err := trv.Traverse(ctx, _q); err != nil { + return err + } + } + } + for _, f := range _q.ctx.Fields { + if !emplacement.ValidColumn(f) { + return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + } + if _q.path != nil { + prev, err := _q.path(ctx) + if err != nil { + return err + } + _q.sql = prev + } + return nil +} + +func (_q *EmplacementQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Emplacement, error) { + var ( + nodes = []*Emplacement{} + _spec = _q.querySpec() + loadedTypes = [3]bool{ + _q.withParent != nil, + _q.withEnfants != nil, + _q.withLiensObjets != nil, + } + ) + _spec.ScanValues = func(columns []string) ([]any, error) { + return (*Emplacement).scanValues(nil, columns) + } + _spec.Assign = func(columns []string, values []any) error { + node := &Emplacement{config: _q.config} + nodes = append(nodes, node) + node.Edges.loadedTypes = loadedTypes + return node.assignValues(columns, values) + } + for i := range hooks { + hooks[i](ctx, _spec) + } + if err := sqlgraph.QueryNodes(ctx, _q.driver, _spec); err != nil { + return nil, err + } + if len(nodes) == 0 { + return nodes, nil + } + if query := _q.withParent; query != nil { + if err := _q.loadParent(ctx, query, nodes, nil, + func(n *Emplacement, e *Emplacement) { n.Edges.Parent = e }); err != nil { + return nil, err + } + } + if query := _q.withEnfants; query != nil { + if err := _q.loadEnfants(ctx, query, nodes, + func(n *Emplacement) { n.Edges.Enfants = []*Emplacement{} }, + func(n *Emplacement, e *Emplacement) { n.Edges.Enfants = append(n.Edges.Enfants, e) }); err != nil { + return nil, err + } + } + if query := _q.withLiensObjets; query != nil { + if err := _q.loadLiensObjets(ctx, query, nodes, + func(n *Emplacement) { n.Edges.LiensObjets = []*LienObjetEmplacement{} }, + func(n *Emplacement, e *LienObjetEmplacement) { n.Edges.LiensObjets = append(n.Edges.LiensObjets, e) }); err != nil { + return nil, err + } + } + return nodes, nil +} + +func (_q *EmplacementQuery) loadParent(ctx context.Context, query *EmplacementQuery, nodes []*Emplacement, init func(*Emplacement), assign func(*Emplacement, *Emplacement)) error { + ids := make([]uuid.UUID, 0, len(nodes)) + nodeids := make(map[uuid.UUID][]*Emplacement) + for i := range nodes { + if nodes[i].ParentID == nil { + continue + } + fk := *nodes[i].ParentID + if _, ok := nodeids[fk]; !ok { + ids = append(ids, fk) + } + nodeids[fk] = append(nodeids[fk], nodes[i]) + } + if len(ids) == 0 { + return nil + } + query.Where(emplacement.IDIn(ids...)) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + nodes, ok := nodeids[n.ID] + if !ok { + return fmt.Errorf(`unexpected foreign-key "parent_id" returned %v`, n.ID) + } + for i := range nodes { + assign(nodes[i], n) + } + } + return nil +} +func (_q *EmplacementQuery) loadEnfants(ctx context.Context, query *EmplacementQuery, nodes []*Emplacement, init func(*Emplacement), assign func(*Emplacement, *Emplacement)) error { + fks := make([]driver.Value, 0, len(nodes)) + nodeids := make(map[uuid.UUID]*Emplacement) + for i := range nodes { + fks = append(fks, nodes[i].ID) + nodeids[nodes[i].ID] = nodes[i] + if init != nil { + init(nodes[i]) + } + } + if len(query.ctx.Fields) > 0 { + query.ctx.AppendFieldOnce(emplacement.FieldParentID) + } + query.Where(predicate.Emplacement(func(s *sql.Selector) { + s.Where(sql.InValues(s.C(emplacement.EnfantsColumn), fks...)) + })) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + fk := n.ParentID + if fk == nil { + return fmt.Errorf(`foreign-key "parent_id" is nil for node %v`, n.ID) + } + node, ok := nodeids[*fk] + if !ok { + return fmt.Errorf(`unexpected referenced foreign-key "parent_id" returned %v for node %v`, *fk, n.ID) + } + assign(node, n) + } + return nil +} +func (_q *EmplacementQuery) loadLiensObjets(ctx context.Context, query *LienObjetEmplacementQuery, nodes []*Emplacement, init func(*Emplacement), assign func(*Emplacement, *LienObjetEmplacement)) error { + fks := make([]driver.Value, 0, len(nodes)) + nodeids := make(map[uuid.UUID]*Emplacement) + for i := range nodes { + fks = append(fks, nodes[i].ID) + nodeids[nodes[i].ID] = nodes[i] + if init != nil { + init(nodes[i]) + } + } + if len(query.ctx.Fields) > 0 { + query.ctx.AppendFieldOnce(lienobjetemplacement.FieldEmplacementID) + } + query.Where(predicate.LienObjetEmplacement(func(s *sql.Selector) { + s.Where(sql.InValues(s.C(emplacement.LiensObjetsColumn), fks...)) + })) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + fk := n.EmplacementID + node, ok := nodeids[fk] + if !ok { + return fmt.Errorf(`unexpected referenced foreign-key "emplacement_id" returned %v for node %v`, fk, n.ID) + } + assign(node, n) + } + return nil +} + +func (_q *EmplacementQuery) sqlCount(ctx context.Context) (int, error) { + _spec := _q.querySpec() + _spec.Node.Columns = _q.ctx.Fields + if len(_q.ctx.Fields) > 0 { + _spec.Unique = _q.ctx.Unique != nil && *_q.ctx.Unique + } + return sqlgraph.CountNodes(ctx, _q.driver, _spec) +} + +func (_q *EmplacementQuery) querySpec() *sqlgraph.QuerySpec { + _spec := sqlgraph.NewQuerySpec(emplacement.Table, emplacement.Columns, sqlgraph.NewFieldSpec(emplacement.FieldID, field.TypeUUID)) + _spec.From = _q.sql + if unique := _q.ctx.Unique; unique != nil { + _spec.Unique = *unique + } else if _q.path != nil { + _spec.Unique = true + } + if fields := _q.ctx.Fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, emplacement.FieldID) + for i := range fields { + if fields[i] != emplacement.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) + } + } + if _q.withParent != nil { + _spec.Node.AddColumnOnce(emplacement.FieldParentID) + } + } + if ps := _q.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if limit := _q.ctx.Limit; limit != nil { + _spec.Limit = *limit + } + if offset := _q.ctx.Offset; offset != nil { + _spec.Offset = *offset + } + if ps := _q.order; len(ps) > 0 { + _spec.Order = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + return _spec +} + +func (_q *EmplacementQuery) sqlQuery(ctx context.Context) *sql.Selector { + builder := sql.Dialect(_q.driver.Dialect()) + t1 := builder.Table(emplacement.Table) + columns := _q.ctx.Fields + if len(columns) == 0 { + columns = emplacement.Columns + } + selector := builder.Select(t1.Columns(columns...)...).From(t1) + if _q.sql != nil { + selector = _q.sql + selector.Select(selector.Columns(columns...)...) + } + if _q.ctx.Unique != nil && *_q.ctx.Unique { + selector.Distinct() + } + for _, p := range _q.predicates { + p(selector) + } + for _, p := range _q.order { + p(selector) + } + if offset := _q.ctx.Offset; offset != nil { + // limit is mandatory for offset clause. We start + // with default value, and override it below if needed. + selector.Offset(*offset).Limit(math.MaxInt32) + } + if limit := _q.ctx.Limit; limit != nil { + selector.Limit(*limit) + } + return selector +} + +// EmplacementGroupBy is the group-by builder for Emplacement entities. +type EmplacementGroupBy struct { + selector + build *EmplacementQuery +} + +// Aggregate adds the given aggregation functions to the group-by query. +func (_g *EmplacementGroupBy) Aggregate(fns ...AggregateFunc) *EmplacementGroupBy { + _g.fns = append(_g.fns, fns...) + return _g +} + +// Scan applies the selector query and scans the result into the given value. +func (_g *EmplacementGroupBy) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, _g.build.ctx, ent.OpQueryGroupBy) + if err := _g.build.prepareQuery(ctx); err != nil { + return err + } + return scanWithInterceptors[*EmplacementQuery, *EmplacementGroupBy](ctx, _g.build, _g, _g.build.inters, v) +} + +func (_g *EmplacementGroupBy) sqlScan(ctx context.Context, root *EmplacementQuery, v any) error { + selector := root.sqlQuery(ctx).Select() + aggregation := make([]string, 0, len(_g.fns)) + for _, fn := range _g.fns { + aggregation = append(aggregation, fn(selector)) + } + if len(selector.SelectedColumns()) == 0 { + columns := make([]string, 0, len(*_g.flds)+len(_g.fns)) + for _, f := range *_g.flds { + columns = append(columns, selector.C(f)) + } + columns = append(columns, aggregation...) + selector.Select(columns...) + } + selector.GroupBy(selector.Columns(*_g.flds...)...) + if err := selector.Err(); err != nil { + return err + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := _g.build.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} + +// EmplacementSelect is the builder for selecting fields of Emplacement entities. +type EmplacementSelect struct { + *EmplacementQuery + selector +} + +// Aggregate adds the given aggregation functions to the selector query. +func (_s *EmplacementSelect) Aggregate(fns ...AggregateFunc) *EmplacementSelect { + _s.fns = append(_s.fns, fns...) + return _s +} + +// Scan applies the selector query and scans the result into the given value. +func (_s *EmplacementSelect) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, _s.ctx, ent.OpQuerySelect) + if err := _s.prepareQuery(ctx); err != nil { + return err + } + return scanWithInterceptors[*EmplacementQuery, *EmplacementSelect](ctx, _s.EmplacementQuery, _s, _s.inters, v) +} + +func (_s *EmplacementSelect) sqlScan(ctx context.Context, root *EmplacementQuery, v any) error { + selector := root.sqlQuery(ctx) + aggregation := make([]string, 0, len(_s.fns)) + for _, fn := range _s.fns { + aggregation = append(aggregation, fn(selector)) + } + switch n := len(*_s.selector.flds); { + case n == 0 && len(aggregation) > 0: + selector.Select(aggregation...) + case n != 0 && len(aggregation) > 0: + selector.AppendSelect(aggregation...) + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := _s.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} diff --git a/backend/internal/data/ent/emplacement_update.go b/backend/internal/data/ent/emplacement_update.go new file mode 100644 index 0000000..6ac52e3 --- /dev/null +++ b/backend/internal/data/ent/emplacement_update.go @@ -0,0 +1,1012 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/emplacement" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/lienobjetemplacement" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/predicate" + "github.com/google/uuid" +) + +// EmplacementUpdate is the builder for updating Emplacement entities. +type EmplacementUpdate struct { + config + hooks []Hook + mutation *EmplacementMutation +} + +// Where appends a list predicates to the EmplacementUpdate builder. +func (_u *EmplacementUpdate) Where(ps ...predicate.Emplacement) *EmplacementUpdate { + _u.mutation.Where(ps...) + return _u +} + +// SetNom sets the "nom" field. +func (_u *EmplacementUpdate) SetNom(v string) *EmplacementUpdate { + _u.mutation.SetNom(v) + return _u +} + +// SetNillableNom sets the "nom" field if the given value is not nil. +func (_u *EmplacementUpdate) SetNillableNom(v *string) *EmplacementUpdate { + if v != nil { + _u.SetNom(*v) + } + return _u +} + +// SetParentID sets the "parent_id" field. +func (_u *EmplacementUpdate) SetParentID(v uuid.UUID) *EmplacementUpdate { + _u.mutation.SetParentID(v) + return _u +} + +// SetNillableParentID sets the "parent_id" field if the given value is not nil. +func (_u *EmplacementUpdate) SetNillableParentID(v *uuid.UUID) *EmplacementUpdate { + if v != nil { + _u.SetParentID(*v) + } + return _u +} + +// ClearParentID clears the value of the "parent_id" field. +func (_u *EmplacementUpdate) ClearParentID() *EmplacementUpdate { + _u.mutation.ClearParentID() + return _u +} + +// SetSlug sets the "slug" field. +func (_u *EmplacementUpdate) SetSlug(v string) *EmplacementUpdate { + _u.mutation.SetSlug(v) + return _u +} + +// SetNillableSlug sets the "slug" field if the given value is not nil. +func (_u *EmplacementUpdate) SetNillableSlug(v *string) *EmplacementUpdate { + if v != nil { + _u.SetSlug(*v) + } + return _u +} + +// ClearSlug clears the value of the "slug" field. +func (_u *EmplacementUpdate) ClearSlug() *EmplacementUpdate { + _u.mutation.ClearSlug() + return _u +} + +// SetPiece sets the "piece" field. +func (_u *EmplacementUpdate) SetPiece(v string) *EmplacementUpdate { + _u.mutation.SetPiece(v) + return _u +} + +// SetNillablePiece sets the "piece" field if the given value is not nil. +func (_u *EmplacementUpdate) SetNillablePiece(v *string) *EmplacementUpdate { + if v != nil { + _u.SetPiece(*v) + } + return _u +} + +// ClearPiece clears the value of the "piece" field. +func (_u *EmplacementUpdate) ClearPiece() *EmplacementUpdate { + _u.mutation.ClearPiece() + return _u +} + +// SetMeuble sets the "meuble" field. +func (_u *EmplacementUpdate) SetMeuble(v string) *EmplacementUpdate { + _u.mutation.SetMeuble(v) + return _u +} + +// SetNillableMeuble sets the "meuble" field if the given value is not nil. +func (_u *EmplacementUpdate) SetNillableMeuble(v *string) *EmplacementUpdate { + if v != nil { + _u.SetMeuble(*v) + } + return _u +} + +// ClearMeuble clears the value of the "meuble" field. +func (_u *EmplacementUpdate) ClearMeuble() *EmplacementUpdate { + _u.mutation.ClearMeuble() + return _u +} + +// SetNumeroBoite sets the "numero_boite" field. +func (_u *EmplacementUpdate) SetNumeroBoite(v string) *EmplacementUpdate { + _u.mutation.SetNumeroBoite(v) + return _u +} + +// SetNillableNumeroBoite sets the "numero_boite" field if the given value is not nil. +func (_u *EmplacementUpdate) SetNillableNumeroBoite(v *string) *EmplacementUpdate { + if v != nil { + _u.SetNumeroBoite(*v) + } + return _u +} + +// ClearNumeroBoite clears the value of the "numero_boite" field. +func (_u *EmplacementUpdate) ClearNumeroBoite() *EmplacementUpdate { + _u.mutation.ClearNumeroBoite() + return _u +} + +// SetIcone sets the "icone" field. +func (_u *EmplacementUpdate) SetIcone(v string) *EmplacementUpdate { + _u.mutation.SetIcone(v) + return _u +} + +// SetNillableIcone sets the "icone" field if the given value is not nil. +func (_u *EmplacementUpdate) SetNillableIcone(v *string) *EmplacementUpdate { + if v != nil { + _u.SetIcone(*v) + } + return _u +} + +// ClearIcone clears the value of the "icone" field. +func (_u *EmplacementUpdate) ClearIcone() *EmplacementUpdate { + _u.mutation.ClearIcone() + return _u +} + +// SetCreatedAt sets the "created_at" field. +func (_u *EmplacementUpdate) SetCreatedAt(v time.Time) *EmplacementUpdate { + _u.mutation.SetCreatedAt(v) + return _u +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (_u *EmplacementUpdate) SetNillableCreatedAt(v *time.Time) *EmplacementUpdate { + if v != nil { + _u.SetCreatedAt(*v) + } + return _u +} + +// SetUpdatedAt sets the "updated_at" field. +func (_u *EmplacementUpdate) SetUpdatedAt(v time.Time) *EmplacementUpdate { + _u.mutation.SetUpdatedAt(v) + return _u +} + +// SetParent sets the "parent" edge to the Emplacement entity. +func (_u *EmplacementUpdate) SetParent(v *Emplacement) *EmplacementUpdate { + return _u.SetParentID(v.ID) +} + +// AddEnfantIDs adds the "enfants" edge to the Emplacement entity by IDs. +func (_u *EmplacementUpdate) AddEnfantIDs(ids ...uuid.UUID) *EmplacementUpdate { + _u.mutation.AddEnfantIDs(ids...) + return _u +} + +// AddEnfants adds the "enfants" edges to the Emplacement entity. +func (_u *EmplacementUpdate) AddEnfants(v ...*Emplacement) *EmplacementUpdate { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.AddEnfantIDs(ids...) +} + +// AddLiensObjetIDs adds the "liens_objets" edge to the LienObjetEmplacement entity by IDs. +func (_u *EmplacementUpdate) AddLiensObjetIDs(ids ...uuid.UUID) *EmplacementUpdate { + _u.mutation.AddLiensObjetIDs(ids...) + return _u +} + +// AddLiensObjets adds the "liens_objets" edges to the LienObjetEmplacement entity. +func (_u *EmplacementUpdate) AddLiensObjets(v ...*LienObjetEmplacement) *EmplacementUpdate { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.AddLiensObjetIDs(ids...) +} + +// Mutation returns the EmplacementMutation object of the builder. +func (_u *EmplacementUpdate) Mutation() *EmplacementMutation { + return _u.mutation +} + +// ClearParent clears the "parent" edge to the Emplacement entity. +func (_u *EmplacementUpdate) ClearParent() *EmplacementUpdate { + _u.mutation.ClearParent() + return _u +} + +// ClearEnfants clears all "enfants" edges to the Emplacement entity. +func (_u *EmplacementUpdate) ClearEnfants() *EmplacementUpdate { + _u.mutation.ClearEnfants() + return _u +} + +// RemoveEnfantIDs removes the "enfants" edge to Emplacement entities by IDs. +func (_u *EmplacementUpdate) RemoveEnfantIDs(ids ...uuid.UUID) *EmplacementUpdate { + _u.mutation.RemoveEnfantIDs(ids...) + return _u +} + +// RemoveEnfants removes "enfants" edges to Emplacement entities. +func (_u *EmplacementUpdate) RemoveEnfants(v ...*Emplacement) *EmplacementUpdate { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.RemoveEnfantIDs(ids...) +} + +// ClearLiensObjets clears all "liens_objets" edges to the LienObjetEmplacement entity. +func (_u *EmplacementUpdate) ClearLiensObjets() *EmplacementUpdate { + _u.mutation.ClearLiensObjets() + return _u +} + +// RemoveLiensObjetIDs removes the "liens_objets" edge to LienObjetEmplacement entities by IDs. +func (_u *EmplacementUpdate) RemoveLiensObjetIDs(ids ...uuid.UUID) *EmplacementUpdate { + _u.mutation.RemoveLiensObjetIDs(ids...) + return _u +} + +// RemoveLiensObjets removes "liens_objets" edges to LienObjetEmplacement entities. +func (_u *EmplacementUpdate) RemoveLiensObjets(v ...*LienObjetEmplacement) *EmplacementUpdate { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.RemoveLiensObjetIDs(ids...) +} + +// Save executes the query and returns the number of nodes affected by the update operation. +func (_u *EmplacementUpdate) Save(ctx context.Context) (int, error) { + _u.defaults() + return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (_u *EmplacementUpdate) SaveX(ctx context.Context) int { + affected, err := _u.Save(ctx) + if err != nil { + panic(err) + } + return affected +} + +// Exec executes the query. +func (_u *EmplacementUpdate) Exec(ctx context.Context) error { + _, err := _u.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_u *EmplacementUpdate) ExecX(ctx context.Context) { + if err := _u.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (_u *EmplacementUpdate) defaults() { + if _, ok := _u.mutation.UpdatedAt(); !ok { + v := emplacement.UpdateDefaultUpdatedAt() + _u.mutation.SetUpdatedAt(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_u *EmplacementUpdate) check() error { + if v, ok := _u.mutation.Nom(); ok { + if err := emplacement.NomValidator(v); err != nil { + return &ValidationError{Name: "nom", err: fmt.Errorf(`ent: validator failed for field "Emplacement.nom": %w`, err)} + } + } + return nil +} + +func (_u *EmplacementUpdate) sqlSave(ctx context.Context) (_node int, err error) { + if err := _u.check(); err != nil { + return _node, err + } + _spec := sqlgraph.NewUpdateSpec(emplacement.Table, emplacement.Columns, sqlgraph.NewFieldSpec(emplacement.FieldID, field.TypeUUID)) + if ps := _u.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := _u.mutation.Nom(); ok { + _spec.SetField(emplacement.FieldNom, field.TypeString, value) + } + if value, ok := _u.mutation.Slug(); ok { + _spec.SetField(emplacement.FieldSlug, field.TypeString, value) + } + if _u.mutation.SlugCleared() { + _spec.ClearField(emplacement.FieldSlug, field.TypeString) + } + if value, ok := _u.mutation.Piece(); ok { + _spec.SetField(emplacement.FieldPiece, field.TypeString, value) + } + if _u.mutation.PieceCleared() { + _spec.ClearField(emplacement.FieldPiece, field.TypeString) + } + if value, ok := _u.mutation.Meuble(); ok { + _spec.SetField(emplacement.FieldMeuble, field.TypeString, value) + } + if _u.mutation.MeubleCleared() { + _spec.ClearField(emplacement.FieldMeuble, field.TypeString) + } + if value, ok := _u.mutation.NumeroBoite(); ok { + _spec.SetField(emplacement.FieldNumeroBoite, field.TypeString, value) + } + if _u.mutation.NumeroBoiteCleared() { + _spec.ClearField(emplacement.FieldNumeroBoite, field.TypeString) + } + if value, ok := _u.mutation.Icone(); ok { + _spec.SetField(emplacement.FieldIcone, field.TypeString, value) + } + if _u.mutation.IconeCleared() { + _spec.ClearField(emplacement.FieldIcone, field.TypeString) + } + if value, ok := _u.mutation.CreatedAt(); ok { + _spec.SetField(emplacement.FieldCreatedAt, field.TypeTime, value) + } + if value, ok := _u.mutation.UpdatedAt(); ok { + _spec.SetField(emplacement.FieldUpdatedAt, field.TypeTime, value) + } + if _u.mutation.ParentCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: emplacement.ParentTable, + Columns: []string{emplacement.ParentColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(emplacement.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.ParentIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: emplacement.ParentTable, + Columns: []string{emplacement.ParentColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(emplacement.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if _u.mutation.EnfantsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: emplacement.EnfantsTable, + Columns: []string{emplacement.EnfantsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(emplacement.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.RemovedEnfantsIDs(); len(nodes) > 0 && !_u.mutation.EnfantsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: emplacement.EnfantsTable, + Columns: []string{emplacement.EnfantsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(emplacement.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.EnfantsIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: emplacement.EnfantsTable, + Columns: []string{emplacement.EnfantsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(emplacement.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if _u.mutation.LiensObjetsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: emplacement.LiensObjetsTable, + Columns: []string{emplacement.LiensObjetsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(lienobjetemplacement.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.RemovedLiensObjetsIDs(); len(nodes) > 0 && !_u.mutation.LiensObjetsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: emplacement.LiensObjetsTable, + Columns: []string{emplacement.LiensObjetsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(lienobjetemplacement.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.LiensObjetsIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: emplacement.LiensObjetsTable, + Columns: []string{emplacement.LiensObjetsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(lienobjetemplacement.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{emplacement.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return 0, err + } + _u.mutation.done = true + return _node, nil +} + +// EmplacementUpdateOne is the builder for updating a single Emplacement entity. +type EmplacementUpdateOne struct { + config + fields []string + hooks []Hook + mutation *EmplacementMutation +} + +// SetNom sets the "nom" field. +func (_u *EmplacementUpdateOne) SetNom(v string) *EmplacementUpdateOne { + _u.mutation.SetNom(v) + return _u +} + +// SetNillableNom sets the "nom" field if the given value is not nil. +func (_u *EmplacementUpdateOne) SetNillableNom(v *string) *EmplacementUpdateOne { + if v != nil { + _u.SetNom(*v) + } + return _u +} + +// SetParentID sets the "parent_id" field. +func (_u *EmplacementUpdateOne) SetParentID(v uuid.UUID) *EmplacementUpdateOne { + _u.mutation.SetParentID(v) + return _u +} + +// SetNillableParentID sets the "parent_id" field if the given value is not nil. +func (_u *EmplacementUpdateOne) SetNillableParentID(v *uuid.UUID) *EmplacementUpdateOne { + if v != nil { + _u.SetParentID(*v) + } + return _u +} + +// ClearParentID clears the value of the "parent_id" field. +func (_u *EmplacementUpdateOne) ClearParentID() *EmplacementUpdateOne { + _u.mutation.ClearParentID() + return _u +} + +// SetSlug sets the "slug" field. +func (_u *EmplacementUpdateOne) SetSlug(v string) *EmplacementUpdateOne { + _u.mutation.SetSlug(v) + return _u +} + +// SetNillableSlug sets the "slug" field if the given value is not nil. +func (_u *EmplacementUpdateOne) SetNillableSlug(v *string) *EmplacementUpdateOne { + if v != nil { + _u.SetSlug(*v) + } + return _u +} + +// ClearSlug clears the value of the "slug" field. +func (_u *EmplacementUpdateOne) ClearSlug() *EmplacementUpdateOne { + _u.mutation.ClearSlug() + return _u +} + +// SetPiece sets the "piece" field. +func (_u *EmplacementUpdateOne) SetPiece(v string) *EmplacementUpdateOne { + _u.mutation.SetPiece(v) + return _u +} + +// SetNillablePiece sets the "piece" field if the given value is not nil. +func (_u *EmplacementUpdateOne) SetNillablePiece(v *string) *EmplacementUpdateOne { + if v != nil { + _u.SetPiece(*v) + } + return _u +} + +// ClearPiece clears the value of the "piece" field. +func (_u *EmplacementUpdateOne) ClearPiece() *EmplacementUpdateOne { + _u.mutation.ClearPiece() + return _u +} + +// SetMeuble sets the "meuble" field. +func (_u *EmplacementUpdateOne) SetMeuble(v string) *EmplacementUpdateOne { + _u.mutation.SetMeuble(v) + return _u +} + +// SetNillableMeuble sets the "meuble" field if the given value is not nil. +func (_u *EmplacementUpdateOne) SetNillableMeuble(v *string) *EmplacementUpdateOne { + if v != nil { + _u.SetMeuble(*v) + } + return _u +} + +// ClearMeuble clears the value of the "meuble" field. +func (_u *EmplacementUpdateOne) ClearMeuble() *EmplacementUpdateOne { + _u.mutation.ClearMeuble() + return _u +} + +// SetNumeroBoite sets the "numero_boite" field. +func (_u *EmplacementUpdateOne) SetNumeroBoite(v string) *EmplacementUpdateOne { + _u.mutation.SetNumeroBoite(v) + return _u +} + +// SetNillableNumeroBoite sets the "numero_boite" field if the given value is not nil. +func (_u *EmplacementUpdateOne) SetNillableNumeroBoite(v *string) *EmplacementUpdateOne { + if v != nil { + _u.SetNumeroBoite(*v) + } + return _u +} + +// ClearNumeroBoite clears the value of the "numero_boite" field. +func (_u *EmplacementUpdateOne) ClearNumeroBoite() *EmplacementUpdateOne { + _u.mutation.ClearNumeroBoite() + return _u +} + +// SetIcone sets the "icone" field. +func (_u *EmplacementUpdateOne) SetIcone(v string) *EmplacementUpdateOne { + _u.mutation.SetIcone(v) + return _u +} + +// SetNillableIcone sets the "icone" field if the given value is not nil. +func (_u *EmplacementUpdateOne) SetNillableIcone(v *string) *EmplacementUpdateOne { + if v != nil { + _u.SetIcone(*v) + } + return _u +} + +// ClearIcone clears the value of the "icone" field. +func (_u *EmplacementUpdateOne) ClearIcone() *EmplacementUpdateOne { + _u.mutation.ClearIcone() + return _u +} + +// SetCreatedAt sets the "created_at" field. +func (_u *EmplacementUpdateOne) SetCreatedAt(v time.Time) *EmplacementUpdateOne { + _u.mutation.SetCreatedAt(v) + return _u +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (_u *EmplacementUpdateOne) SetNillableCreatedAt(v *time.Time) *EmplacementUpdateOne { + if v != nil { + _u.SetCreatedAt(*v) + } + return _u +} + +// SetUpdatedAt sets the "updated_at" field. +func (_u *EmplacementUpdateOne) SetUpdatedAt(v time.Time) *EmplacementUpdateOne { + _u.mutation.SetUpdatedAt(v) + return _u +} + +// SetParent sets the "parent" edge to the Emplacement entity. +func (_u *EmplacementUpdateOne) SetParent(v *Emplacement) *EmplacementUpdateOne { + return _u.SetParentID(v.ID) +} + +// AddEnfantIDs adds the "enfants" edge to the Emplacement entity by IDs. +func (_u *EmplacementUpdateOne) AddEnfantIDs(ids ...uuid.UUID) *EmplacementUpdateOne { + _u.mutation.AddEnfantIDs(ids...) + return _u +} + +// AddEnfants adds the "enfants" edges to the Emplacement entity. +func (_u *EmplacementUpdateOne) AddEnfants(v ...*Emplacement) *EmplacementUpdateOne { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.AddEnfantIDs(ids...) +} + +// AddLiensObjetIDs adds the "liens_objets" edge to the LienObjetEmplacement entity by IDs. +func (_u *EmplacementUpdateOne) AddLiensObjetIDs(ids ...uuid.UUID) *EmplacementUpdateOne { + _u.mutation.AddLiensObjetIDs(ids...) + return _u +} + +// AddLiensObjets adds the "liens_objets" edges to the LienObjetEmplacement entity. +func (_u *EmplacementUpdateOne) AddLiensObjets(v ...*LienObjetEmplacement) *EmplacementUpdateOne { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.AddLiensObjetIDs(ids...) +} + +// Mutation returns the EmplacementMutation object of the builder. +func (_u *EmplacementUpdateOne) Mutation() *EmplacementMutation { + return _u.mutation +} + +// ClearParent clears the "parent" edge to the Emplacement entity. +func (_u *EmplacementUpdateOne) ClearParent() *EmplacementUpdateOne { + _u.mutation.ClearParent() + return _u +} + +// ClearEnfants clears all "enfants" edges to the Emplacement entity. +func (_u *EmplacementUpdateOne) ClearEnfants() *EmplacementUpdateOne { + _u.mutation.ClearEnfants() + return _u +} + +// RemoveEnfantIDs removes the "enfants" edge to Emplacement entities by IDs. +func (_u *EmplacementUpdateOne) RemoveEnfantIDs(ids ...uuid.UUID) *EmplacementUpdateOne { + _u.mutation.RemoveEnfantIDs(ids...) + return _u +} + +// RemoveEnfants removes "enfants" edges to Emplacement entities. +func (_u *EmplacementUpdateOne) RemoveEnfants(v ...*Emplacement) *EmplacementUpdateOne { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.RemoveEnfantIDs(ids...) +} + +// ClearLiensObjets clears all "liens_objets" edges to the LienObjetEmplacement entity. +func (_u *EmplacementUpdateOne) ClearLiensObjets() *EmplacementUpdateOne { + _u.mutation.ClearLiensObjets() + return _u +} + +// RemoveLiensObjetIDs removes the "liens_objets" edge to LienObjetEmplacement entities by IDs. +func (_u *EmplacementUpdateOne) RemoveLiensObjetIDs(ids ...uuid.UUID) *EmplacementUpdateOne { + _u.mutation.RemoveLiensObjetIDs(ids...) + return _u +} + +// RemoveLiensObjets removes "liens_objets" edges to LienObjetEmplacement entities. +func (_u *EmplacementUpdateOne) RemoveLiensObjets(v ...*LienObjetEmplacement) *EmplacementUpdateOne { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.RemoveLiensObjetIDs(ids...) +} + +// Where appends a list predicates to the EmplacementUpdate builder. +func (_u *EmplacementUpdateOne) Where(ps ...predicate.Emplacement) *EmplacementUpdateOne { + _u.mutation.Where(ps...) + return _u +} + +// Select allows selecting one or more fields (columns) of the returned entity. +// The default is selecting all fields defined in the entity schema. +func (_u *EmplacementUpdateOne) Select(field string, fields ...string) *EmplacementUpdateOne { + _u.fields = append([]string{field}, fields...) + return _u +} + +// Save executes the query and returns the updated Emplacement entity. +func (_u *EmplacementUpdateOne) Save(ctx context.Context) (*Emplacement, error) { + _u.defaults() + return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (_u *EmplacementUpdateOne) SaveX(ctx context.Context) *Emplacement { + node, err := _u.Save(ctx) + if err != nil { + panic(err) + } + return node +} + +// Exec executes the query on the entity. +func (_u *EmplacementUpdateOne) Exec(ctx context.Context) error { + _, err := _u.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_u *EmplacementUpdateOne) ExecX(ctx context.Context) { + if err := _u.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (_u *EmplacementUpdateOne) defaults() { + if _, ok := _u.mutation.UpdatedAt(); !ok { + v := emplacement.UpdateDefaultUpdatedAt() + _u.mutation.SetUpdatedAt(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_u *EmplacementUpdateOne) check() error { + if v, ok := _u.mutation.Nom(); ok { + if err := emplacement.NomValidator(v); err != nil { + return &ValidationError{Name: "nom", err: fmt.Errorf(`ent: validator failed for field "Emplacement.nom": %w`, err)} + } + } + return nil +} + +func (_u *EmplacementUpdateOne) sqlSave(ctx context.Context) (_node *Emplacement, err error) { + if err := _u.check(); err != nil { + return _node, err + } + _spec := sqlgraph.NewUpdateSpec(emplacement.Table, emplacement.Columns, sqlgraph.NewFieldSpec(emplacement.FieldID, field.TypeUUID)) + id, ok := _u.mutation.ID() + if !ok { + return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Emplacement.id" for update`)} + } + _spec.Node.ID.Value = id + if fields := _u.fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, emplacement.FieldID) + for _, f := range fields { + if !emplacement.ValidColumn(f) { + return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + if f != emplacement.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, f) + } + } + } + if ps := _u.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := _u.mutation.Nom(); ok { + _spec.SetField(emplacement.FieldNom, field.TypeString, value) + } + if value, ok := _u.mutation.Slug(); ok { + _spec.SetField(emplacement.FieldSlug, field.TypeString, value) + } + if _u.mutation.SlugCleared() { + _spec.ClearField(emplacement.FieldSlug, field.TypeString) + } + if value, ok := _u.mutation.Piece(); ok { + _spec.SetField(emplacement.FieldPiece, field.TypeString, value) + } + if _u.mutation.PieceCleared() { + _spec.ClearField(emplacement.FieldPiece, field.TypeString) + } + if value, ok := _u.mutation.Meuble(); ok { + _spec.SetField(emplacement.FieldMeuble, field.TypeString, value) + } + if _u.mutation.MeubleCleared() { + _spec.ClearField(emplacement.FieldMeuble, field.TypeString) + } + if value, ok := _u.mutation.NumeroBoite(); ok { + _spec.SetField(emplacement.FieldNumeroBoite, field.TypeString, value) + } + if _u.mutation.NumeroBoiteCleared() { + _spec.ClearField(emplacement.FieldNumeroBoite, field.TypeString) + } + if value, ok := _u.mutation.Icone(); ok { + _spec.SetField(emplacement.FieldIcone, field.TypeString, value) + } + if _u.mutation.IconeCleared() { + _spec.ClearField(emplacement.FieldIcone, field.TypeString) + } + if value, ok := _u.mutation.CreatedAt(); ok { + _spec.SetField(emplacement.FieldCreatedAt, field.TypeTime, value) + } + if value, ok := _u.mutation.UpdatedAt(); ok { + _spec.SetField(emplacement.FieldUpdatedAt, field.TypeTime, value) + } + if _u.mutation.ParentCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: emplacement.ParentTable, + Columns: []string{emplacement.ParentColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(emplacement.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.ParentIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: emplacement.ParentTable, + Columns: []string{emplacement.ParentColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(emplacement.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if _u.mutation.EnfantsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: emplacement.EnfantsTable, + Columns: []string{emplacement.EnfantsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(emplacement.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.RemovedEnfantsIDs(); len(nodes) > 0 && !_u.mutation.EnfantsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: emplacement.EnfantsTable, + Columns: []string{emplacement.EnfantsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(emplacement.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.EnfantsIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: emplacement.EnfantsTable, + Columns: []string{emplacement.EnfantsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(emplacement.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if _u.mutation.LiensObjetsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: emplacement.LiensObjetsTable, + Columns: []string{emplacement.LiensObjetsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(lienobjetemplacement.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.RemovedLiensObjetsIDs(); len(nodes) > 0 && !_u.mutation.LiensObjetsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: emplacement.LiensObjetsTable, + Columns: []string{emplacement.LiensObjetsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(lienobjetemplacement.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.LiensObjetsIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: emplacement.LiensObjetsTable, + Columns: []string{emplacement.LiensObjetsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(lienobjetemplacement.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + _node = &Emplacement{config: _u.config} + _spec.Assign = _node.assignValues + _spec.ScanValues = _node.scanValues + if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{emplacement.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + _u.mutation.done = true + return _node, nil +} diff --git a/backend/internal/data/ent/ent.go b/backend/internal/data/ent/ent.go new file mode 100644 index 0000000..2df830d --- /dev/null +++ b/backend/internal/data/ent/ent.go @@ -0,0 +1,618 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + "reflect" + "sync" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/categorie" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/champpersonnalise" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/emplacement" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/lienobjetemplacement" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/objet" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/piecejointe" +) + +// ent aliases to avoid import conflicts in user's code. +type ( + Op = ent.Op + Hook = ent.Hook + Value = ent.Value + Query = ent.Query + QueryContext = ent.QueryContext + Querier = ent.Querier + QuerierFunc = ent.QuerierFunc + Interceptor = ent.Interceptor + InterceptFunc = ent.InterceptFunc + Traverser = ent.Traverser + TraverseFunc = ent.TraverseFunc + Policy = ent.Policy + Mutator = ent.Mutator + Mutation = ent.Mutation + MutateFunc = ent.MutateFunc +) + +type clientCtxKey struct{} + +// FromContext returns a Client stored inside a context, or nil if there isn't one. +func FromContext(ctx context.Context) *Client { + c, _ := ctx.Value(clientCtxKey{}).(*Client) + return c +} + +// NewContext returns a new context with the given Client attached. +func NewContext(parent context.Context, c *Client) context.Context { + return context.WithValue(parent, clientCtxKey{}, c) +} + +type txCtxKey struct{} + +// TxFromContext returns a Tx stored inside a context, or nil if there isn't one. +func TxFromContext(ctx context.Context) *Tx { + tx, _ := ctx.Value(txCtxKey{}).(*Tx) + return tx +} + +// NewTxContext returns a new context with the given Tx attached. +func NewTxContext(parent context.Context, tx *Tx) context.Context { + return context.WithValue(parent, txCtxKey{}, tx) +} + +// OrderFunc applies an ordering on the sql selector. +// Deprecated: Use Asc/Desc functions or the package builders instead. +type OrderFunc func(*sql.Selector) + +var ( + initCheck sync.Once + columnCheck sql.ColumnCheck +) + +// checkColumn checks if the column exists in the given table. +func checkColumn(t, c string) error { + initCheck.Do(func() { + columnCheck = sql.NewColumnCheck(map[string]func(string) bool{ + categorie.Table: categorie.ValidColumn, + champpersonnalise.Table: champpersonnalise.ValidColumn, + emplacement.Table: emplacement.ValidColumn, + lienobjetemplacement.Table: lienobjetemplacement.ValidColumn, + objet.Table: objet.ValidColumn, + piecejointe.Table: piecejointe.ValidColumn, + }) + }) + return columnCheck(t, c) +} + +// Asc applies the given fields in ASC order. +func Asc(fields ...string) func(*sql.Selector) { + return func(s *sql.Selector) { + for _, f := range fields { + if err := checkColumn(s.TableName(), f); err != nil { + s.AddError(&ValidationError{Name: f, err: fmt.Errorf("ent: %w", err)}) + } + s.OrderBy(sql.Asc(s.C(f))) + } + } +} + +// Desc applies the given fields in DESC order. +func Desc(fields ...string) func(*sql.Selector) { + return func(s *sql.Selector) { + for _, f := range fields { + if err := checkColumn(s.TableName(), f); err != nil { + s.AddError(&ValidationError{Name: f, err: fmt.Errorf("ent: %w", err)}) + } + s.OrderBy(sql.Desc(s.C(f))) + } + } +} + +// AggregateFunc applies an aggregation step on the group-by traversal/selector. +type AggregateFunc func(*sql.Selector) string + +// As is a pseudo aggregation function for renaming another other functions with custom names. For example: +// +// GroupBy(field1, field2). +// Aggregate(ent.As(ent.Sum(field1), "sum_field1"), (ent.As(ent.Sum(field2), "sum_field2")). +// Scan(ctx, &v) +func As(fn AggregateFunc, end string) AggregateFunc { + return func(s *sql.Selector) string { + return sql.As(fn(s), end) + } +} + +// Count applies the "count" aggregation function on each group. +func Count() AggregateFunc { + return func(s *sql.Selector) string { + return sql.Count("*") + } +} + +// Max applies the "max" aggregation function on the given field of each group. +func Max(field string) AggregateFunc { + return func(s *sql.Selector) string { + if err := checkColumn(s.TableName(), field); err != nil { + s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)}) + return "" + } + return sql.Max(s.C(field)) + } +} + +// Mean applies the "mean" aggregation function on the given field of each group. +func Mean(field string) AggregateFunc { + return func(s *sql.Selector) string { + if err := checkColumn(s.TableName(), field); err != nil { + s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)}) + return "" + } + return sql.Avg(s.C(field)) + } +} + +// Min applies the "min" aggregation function on the given field of each group. +func Min(field string) AggregateFunc { + return func(s *sql.Selector) string { + if err := checkColumn(s.TableName(), field); err != nil { + s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)}) + return "" + } + return sql.Min(s.C(field)) + } +} + +// Sum applies the "sum" aggregation function on the given field of each group. +func Sum(field string) AggregateFunc { + return func(s *sql.Selector) string { + if err := checkColumn(s.TableName(), field); err != nil { + s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)}) + return "" + } + return sql.Sum(s.C(field)) + } +} + +// ValidationError returns when validating a field or edge fails. +type ValidationError struct { + Name string // Field or edge name. + err error +} + +// Error implements the error interface. +func (e *ValidationError) Error() string { + return e.err.Error() +} + +// Unwrap implements the errors.Wrapper interface. +func (e *ValidationError) Unwrap() error { + return e.err +} + +// IsValidationError returns a boolean indicating whether the error is a validation error. +func IsValidationError(err error) bool { + if err == nil { + return false + } + var e *ValidationError + return errors.As(err, &e) +} + +// NotFoundError returns when trying to fetch a specific entity and it was not found in the database. +type NotFoundError struct { + label string +} + +// Error implements the error interface. +func (e *NotFoundError) Error() string { + return "ent: " + e.label + " not found" +} + +// IsNotFound returns a boolean indicating whether the error is a not found error. +func IsNotFound(err error) bool { + if err == nil { + return false + } + var e *NotFoundError + return errors.As(err, &e) +} + +// MaskNotFound masks not found error. +func MaskNotFound(err error) error { + if IsNotFound(err) { + return nil + } + return err +} + +// NotSingularError returns when trying to fetch a singular entity and more then one was found in the database. +type NotSingularError struct { + label string +} + +// Error implements the error interface. +func (e *NotSingularError) Error() string { + return "ent: " + e.label + " not singular" +} + +// IsNotSingular returns a boolean indicating whether the error is a not singular error. +func IsNotSingular(err error) bool { + if err == nil { + return false + } + var e *NotSingularError + return errors.As(err, &e) +} + +// NotLoadedError returns when trying to get a node that was not loaded by the query. +type NotLoadedError struct { + edge string +} + +// Error implements the error interface. +func (e *NotLoadedError) Error() string { + return "ent: " + e.edge + " edge was not loaded" +} + +// IsNotLoaded returns a boolean indicating whether the error is a not loaded error. +func IsNotLoaded(err error) bool { + if err == nil { + return false + } + var e *NotLoadedError + return errors.As(err, &e) +} + +// ConstraintError returns when trying to create/update one or more entities and +// one or more of their constraints failed. For example, violation of edge or +// field uniqueness. +type ConstraintError struct { + msg string + wrap error +} + +// Error implements the error interface. +func (e ConstraintError) Error() string { + return "ent: constraint failed: " + e.msg +} + +// Unwrap implements the errors.Wrapper interface. +func (e *ConstraintError) Unwrap() error { + return e.wrap +} + +// IsConstraintError returns a boolean indicating whether the error is a constraint failure. +func IsConstraintError(err error) bool { + if err == nil { + return false + } + var e *ConstraintError + return errors.As(err, &e) +} + +// selector embedded by the different Select/GroupBy builders. +type selector struct { + label string + flds *[]string + fns []AggregateFunc + scan func(context.Context, any) error +} + +// ScanX is like Scan, but panics if an error occurs. +func (s *selector) ScanX(ctx context.Context, v any) { + if err := s.scan(ctx, v); err != nil { + panic(err) + } +} + +// Strings returns list of strings from a selector. It is only allowed when selecting one field. +func (s *selector) Strings(ctx context.Context) ([]string, error) { + if len(*s.flds) > 1 { + return nil, errors.New("ent: Strings is not achievable when selecting more than 1 field") + } + var v []string + if err := s.scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// StringsX is like Strings, but panics if an error occurs. +func (s *selector) StringsX(ctx context.Context) []string { + v, err := s.Strings(ctx) + if err != nil { + panic(err) + } + return v +} + +// String returns a single string from a selector. It is only allowed when selecting one field. +func (s *selector) String(ctx context.Context) (_ string, err error) { + var v []string + if v, err = s.Strings(ctx); err != nil { + return + } + switch len(v) { + case 1: + return v[0], nil + case 0: + err = &NotFoundError{s.label} + default: + err = fmt.Errorf("ent: Strings returned %d results when one was expected", len(v)) + } + return +} + +// StringX is like String, but panics if an error occurs. +func (s *selector) StringX(ctx context.Context) string { + v, err := s.String(ctx) + if err != nil { + panic(err) + } + return v +} + +// Ints returns list of ints from a selector. It is only allowed when selecting one field. +func (s *selector) Ints(ctx context.Context) ([]int, error) { + if len(*s.flds) > 1 { + return nil, errors.New("ent: Ints is not achievable when selecting more than 1 field") + } + var v []int + if err := s.scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// IntsX is like Ints, but panics if an error occurs. +func (s *selector) IntsX(ctx context.Context) []int { + v, err := s.Ints(ctx) + if err != nil { + panic(err) + } + return v +} + +// Int returns a single int from a selector. It is only allowed when selecting one field. +func (s *selector) Int(ctx context.Context) (_ int, err error) { + var v []int + if v, err = s.Ints(ctx); err != nil { + return + } + switch len(v) { + case 1: + return v[0], nil + case 0: + err = &NotFoundError{s.label} + default: + err = fmt.Errorf("ent: Ints returned %d results when one was expected", len(v)) + } + return +} + +// IntX is like Int, but panics if an error occurs. +func (s *selector) IntX(ctx context.Context) int { + v, err := s.Int(ctx) + if err != nil { + panic(err) + } + return v +} + +// Float64s returns list of float64s from a selector. It is only allowed when selecting one field. +func (s *selector) Float64s(ctx context.Context) ([]float64, error) { + if len(*s.flds) > 1 { + return nil, errors.New("ent: Float64s is not achievable when selecting more than 1 field") + } + var v []float64 + if err := s.scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// Float64sX is like Float64s, but panics if an error occurs. +func (s *selector) Float64sX(ctx context.Context) []float64 { + v, err := s.Float64s(ctx) + if err != nil { + panic(err) + } + return v +} + +// Float64 returns a single float64 from a selector. It is only allowed when selecting one field. +func (s *selector) Float64(ctx context.Context) (_ float64, err error) { + var v []float64 + if v, err = s.Float64s(ctx); err != nil { + return + } + switch len(v) { + case 1: + return v[0], nil + case 0: + err = &NotFoundError{s.label} + default: + err = fmt.Errorf("ent: Float64s returned %d results when one was expected", len(v)) + } + return +} + +// Float64X is like Float64, but panics if an error occurs. +func (s *selector) Float64X(ctx context.Context) float64 { + v, err := s.Float64(ctx) + if err != nil { + panic(err) + } + return v +} + +// Bools returns list of bools from a selector. It is only allowed when selecting one field. +func (s *selector) Bools(ctx context.Context) ([]bool, error) { + if len(*s.flds) > 1 { + return nil, errors.New("ent: Bools is not achievable when selecting more than 1 field") + } + var v []bool + if err := s.scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// BoolsX is like Bools, but panics if an error occurs. +func (s *selector) BoolsX(ctx context.Context) []bool { + v, err := s.Bools(ctx) + if err != nil { + panic(err) + } + return v +} + +// Bool returns a single bool from a selector. It is only allowed when selecting one field. +func (s *selector) Bool(ctx context.Context) (_ bool, err error) { + var v []bool + if v, err = s.Bools(ctx); err != nil { + return + } + switch len(v) { + case 1: + return v[0], nil + case 0: + err = &NotFoundError{s.label} + default: + err = fmt.Errorf("ent: Bools returned %d results when one was expected", len(v)) + } + return +} + +// BoolX is like Bool, but panics if an error occurs. +func (s *selector) BoolX(ctx context.Context) bool { + v, err := s.Bool(ctx) + if err != nil { + panic(err) + } + return v +} + +// withHooks invokes the builder operation with the given hooks, if any. +func withHooks[V Value, M any, PM interface { + *M + Mutation +}](ctx context.Context, exec func(context.Context) (V, error), mutation PM, hooks []Hook) (value V, err error) { + if len(hooks) == 0 { + return exec(ctx) + } + var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { + mutationT, ok := any(m).(PM) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T", m) + } + // Set the mutation to the builder. + *mutation = *mutationT + return exec(ctx) + }) + for i := len(hooks) - 1; i >= 0; i-- { + if hooks[i] == nil { + return value, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") + } + mut = hooks[i](mut) + } + v, err := mut.Mutate(ctx, mutation) + if err != nil { + return value, err + } + nv, ok := v.(V) + if !ok { + return value, fmt.Errorf("unexpected node type %T returned from %T", v, mutation) + } + return nv, nil +} + +// setContextOp returns a new context with the given QueryContext attached (including its op) in case it does not exist. +func setContextOp(ctx context.Context, qc *QueryContext, op string) context.Context { + if ent.QueryFromContext(ctx) == nil { + qc.Op = op + ctx = ent.NewQueryContext(ctx, qc) + } + return ctx +} + +func querierAll[V Value, Q interface { + sqlAll(context.Context, ...queryHook) (V, error) +}]() Querier { + return QuerierFunc(func(ctx context.Context, q Query) (Value, error) { + query, ok := q.(Q) + if !ok { + return nil, fmt.Errorf("unexpected query type %T", q) + } + return query.sqlAll(ctx) + }) +} + +func querierCount[Q interface { + sqlCount(context.Context) (int, error) +}]() Querier { + return QuerierFunc(func(ctx context.Context, q Query) (Value, error) { + query, ok := q.(Q) + if !ok { + return nil, fmt.Errorf("unexpected query type %T", q) + } + return query.sqlCount(ctx) + }) +} + +func withInterceptors[V Value](ctx context.Context, q Query, qr Querier, inters []Interceptor) (v V, err error) { + for i := len(inters) - 1; i >= 0; i-- { + qr = inters[i].Intercept(qr) + } + rv, err := qr.Query(ctx, q) + if err != nil { + return v, err + } + vt, ok := rv.(V) + if !ok { + return v, fmt.Errorf("unexpected type %T returned from %T. expected type: %T", vt, q, v) + } + return vt, nil +} + +func scanWithInterceptors[Q1 ent.Query, Q2 interface { + sqlScan(context.Context, Q1, any) error +}](ctx context.Context, rootQuery Q1, selectOrGroup Q2, inters []Interceptor, v any) error { + rv := reflect.ValueOf(v) + var qr Querier = QuerierFunc(func(ctx context.Context, q Query) (Value, error) { + query, ok := q.(Q1) + if !ok { + return nil, fmt.Errorf("unexpected query type %T", q) + } + if err := selectOrGroup.sqlScan(ctx, query, v); err != nil { + return nil, err + } + if k := rv.Kind(); k == reflect.Pointer && rv.Elem().CanInterface() { + return rv.Elem().Interface(), nil + } + return v, nil + }) + for i := len(inters) - 1; i >= 0; i-- { + qr = inters[i].Intercept(qr) + } + vv, err := qr.Query(ctx, rootQuery) + if err != nil { + return err + } + switch rv2 := reflect.ValueOf(vv); { + case rv.IsNil(), rv2.IsNil(), rv.Kind() != reflect.Pointer: + case rv.Type() == rv2.Type(): + rv.Elem().Set(rv2.Elem()) + case rv.Elem().Type() == rv2.Type(): + rv.Elem().Set(rv2) + } + return nil +} + +// queryHook describes an internal hook for the different sqlAll methods. +type queryHook func(context.Context, *sqlgraph.QuerySpec) diff --git a/backend/internal/data/ent/enttest/enttest.go b/backend/internal/data/ent/enttest/enttest.go new file mode 100644 index 0000000..409c433 --- /dev/null +++ b/backend/internal/data/ent/enttest/enttest.go @@ -0,0 +1,84 @@ +// Code generated by ent, DO NOT EDIT. + +package enttest + +import ( + "context" + + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent" + // required by schema hooks. + _ "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/runtime" + + "entgo.io/ent/dialect/sql/schema" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/migrate" +) + +type ( + // TestingT is the interface that is shared between + // testing.T and testing.B and used by enttest. + TestingT interface { + FailNow() + Error(...any) + } + + // Option configures client creation. + Option func(*options) + + options struct { + opts []ent.Option + migrateOpts []schema.MigrateOption + } +) + +// WithOptions forwards options to client creation. +func WithOptions(opts ...ent.Option) Option { + return func(o *options) { + o.opts = append(o.opts, opts...) + } +} + +// WithMigrateOptions forwards options to auto migration. +func WithMigrateOptions(opts ...schema.MigrateOption) Option { + return func(o *options) { + o.migrateOpts = append(o.migrateOpts, opts...) + } +} + +func newOptions(opts []Option) *options { + o := &options{} + for _, opt := range opts { + opt(o) + } + return o +} + +// Open calls ent.Open and auto-run migration. +func Open(t TestingT, driverName, dataSourceName string, opts ...Option) *ent.Client { + o := newOptions(opts) + c, err := ent.Open(driverName, dataSourceName, o.opts...) + if err != nil { + t.Error(err) + t.FailNow() + } + migrateSchema(t, c, o) + return c +} + +// NewClient calls ent.NewClient and auto-run migration. +func NewClient(t TestingT, opts ...Option) *ent.Client { + o := newOptions(opts) + c := ent.NewClient(o.opts...) + migrateSchema(t, c, o) + return c +} +func migrateSchema(t TestingT, c *ent.Client, o *options) { + tables, err := schema.CopyTables(migrate.Tables) + if err != nil { + t.Error(err) + t.FailNow() + } + if err := migrate.Create(context.Background(), c.Schema, tables, o.migrateOpts...); err != nil { + t.Error(err) + t.FailNow() + } +} diff --git a/backend/internal/data/ent/hook/hook.go b/backend/internal/data/ent/hook/hook.go new file mode 100644 index 0000000..0b0af94 --- /dev/null +++ b/backend/internal/data/ent/hook/hook.go @@ -0,0 +1,259 @@ +// Code generated by ent, DO NOT EDIT. + +package hook + +import ( + "context" + "fmt" + + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent" +) + +// The CategorieFunc type is an adapter to allow the use of ordinary +// function as Categorie mutator. +type CategorieFunc func(context.Context, *ent.CategorieMutation) (ent.Value, error) + +// Mutate calls f(ctx, m). +func (f CategorieFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { + if mv, ok := m.(*ent.CategorieMutation); ok { + return f(ctx, mv) + } + return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.CategorieMutation", m) +} + +// The ChampPersonnaliseFunc type is an adapter to allow the use of ordinary +// function as ChampPersonnalise mutator. +type ChampPersonnaliseFunc func(context.Context, *ent.ChampPersonnaliseMutation) (ent.Value, error) + +// Mutate calls f(ctx, m). +func (f ChampPersonnaliseFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { + if mv, ok := m.(*ent.ChampPersonnaliseMutation); ok { + return f(ctx, mv) + } + return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.ChampPersonnaliseMutation", m) +} + +// The EmplacementFunc type is an adapter to allow the use of ordinary +// function as Emplacement mutator. +type EmplacementFunc func(context.Context, *ent.EmplacementMutation) (ent.Value, error) + +// Mutate calls f(ctx, m). +func (f EmplacementFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { + if mv, ok := m.(*ent.EmplacementMutation); ok { + return f(ctx, mv) + } + return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.EmplacementMutation", m) +} + +// The LienObjetEmplacementFunc type is an adapter to allow the use of ordinary +// function as LienObjetEmplacement mutator. +type LienObjetEmplacementFunc func(context.Context, *ent.LienObjetEmplacementMutation) (ent.Value, error) + +// Mutate calls f(ctx, m). +func (f LienObjetEmplacementFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { + if mv, ok := m.(*ent.LienObjetEmplacementMutation); ok { + return f(ctx, mv) + } + return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.LienObjetEmplacementMutation", m) +} + +// The ObjetFunc type is an adapter to allow the use of ordinary +// function as Objet mutator. +type ObjetFunc func(context.Context, *ent.ObjetMutation) (ent.Value, error) + +// Mutate calls f(ctx, m). +func (f ObjetFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { + if mv, ok := m.(*ent.ObjetMutation); ok { + return f(ctx, mv) + } + return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.ObjetMutation", m) +} + +// The PieceJointeFunc type is an adapter to allow the use of ordinary +// function as PieceJointe mutator. +type PieceJointeFunc func(context.Context, *ent.PieceJointeMutation) (ent.Value, error) + +// Mutate calls f(ctx, m). +func (f PieceJointeFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { + if mv, ok := m.(*ent.PieceJointeMutation); ok { + return f(ctx, mv) + } + return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.PieceJointeMutation", m) +} + +// Condition is a hook condition function. +type Condition func(context.Context, ent.Mutation) bool + +// And groups conditions with the AND operator. +func And(first, second Condition, rest ...Condition) Condition { + return func(ctx context.Context, m ent.Mutation) bool { + if !first(ctx, m) || !second(ctx, m) { + return false + } + for _, cond := range rest { + if !cond(ctx, m) { + return false + } + } + return true + } +} + +// Or groups conditions with the OR operator. +func Or(first, second Condition, rest ...Condition) Condition { + return func(ctx context.Context, m ent.Mutation) bool { + if first(ctx, m) || second(ctx, m) { + return true + } + for _, cond := range rest { + if cond(ctx, m) { + return true + } + } + return false + } +} + +// Not negates a given condition. +func Not(cond Condition) Condition { + return func(ctx context.Context, m ent.Mutation) bool { + return !cond(ctx, m) + } +} + +// HasOp is a condition testing mutation operation. +func HasOp(op ent.Op) Condition { + return func(_ context.Context, m ent.Mutation) bool { + return m.Op().Is(op) + } +} + +// HasAddedFields is a condition validating `.AddedField` on fields. +func HasAddedFields(field string, fields ...string) Condition { + return func(_ context.Context, m ent.Mutation) bool { + if _, exists := m.AddedField(field); !exists { + return false + } + for _, field := range fields { + if _, exists := m.AddedField(field); !exists { + return false + } + } + return true + } +} + +// HasClearedFields is a condition validating `.FieldCleared` on fields. +func HasClearedFields(field string, fields ...string) Condition { + return func(_ context.Context, m ent.Mutation) bool { + if exists := m.FieldCleared(field); !exists { + return false + } + for _, field := range fields { + if exists := m.FieldCleared(field); !exists { + return false + } + } + return true + } +} + +// HasFields is a condition validating `.Field` on fields. +func HasFields(field string, fields ...string) Condition { + return func(_ context.Context, m ent.Mutation) bool { + if _, exists := m.Field(field); !exists { + return false + } + for _, field := range fields { + if _, exists := m.Field(field); !exists { + return false + } + } + return true + } +} + +// If executes the given hook under condition. +// +// hook.If(ComputeAverage, And(HasFields(...), HasAddedFields(...))) +func If(hk ent.Hook, cond Condition) ent.Hook { + return func(next ent.Mutator) ent.Mutator { + return ent.MutateFunc(func(ctx context.Context, m ent.Mutation) (ent.Value, error) { + if cond(ctx, m) { + return hk(next).Mutate(ctx, m) + } + return next.Mutate(ctx, m) + }) + } +} + +// On executes the given hook only for the given operation. +// +// hook.On(Log, ent.Delete|ent.Create) +func On(hk ent.Hook, op ent.Op) ent.Hook { + return If(hk, HasOp(op)) +} + +// Unless skips the given hook only for the given operation. +// +// hook.Unless(Log, ent.Update|ent.UpdateOne) +func Unless(hk ent.Hook, op ent.Op) ent.Hook { + return If(hk, Not(HasOp(op))) +} + +// FixedError is a hook returning a fixed error. +func FixedError(err error) ent.Hook { + return func(ent.Mutator) ent.Mutator { + return ent.MutateFunc(func(context.Context, ent.Mutation) (ent.Value, error) { + return nil, err + }) + } +} + +// Reject returns a hook that rejects all operations that match op. +// +// func (T) Hooks() []ent.Hook { +// return []ent.Hook{ +// Reject(ent.Delete|ent.Update), +// } +// } +func Reject(op ent.Op) ent.Hook { + hk := FixedError(fmt.Errorf("%s operation is not allowed", op)) + return On(hk, op) +} + +// Chain acts as a list of hooks and is effectively immutable. +// Once created, it will always hold the same set of hooks in the same order. +type Chain struct { + hooks []ent.Hook +} + +// NewChain creates a new chain of hooks. +func NewChain(hooks ...ent.Hook) Chain { + return Chain{append([]ent.Hook(nil), hooks...)} +} + +// Hook chains the list of hooks and returns the final hook. +func (c Chain) Hook() ent.Hook { + return func(mutator ent.Mutator) ent.Mutator { + for i := len(c.hooks) - 1; i >= 0; i-- { + mutator = c.hooks[i](mutator) + } + return mutator + } +} + +// Append extends a chain, adding the specified hook +// as the last ones in the mutation flow. +func (c Chain) Append(hooks ...ent.Hook) Chain { + newHooks := make([]ent.Hook, 0, len(c.hooks)+len(hooks)) + newHooks = append(newHooks, c.hooks...) + newHooks = append(newHooks, hooks...) + return Chain{newHooks} +} + +// Extend extends a chain, adding the specified chain +// as the last ones in the mutation flow. +func (c Chain) Extend(chain Chain) Chain { + return c.Append(chain.hooks...) +} diff --git a/backend/internal/data/ent/lienobjetemplacement.go b/backend/internal/data/ent/lienobjetemplacement.go new file mode 100644 index 0000000..f8650ef --- /dev/null +++ b/backend/internal/data/ent/lienobjetemplacement.go @@ -0,0 +1,200 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "fmt" + "strings" + "time" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/emplacement" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/lienobjetemplacement" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/objet" + "github.com/google/uuid" +) + +// LienObjetEmplacement is the model entity for the LienObjetEmplacement schema. +type LienObjetEmplacement struct { + config `json:"-"` + // ID of the ent. + // Identifiant unique du lien + ID uuid.UUID `json:"id,omitempty"` + // Identifiant de l'objet + ObjetID uuid.UUID `json:"objet_id,omitempty"` + // Identifiant de l'emplacement + EmplacementID uuid.UUID `json:"emplacement_id,omitempty"` + // Type de relation + Type lienobjetemplacement.Type `json:"type,omitempty"` + // Date de creation + CreatedAt time.Time `json:"created_at,omitempty"` + // Date de derniere mise a jour + UpdatedAt time.Time `json:"updated_at,omitempty"` + // Edges holds the relations/edges for other nodes in the graph. + // The values are being populated by the LienObjetEmplacementQuery when eager-loading is set. + Edges LienObjetEmplacementEdges `json:"edges"` + selectValues sql.SelectValues +} + +// LienObjetEmplacementEdges holds the relations/edges for other nodes in the graph. +type LienObjetEmplacementEdges struct { + // Objet holds the value of the objet edge. + Objet *Objet `json:"objet,omitempty"` + // Emplacement holds the value of the emplacement edge. + Emplacement *Emplacement `json:"emplacement,omitempty"` + // loadedTypes holds the information for reporting if a + // type was loaded (or requested) in eager-loading or not. + loadedTypes [2]bool +} + +// ObjetOrErr returns the Objet value or an error if the edge +// was not loaded in eager-loading, or loaded but was not found. +func (e LienObjetEmplacementEdges) ObjetOrErr() (*Objet, error) { + if e.Objet != nil { + return e.Objet, nil + } else if e.loadedTypes[0] { + return nil, &NotFoundError{label: objet.Label} + } + return nil, &NotLoadedError{edge: "objet"} +} + +// EmplacementOrErr returns the Emplacement value or an error if the edge +// was not loaded in eager-loading, or loaded but was not found. +func (e LienObjetEmplacementEdges) EmplacementOrErr() (*Emplacement, error) { + if e.Emplacement != nil { + return e.Emplacement, nil + } else if e.loadedTypes[1] { + return nil, &NotFoundError{label: emplacement.Label} + } + return nil, &NotLoadedError{edge: "emplacement"} +} + +// scanValues returns the types for scanning values from sql.Rows. +func (*LienObjetEmplacement) scanValues(columns []string) ([]any, error) { + values := make([]any, len(columns)) + for i := range columns { + switch columns[i] { + case lienobjetemplacement.FieldType: + values[i] = new(sql.NullString) + case lienobjetemplacement.FieldCreatedAt, lienobjetemplacement.FieldUpdatedAt: + values[i] = new(sql.NullTime) + case lienobjetemplacement.FieldID, lienobjetemplacement.FieldObjetID, lienobjetemplacement.FieldEmplacementID: + values[i] = new(uuid.UUID) + default: + values[i] = new(sql.UnknownType) + } + } + return values, nil +} + +// assignValues assigns the values that were returned from sql.Rows (after scanning) +// to the LienObjetEmplacement fields. +func (_m *LienObjetEmplacement) assignValues(columns []string, values []any) error { + if m, n := len(values), len(columns); m < n { + return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) + } + for i := range columns { + switch columns[i] { + case lienobjetemplacement.FieldID: + if value, ok := values[i].(*uuid.UUID); !ok { + return fmt.Errorf("unexpected type %T for field id", values[i]) + } else if value != nil { + _m.ID = *value + } + case lienobjetemplacement.FieldObjetID: + if value, ok := values[i].(*uuid.UUID); !ok { + return fmt.Errorf("unexpected type %T for field objet_id", values[i]) + } else if value != nil { + _m.ObjetID = *value + } + case lienobjetemplacement.FieldEmplacementID: + if value, ok := values[i].(*uuid.UUID); !ok { + return fmt.Errorf("unexpected type %T for field emplacement_id", values[i]) + } else if value != nil { + _m.EmplacementID = *value + } + case lienobjetemplacement.FieldType: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field type", values[i]) + } else if value.Valid { + _m.Type = lienobjetemplacement.Type(value.String) + } + case lienobjetemplacement.FieldCreatedAt: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field created_at", values[i]) + } else if value.Valid { + _m.CreatedAt = value.Time + } + case lienobjetemplacement.FieldUpdatedAt: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field updated_at", values[i]) + } else if value.Valid { + _m.UpdatedAt = value.Time + } + default: + _m.selectValues.Set(columns[i], values[i]) + } + } + return nil +} + +// Value returns the ent.Value that was dynamically selected and assigned to the LienObjetEmplacement. +// This includes values selected through modifiers, order, etc. +func (_m *LienObjetEmplacement) Value(name string) (ent.Value, error) { + return _m.selectValues.Get(name) +} + +// QueryObjet queries the "objet" edge of the LienObjetEmplacement entity. +func (_m *LienObjetEmplacement) QueryObjet() *ObjetQuery { + return NewLienObjetEmplacementClient(_m.config).QueryObjet(_m) +} + +// QueryEmplacement queries the "emplacement" edge of the LienObjetEmplacement entity. +func (_m *LienObjetEmplacement) QueryEmplacement() *EmplacementQuery { + return NewLienObjetEmplacementClient(_m.config).QueryEmplacement(_m) +} + +// Update returns a builder for updating this LienObjetEmplacement. +// Note that you need to call LienObjetEmplacement.Unwrap() before calling this method if this LienObjetEmplacement +// was returned from a transaction, and the transaction was committed or rolled back. +func (_m *LienObjetEmplacement) Update() *LienObjetEmplacementUpdateOne { + return NewLienObjetEmplacementClient(_m.config).UpdateOne(_m) +} + +// Unwrap unwraps the LienObjetEmplacement entity that was returned from a transaction after it was closed, +// so that all future queries will be executed through the driver which created the transaction. +func (_m *LienObjetEmplacement) Unwrap() *LienObjetEmplacement { + _tx, ok := _m.config.driver.(*txDriver) + if !ok { + panic("ent: LienObjetEmplacement is not a transactional entity") + } + _m.config.driver = _tx.drv + return _m +} + +// String implements the fmt.Stringer. +func (_m *LienObjetEmplacement) String() string { + var builder strings.Builder + builder.WriteString("LienObjetEmplacement(") + builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID)) + builder.WriteString("objet_id=") + builder.WriteString(fmt.Sprintf("%v", _m.ObjetID)) + builder.WriteString(", ") + builder.WriteString("emplacement_id=") + builder.WriteString(fmt.Sprintf("%v", _m.EmplacementID)) + builder.WriteString(", ") + builder.WriteString("type=") + builder.WriteString(fmt.Sprintf("%v", _m.Type)) + builder.WriteString(", ") + builder.WriteString("created_at=") + builder.WriteString(_m.CreatedAt.Format(time.ANSIC)) + builder.WriteString(", ") + builder.WriteString("updated_at=") + builder.WriteString(_m.UpdatedAt.Format(time.ANSIC)) + builder.WriteByte(')') + return builder.String() +} + +// LienObjetEmplacements is a parsable slice of LienObjetEmplacement. +type LienObjetEmplacements []*LienObjetEmplacement diff --git a/backend/internal/data/ent/lienobjetemplacement/lienobjetemplacement.go b/backend/internal/data/ent/lienobjetemplacement/lienobjetemplacement.go new file mode 100644 index 0000000..ace8319 --- /dev/null +++ b/backend/internal/data/ent/lienobjetemplacement/lienobjetemplacement.go @@ -0,0 +1,167 @@ +// Code generated by ent, DO NOT EDIT. + +package lienobjetemplacement + +import ( + "fmt" + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "github.com/google/uuid" +) + +const ( + // Label holds the string label denoting the lienobjetemplacement type in the database. + Label = "lien_objet_emplacement" + // FieldID holds the string denoting the id field in the database. + FieldID = "id" + // FieldObjetID holds the string denoting the objet_id field in the database. + FieldObjetID = "objet_id" + // FieldEmplacementID holds the string denoting the emplacement_id field in the database. + FieldEmplacementID = "emplacement_id" + // FieldType holds the string denoting the type field in the database. + FieldType = "type" + // FieldCreatedAt holds the string denoting the created_at field in the database. + FieldCreatedAt = "created_at" + // FieldUpdatedAt holds the string denoting the updated_at field in the database. + FieldUpdatedAt = "updated_at" + // EdgeObjet holds the string denoting the objet edge name in mutations. + EdgeObjet = "objet" + // EdgeEmplacement holds the string denoting the emplacement edge name in mutations. + EdgeEmplacement = "emplacement" + // Table holds the table name of the lienobjetemplacement in the database. + Table = "lien_objet_emplacement" + // ObjetTable is the table that holds the objet relation/edge. + ObjetTable = "lien_objet_emplacement" + // ObjetInverseTable is the table name for the Objet entity. + // It exists in this package in order to avoid circular dependency with the "objet" package. + ObjetInverseTable = "objet" + // ObjetColumn is the table column denoting the objet relation/edge. + ObjetColumn = "objet_id" + // EmplacementTable is the table that holds the emplacement relation/edge. + EmplacementTable = "lien_objet_emplacement" + // EmplacementInverseTable is the table name for the Emplacement entity. + // It exists in this package in order to avoid circular dependency with the "emplacement" package. + EmplacementInverseTable = "emplacement" + // EmplacementColumn is the table column denoting the emplacement relation/edge. + EmplacementColumn = "emplacement_id" +) + +// Columns holds all SQL columns for lienobjetemplacement fields. +var Columns = []string{ + FieldID, + FieldObjetID, + FieldEmplacementID, + FieldType, + FieldCreatedAt, + FieldUpdatedAt, +} + +// ValidColumn reports if the column name is valid (part of the table columns). +func ValidColumn(column string) bool { + for i := range Columns { + if column == Columns[i] { + return true + } + } + return false +} + +var ( + // DefaultCreatedAt holds the default value on creation for the "created_at" field. + DefaultCreatedAt func() time.Time + // DefaultUpdatedAt holds the default value on creation for the "updated_at" field. + DefaultUpdatedAt func() time.Time + // UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field. + UpdateDefaultUpdatedAt func() time.Time + // DefaultID holds the default value on creation for the "id" field. + DefaultID func() uuid.UUID +) + +// Type defines the type for the "type" enum field. +type Type string + +// TypeStocke is the default value of the Type enum. +const DefaultType = TypeStocke + +// Type values. +const ( + TypeStocke Type = "stocke" + TypeUtiliseDans Type = "utilise_dans" +) + +func (_type Type) String() string { + return string(_type) +} + +// TypeValidator is a validator for the "type" field enum values. It is called by the builders before save. +func TypeValidator(_type Type) error { + switch _type { + case TypeStocke, TypeUtiliseDans: + return nil + default: + return fmt.Errorf("lienobjetemplacement: invalid enum value for type field: %q", _type) + } +} + +// OrderOption defines the ordering options for the LienObjetEmplacement queries. +type OrderOption func(*sql.Selector) + +// ByID orders the results by the id field. +func ByID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldID, opts...).ToFunc() +} + +// ByObjetID orders the results by the objet_id field. +func ByObjetID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldObjetID, opts...).ToFunc() +} + +// ByEmplacementID orders the results by the emplacement_id field. +func ByEmplacementID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldEmplacementID, opts...).ToFunc() +} + +// ByType orders the results by the type field. +func ByType(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldType, opts...).ToFunc() +} + +// ByCreatedAt orders the results by the created_at field. +func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() +} + +// ByUpdatedAt orders the results by the updated_at field. +func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc() +} + +// ByObjetField orders the results by objet field. +func ByObjetField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newObjetStep(), sql.OrderByField(field, opts...)) + } +} + +// ByEmplacementField orders the results by emplacement field. +func ByEmplacementField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newEmplacementStep(), sql.OrderByField(field, opts...)) + } +} +func newObjetStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(ObjetInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, ObjetTable, ObjetColumn), + ) +} +func newEmplacementStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(EmplacementInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, EmplacementTable, EmplacementColumn), + ) +} diff --git a/backend/internal/data/ent/lienobjetemplacement/where.go b/backend/internal/data/ent/lienobjetemplacement/where.go new file mode 100644 index 0000000..6c02318 --- /dev/null +++ b/backend/internal/data/ent/lienobjetemplacement/where.go @@ -0,0 +1,278 @@ +// Code generated by ent, DO NOT EDIT. + +package lienobjetemplacement + +import ( + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/predicate" + "github.com/google/uuid" +) + +// ID filters vertices based on their ID field. +func ID(id uuid.UUID) predicate.LienObjetEmplacement { + return predicate.LienObjetEmplacement(sql.FieldEQ(FieldID, id)) +} + +// IDEQ applies the EQ predicate on the ID field. +func IDEQ(id uuid.UUID) predicate.LienObjetEmplacement { + return predicate.LienObjetEmplacement(sql.FieldEQ(FieldID, id)) +} + +// IDNEQ applies the NEQ predicate on the ID field. +func IDNEQ(id uuid.UUID) predicate.LienObjetEmplacement { + return predicate.LienObjetEmplacement(sql.FieldNEQ(FieldID, id)) +} + +// IDIn applies the In predicate on the ID field. +func IDIn(ids ...uuid.UUID) predicate.LienObjetEmplacement { + return predicate.LienObjetEmplacement(sql.FieldIn(FieldID, ids...)) +} + +// IDNotIn applies the NotIn predicate on the ID field. +func IDNotIn(ids ...uuid.UUID) predicate.LienObjetEmplacement { + return predicate.LienObjetEmplacement(sql.FieldNotIn(FieldID, ids...)) +} + +// IDGT applies the GT predicate on the ID field. +func IDGT(id uuid.UUID) predicate.LienObjetEmplacement { + return predicate.LienObjetEmplacement(sql.FieldGT(FieldID, id)) +} + +// IDGTE applies the GTE predicate on the ID field. +func IDGTE(id uuid.UUID) predicate.LienObjetEmplacement { + return predicate.LienObjetEmplacement(sql.FieldGTE(FieldID, id)) +} + +// IDLT applies the LT predicate on the ID field. +func IDLT(id uuid.UUID) predicate.LienObjetEmplacement { + return predicate.LienObjetEmplacement(sql.FieldLT(FieldID, id)) +} + +// IDLTE applies the LTE predicate on the ID field. +func IDLTE(id uuid.UUID) predicate.LienObjetEmplacement { + return predicate.LienObjetEmplacement(sql.FieldLTE(FieldID, id)) +} + +// ObjetID applies equality check predicate on the "objet_id" field. It's identical to ObjetIDEQ. +func ObjetID(v uuid.UUID) predicate.LienObjetEmplacement { + return predicate.LienObjetEmplacement(sql.FieldEQ(FieldObjetID, v)) +} + +// EmplacementID applies equality check predicate on the "emplacement_id" field. It's identical to EmplacementIDEQ. +func EmplacementID(v uuid.UUID) predicate.LienObjetEmplacement { + return predicate.LienObjetEmplacement(sql.FieldEQ(FieldEmplacementID, v)) +} + +// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. +func CreatedAt(v time.Time) predicate.LienObjetEmplacement { + return predicate.LienObjetEmplacement(sql.FieldEQ(FieldCreatedAt, v)) +} + +// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ. +func UpdatedAt(v time.Time) predicate.LienObjetEmplacement { + return predicate.LienObjetEmplacement(sql.FieldEQ(FieldUpdatedAt, v)) +} + +// ObjetIDEQ applies the EQ predicate on the "objet_id" field. +func ObjetIDEQ(v uuid.UUID) predicate.LienObjetEmplacement { + return predicate.LienObjetEmplacement(sql.FieldEQ(FieldObjetID, v)) +} + +// ObjetIDNEQ applies the NEQ predicate on the "objet_id" field. +func ObjetIDNEQ(v uuid.UUID) predicate.LienObjetEmplacement { + return predicate.LienObjetEmplacement(sql.FieldNEQ(FieldObjetID, v)) +} + +// ObjetIDIn applies the In predicate on the "objet_id" field. +func ObjetIDIn(vs ...uuid.UUID) predicate.LienObjetEmplacement { + return predicate.LienObjetEmplacement(sql.FieldIn(FieldObjetID, vs...)) +} + +// ObjetIDNotIn applies the NotIn predicate on the "objet_id" field. +func ObjetIDNotIn(vs ...uuid.UUID) predicate.LienObjetEmplacement { + return predicate.LienObjetEmplacement(sql.FieldNotIn(FieldObjetID, vs...)) +} + +// EmplacementIDEQ applies the EQ predicate on the "emplacement_id" field. +func EmplacementIDEQ(v uuid.UUID) predicate.LienObjetEmplacement { + return predicate.LienObjetEmplacement(sql.FieldEQ(FieldEmplacementID, v)) +} + +// EmplacementIDNEQ applies the NEQ predicate on the "emplacement_id" field. +func EmplacementIDNEQ(v uuid.UUID) predicate.LienObjetEmplacement { + return predicate.LienObjetEmplacement(sql.FieldNEQ(FieldEmplacementID, v)) +} + +// EmplacementIDIn applies the In predicate on the "emplacement_id" field. +func EmplacementIDIn(vs ...uuid.UUID) predicate.LienObjetEmplacement { + return predicate.LienObjetEmplacement(sql.FieldIn(FieldEmplacementID, vs...)) +} + +// EmplacementIDNotIn applies the NotIn predicate on the "emplacement_id" field. +func EmplacementIDNotIn(vs ...uuid.UUID) predicate.LienObjetEmplacement { + return predicate.LienObjetEmplacement(sql.FieldNotIn(FieldEmplacementID, vs...)) +} + +// TypeEQ applies the EQ predicate on the "type" field. +func TypeEQ(v Type) predicate.LienObjetEmplacement { + return predicate.LienObjetEmplacement(sql.FieldEQ(FieldType, v)) +} + +// TypeNEQ applies the NEQ predicate on the "type" field. +func TypeNEQ(v Type) predicate.LienObjetEmplacement { + return predicate.LienObjetEmplacement(sql.FieldNEQ(FieldType, v)) +} + +// TypeIn applies the In predicate on the "type" field. +func TypeIn(vs ...Type) predicate.LienObjetEmplacement { + return predicate.LienObjetEmplacement(sql.FieldIn(FieldType, vs...)) +} + +// TypeNotIn applies the NotIn predicate on the "type" field. +func TypeNotIn(vs ...Type) predicate.LienObjetEmplacement { + return predicate.LienObjetEmplacement(sql.FieldNotIn(FieldType, vs...)) +} + +// CreatedAtEQ applies the EQ predicate on the "created_at" field. +func CreatedAtEQ(v time.Time) predicate.LienObjetEmplacement { + return predicate.LienObjetEmplacement(sql.FieldEQ(FieldCreatedAt, v)) +} + +// CreatedAtNEQ applies the NEQ predicate on the "created_at" field. +func CreatedAtNEQ(v time.Time) predicate.LienObjetEmplacement { + return predicate.LienObjetEmplacement(sql.FieldNEQ(FieldCreatedAt, v)) +} + +// CreatedAtIn applies the In predicate on the "created_at" field. +func CreatedAtIn(vs ...time.Time) predicate.LienObjetEmplacement { + return predicate.LienObjetEmplacement(sql.FieldIn(FieldCreatedAt, vs...)) +} + +// CreatedAtNotIn applies the NotIn predicate on the "created_at" field. +func CreatedAtNotIn(vs ...time.Time) predicate.LienObjetEmplacement { + return predicate.LienObjetEmplacement(sql.FieldNotIn(FieldCreatedAt, vs...)) +} + +// CreatedAtGT applies the GT predicate on the "created_at" field. +func CreatedAtGT(v time.Time) predicate.LienObjetEmplacement { + return predicate.LienObjetEmplacement(sql.FieldGT(FieldCreatedAt, v)) +} + +// CreatedAtGTE applies the GTE predicate on the "created_at" field. +func CreatedAtGTE(v time.Time) predicate.LienObjetEmplacement { + return predicate.LienObjetEmplacement(sql.FieldGTE(FieldCreatedAt, v)) +} + +// CreatedAtLT applies the LT predicate on the "created_at" field. +func CreatedAtLT(v time.Time) predicate.LienObjetEmplacement { + return predicate.LienObjetEmplacement(sql.FieldLT(FieldCreatedAt, v)) +} + +// CreatedAtLTE applies the LTE predicate on the "created_at" field. +func CreatedAtLTE(v time.Time) predicate.LienObjetEmplacement { + return predicate.LienObjetEmplacement(sql.FieldLTE(FieldCreatedAt, v)) +} + +// UpdatedAtEQ applies the EQ predicate on the "updated_at" field. +func UpdatedAtEQ(v time.Time) predicate.LienObjetEmplacement { + return predicate.LienObjetEmplacement(sql.FieldEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field. +func UpdatedAtNEQ(v time.Time) predicate.LienObjetEmplacement { + return predicate.LienObjetEmplacement(sql.FieldNEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtIn applies the In predicate on the "updated_at" field. +func UpdatedAtIn(vs ...time.Time) predicate.LienObjetEmplacement { + return predicate.LienObjetEmplacement(sql.FieldIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field. +func UpdatedAtNotIn(vs ...time.Time) predicate.LienObjetEmplacement { + return predicate.LienObjetEmplacement(sql.FieldNotIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtGT applies the GT predicate on the "updated_at" field. +func UpdatedAtGT(v time.Time) predicate.LienObjetEmplacement { + return predicate.LienObjetEmplacement(sql.FieldGT(FieldUpdatedAt, v)) +} + +// UpdatedAtGTE applies the GTE predicate on the "updated_at" field. +func UpdatedAtGTE(v time.Time) predicate.LienObjetEmplacement { + return predicate.LienObjetEmplacement(sql.FieldGTE(FieldUpdatedAt, v)) +} + +// UpdatedAtLT applies the LT predicate on the "updated_at" field. +func UpdatedAtLT(v time.Time) predicate.LienObjetEmplacement { + return predicate.LienObjetEmplacement(sql.FieldLT(FieldUpdatedAt, v)) +} + +// UpdatedAtLTE applies the LTE predicate on the "updated_at" field. +func UpdatedAtLTE(v time.Time) predicate.LienObjetEmplacement { + return predicate.LienObjetEmplacement(sql.FieldLTE(FieldUpdatedAt, v)) +} + +// HasObjet applies the HasEdge predicate on the "objet" edge. +func HasObjet() predicate.LienObjetEmplacement { + return predicate.LienObjetEmplacement(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, ObjetTable, ObjetColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasObjetWith applies the HasEdge predicate on the "objet" edge with a given conditions (other predicates). +func HasObjetWith(preds ...predicate.Objet) predicate.LienObjetEmplacement { + return predicate.LienObjetEmplacement(func(s *sql.Selector) { + step := newObjetStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + +// HasEmplacement applies the HasEdge predicate on the "emplacement" edge. +func HasEmplacement() predicate.LienObjetEmplacement { + return predicate.LienObjetEmplacement(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, EmplacementTable, EmplacementColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasEmplacementWith applies the HasEdge predicate on the "emplacement" edge with a given conditions (other predicates). +func HasEmplacementWith(preds ...predicate.Emplacement) predicate.LienObjetEmplacement { + return predicate.LienObjetEmplacement(func(s *sql.Selector) { + step := newEmplacementStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + +// And groups predicates with the AND operator between them. +func And(predicates ...predicate.LienObjetEmplacement) predicate.LienObjetEmplacement { + return predicate.LienObjetEmplacement(sql.AndPredicates(predicates...)) +} + +// Or groups predicates with the OR operator between them. +func Or(predicates ...predicate.LienObjetEmplacement) predicate.LienObjetEmplacement { + return predicate.LienObjetEmplacement(sql.OrPredicates(predicates...)) +} + +// Not applies the not operator on the given predicate. +func Not(p predicate.LienObjetEmplacement) predicate.LienObjetEmplacement { + return predicate.LienObjetEmplacement(sql.NotPredicates(p)) +} diff --git a/backend/internal/data/ent/lienobjetemplacement_create.go b/backend/internal/data/ent/lienobjetemplacement_create.go new file mode 100644 index 0000000..164b550 --- /dev/null +++ b/backend/internal/data/ent/lienobjetemplacement_create.go @@ -0,0 +1,351 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + "time" + + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/emplacement" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/lienobjetemplacement" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/objet" + "github.com/google/uuid" +) + +// LienObjetEmplacementCreate is the builder for creating a LienObjetEmplacement entity. +type LienObjetEmplacementCreate struct { + config + mutation *LienObjetEmplacementMutation + hooks []Hook +} + +// SetObjetID sets the "objet_id" field. +func (_c *LienObjetEmplacementCreate) SetObjetID(v uuid.UUID) *LienObjetEmplacementCreate { + _c.mutation.SetObjetID(v) + return _c +} + +// SetEmplacementID sets the "emplacement_id" field. +func (_c *LienObjetEmplacementCreate) SetEmplacementID(v uuid.UUID) *LienObjetEmplacementCreate { + _c.mutation.SetEmplacementID(v) + return _c +} + +// SetType sets the "type" field. +func (_c *LienObjetEmplacementCreate) SetType(v lienobjetemplacement.Type) *LienObjetEmplacementCreate { + _c.mutation.SetType(v) + return _c +} + +// SetNillableType sets the "type" field if the given value is not nil. +func (_c *LienObjetEmplacementCreate) SetNillableType(v *lienobjetemplacement.Type) *LienObjetEmplacementCreate { + if v != nil { + _c.SetType(*v) + } + return _c +} + +// SetCreatedAt sets the "created_at" field. +func (_c *LienObjetEmplacementCreate) SetCreatedAt(v time.Time) *LienObjetEmplacementCreate { + _c.mutation.SetCreatedAt(v) + return _c +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (_c *LienObjetEmplacementCreate) SetNillableCreatedAt(v *time.Time) *LienObjetEmplacementCreate { + if v != nil { + _c.SetCreatedAt(*v) + } + return _c +} + +// SetUpdatedAt sets the "updated_at" field. +func (_c *LienObjetEmplacementCreate) SetUpdatedAt(v time.Time) *LienObjetEmplacementCreate { + _c.mutation.SetUpdatedAt(v) + return _c +} + +// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. +func (_c *LienObjetEmplacementCreate) SetNillableUpdatedAt(v *time.Time) *LienObjetEmplacementCreate { + if v != nil { + _c.SetUpdatedAt(*v) + } + return _c +} + +// SetID sets the "id" field. +func (_c *LienObjetEmplacementCreate) SetID(v uuid.UUID) *LienObjetEmplacementCreate { + _c.mutation.SetID(v) + return _c +} + +// SetNillableID sets the "id" field if the given value is not nil. +func (_c *LienObjetEmplacementCreate) SetNillableID(v *uuid.UUID) *LienObjetEmplacementCreate { + if v != nil { + _c.SetID(*v) + } + return _c +} + +// SetObjet sets the "objet" edge to the Objet entity. +func (_c *LienObjetEmplacementCreate) SetObjet(v *Objet) *LienObjetEmplacementCreate { + return _c.SetObjetID(v.ID) +} + +// SetEmplacement sets the "emplacement" edge to the Emplacement entity. +func (_c *LienObjetEmplacementCreate) SetEmplacement(v *Emplacement) *LienObjetEmplacementCreate { + return _c.SetEmplacementID(v.ID) +} + +// Mutation returns the LienObjetEmplacementMutation object of the builder. +func (_c *LienObjetEmplacementCreate) Mutation() *LienObjetEmplacementMutation { + return _c.mutation +} + +// Save creates the LienObjetEmplacement in the database. +func (_c *LienObjetEmplacementCreate) Save(ctx context.Context) (*LienObjetEmplacement, error) { + _c.defaults() + return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks) +} + +// SaveX calls Save and panics if Save returns an error. +func (_c *LienObjetEmplacementCreate) SaveX(ctx context.Context) *LienObjetEmplacement { + v, err := _c.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (_c *LienObjetEmplacementCreate) Exec(ctx context.Context) error { + _, err := _c.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_c *LienObjetEmplacementCreate) ExecX(ctx context.Context) { + if err := _c.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (_c *LienObjetEmplacementCreate) defaults() { + if _, ok := _c.mutation.GetType(); !ok { + v := lienobjetemplacement.DefaultType + _c.mutation.SetType(v) + } + if _, ok := _c.mutation.CreatedAt(); !ok { + v := lienobjetemplacement.DefaultCreatedAt() + _c.mutation.SetCreatedAt(v) + } + if _, ok := _c.mutation.UpdatedAt(); !ok { + v := lienobjetemplacement.DefaultUpdatedAt() + _c.mutation.SetUpdatedAt(v) + } + if _, ok := _c.mutation.ID(); !ok { + v := lienobjetemplacement.DefaultID() + _c.mutation.SetID(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_c *LienObjetEmplacementCreate) check() error { + if _, ok := _c.mutation.ObjetID(); !ok { + return &ValidationError{Name: "objet_id", err: errors.New(`ent: missing required field "LienObjetEmplacement.objet_id"`)} + } + if _, ok := _c.mutation.EmplacementID(); !ok { + return &ValidationError{Name: "emplacement_id", err: errors.New(`ent: missing required field "LienObjetEmplacement.emplacement_id"`)} + } + if _, ok := _c.mutation.GetType(); !ok { + return &ValidationError{Name: "type", err: errors.New(`ent: missing required field "LienObjetEmplacement.type"`)} + } + if v, ok := _c.mutation.GetType(); ok { + if err := lienobjetemplacement.TypeValidator(v); err != nil { + return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "LienObjetEmplacement.type": %w`, err)} + } + } + if _, ok := _c.mutation.CreatedAt(); !ok { + return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "LienObjetEmplacement.created_at"`)} + } + if _, ok := _c.mutation.UpdatedAt(); !ok { + return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "LienObjetEmplacement.updated_at"`)} + } + if len(_c.mutation.ObjetIDs()) == 0 { + return &ValidationError{Name: "objet", err: errors.New(`ent: missing required edge "LienObjetEmplacement.objet"`)} + } + if len(_c.mutation.EmplacementIDs()) == 0 { + return &ValidationError{Name: "emplacement", err: errors.New(`ent: missing required edge "LienObjetEmplacement.emplacement"`)} + } + return nil +} + +func (_c *LienObjetEmplacementCreate) sqlSave(ctx context.Context) (*LienObjetEmplacement, error) { + if err := _c.check(); err != nil { + return nil, err + } + _node, _spec := _c.createSpec() + if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + if _spec.ID.Value != nil { + if id, ok := _spec.ID.Value.(*uuid.UUID); ok { + _node.ID = *id + } else if err := _node.ID.Scan(_spec.ID.Value); err != nil { + return nil, err + } + } + _c.mutation.id = &_node.ID + _c.mutation.done = true + return _node, nil +} + +func (_c *LienObjetEmplacementCreate) createSpec() (*LienObjetEmplacement, *sqlgraph.CreateSpec) { + var ( + _node = &LienObjetEmplacement{config: _c.config} + _spec = sqlgraph.NewCreateSpec(lienobjetemplacement.Table, sqlgraph.NewFieldSpec(lienobjetemplacement.FieldID, field.TypeUUID)) + ) + if id, ok := _c.mutation.ID(); ok { + _node.ID = id + _spec.ID.Value = &id + } + if value, ok := _c.mutation.GetType(); ok { + _spec.SetField(lienobjetemplacement.FieldType, field.TypeEnum, value) + _node.Type = value + } + if value, ok := _c.mutation.CreatedAt(); ok { + _spec.SetField(lienobjetemplacement.FieldCreatedAt, field.TypeTime, value) + _node.CreatedAt = value + } + if value, ok := _c.mutation.UpdatedAt(); ok { + _spec.SetField(lienobjetemplacement.FieldUpdatedAt, field.TypeTime, value) + _node.UpdatedAt = value + } + if nodes := _c.mutation.ObjetIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: lienobjetemplacement.ObjetTable, + Columns: []string{lienobjetemplacement.ObjetColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(objet.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _node.ObjetID = nodes[0] + _spec.Edges = append(_spec.Edges, edge) + } + if nodes := _c.mutation.EmplacementIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: lienobjetemplacement.EmplacementTable, + Columns: []string{lienobjetemplacement.EmplacementColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(emplacement.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _node.EmplacementID = nodes[0] + _spec.Edges = append(_spec.Edges, edge) + } + return _node, _spec +} + +// LienObjetEmplacementCreateBulk is the builder for creating many LienObjetEmplacement entities in bulk. +type LienObjetEmplacementCreateBulk struct { + config + err error + builders []*LienObjetEmplacementCreate +} + +// Save creates the LienObjetEmplacement entities in the database. +func (_c *LienObjetEmplacementCreateBulk) Save(ctx context.Context) ([]*LienObjetEmplacement, error) { + if _c.err != nil { + return nil, _c.err + } + specs := make([]*sqlgraph.CreateSpec, len(_c.builders)) + nodes := make([]*LienObjetEmplacement, len(_c.builders)) + mutators := make([]Mutator, len(_c.builders)) + for i := range _c.builders { + func(i int, root context.Context) { + builder := _c.builders[i] + builder.defaults() + var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { + mutation, ok := m.(*LienObjetEmplacementMutation) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T", m) + } + if err := builder.check(); err != nil { + return nil, err + } + builder.mutation = mutation + var err error + nodes[i], specs[i] = builder.createSpec() + if i < len(mutators)-1 { + _, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation) + } else { + spec := &sqlgraph.BatchCreateSpec{Nodes: specs} + // Invoke the actual operation on the latest mutation in the chain. + if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + } + } + if err != nil { + return nil, err + } + mutation.id = &nodes[i].ID + mutation.done = true + return nodes[i], nil + }) + for i := len(builder.hooks) - 1; i >= 0; i-- { + mut = builder.hooks[i](mut) + } + mutators[i] = mut + }(i, ctx) + } + if len(mutators) > 0 { + if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil { + return nil, err + } + } + return nodes, nil +} + +// SaveX is like Save, but panics if an error occurs. +func (_c *LienObjetEmplacementCreateBulk) SaveX(ctx context.Context) []*LienObjetEmplacement { + v, err := _c.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (_c *LienObjetEmplacementCreateBulk) Exec(ctx context.Context) error { + _, err := _c.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_c *LienObjetEmplacementCreateBulk) ExecX(ctx context.Context) { + if err := _c.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/backend/internal/data/ent/lienobjetemplacement_delete.go b/backend/internal/data/ent/lienobjetemplacement_delete.go new file mode 100644 index 0000000..dacac98 --- /dev/null +++ b/backend/internal/data/ent/lienobjetemplacement_delete.go @@ -0,0 +1,88 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/lienobjetemplacement" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/predicate" +) + +// LienObjetEmplacementDelete is the builder for deleting a LienObjetEmplacement entity. +type LienObjetEmplacementDelete struct { + config + hooks []Hook + mutation *LienObjetEmplacementMutation +} + +// Where appends a list predicates to the LienObjetEmplacementDelete builder. +func (_d *LienObjetEmplacementDelete) Where(ps ...predicate.LienObjetEmplacement) *LienObjetEmplacementDelete { + _d.mutation.Where(ps...) + return _d +} + +// Exec executes the deletion query and returns how many vertices were deleted. +func (_d *LienObjetEmplacementDelete) Exec(ctx context.Context) (int, error) { + return withHooks(ctx, _d.sqlExec, _d.mutation, _d.hooks) +} + +// ExecX is like Exec, but panics if an error occurs. +func (_d *LienObjetEmplacementDelete) ExecX(ctx context.Context) int { + n, err := _d.Exec(ctx) + if err != nil { + panic(err) + } + return n +} + +func (_d *LienObjetEmplacementDelete) sqlExec(ctx context.Context) (int, error) { + _spec := sqlgraph.NewDeleteSpec(lienobjetemplacement.Table, sqlgraph.NewFieldSpec(lienobjetemplacement.FieldID, field.TypeUUID)) + if ps := _d.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + affected, err := sqlgraph.DeleteNodes(ctx, _d.driver, _spec) + if err != nil && sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + _d.mutation.done = true + return affected, err +} + +// LienObjetEmplacementDeleteOne is the builder for deleting a single LienObjetEmplacement entity. +type LienObjetEmplacementDeleteOne struct { + _d *LienObjetEmplacementDelete +} + +// Where appends a list predicates to the LienObjetEmplacementDelete builder. +func (_d *LienObjetEmplacementDeleteOne) Where(ps ...predicate.LienObjetEmplacement) *LienObjetEmplacementDeleteOne { + _d._d.mutation.Where(ps...) + return _d +} + +// Exec executes the deletion query. +func (_d *LienObjetEmplacementDeleteOne) Exec(ctx context.Context) error { + n, err := _d._d.Exec(ctx) + switch { + case err != nil: + return err + case n == 0: + return &NotFoundError{lienobjetemplacement.Label} + default: + return nil + } +} + +// ExecX is like Exec, but panics if an error occurs. +func (_d *LienObjetEmplacementDeleteOne) ExecX(ctx context.Context) { + if err := _d.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/backend/internal/data/ent/lienobjetemplacement_query.go b/backend/internal/data/ent/lienobjetemplacement_query.go new file mode 100644 index 0000000..c83b7f4 --- /dev/null +++ b/backend/internal/data/ent/lienobjetemplacement_query.go @@ -0,0 +1,682 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "fmt" + "math" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/emplacement" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/lienobjetemplacement" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/objet" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/predicate" + "github.com/google/uuid" +) + +// LienObjetEmplacementQuery is the builder for querying LienObjetEmplacement entities. +type LienObjetEmplacementQuery struct { + config + ctx *QueryContext + order []lienobjetemplacement.OrderOption + inters []Interceptor + predicates []predicate.LienObjetEmplacement + withObjet *ObjetQuery + withEmplacement *EmplacementQuery + // intermediate query (i.e. traversal path). + sql *sql.Selector + path func(context.Context) (*sql.Selector, error) +} + +// Where adds a new predicate for the LienObjetEmplacementQuery builder. +func (_q *LienObjetEmplacementQuery) Where(ps ...predicate.LienObjetEmplacement) *LienObjetEmplacementQuery { + _q.predicates = append(_q.predicates, ps...) + return _q +} + +// Limit the number of records to be returned by this query. +func (_q *LienObjetEmplacementQuery) Limit(limit int) *LienObjetEmplacementQuery { + _q.ctx.Limit = &limit + return _q +} + +// Offset to start from. +func (_q *LienObjetEmplacementQuery) Offset(offset int) *LienObjetEmplacementQuery { + _q.ctx.Offset = &offset + return _q +} + +// Unique configures the query builder to filter duplicate records on query. +// By default, unique is set to true, and can be disabled using this method. +func (_q *LienObjetEmplacementQuery) Unique(unique bool) *LienObjetEmplacementQuery { + _q.ctx.Unique = &unique + return _q +} + +// Order specifies how the records should be ordered. +func (_q *LienObjetEmplacementQuery) Order(o ...lienobjetemplacement.OrderOption) *LienObjetEmplacementQuery { + _q.order = append(_q.order, o...) + return _q +} + +// QueryObjet chains the current query on the "objet" edge. +func (_q *LienObjetEmplacementQuery) QueryObjet() *ObjetQuery { + query := (&ObjetClient{config: _q.config}).Query() + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + selector := _q.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(lienobjetemplacement.Table, lienobjetemplacement.FieldID, selector), + sqlgraph.To(objet.Table, objet.FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, lienobjetemplacement.ObjetTable, lienobjetemplacement.ObjetColumn), + ) + fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) + return fromU, nil + } + return query +} + +// QueryEmplacement chains the current query on the "emplacement" edge. +func (_q *LienObjetEmplacementQuery) QueryEmplacement() *EmplacementQuery { + query := (&EmplacementClient{config: _q.config}).Query() + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + selector := _q.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(lienobjetemplacement.Table, lienobjetemplacement.FieldID, selector), + sqlgraph.To(emplacement.Table, emplacement.FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, lienobjetemplacement.EmplacementTable, lienobjetemplacement.EmplacementColumn), + ) + fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) + return fromU, nil + } + return query +} + +// First returns the first LienObjetEmplacement entity from the query. +// Returns a *NotFoundError when no LienObjetEmplacement was found. +func (_q *LienObjetEmplacementQuery) First(ctx context.Context) (*LienObjetEmplacement, error) { + nodes, err := _q.Limit(1).All(setContextOp(ctx, _q.ctx, ent.OpQueryFirst)) + if err != nil { + return nil, err + } + if len(nodes) == 0 { + return nil, &NotFoundError{lienobjetemplacement.Label} + } + return nodes[0], nil +} + +// FirstX is like First, but panics if an error occurs. +func (_q *LienObjetEmplacementQuery) FirstX(ctx context.Context) *LienObjetEmplacement { + node, err := _q.First(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return node +} + +// FirstID returns the first LienObjetEmplacement ID from the query. +// Returns a *NotFoundError when no LienObjetEmplacement ID was found. +func (_q *LienObjetEmplacementQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { + var ids []uuid.UUID + if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil { + return + } + if len(ids) == 0 { + err = &NotFoundError{lienobjetemplacement.Label} + return + } + return ids[0], nil +} + +// FirstIDX is like FirstID, but panics if an error occurs. +func (_q *LienObjetEmplacementQuery) FirstIDX(ctx context.Context) uuid.UUID { + id, err := _q.FirstID(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return id +} + +// Only returns a single LienObjetEmplacement entity found by the query, ensuring it only returns one. +// Returns a *NotSingularError when more than one LienObjetEmplacement entity is found. +// Returns a *NotFoundError when no LienObjetEmplacement entities are found. +func (_q *LienObjetEmplacementQuery) Only(ctx context.Context) (*LienObjetEmplacement, error) { + nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly)) + if err != nil { + return nil, err + } + switch len(nodes) { + case 1: + return nodes[0], nil + case 0: + return nil, &NotFoundError{lienobjetemplacement.Label} + default: + return nil, &NotSingularError{lienobjetemplacement.Label} + } +} + +// OnlyX is like Only, but panics if an error occurs. +func (_q *LienObjetEmplacementQuery) OnlyX(ctx context.Context) *LienObjetEmplacement { + node, err := _q.Only(ctx) + if err != nil { + panic(err) + } + return node +} + +// OnlyID is like Only, but returns the only LienObjetEmplacement ID in the query. +// Returns a *NotSingularError when more than one LienObjetEmplacement ID is found. +// Returns a *NotFoundError when no entities are found. +func (_q *LienObjetEmplacementQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { + var ids []uuid.UUID + if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryOnlyID)); err != nil { + return + } + switch len(ids) { + case 1: + id = ids[0] + case 0: + err = &NotFoundError{lienobjetemplacement.Label} + default: + err = &NotSingularError{lienobjetemplacement.Label} + } + return +} + +// OnlyIDX is like OnlyID, but panics if an error occurs. +func (_q *LienObjetEmplacementQuery) OnlyIDX(ctx context.Context) uuid.UUID { + id, err := _q.OnlyID(ctx) + if err != nil { + panic(err) + } + return id +} + +// All executes the query and returns a list of LienObjetEmplacements. +func (_q *LienObjetEmplacementQuery) All(ctx context.Context) ([]*LienObjetEmplacement, error) { + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll) + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + qr := querierAll[[]*LienObjetEmplacement, *LienObjetEmplacementQuery]() + return withInterceptors[[]*LienObjetEmplacement](ctx, _q, qr, _q.inters) +} + +// AllX is like All, but panics if an error occurs. +func (_q *LienObjetEmplacementQuery) AllX(ctx context.Context) []*LienObjetEmplacement { + nodes, err := _q.All(ctx) + if err != nil { + panic(err) + } + return nodes +} + +// IDs executes the query and returns a list of LienObjetEmplacement IDs. +func (_q *LienObjetEmplacementQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) { + if _q.ctx.Unique == nil && _q.path != nil { + _q.Unique(true) + } + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryIDs) + if err = _q.Select(lienobjetemplacement.FieldID).Scan(ctx, &ids); err != nil { + return nil, err + } + return ids, nil +} + +// IDsX is like IDs, but panics if an error occurs. +func (_q *LienObjetEmplacementQuery) IDsX(ctx context.Context) []uuid.UUID { + ids, err := _q.IDs(ctx) + if err != nil { + panic(err) + } + return ids +} + +// Count returns the count of the given query. +func (_q *LienObjetEmplacementQuery) Count(ctx context.Context) (int, error) { + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryCount) + if err := _q.prepareQuery(ctx); err != nil { + return 0, err + } + return withInterceptors[int](ctx, _q, querierCount[*LienObjetEmplacementQuery](), _q.inters) +} + +// CountX is like Count, but panics if an error occurs. +func (_q *LienObjetEmplacementQuery) CountX(ctx context.Context) int { + count, err := _q.Count(ctx) + if err != nil { + panic(err) + } + return count +} + +// Exist returns true if the query has elements in the graph. +func (_q *LienObjetEmplacementQuery) Exist(ctx context.Context) (bool, error) { + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryExist) + switch _, err := _q.FirstID(ctx); { + case IsNotFound(err): + return false, nil + case err != nil: + return false, fmt.Errorf("ent: check existence: %w", err) + default: + return true, nil + } +} + +// ExistX is like Exist, but panics if an error occurs. +func (_q *LienObjetEmplacementQuery) ExistX(ctx context.Context) bool { + exist, err := _q.Exist(ctx) + if err != nil { + panic(err) + } + return exist +} + +// Clone returns a duplicate of the LienObjetEmplacementQuery builder, including all associated steps. It can be +// used to prepare common query builders and use them differently after the clone is made. +func (_q *LienObjetEmplacementQuery) Clone() *LienObjetEmplacementQuery { + if _q == nil { + return nil + } + return &LienObjetEmplacementQuery{ + config: _q.config, + ctx: _q.ctx.Clone(), + order: append([]lienobjetemplacement.OrderOption{}, _q.order...), + inters: append([]Interceptor{}, _q.inters...), + predicates: append([]predicate.LienObjetEmplacement{}, _q.predicates...), + withObjet: _q.withObjet.Clone(), + withEmplacement: _q.withEmplacement.Clone(), + // clone intermediate query. + sql: _q.sql.Clone(), + path: _q.path, + } +} + +// WithObjet tells the query-builder to eager-load the nodes that are connected to +// the "objet" edge. The optional arguments are used to configure the query builder of the edge. +func (_q *LienObjetEmplacementQuery) WithObjet(opts ...func(*ObjetQuery)) *LienObjetEmplacementQuery { + query := (&ObjetClient{config: _q.config}).Query() + for _, opt := range opts { + opt(query) + } + _q.withObjet = query + return _q +} + +// WithEmplacement tells the query-builder to eager-load the nodes that are connected to +// the "emplacement" edge. The optional arguments are used to configure the query builder of the edge. +func (_q *LienObjetEmplacementQuery) WithEmplacement(opts ...func(*EmplacementQuery)) *LienObjetEmplacementQuery { + query := (&EmplacementClient{config: _q.config}).Query() + for _, opt := range opts { + opt(query) + } + _q.withEmplacement = query + return _q +} + +// GroupBy is used to group vertices by one or more fields/columns. +// It is often used with aggregate functions, like: count, max, mean, min, sum. +// +// Example: +// +// var v []struct { +// ObjetID uuid.UUID `json:"objet_id,omitempty"` +// Count int `json:"count,omitempty"` +// } +// +// client.LienObjetEmplacement.Query(). +// GroupBy(lienobjetemplacement.FieldObjetID). +// Aggregate(ent.Count()). +// Scan(ctx, &v) +func (_q *LienObjetEmplacementQuery) GroupBy(field string, fields ...string) *LienObjetEmplacementGroupBy { + _q.ctx.Fields = append([]string{field}, fields...) + grbuild := &LienObjetEmplacementGroupBy{build: _q} + grbuild.flds = &_q.ctx.Fields + grbuild.label = lienobjetemplacement.Label + grbuild.scan = grbuild.Scan + return grbuild +} + +// Select allows the selection one or more fields/columns for the given query, +// instead of selecting all fields in the entity. +// +// Example: +// +// var v []struct { +// ObjetID uuid.UUID `json:"objet_id,omitempty"` +// } +// +// client.LienObjetEmplacement.Query(). +// Select(lienobjetemplacement.FieldObjetID). +// Scan(ctx, &v) +func (_q *LienObjetEmplacementQuery) Select(fields ...string) *LienObjetEmplacementSelect { + _q.ctx.Fields = append(_q.ctx.Fields, fields...) + sbuild := &LienObjetEmplacementSelect{LienObjetEmplacementQuery: _q} + sbuild.label = lienobjetemplacement.Label + sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan + return sbuild +} + +// Aggregate returns a LienObjetEmplacementSelect configured with the given aggregations. +func (_q *LienObjetEmplacementQuery) Aggregate(fns ...AggregateFunc) *LienObjetEmplacementSelect { + return _q.Select().Aggregate(fns...) +} + +func (_q *LienObjetEmplacementQuery) prepareQuery(ctx context.Context) error { + for _, inter := range _q.inters { + if inter == nil { + return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)") + } + if trv, ok := inter.(Traverser); ok { + if err := trv.Traverse(ctx, _q); err != nil { + return err + } + } + } + for _, f := range _q.ctx.Fields { + if !lienobjetemplacement.ValidColumn(f) { + return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + } + if _q.path != nil { + prev, err := _q.path(ctx) + if err != nil { + return err + } + _q.sql = prev + } + return nil +} + +func (_q *LienObjetEmplacementQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*LienObjetEmplacement, error) { + var ( + nodes = []*LienObjetEmplacement{} + _spec = _q.querySpec() + loadedTypes = [2]bool{ + _q.withObjet != nil, + _q.withEmplacement != nil, + } + ) + _spec.ScanValues = func(columns []string) ([]any, error) { + return (*LienObjetEmplacement).scanValues(nil, columns) + } + _spec.Assign = func(columns []string, values []any) error { + node := &LienObjetEmplacement{config: _q.config} + nodes = append(nodes, node) + node.Edges.loadedTypes = loadedTypes + return node.assignValues(columns, values) + } + for i := range hooks { + hooks[i](ctx, _spec) + } + if err := sqlgraph.QueryNodes(ctx, _q.driver, _spec); err != nil { + return nil, err + } + if len(nodes) == 0 { + return nodes, nil + } + if query := _q.withObjet; query != nil { + if err := _q.loadObjet(ctx, query, nodes, nil, + func(n *LienObjetEmplacement, e *Objet) { n.Edges.Objet = e }); err != nil { + return nil, err + } + } + if query := _q.withEmplacement; query != nil { + if err := _q.loadEmplacement(ctx, query, nodes, nil, + func(n *LienObjetEmplacement, e *Emplacement) { n.Edges.Emplacement = e }); err != nil { + return nil, err + } + } + return nodes, nil +} + +func (_q *LienObjetEmplacementQuery) loadObjet(ctx context.Context, query *ObjetQuery, nodes []*LienObjetEmplacement, init func(*LienObjetEmplacement), assign func(*LienObjetEmplacement, *Objet)) error { + ids := make([]uuid.UUID, 0, len(nodes)) + nodeids := make(map[uuid.UUID][]*LienObjetEmplacement) + for i := range nodes { + fk := nodes[i].ObjetID + if _, ok := nodeids[fk]; !ok { + ids = append(ids, fk) + } + nodeids[fk] = append(nodeids[fk], nodes[i]) + } + if len(ids) == 0 { + return nil + } + query.Where(objet.IDIn(ids...)) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + nodes, ok := nodeids[n.ID] + if !ok { + return fmt.Errorf(`unexpected foreign-key "objet_id" returned %v`, n.ID) + } + for i := range nodes { + assign(nodes[i], n) + } + } + return nil +} +func (_q *LienObjetEmplacementQuery) loadEmplacement(ctx context.Context, query *EmplacementQuery, nodes []*LienObjetEmplacement, init func(*LienObjetEmplacement), assign func(*LienObjetEmplacement, *Emplacement)) error { + ids := make([]uuid.UUID, 0, len(nodes)) + nodeids := make(map[uuid.UUID][]*LienObjetEmplacement) + for i := range nodes { + fk := nodes[i].EmplacementID + if _, ok := nodeids[fk]; !ok { + ids = append(ids, fk) + } + nodeids[fk] = append(nodeids[fk], nodes[i]) + } + if len(ids) == 0 { + return nil + } + query.Where(emplacement.IDIn(ids...)) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + nodes, ok := nodeids[n.ID] + if !ok { + return fmt.Errorf(`unexpected foreign-key "emplacement_id" returned %v`, n.ID) + } + for i := range nodes { + assign(nodes[i], n) + } + } + return nil +} + +func (_q *LienObjetEmplacementQuery) sqlCount(ctx context.Context) (int, error) { + _spec := _q.querySpec() + _spec.Node.Columns = _q.ctx.Fields + if len(_q.ctx.Fields) > 0 { + _spec.Unique = _q.ctx.Unique != nil && *_q.ctx.Unique + } + return sqlgraph.CountNodes(ctx, _q.driver, _spec) +} + +func (_q *LienObjetEmplacementQuery) querySpec() *sqlgraph.QuerySpec { + _spec := sqlgraph.NewQuerySpec(lienobjetemplacement.Table, lienobjetemplacement.Columns, sqlgraph.NewFieldSpec(lienobjetemplacement.FieldID, field.TypeUUID)) + _spec.From = _q.sql + if unique := _q.ctx.Unique; unique != nil { + _spec.Unique = *unique + } else if _q.path != nil { + _spec.Unique = true + } + if fields := _q.ctx.Fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, lienobjetemplacement.FieldID) + for i := range fields { + if fields[i] != lienobjetemplacement.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) + } + } + if _q.withObjet != nil { + _spec.Node.AddColumnOnce(lienobjetemplacement.FieldObjetID) + } + if _q.withEmplacement != nil { + _spec.Node.AddColumnOnce(lienobjetemplacement.FieldEmplacementID) + } + } + if ps := _q.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if limit := _q.ctx.Limit; limit != nil { + _spec.Limit = *limit + } + if offset := _q.ctx.Offset; offset != nil { + _spec.Offset = *offset + } + if ps := _q.order; len(ps) > 0 { + _spec.Order = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + return _spec +} + +func (_q *LienObjetEmplacementQuery) sqlQuery(ctx context.Context) *sql.Selector { + builder := sql.Dialect(_q.driver.Dialect()) + t1 := builder.Table(lienobjetemplacement.Table) + columns := _q.ctx.Fields + if len(columns) == 0 { + columns = lienobjetemplacement.Columns + } + selector := builder.Select(t1.Columns(columns...)...).From(t1) + if _q.sql != nil { + selector = _q.sql + selector.Select(selector.Columns(columns...)...) + } + if _q.ctx.Unique != nil && *_q.ctx.Unique { + selector.Distinct() + } + for _, p := range _q.predicates { + p(selector) + } + for _, p := range _q.order { + p(selector) + } + if offset := _q.ctx.Offset; offset != nil { + // limit is mandatory for offset clause. We start + // with default value, and override it below if needed. + selector.Offset(*offset).Limit(math.MaxInt32) + } + if limit := _q.ctx.Limit; limit != nil { + selector.Limit(*limit) + } + return selector +} + +// LienObjetEmplacementGroupBy is the group-by builder for LienObjetEmplacement entities. +type LienObjetEmplacementGroupBy struct { + selector + build *LienObjetEmplacementQuery +} + +// Aggregate adds the given aggregation functions to the group-by query. +func (_g *LienObjetEmplacementGroupBy) Aggregate(fns ...AggregateFunc) *LienObjetEmplacementGroupBy { + _g.fns = append(_g.fns, fns...) + return _g +} + +// Scan applies the selector query and scans the result into the given value. +func (_g *LienObjetEmplacementGroupBy) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, _g.build.ctx, ent.OpQueryGroupBy) + if err := _g.build.prepareQuery(ctx); err != nil { + return err + } + return scanWithInterceptors[*LienObjetEmplacementQuery, *LienObjetEmplacementGroupBy](ctx, _g.build, _g, _g.build.inters, v) +} + +func (_g *LienObjetEmplacementGroupBy) sqlScan(ctx context.Context, root *LienObjetEmplacementQuery, v any) error { + selector := root.sqlQuery(ctx).Select() + aggregation := make([]string, 0, len(_g.fns)) + for _, fn := range _g.fns { + aggregation = append(aggregation, fn(selector)) + } + if len(selector.SelectedColumns()) == 0 { + columns := make([]string, 0, len(*_g.flds)+len(_g.fns)) + for _, f := range *_g.flds { + columns = append(columns, selector.C(f)) + } + columns = append(columns, aggregation...) + selector.Select(columns...) + } + selector.GroupBy(selector.Columns(*_g.flds...)...) + if err := selector.Err(); err != nil { + return err + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := _g.build.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} + +// LienObjetEmplacementSelect is the builder for selecting fields of LienObjetEmplacement entities. +type LienObjetEmplacementSelect struct { + *LienObjetEmplacementQuery + selector +} + +// Aggregate adds the given aggregation functions to the selector query. +func (_s *LienObjetEmplacementSelect) Aggregate(fns ...AggregateFunc) *LienObjetEmplacementSelect { + _s.fns = append(_s.fns, fns...) + return _s +} + +// Scan applies the selector query and scans the result into the given value. +func (_s *LienObjetEmplacementSelect) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, _s.ctx, ent.OpQuerySelect) + if err := _s.prepareQuery(ctx); err != nil { + return err + } + return scanWithInterceptors[*LienObjetEmplacementQuery, *LienObjetEmplacementSelect](ctx, _s.LienObjetEmplacementQuery, _s, _s.inters, v) +} + +func (_s *LienObjetEmplacementSelect) sqlScan(ctx context.Context, root *LienObjetEmplacementQuery, v any) error { + selector := root.sqlQuery(ctx) + aggregation := make([]string, 0, len(_s.fns)) + for _, fn := range _s.fns { + aggregation = append(aggregation, fn(selector)) + } + switch n := len(*_s.selector.flds); { + case n == 0 && len(aggregation) > 0: + selector.Select(aggregation...) + case n != 0 && len(aggregation) > 0: + selector.AppendSelect(aggregation...) + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := _s.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} diff --git a/backend/internal/data/ent/lienobjetemplacement_update.go b/backend/internal/data/ent/lienobjetemplacement_update.go new file mode 100644 index 0000000..b472ec9 --- /dev/null +++ b/backend/internal/data/ent/lienobjetemplacement_update.go @@ -0,0 +1,537 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/emplacement" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/lienobjetemplacement" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/objet" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/predicate" + "github.com/google/uuid" +) + +// LienObjetEmplacementUpdate is the builder for updating LienObjetEmplacement entities. +type LienObjetEmplacementUpdate struct { + config + hooks []Hook + mutation *LienObjetEmplacementMutation +} + +// Where appends a list predicates to the LienObjetEmplacementUpdate builder. +func (_u *LienObjetEmplacementUpdate) Where(ps ...predicate.LienObjetEmplacement) *LienObjetEmplacementUpdate { + _u.mutation.Where(ps...) + return _u +} + +// SetObjetID sets the "objet_id" field. +func (_u *LienObjetEmplacementUpdate) SetObjetID(v uuid.UUID) *LienObjetEmplacementUpdate { + _u.mutation.SetObjetID(v) + return _u +} + +// SetNillableObjetID sets the "objet_id" field if the given value is not nil. +func (_u *LienObjetEmplacementUpdate) SetNillableObjetID(v *uuid.UUID) *LienObjetEmplacementUpdate { + if v != nil { + _u.SetObjetID(*v) + } + return _u +} + +// SetEmplacementID sets the "emplacement_id" field. +func (_u *LienObjetEmplacementUpdate) SetEmplacementID(v uuid.UUID) *LienObjetEmplacementUpdate { + _u.mutation.SetEmplacementID(v) + return _u +} + +// SetNillableEmplacementID sets the "emplacement_id" field if the given value is not nil. +func (_u *LienObjetEmplacementUpdate) SetNillableEmplacementID(v *uuid.UUID) *LienObjetEmplacementUpdate { + if v != nil { + _u.SetEmplacementID(*v) + } + return _u +} + +// SetType sets the "type" field. +func (_u *LienObjetEmplacementUpdate) SetType(v lienobjetemplacement.Type) *LienObjetEmplacementUpdate { + _u.mutation.SetType(v) + return _u +} + +// SetNillableType sets the "type" field if the given value is not nil. +func (_u *LienObjetEmplacementUpdate) SetNillableType(v *lienobjetemplacement.Type) *LienObjetEmplacementUpdate { + if v != nil { + _u.SetType(*v) + } + return _u +} + +// SetCreatedAt sets the "created_at" field. +func (_u *LienObjetEmplacementUpdate) SetCreatedAt(v time.Time) *LienObjetEmplacementUpdate { + _u.mutation.SetCreatedAt(v) + return _u +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (_u *LienObjetEmplacementUpdate) SetNillableCreatedAt(v *time.Time) *LienObjetEmplacementUpdate { + if v != nil { + _u.SetCreatedAt(*v) + } + return _u +} + +// SetUpdatedAt sets the "updated_at" field. +func (_u *LienObjetEmplacementUpdate) SetUpdatedAt(v time.Time) *LienObjetEmplacementUpdate { + _u.mutation.SetUpdatedAt(v) + return _u +} + +// SetObjet sets the "objet" edge to the Objet entity. +func (_u *LienObjetEmplacementUpdate) SetObjet(v *Objet) *LienObjetEmplacementUpdate { + return _u.SetObjetID(v.ID) +} + +// SetEmplacement sets the "emplacement" edge to the Emplacement entity. +func (_u *LienObjetEmplacementUpdate) SetEmplacement(v *Emplacement) *LienObjetEmplacementUpdate { + return _u.SetEmplacementID(v.ID) +} + +// Mutation returns the LienObjetEmplacementMutation object of the builder. +func (_u *LienObjetEmplacementUpdate) Mutation() *LienObjetEmplacementMutation { + return _u.mutation +} + +// ClearObjet clears the "objet" edge to the Objet entity. +func (_u *LienObjetEmplacementUpdate) ClearObjet() *LienObjetEmplacementUpdate { + _u.mutation.ClearObjet() + return _u +} + +// ClearEmplacement clears the "emplacement" edge to the Emplacement entity. +func (_u *LienObjetEmplacementUpdate) ClearEmplacement() *LienObjetEmplacementUpdate { + _u.mutation.ClearEmplacement() + return _u +} + +// Save executes the query and returns the number of nodes affected by the update operation. +func (_u *LienObjetEmplacementUpdate) Save(ctx context.Context) (int, error) { + _u.defaults() + return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (_u *LienObjetEmplacementUpdate) SaveX(ctx context.Context) int { + affected, err := _u.Save(ctx) + if err != nil { + panic(err) + } + return affected +} + +// Exec executes the query. +func (_u *LienObjetEmplacementUpdate) Exec(ctx context.Context) error { + _, err := _u.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_u *LienObjetEmplacementUpdate) ExecX(ctx context.Context) { + if err := _u.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (_u *LienObjetEmplacementUpdate) defaults() { + if _, ok := _u.mutation.UpdatedAt(); !ok { + v := lienobjetemplacement.UpdateDefaultUpdatedAt() + _u.mutation.SetUpdatedAt(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_u *LienObjetEmplacementUpdate) check() error { + if v, ok := _u.mutation.GetType(); ok { + if err := lienobjetemplacement.TypeValidator(v); err != nil { + return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "LienObjetEmplacement.type": %w`, err)} + } + } + if _u.mutation.ObjetCleared() && len(_u.mutation.ObjetIDs()) > 0 { + return errors.New(`ent: clearing a required unique edge "LienObjetEmplacement.objet"`) + } + if _u.mutation.EmplacementCleared() && len(_u.mutation.EmplacementIDs()) > 0 { + return errors.New(`ent: clearing a required unique edge "LienObjetEmplacement.emplacement"`) + } + return nil +} + +func (_u *LienObjetEmplacementUpdate) sqlSave(ctx context.Context) (_node int, err error) { + if err := _u.check(); err != nil { + return _node, err + } + _spec := sqlgraph.NewUpdateSpec(lienobjetemplacement.Table, lienobjetemplacement.Columns, sqlgraph.NewFieldSpec(lienobjetemplacement.FieldID, field.TypeUUID)) + if ps := _u.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := _u.mutation.GetType(); ok { + _spec.SetField(lienobjetemplacement.FieldType, field.TypeEnum, value) + } + if value, ok := _u.mutation.CreatedAt(); ok { + _spec.SetField(lienobjetemplacement.FieldCreatedAt, field.TypeTime, value) + } + if value, ok := _u.mutation.UpdatedAt(); ok { + _spec.SetField(lienobjetemplacement.FieldUpdatedAt, field.TypeTime, value) + } + if _u.mutation.ObjetCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: lienobjetemplacement.ObjetTable, + Columns: []string{lienobjetemplacement.ObjetColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(objet.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.ObjetIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: lienobjetemplacement.ObjetTable, + Columns: []string{lienobjetemplacement.ObjetColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(objet.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if _u.mutation.EmplacementCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: lienobjetemplacement.EmplacementTable, + Columns: []string{lienobjetemplacement.EmplacementColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(emplacement.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.EmplacementIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: lienobjetemplacement.EmplacementTable, + Columns: []string{lienobjetemplacement.EmplacementColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(emplacement.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{lienobjetemplacement.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return 0, err + } + _u.mutation.done = true + return _node, nil +} + +// LienObjetEmplacementUpdateOne is the builder for updating a single LienObjetEmplacement entity. +type LienObjetEmplacementUpdateOne struct { + config + fields []string + hooks []Hook + mutation *LienObjetEmplacementMutation +} + +// SetObjetID sets the "objet_id" field. +func (_u *LienObjetEmplacementUpdateOne) SetObjetID(v uuid.UUID) *LienObjetEmplacementUpdateOne { + _u.mutation.SetObjetID(v) + return _u +} + +// SetNillableObjetID sets the "objet_id" field if the given value is not nil. +func (_u *LienObjetEmplacementUpdateOne) SetNillableObjetID(v *uuid.UUID) *LienObjetEmplacementUpdateOne { + if v != nil { + _u.SetObjetID(*v) + } + return _u +} + +// SetEmplacementID sets the "emplacement_id" field. +func (_u *LienObjetEmplacementUpdateOne) SetEmplacementID(v uuid.UUID) *LienObjetEmplacementUpdateOne { + _u.mutation.SetEmplacementID(v) + return _u +} + +// SetNillableEmplacementID sets the "emplacement_id" field if the given value is not nil. +func (_u *LienObjetEmplacementUpdateOne) SetNillableEmplacementID(v *uuid.UUID) *LienObjetEmplacementUpdateOne { + if v != nil { + _u.SetEmplacementID(*v) + } + return _u +} + +// SetType sets the "type" field. +func (_u *LienObjetEmplacementUpdateOne) SetType(v lienobjetemplacement.Type) *LienObjetEmplacementUpdateOne { + _u.mutation.SetType(v) + return _u +} + +// SetNillableType sets the "type" field if the given value is not nil. +func (_u *LienObjetEmplacementUpdateOne) SetNillableType(v *lienobjetemplacement.Type) *LienObjetEmplacementUpdateOne { + if v != nil { + _u.SetType(*v) + } + return _u +} + +// SetCreatedAt sets the "created_at" field. +func (_u *LienObjetEmplacementUpdateOne) SetCreatedAt(v time.Time) *LienObjetEmplacementUpdateOne { + _u.mutation.SetCreatedAt(v) + return _u +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (_u *LienObjetEmplacementUpdateOne) SetNillableCreatedAt(v *time.Time) *LienObjetEmplacementUpdateOne { + if v != nil { + _u.SetCreatedAt(*v) + } + return _u +} + +// SetUpdatedAt sets the "updated_at" field. +func (_u *LienObjetEmplacementUpdateOne) SetUpdatedAt(v time.Time) *LienObjetEmplacementUpdateOne { + _u.mutation.SetUpdatedAt(v) + return _u +} + +// SetObjet sets the "objet" edge to the Objet entity. +func (_u *LienObjetEmplacementUpdateOne) SetObjet(v *Objet) *LienObjetEmplacementUpdateOne { + return _u.SetObjetID(v.ID) +} + +// SetEmplacement sets the "emplacement" edge to the Emplacement entity. +func (_u *LienObjetEmplacementUpdateOne) SetEmplacement(v *Emplacement) *LienObjetEmplacementUpdateOne { + return _u.SetEmplacementID(v.ID) +} + +// Mutation returns the LienObjetEmplacementMutation object of the builder. +func (_u *LienObjetEmplacementUpdateOne) Mutation() *LienObjetEmplacementMutation { + return _u.mutation +} + +// ClearObjet clears the "objet" edge to the Objet entity. +func (_u *LienObjetEmplacementUpdateOne) ClearObjet() *LienObjetEmplacementUpdateOne { + _u.mutation.ClearObjet() + return _u +} + +// ClearEmplacement clears the "emplacement" edge to the Emplacement entity. +func (_u *LienObjetEmplacementUpdateOne) ClearEmplacement() *LienObjetEmplacementUpdateOne { + _u.mutation.ClearEmplacement() + return _u +} + +// Where appends a list predicates to the LienObjetEmplacementUpdate builder. +func (_u *LienObjetEmplacementUpdateOne) Where(ps ...predicate.LienObjetEmplacement) *LienObjetEmplacementUpdateOne { + _u.mutation.Where(ps...) + return _u +} + +// Select allows selecting one or more fields (columns) of the returned entity. +// The default is selecting all fields defined in the entity schema. +func (_u *LienObjetEmplacementUpdateOne) Select(field string, fields ...string) *LienObjetEmplacementUpdateOne { + _u.fields = append([]string{field}, fields...) + return _u +} + +// Save executes the query and returns the updated LienObjetEmplacement entity. +func (_u *LienObjetEmplacementUpdateOne) Save(ctx context.Context) (*LienObjetEmplacement, error) { + _u.defaults() + return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (_u *LienObjetEmplacementUpdateOne) SaveX(ctx context.Context) *LienObjetEmplacement { + node, err := _u.Save(ctx) + if err != nil { + panic(err) + } + return node +} + +// Exec executes the query on the entity. +func (_u *LienObjetEmplacementUpdateOne) Exec(ctx context.Context) error { + _, err := _u.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_u *LienObjetEmplacementUpdateOne) ExecX(ctx context.Context) { + if err := _u.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (_u *LienObjetEmplacementUpdateOne) defaults() { + if _, ok := _u.mutation.UpdatedAt(); !ok { + v := lienobjetemplacement.UpdateDefaultUpdatedAt() + _u.mutation.SetUpdatedAt(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_u *LienObjetEmplacementUpdateOne) check() error { + if v, ok := _u.mutation.GetType(); ok { + if err := lienobjetemplacement.TypeValidator(v); err != nil { + return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "LienObjetEmplacement.type": %w`, err)} + } + } + if _u.mutation.ObjetCleared() && len(_u.mutation.ObjetIDs()) > 0 { + return errors.New(`ent: clearing a required unique edge "LienObjetEmplacement.objet"`) + } + if _u.mutation.EmplacementCleared() && len(_u.mutation.EmplacementIDs()) > 0 { + return errors.New(`ent: clearing a required unique edge "LienObjetEmplacement.emplacement"`) + } + return nil +} + +func (_u *LienObjetEmplacementUpdateOne) sqlSave(ctx context.Context) (_node *LienObjetEmplacement, err error) { + if err := _u.check(); err != nil { + return _node, err + } + _spec := sqlgraph.NewUpdateSpec(lienobjetemplacement.Table, lienobjetemplacement.Columns, sqlgraph.NewFieldSpec(lienobjetemplacement.FieldID, field.TypeUUID)) + id, ok := _u.mutation.ID() + if !ok { + return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "LienObjetEmplacement.id" for update`)} + } + _spec.Node.ID.Value = id + if fields := _u.fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, lienobjetemplacement.FieldID) + for _, f := range fields { + if !lienobjetemplacement.ValidColumn(f) { + return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + if f != lienobjetemplacement.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, f) + } + } + } + if ps := _u.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := _u.mutation.GetType(); ok { + _spec.SetField(lienobjetemplacement.FieldType, field.TypeEnum, value) + } + if value, ok := _u.mutation.CreatedAt(); ok { + _spec.SetField(lienobjetemplacement.FieldCreatedAt, field.TypeTime, value) + } + if value, ok := _u.mutation.UpdatedAt(); ok { + _spec.SetField(lienobjetemplacement.FieldUpdatedAt, field.TypeTime, value) + } + if _u.mutation.ObjetCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: lienobjetemplacement.ObjetTable, + Columns: []string{lienobjetemplacement.ObjetColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(objet.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.ObjetIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: lienobjetemplacement.ObjetTable, + Columns: []string{lienobjetemplacement.ObjetColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(objet.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if _u.mutation.EmplacementCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: lienobjetemplacement.EmplacementTable, + Columns: []string{lienobjetemplacement.EmplacementColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(emplacement.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.EmplacementIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: lienobjetemplacement.EmplacementTable, + Columns: []string{lienobjetemplacement.EmplacementColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(emplacement.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + _node = &LienObjetEmplacement{config: _u.config} + _spec.Assign = _node.assignValues + _spec.ScanValues = _node.scanValues + if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{lienobjetemplacement.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + _u.mutation.done = true + return _node, nil +} diff --git a/backend/internal/data/ent/migrate/migrate.go b/backend/internal/data/ent/migrate/migrate.go new file mode 100644 index 0000000..1956a6b --- /dev/null +++ b/backend/internal/data/ent/migrate/migrate.go @@ -0,0 +1,64 @@ +// Code generated by ent, DO NOT EDIT. + +package migrate + +import ( + "context" + "fmt" + "io" + + "entgo.io/ent/dialect" + "entgo.io/ent/dialect/sql/schema" +) + +var ( + // WithGlobalUniqueID sets the universal ids options to the migration. + // If this option is enabled, ent migration will allocate a 1<<32 range + // for the ids of each entity (table). + // Note that this option cannot be applied on tables that already exist. + WithGlobalUniqueID = schema.WithGlobalUniqueID + // WithDropColumn sets the drop column option to the migration. + // If this option is enabled, ent migration will drop old columns + // that were used for both fields and edges. This defaults to false. + WithDropColumn = schema.WithDropColumn + // WithDropIndex sets the drop index option to the migration. + // If this option is enabled, ent migration will drop old indexes + // that were defined in the schema. This defaults to false. + // Note that unique constraints are defined using `UNIQUE INDEX`, + // and therefore, it's recommended to enable this option to get more + // flexibility in the schema changes. + WithDropIndex = schema.WithDropIndex + // WithForeignKeys enables creating foreign-key in schema DDL. This defaults to true. + WithForeignKeys = schema.WithForeignKeys +) + +// Schema is the API for creating, migrating and dropping a schema. +type Schema struct { + drv dialect.Driver +} + +// NewSchema creates a new schema client. +func NewSchema(drv dialect.Driver) *Schema { return &Schema{drv: drv} } + +// Create creates all schema resources. +func (s *Schema) Create(ctx context.Context, opts ...schema.MigrateOption) error { + return Create(ctx, s, Tables, opts...) +} + +// Create creates all table resources using the given schema driver. +func Create(ctx context.Context, s *Schema, tables []*schema.Table, opts ...schema.MigrateOption) error { + migrate, err := schema.NewMigrate(s.drv, opts...) + if err != nil { + return fmt.Errorf("ent/migrate: %w", err) + } + return migrate.Create(ctx, tables...) +} + +// WriteTo writes the schema changes to w instead of running them against the database. +// +// if err := client.Schema.WriteTo(context.Background(), os.Stdout); err != nil { +// log.Fatal(err) +// } +func (s *Schema) WriteTo(ctx context.Context, w io.Writer, opts ...schema.MigrateOption) error { + return Create(ctx, &Schema{drv: &schema.WriteDriver{Writer: w, Driver: s.drv}}, Tables, opts...) +} diff --git a/backend/internal/data/ent/migrate/schema.go b/backend/internal/data/ent/migrate/schema.go new file mode 100644 index 0000000..7b5adf7 --- /dev/null +++ b/backend/internal/data/ent/migrate/schema.go @@ -0,0 +1,202 @@ +// Code generated by ent, DO NOT EDIT. + +package migrate + +import ( + "entgo.io/ent/dialect/entsql" + "entgo.io/ent/dialect/sql/schema" + "entgo.io/ent/schema/field" +) + +var ( + // CategorieColumns holds the columns for the "categorie" table. + CategorieColumns = []*schema.Column{ + {Name: "id", Type: field.TypeUUID}, + {Name: "nom", Type: field.TypeString}, + {Name: "slug", Type: field.TypeString, Nullable: true}, + {Name: "icone", Type: field.TypeString, Nullable: true}, + {Name: "created_at", Type: field.TypeTime}, + {Name: "updated_at", Type: field.TypeTime}, + {Name: "parent_id", Type: field.TypeUUID, Nullable: true}, + } + // CategorieTable holds the schema information for the "categorie" table. + CategorieTable = &schema.Table{ + Name: "categorie", + Columns: CategorieColumns, + PrimaryKey: []*schema.Column{CategorieColumns[0]}, + ForeignKeys: []*schema.ForeignKey{ + { + Symbol: "categorie_categorie_enfants", + Columns: []*schema.Column{CategorieColumns[6]}, + RefColumns: []*schema.Column{CategorieColumns[0]}, + OnDelete: schema.SetNull, + }, + }, + } + // ChampPersonnaliseColumns holds the columns for the "champ_personnalise" table. + ChampPersonnaliseColumns = []*schema.Column{ + {Name: "id", Type: field.TypeUUID}, + {Name: "nom_champ", Type: field.TypeString}, + {Name: "type_champ", Type: field.TypeEnum, Enums: []string{"string", "int", "bool", "date"}, Default: "string"}, + {Name: "valeur", Type: field.TypeString, Nullable: true}, + {Name: "unite", Type: field.TypeString, Nullable: true}, + {Name: "created_at", Type: field.TypeTime}, + {Name: "updated_at", Type: field.TypeTime}, + {Name: "objet_id", Type: field.TypeUUID}, + } + // ChampPersonnaliseTable holds the schema information for the "champ_personnalise" table. + ChampPersonnaliseTable = &schema.Table{ + Name: "champ_personnalise", + Columns: ChampPersonnaliseColumns, + PrimaryKey: []*schema.Column{ChampPersonnaliseColumns[0]}, + ForeignKeys: []*schema.ForeignKey{ + { + Symbol: "champ_personnalise_objet_champs_personnalises", + Columns: []*schema.Column{ChampPersonnaliseColumns[7]}, + RefColumns: []*schema.Column{ObjetColumns[0]}, + OnDelete: schema.NoAction, + }, + }, + } + // EmplacementColumns holds the columns for the "emplacement" table. + EmplacementColumns = []*schema.Column{ + {Name: "id", Type: field.TypeUUID}, + {Name: "nom", Type: field.TypeString}, + {Name: "slug", Type: field.TypeString, Nullable: true}, + {Name: "piece", Type: field.TypeString, Nullable: true}, + {Name: "meuble", Type: field.TypeString, Nullable: true}, + {Name: "numero_boite", Type: field.TypeString, Nullable: true}, + {Name: "icone", Type: field.TypeString, Nullable: true}, + {Name: "created_at", Type: field.TypeTime}, + {Name: "updated_at", Type: field.TypeTime}, + {Name: "parent_id", Type: field.TypeUUID, Nullable: true}, + } + // EmplacementTable holds the schema information for the "emplacement" table. + EmplacementTable = &schema.Table{ + Name: "emplacement", + Columns: EmplacementColumns, + PrimaryKey: []*schema.Column{EmplacementColumns[0]}, + ForeignKeys: []*schema.ForeignKey{ + { + Symbol: "emplacement_emplacement_enfants", + Columns: []*schema.Column{EmplacementColumns[9]}, + RefColumns: []*schema.Column{EmplacementColumns[0]}, + OnDelete: schema.SetNull, + }, + }, + } + // LienObjetEmplacementColumns holds the columns for the "lien_objet_emplacement" table. + LienObjetEmplacementColumns = []*schema.Column{ + {Name: "id", Type: field.TypeUUID}, + {Name: "type", Type: field.TypeEnum, Enums: []string{"stocke", "utilise_dans"}, Default: "stocke"}, + {Name: "created_at", Type: field.TypeTime}, + {Name: "updated_at", Type: field.TypeTime}, + {Name: "emplacement_id", Type: field.TypeUUID}, + {Name: "objet_id", Type: field.TypeUUID}, + } + // LienObjetEmplacementTable holds the schema information for the "lien_objet_emplacement" table. + LienObjetEmplacementTable = &schema.Table{ + Name: "lien_objet_emplacement", + Columns: LienObjetEmplacementColumns, + PrimaryKey: []*schema.Column{LienObjetEmplacementColumns[0]}, + ForeignKeys: []*schema.ForeignKey{ + { + Symbol: "lien_objet_emplacement_emplacement_liens_objets", + Columns: []*schema.Column{LienObjetEmplacementColumns[4]}, + RefColumns: []*schema.Column{EmplacementColumns[0]}, + OnDelete: schema.NoAction, + }, + { + Symbol: "lien_objet_emplacement_objet_liens_emplacements", + Columns: []*schema.Column{LienObjetEmplacementColumns[5]}, + RefColumns: []*schema.Column{ObjetColumns[0]}, + OnDelete: schema.NoAction, + }, + }, + } + // ObjetColumns holds the columns for the "objet" table. + ObjetColumns = []*schema.Column{ + {Name: "id", Type: field.TypeUUID}, + {Name: "nom", Type: field.TypeString}, + {Name: "description", Type: field.TypeString, Nullable: true}, + {Name: "quantite", Type: field.TypeInt, Default: 0}, + {Name: "prix_achat", Type: field.TypeFloat64, Nullable: true}, + {Name: "date_achat", Type: field.TypeTime, Nullable: true}, + {Name: "boutique", Type: field.TypeString, Nullable: true}, + {Name: "numero_serie", Type: field.TypeString, Nullable: true}, + {Name: "numero_modele", Type: field.TypeString, Nullable: true}, + {Name: "fabricant", Type: field.TypeString, Nullable: true}, + {Name: "statut", Type: field.TypeEnum, Enums: []string{"en_stock", "pret", "hors_service", "archive"}, Default: "en_stock"}, + {Name: "caracteristiques", Type: field.TypeJSON, Nullable: true}, + {Name: "created_at", Type: field.TypeTime}, + {Name: "updated_at", Type: field.TypeTime}, + } + // ObjetTable holds the schema information for the "objet" table. + ObjetTable = &schema.Table{ + Name: "objet", + Columns: ObjetColumns, + PrimaryKey: []*schema.Column{ObjetColumns[0]}, + } + // PieceJointeColumns holds the columns for the "piece_jointe" table. + PieceJointeColumns = []*schema.Column{ + {Name: "id", Type: field.TypeUUID}, + {Name: "nom_fichier", Type: field.TypeString}, + {Name: "chemin", Type: field.TypeString}, + {Name: "type_mime", Type: field.TypeString}, + {Name: "est_principale", Type: field.TypeBool, Default: false}, + {Name: "categorie", Type: field.TypeEnum, Enums: []string{"image", "pdf_notice", "markdown_tuto"}, Default: "image"}, + {Name: "created_at", Type: field.TypeTime}, + {Name: "updated_at", Type: field.TypeTime}, + {Name: "objet_id", Type: field.TypeUUID}, + } + // PieceJointeTable holds the schema information for the "piece_jointe" table. + PieceJointeTable = &schema.Table{ + Name: "piece_jointe", + Columns: PieceJointeColumns, + PrimaryKey: []*schema.Column{PieceJointeColumns[0]}, + ForeignKeys: []*schema.ForeignKey{ + { + Symbol: "piece_jointe_objet_pieces_jointes", + Columns: []*schema.Column{PieceJointeColumns[8]}, + RefColumns: []*schema.Column{ObjetColumns[0]}, + OnDelete: schema.NoAction, + }, + }, + } + // Tables holds all the tables in the schema. + Tables = []*schema.Table{ + CategorieTable, + ChampPersonnaliseTable, + EmplacementTable, + LienObjetEmplacementTable, + ObjetTable, + PieceJointeTable, + } +) + +func init() { + CategorieTable.ForeignKeys[0].RefTable = CategorieTable + CategorieTable.Annotation = &entsql.Annotation{ + Table: "categorie", + } + ChampPersonnaliseTable.ForeignKeys[0].RefTable = ObjetTable + ChampPersonnaliseTable.Annotation = &entsql.Annotation{ + Table: "champ_personnalise", + } + EmplacementTable.ForeignKeys[0].RefTable = EmplacementTable + EmplacementTable.Annotation = &entsql.Annotation{ + Table: "emplacement", + } + LienObjetEmplacementTable.ForeignKeys[0].RefTable = EmplacementTable + LienObjetEmplacementTable.ForeignKeys[1].RefTable = ObjetTable + LienObjetEmplacementTable.Annotation = &entsql.Annotation{ + Table: "lien_objet_emplacement", + } + ObjetTable.Annotation = &entsql.Annotation{ + Table: "objet", + } + PieceJointeTable.ForeignKeys[0].RefTable = ObjetTable + PieceJointeTable.Annotation = &entsql.Annotation{ + Table: "piece_jointe", + } +} diff --git a/backend/internal/data/ent/mutation.go b/backend/internal/data/ent/mutation.go new file mode 100644 index 0000000..ddbbd84 --- /dev/null +++ b/backend/internal/data/ent/mutation.go @@ -0,0 +1,5570 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + "sync" + "time" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/categorie" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/champpersonnalise" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/emplacement" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/lienobjetemplacement" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/objet" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/piecejointe" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/predicate" + "github.com/google/uuid" +) + +const ( + // Operation types. + OpCreate = ent.OpCreate + OpDelete = ent.OpDelete + OpDeleteOne = ent.OpDeleteOne + OpUpdate = ent.OpUpdate + OpUpdateOne = ent.OpUpdateOne + + // Node types. + TypeCategorie = "Categorie" + TypeChampPersonnalise = "ChampPersonnalise" + TypeEmplacement = "Emplacement" + TypeLienObjetEmplacement = "LienObjetEmplacement" + TypeObjet = "Objet" + TypePieceJointe = "PieceJointe" +) + +// CategorieMutation represents an operation that mutates the Categorie nodes in the graph. +type CategorieMutation struct { + config + op Op + typ string + id *uuid.UUID + nom *string + slug *string + icone *string + created_at *time.Time + updated_at *time.Time + clearedFields map[string]struct{} + parent *uuid.UUID + clearedparent bool + enfants map[uuid.UUID]struct{} + removedenfants map[uuid.UUID]struct{} + clearedenfants bool + done bool + oldValue func(context.Context) (*Categorie, error) + predicates []predicate.Categorie +} + +var _ ent.Mutation = (*CategorieMutation)(nil) + +// categorieOption allows management of the mutation configuration using functional options. +type categorieOption func(*CategorieMutation) + +// newCategorieMutation creates new mutation for the Categorie entity. +func newCategorieMutation(c config, op Op, opts ...categorieOption) *CategorieMutation { + m := &CategorieMutation{ + config: c, + op: op, + typ: TypeCategorie, + clearedFields: make(map[string]struct{}), + } + for _, opt := range opts { + opt(m) + } + return m +} + +// withCategorieID sets the ID field of the mutation. +func withCategorieID(id uuid.UUID) categorieOption { + return func(m *CategorieMutation) { + var ( + err error + once sync.Once + value *Categorie + ) + m.oldValue = func(ctx context.Context) (*Categorie, error) { + once.Do(func() { + if m.done { + err = errors.New("querying old values post mutation is not allowed") + } else { + value, err = m.Client().Categorie.Get(ctx, id) + } + }) + return value, err + } + m.id = &id + } +} + +// withCategorie sets the old Categorie of the mutation. +func withCategorie(node *Categorie) categorieOption { + return func(m *CategorieMutation) { + m.oldValue = func(context.Context) (*Categorie, error) { + return node, nil + } + m.id = &node.ID + } +} + +// Client returns a new `ent.Client` from the mutation. If the mutation was +// executed in a transaction (ent.Tx), a transactional client is returned. +func (m CategorieMutation) Client() *Client { + client := &Client{config: m.config} + client.init() + return client +} + +// Tx returns an `ent.Tx` for mutations that were executed in transactions; +// it returns an error otherwise. +func (m CategorieMutation) Tx() (*Tx, error) { + if _, ok := m.driver.(*txDriver); !ok { + return nil, errors.New("ent: mutation is not running in a transaction") + } + tx := &Tx{config: m.config} + tx.init() + return tx, nil +} + +// SetID sets the value of the id field. Note that this +// operation is only accepted on creation of Categorie entities. +func (m *CategorieMutation) SetID(id uuid.UUID) { + m.id = &id +} + +// ID returns the ID value in the mutation. Note that the ID is only available +// if it was provided to the builder or after it was returned from the database. +func (m *CategorieMutation) ID() (id uuid.UUID, exists bool) { + if m.id == nil { + return + } + return *m.id, true +} + +// IDs queries the database and returns the entity ids that match the mutation's predicate. +// That means, if the mutation is applied within a transaction with an isolation level such +// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated +// or updated by the mutation. +func (m *CategorieMutation) IDs(ctx context.Context) ([]uuid.UUID, error) { + switch { + case m.op.Is(OpUpdateOne | OpDeleteOne): + id, exists := m.ID() + if exists { + return []uuid.UUID{id}, nil + } + fallthrough + case m.op.Is(OpUpdate | OpDelete): + return m.Client().Categorie.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) + } +} + +// SetNom sets the "nom" field. +func (m *CategorieMutation) SetNom(s string) { + m.nom = &s +} + +// Nom returns the value of the "nom" field in the mutation. +func (m *CategorieMutation) Nom() (r string, exists bool) { + v := m.nom + if v == nil { + return + } + return *v, true +} + +// OldNom returns the old "nom" field's value of the Categorie entity. +// If the Categorie object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *CategorieMutation) OldNom(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldNom is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldNom requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldNom: %w", err) + } + return oldValue.Nom, nil +} + +// ResetNom resets all changes to the "nom" field. +func (m *CategorieMutation) ResetNom() { + m.nom = nil +} + +// SetParentID sets the "parent_id" field. +func (m *CategorieMutation) SetParentID(u uuid.UUID) { + m.parent = &u +} + +// ParentID returns the value of the "parent_id" field in the mutation. +func (m *CategorieMutation) ParentID() (r uuid.UUID, exists bool) { + v := m.parent + if v == nil { + return + } + return *v, true +} + +// OldParentID returns the old "parent_id" field's value of the Categorie entity. +// If the Categorie object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *CategorieMutation) OldParentID(ctx context.Context) (v *uuid.UUID, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldParentID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldParentID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldParentID: %w", err) + } + return oldValue.ParentID, nil +} + +// ClearParentID clears the value of the "parent_id" field. +func (m *CategorieMutation) ClearParentID() { + m.parent = nil + m.clearedFields[categorie.FieldParentID] = struct{}{} +} + +// ParentIDCleared returns if the "parent_id" field was cleared in this mutation. +func (m *CategorieMutation) ParentIDCleared() bool { + _, ok := m.clearedFields[categorie.FieldParentID] + return ok +} + +// ResetParentID resets all changes to the "parent_id" field. +func (m *CategorieMutation) ResetParentID() { + m.parent = nil + delete(m.clearedFields, categorie.FieldParentID) +} + +// SetSlug sets the "slug" field. +func (m *CategorieMutation) SetSlug(s string) { + m.slug = &s +} + +// Slug returns the value of the "slug" field in the mutation. +func (m *CategorieMutation) Slug() (r string, exists bool) { + v := m.slug + if v == nil { + return + } + return *v, true +} + +// OldSlug returns the old "slug" field's value of the Categorie entity. +// If the Categorie object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *CategorieMutation) OldSlug(ctx context.Context) (v *string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldSlug is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldSlug requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldSlug: %w", err) + } + return oldValue.Slug, nil +} + +// ClearSlug clears the value of the "slug" field. +func (m *CategorieMutation) ClearSlug() { + m.slug = nil + m.clearedFields[categorie.FieldSlug] = struct{}{} +} + +// SlugCleared returns if the "slug" field was cleared in this mutation. +func (m *CategorieMutation) SlugCleared() bool { + _, ok := m.clearedFields[categorie.FieldSlug] + return ok +} + +// ResetSlug resets all changes to the "slug" field. +func (m *CategorieMutation) ResetSlug() { + m.slug = nil + delete(m.clearedFields, categorie.FieldSlug) +} + +// SetIcone sets the "icone" field. +func (m *CategorieMutation) SetIcone(s string) { + m.icone = &s +} + +// Icone returns the value of the "icone" field in the mutation. +func (m *CategorieMutation) Icone() (r string, exists bool) { + v := m.icone + if v == nil { + return + } + return *v, true +} + +// OldIcone returns the old "icone" field's value of the Categorie entity. +// If the Categorie object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *CategorieMutation) OldIcone(ctx context.Context) (v *string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldIcone is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldIcone requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldIcone: %w", err) + } + return oldValue.Icone, nil +} + +// ClearIcone clears the value of the "icone" field. +func (m *CategorieMutation) ClearIcone() { + m.icone = nil + m.clearedFields[categorie.FieldIcone] = struct{}{} +} + +// IconeCleared returns if the "icone" field was cleared in this mutation. +func (m *CategorieMutation) IconeCleared() bool { + _, ok := m.clearedFields[categorie.FieldIcone] + return ok +} + +// ResetIcone resets all changes to the "icone" field. +func (m *CategorieMutation) ResetIcone() { + m.icone = nil + delete(m.clearedFields, categorie.FieldIcone) +} + +// SetCreatedAt sets the "created_at" field. +func (m *CategorieMutation) SetCreatedAt(t time.Time) { + m.created_at = &t +} + +// CreatedAt returns the value of the "created_at" field in the mutation. +func (m *CategorieMutation) CreatedAt() (r time.Time, exists bool) { + v := m.created_at + if v == nil { + return + } + return *v, true +} + +// OldCreatedAt returns the old "created_at" field's value of the Categorie entity. +// If the Categorie object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *CategorieMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldCreatedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) + } + return oldValue.CreatedAt, nil +} + +// ResetCreatedAt resets all changes to the "created_at" field. +func (m *CategorieMutation) ResetCreatedAt() { + m.created_at = nil +} + +// SetUpdatedAt sets the "updated_at" field. +func (m *CategorieMutation) SetUpdatedAt(t time.Time) { + m.updated_at = &t +} + +// UpdatedAt returns the value of the "updated_at" field in the mutation. +func (m *CategorieMutation) UpdatedAt() (r time.Time, exists bool) { + v := m.updated_at + if v == nil { + return + } + return *v, true +} + +// OldUpdatedAt returns the old "updated_at" field's value of the Categorie entity. +// If the Categorie object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *CategorieMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldUpdatedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) + } + return oldValue.UpdatedAt, nil +} + +// ResetUpdatedAt resets all changes to the "updated_at" field. +func (m *CategorieMutation) ResetUpdatedAt() { + m.updated_at = nil +} + +// ClearParent clears the "parent" edge to the Categorie entity. +func (m *CategorieMutation) ClearParent() { + m.clearedparent = true + m.clearedFields[categorie.FieldParentID] = struct{}{} +} + +// ParentCleared reports if the "parent" edge to the Categorie entity was cleared. +func (m *CategorieMutation) ParentCleared() bool { + return m.ParentIDCleared() || m.clearedparent +} + +// ParentIDs returns the "parent" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// ParentID instead. It exists only for internal usage by the builders. +func (m *CategorieMutation) ParentIDs() (ids []uuid.UUID) { + if id := m.parent; id != nil { + ids = append(ids, *id) + } + return +} + +// ResetParent resets all changes to the "parent" edge. +func (m *CategorieMutation) ResetParent() { + m.parent = nil + m.clearedparent = false +} + +// AddEnfantIDs adds the "enfants" edge to the Categorie entity by ids. +func (m *CategorieMutation) AddEnfantIDs(ids ...uuid.UUID) { + if m.enfants == nil { + m.enfants = make(map[uuid.UUID]struct{}) + } + for i := range ids { + m.enfants[ids[i]] = struct{}{} + } +} + +// ClearEnfants clears the "enfants" edge to the Categorie entity. +func (m *CategorieMutation) ClearEnfants() { + m.clearedenfants = true +} + +// EnfantsCleared reports if the "enfants" edge to the Categorie entity was cleared. +func (m *CategorieMutation) EnfantsCleared() bool { + return m.clearedenfants +} + +// RemoveEnfantIDs removes the "enfants" edge to the Categorie entity by IDs. +func (m *CategorieMutation) RemoveEnfantIDs(ids ...uuid.UUID) { + if m.removedenfants == nil { + m.removedenfants = make(map[uuid.UUID]struct{}) + } + for i := range ids { + delete(m.enfants, ids[i]) + m.removedenfants[ids[i]] = struct{}{} + } +} + +// RemovedEnfants returns the removed IDs of the "enfants" edge to the Categorie entity. +func (m *CategorieMutation) RemovedEnfantsIDs() (ids []uuid.UUID) { + for id := range m.removedenfants { + ids = append(ids, id) + } + return +} + +// EnfantsIDs returns the "enfants" edge IDs in the mutation. +func (m *CategorieMutation) EnfantsIDs() (ids []uuid.UUID) { + for id := range m.enfants { + ids = append(ids, id) + } + return +} + +// ResetEnfants resets all changes to the "enfants" edge. +func (m *CategorieMutation) ResetEnfants() { + m.enfants = nil + m.clearedenfants = false + m.removedenfants = nil +} + +// Where appends a list predicates to the CategorieMutation builder. +func (m *CategorieMutation) Where(ps ...predicate.Categorie) { + m.predicates = append(m.predicates, ps...) +} + +// WhereP appends storage-level predicates to the CategorieMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *CategorieMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.Categorie, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + +// Op returns the operation name. +func (m *CategorieMutation) Op() Op { + return m.op +} + +// SetOp allows setting the mutation operation. +func (m *CategorieMutation) SetOp(op Op) { + m.op = op +} + +// Type returns the node type of this mutation (Categorie). +func (m *CategorieMutation) Type() string { + return m.typ +} + +// Fields returns all fields that were changed during this mutation. Note that in +// order to get all numeric fields that were incremented/decremented, call +// AddedFields(). +func (m *CategorieMutation) Fields() []string { + fields := make([]string, 0, 6) + if m.nom != nil { + fields = append(fields, categorie.FieldNom) + } + if m.parent != nil { + fields = append(fields, categorie.FieldParentID) + } + if m.slug != nil { + fields = append(fields, categorie.FieldSlug) + } + if m.icone != nil { + fields = append(fields, categorie.FieldIcone) + } + if m.created_at != nil { + fields = append(fields, categorie.FieldCreatedAt) + } + if m.updated_at != nil { + fields = append(fields, categorie.FieldUpdatedAt) + } + return fields +} + +// Field returns the value of a field with the given name. The second boolean +// return value indicates that this field was not set, or was not defined in the +// schema. +func (m *CategorieMutation) Field(name string) (ent.Value, bool) { + switch name { + case categorie.FieldNom: + return m.Nom() + case categorie.FieldParentID: + return m.ParentID() + case categorie.FieldSlug: + return m.Slug() + case categorie.FieldIcone: + return m.Icone() + case categorie.FieldCreatedAt: + return m.CreatedAt() + case categorie.FieldUpdatedAt: + return m.UpdatedAt() + } + return nil, false +} + +// OldField returns the old value of the field from the database. An error is +// returned if the mutation operation is not UpdateOne, or the query to the +// database failed. +func (m *CategorieMutation) OldField(ctx context.Context, name string) (ent.Value, error) { + switch name { + case categorie.FieldNom: + return m.OldNom(ctx) + case categorie.FieldParentID: + return m.OldParentID(ctx) + case categorie.FieldSlug: + return m.OldSlug(ctx) + case categorie.FieldIcone: + return m.OldIcone(ctx) + case categorie.FieldCreatedAt: + return m.OldCreatedAt(ctx) + case categorie.FieldUpdatedAt: + return m.OldUpdatedAt(ctx) + } + return nil, fmt.Errorf("unknown Categorie field %s", name) +} + +// SetField sets the value of a field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *CategorieMutation) SetField(name string, value ent.Value) error { + switch name { + case categorie.FieldNom: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetNom(v) + return nil + case categorie.FieldParentID: + v, ok := value.(uuid.UUID) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetParentID(v) + return nil + case categorie.FieldSlug: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetSlug(v) + return nil + case categorie.FieldIcone: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetIcone(v) + return nil + case categorie.FieldCreatedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetCreatedAt(v) + return nil + case categorie.FieldUpdatedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetUpdatedAt(v) + return nil + } + return fmt.Errorf("unknown Categorie field %s", name) +} + +// AddedFields returns all numeric fields that were incremented/decremented during +// this mutation. +func (m *CategorieMutation) AddedFields() []string { + return nil +} + +// AddedField returns the numeric value that was incremented/decremented on a field +// with the given name. The second boolean return value indicates that this field +// was not set, or was not defined in the schema. +func (m *CategorieMutation) AddedField(name string) (ent.Value, bool) { + return nil, false +} + +// AddField adds the value to the field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *CategorieMutation) AddField(name string, value ent.Value) error { + switch name { + } + return fmt.Errorf("unknown Categorie numeric field %s", name) +} + +// ClearedFields returns all nullable fields that were cleared during this +// mutation. +func (m *CategorieMutation) ClearedFields() []string { + var fields []string + if m.FieldCleared(categorie.FieldParentID) { + fields = append(fields, categorie.FieldParentID) + } + if m.FieldCleared(categorie.FieldSlug) { + fields = append(fields, categorie.FieldSlug) + } + if m.FieldCleared(categorie.FieldIcone) { + fields = append(fields, categorie.FieldIcone) + } + return fields +} + +// FieldCleared returns a boolean indicating if a field with the given name was +// cleared in this mutation. +func (m *CategorieMutation) FieldCleared(name string) bool { + _, ok := m.clearedFields[name] + return ok +} + +// ClearField clears the value of the field with the given name. It returns an +// error if the field is not defined in the schema. +func (m *CategorieMutation) ClearField(name string) error { + switch name { + case categorie.FieldParentID: + m.ClearParentID() + return nil + case categorie.FieldSlug: + m.ClearSlug() + return nil + case categorie.FieldIcone: + m.ClearIcone() + return nil + } + return fmt.Errorf("unknown Categorie nullable field %s", name) +} + +// ResetField resets all changes in the mutation for the field with the given name. +// It returns an error if the field is not defined in the schema. +func (m *CategorieMutation) ResetField(name string) error { + switch name { + case categorie.FieldNom: + m.ResetNom() + return nil + case categorie.FieldParentID: + m.ResetParentID() + return nil + case categorie.FieldSlug: + m.ResetSlug() + return nil + case categorie.FieldIcone: + m.ResetIcone() + return nil + case categorie.FieldCreatedAt: + m.ResetCreatedAt() + return nil + case categorie.FieldUpdatedAt: + m.ResetUpdatedAt() + return nil + } + return fmt.Errorf("unknown Categorie field %s", name) +} + +// AddedEdges returns all edge names that were set/added in this mutation. +func (m *CategorieMutation) AddedEdges() []string { + edges := make([]string, 0, 2) + if m.parent != nil { + edges = append(edges, categorie.EdgeParent) + } + if m.enfants != nil { + edges = append(edges, categorie.EdgeEnfants) + } + return edges +} + +// AddedIDs returns all IDs (to other nodes) that were added for the given edge +// name in this mutation. +func (m *CategorieMutation) AddedIDs(name string) []ent.Value { + switch name { + case categorie.EdgeParent: + if id := m.parent; id != nil { + return []ent.Value{*id} + } + case categorie.EdgeEnfants: + ids := make([]ent.Value, 0, len(m.enfants)) + for id := range m.enfants { + ids = append(ids, id) + } + return ids + } + return nil +} + +// RemovedEdges returns all edge names that were removed in this mutation. +func (m *CategorieMutation) RemovedEdges() []string { + edges := make([]string, 0, 2) + if m.removedenfants != nil { + edges = append(edges, categorie.EdgeEnfants) + } + return edges +} + +// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with +// the given name in this mutation. +func (m *CategorieMutation) RemovedIDs(name string) []ent.Value { + switch name { + case categorie.EdgeEnfants: + ids := make([]ent.Value, 0, len(m.removedenfants)) + for id := range m.removedenfants { + ids = append(ids, id) + } + return ids + } + return nil +} + +// ClearedEdges returns all edge names that were cleared in this mutation. +func (m *CategorieMutation) ClearedEdges() []string { + edges := make([]string, 0, 2) + if m.clearedparent { + edges = append(edges, categorie.EdgeParent) + } + if m.clearedenfants { + edges = append(edges, categorie.EdgeEnfants) + } + return edges +} + +// EdgeCleared returns a boolean which indicates if the edge with the given name +// was cleared in this mutation. +func (m *CategorieMutation) EdgeCleared(name string) bool { + switch name { + case categorie.EdgeParent: + return m.clearedparent + case categorie.EdgeEnfants: + return m.clearedenfants + } + return false +} + +// ClearEdge clears the value of the edge with the given name. It returns an error +// if that edge is not defined in the schema. +func (m *CategorieMutation) ClearEdge(name string) error { + switch name { + case categorie.EdgeParent: + m.ClearParent() + return nil + } + return fmt.Errorf("unknown Categorie unique edge %s", name) +} + +// ResetEdge resets all changes to the edge with the given name in this mutation. +// It returns an error if the edge is not defined in the schema. +func (m *CategorieMutation) ResetEdge(name string) error { + switch name { + case categorie.EdgeParent: + m.ResetParent() + return nil + case categorie.EdgeEnfants: + m.ResetEnfants() + return nil + } + return fmt.Errorf("unknown Categorie edge %s", name) +} + +// ChampPersonnaliseMutation represents an operation that mutates the ChampPersonnalise nodes in the graph. +type ChampPersonnaliseMutation struct { + config + op Op + typ string + id *uuid.UUID + nom_champ *string + type_champ *champpersonnalise.TypeChamp + valeur *string + unite *string + created_at *time.Time + updated_at *time.Time + clearedFields map[string]struct{} + objet *uuid.UUID + clearedobjet bool + done bool + oldValue func(context.Context) (*ChampPersonnalise, error) + predicates []predicate.ChampPersonnalise +} + +var _ ent.Mutation = (*ChampPersonnaliseMutation)(nil) + +// champpersonnaliseOption allows management of the mutation configuration using functional options. +type champpersonnaliseOption func(*ChampPersonnaliseMutation) + +// newChampPersonnaliseMutation creates new mutation for the ChampPersonnalise entity. +func newChampPersonnaliseMutation(c config, op Op, opts ...champpersonnaliseOption) *ChampPersonnaliseMutation { + m := &ChampPersonnaliseMutation{ + config: c, + op: op, + typ: TypeChampPersonnalise, + clearedFields: make(map[string]struct{}), + } + for _, opt := range opts { + opt(m) + } + return m +} + +// withChampPersonnaliseID sets the ID field of the mutation. +func withChampPersonnaliseID(id uuid.UUID) champpersonnaliseOption { + return func(m *ChampPersonnaliseMutation) { + var ( + err error + once sync.Once + value *ChampPersonnalise + ) + m.oldValue = func(ctx context.Context) (*ChampPersonnalise, error) { + once.Do(func() { + if m.done { + err = errors.New("querying old values post mutation is not allowed") + } else { + value, err = m.Client().ChampPersonnalise.Get(ctx, id) + } + }) + return value, err + } + m.id = &id + } +} + +// withChampPersonnalise sets the old ChampPersonnalise of the mutation. +func withChampPersonnalise(node *ChampPersonnalise) champpersonnaliseOption { + return func(m *ChampPersonnaliseMutation) { + m.oldValue = func(context.Context) (*ChampPersonnalise, error) { + return node, nil + } + m.id = &node.ID + } +} + +// Client returns a new `ent.Client` from the mutation. If the mutation was +// executed in a transaction (ent.Tx), a transactional client is returned. +func (m ChampPersonnaliseMutation) Client() *Client { + client := &Client{config: m.config} + client.init() + return client +} + +// Tx returns an `ent.Tx` for mutations that were executed in transactions; +// it returns an error otherwise. +func (m ChampPersonnaliseMutation) Tx() (*Tx, error) { + if _, ok := m.driver.(*txDriver); !ok { + return nil, errors.New("ent: mutation is not running in a transaction") + } + tx := &Tx{config: m.config} + tx.init() + return tx, nil +} + +// SetID sets the value of the id field. Note that this +// operation is only accepted on creation of ChampPersonnalise entities. +func (m *ChampPersonnaliseMutation) SetID(id uuid.UUID) { + m.id = &id +} + +// ID returns the ID value in the mutation. Note that the ID is only available +// if it was provided to the builder or after it was returned from the database. +func (m *ChampPersonnaliseMutation) ID() (id uuid.UUID, exists bool) { + if m.id == nil { + return + } + return *m.id, true +} + +// IDs queries the database and returns the entity ids that match the mutation's predicate. +// That means, if the mutation is applied within a transaction with an isolation level such +// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated +// or updated by the mutation. +func (m *ChampPersonnaliseMutation) IDs(ctx context.Context) ([]uuid.UUID, error) { + switch { + case m.op.Is(OpUpdateOne | OpDeleteOne): + id, exists := m.ID() + if exists { + return []uuid.UUID{id}, nil + } + fallthrough + case m.op.Is(OpUpdate | OpDelete): + return m.Client().ChampPersonnalise.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) + } +} + +// SetObjetID sets the "objet_id" field. +func (m *ChampPersonnaliseMutation) SetObjetID(u uuid.UUID) { + m.objet = &u +} + +// ObjetID returns the value of the "objet_id" field in the mutation. +func (m *ChampPersonnaliseMutation) ObjetID() (r uuid.UUID, exists bool) { + v := m.objet + if v == nil { + return + } + return *v, true +} + +// OldObjetID returns the old "objet_id" field's value of the ChampPersonnalise entity. +// If the ChampPersonnalise object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ChampPersonnaliseMutation) OldObjetID(ctx context.Context) (v uuid.UUID, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldObjetID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldObjetID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldObjetID: %w", err) + } + return oldValue.ObjetID, nil +} + +// ResetObjetID resets all changes to the "objet_id" field. +func (m *ChampPersonnaliseMutation) ResetObjetID() { + m.objet = nil +} + +// SetNomChamp sets the "nom_champ" field. +func (m *ChampPersonnaliseMutation) SetNomChamp(s string) { + m.nom_champ = &s +} + +// NomChamp returns the value of the "nom_champ" field in the mutation. +func (m *ChampPersonnaliseMutation) NomChamp() (r string, exists bool) { + v := m.nom_champ + if v == nil { + return + } + return *v, true +} + +// OldNomChamp returns the old "nom_champ" field's value of the ChampPersonnalise entity. +// If the ChampPersonnalise object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ChampPersonnaliseMutation) OldNomChamp(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldNomChamp is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldNomChamp requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldNomChamp: %w", err) + } + return oldValue.NomChamp, nil +} + +// ResetNomChamp resets all changes to the "nom_champ" field. +func (m *ChampPersonnaliseMutation) ResetNomChamp() { + m.nom_champ = nil +} + +// SetTypeChamp sets the "type_champ" field. +func (m *ChampPersonnaliseMutation) SetTypeChamp(cc champpersonnalise.TypeChamp) { + m.type_champ = &cc +} + +// TypeChamp returns the value of the "type_champ" field in the mutation. +func (m *ChampPersonnaliseMutation) TypeChamp() (r champpersonnalise.TypeChamp, exists bool) { + v := m.type_champ + if v == nil { + return + } + return *v, true +} + +// OldTypeChamp returns the old "type_champ" field's value of the ChampPersonnalise entity. +// If the ChampPersonnalise object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ChampPersonnaliseMutation) OldTypeChamp(ctx context.Context) (v champpersonnalise.TypeChamp, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldTypeChamp is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldTypeChamp requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldTypeChamp: %w", err) + } + return oldValue.TypeChamp, nil +} + +// ResetTypeChamp resets all changes to the "type_champ" field. +func (m *ChampPersonnaliseMutation) ResetTypeChamp() { + m.type_champ = nil +} + +// SetValeur sets the "valeur" field. +func (m *ChampPersonnaliseMutation) SetValeur(s string) { + m.valeur = &s +} + +// Valeur returns the value of the "valeur" field in the mutation. +func (m *ChampPersonnaliseMutation) Valeur() (r string, exists bool) { + v := m.valeur + if v == nil { + return + } + return *v, true +} + +// OldValeur returns the old "valeur" field's value of the ChampPersonnalise entity. +// If the ChampPersonnalise object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ChampPersonnaliseMutation) OldValeur(ctx context.Context) (v *string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldValeur is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldValeur requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldValeur: %w", err) + } + return oldValue.Valeur, nil +} + +// ClearValeur clears the value of the "valeur" field. +func (m *ChampPersonnaliseMutation) ClearValeur() { + m.valeur = nil + m.clearedFields[champpersonnalise.FieldValeur] = struct{}{} +} + +// ValeurCleared returns if the "valeur" field was cleared in this mutation. +func (m *ChampPersonnaliseMutation) ValeurCleared() bool { + _, ok := m.clearedFields[champpersonnalise.FieldValeur] + return ok +} + +// ResetValeur resets all changes to the "valeur" field. +func (m *ChampPersonnaliseMutation) ResetValeur() { + m.valeur = nil + delete(m.clearedFields, champpersonnalise.FieldValeur) +} + +// SetUnite sets the "unite" field. +func (m *ChampPersonnaliseMutation) SetUnite(s string) { + m.unite = &s +} + +// Unite returns the value of the "unite" field in the mutation. +func (m *ChampPersonnaliseMutation) Unite() (r string, exists bool) { + v := m.unite + if v == nil { + return + } + return *v, true +} + +// OldUnite returns the old "unite" field's value of the ChampPersonnalise entity. +// If the ChampPersonnalise object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ChampPersonnaliseMutation) OldUnite(ctx context.Context) (v *string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldUnite is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldUnite requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldUnite: %w", err) + } + return oldValue.Unite, nil +} + +// ClearUnite clears the value of the "unite" field. +func (m *ChampPersonnaliseMutation) ClearUnite() { + m.unite = nil + m.clearedFields[champpersonnalise.FieldUnite] = struct{}{} +} + +// UniteCleared returns if the "unite" field was cleared in this mutation. +func (m *ChampPersonnaliseMutation) UniteCleared() bool { + _, ok := m.clearedFields[champpersonnalise.FieldUnite] + return ok +} + +// ResetUnite resets all changes to the "unite" field. +func (m *ChampPersonnaliseMutation) ResetUnite() { + m.unite = nil + delete(m.clearedFields, champpersonnalise.FieldUnite) +} + +// SetCreatedAt sets the "created_at" field. +func (m *ChampPersonnaliseMutation) SetCreatedAt(t time.Time) { + m.created_at = &t +} + +// CreatedAt returns the value of the "created_at" field in the mutation. +func (m *ChampPersonnaliseMutation) CreatedAt() (r time.Time, exists bool) { + v := m.created_at + if v == nil { + return + } + return *v, true +} + +// OldCreatedAt returns the old "created_at" field's value of the ChampPersonnalise entity. +// If the ChampPersonnalise object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ChampPersonnaliseMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldCreatedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) + } + return oldValue.CreatedAt, nil +} + +// ResetCreatedAt resets all changes to the "created_at" field. +func (m *ChampPersonnaliseMutation) ResetCreatedAt() { + m.created_at = nil +} + +// SetUpdatedAt sets the "updated_at" field. +func (m *ChampPersonnaliseMutation) SetUpdatedAt(t time.Time) { + m.updated_at = &t +} + +// UpdatedAt returns the value of the "updated_at" field in the mutation. +func (m *ChampPersonnaliseMutation) UpdatedAt() (r time.Time, exists bool) { + v := m.updated_at + if v == nil { + return + } + return *v, true +} + +// OldUpdatedAt returns the old "updated_at" field's value of the ChampPersonnalise entity. +// If the ChampPersonnalise object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ChampPersonnaliseMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldUpdatedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) + } + return oldValue.UpdatedAt, nil +} + +// ResetUpdatedAt resets all changes to the "updated_at" field. +func (m *ChampPersonnaliseMutation) ResetUpdatedAt() { + m.updated_at = nil +} + +// ClearObjet clears the "objet" edge to the Objet entity. +func (m *ChampPersonnaliseMutation) ClearObjet() { + m.clearedobjet = true + m.clearedFields[champpersonnalise.FieldObjetID] = struct{}{} +} + +// ObjetCleared reports if the "objet" edge to the Objet entity was cleared. +func (m *ChampPersonnaliseMutation) ObjetCleared() bool { + return m.clearedobjet +} + +// ObjetIDs returns the "objet" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// ObjetID instead. It exists only for internal usage by the builders. +func (m *ChampPersonnaliseMutation) ObjetIDs() (ids []uuid.UUID) { + if id := m.objet; id != nil { + ids = append(ids, *id) + } + return +} + +// ResetObjet resets all changes to the "objet" edge. +func (m *ChampPersonnaliseMutation) ResetObjet() { + m.objet = nil + m.clearedobjet = false +} + +// Where appends a list predicates to the ChampPersonnaliseMutation builder. +func (m *ChampPersonnaliseMutation) Where(ps ...predicate.ChampPersonnalise) { + m.predicates = append(m.predicates, ps...) +} + +// WhereP appends storage-level predicates to the ChampPersonnaliseMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *ChampPersonnaliseMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.ChampPersonnalise, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + +// Op returns the operation name. +func (m *ChampPersonnaliseMutation) Op() Op { + return m.op +} + +// SetOp allows setting the mutation operation. +func (m *ChampPersonnaliseMutation) SetOp(op Op) { + m.op = op +} + +// Type returns the node type of this mutation (ChampPersonnalise). +func (m *ChampPersonnaliseMutation) Type() string { + return m.typ +} + +// Fields returns all fields that were changed during this mutation. Note that in +// order to get all numeric fields that were incremented/decremented, call +// AddedFields(). +func (m *ChampPersonnaliseMutation) Fields() []string { + fields := make([]string, 0, 7) + if m.objet != nil { + fields = append(fields, champpersonnalise.FieldObjetID) + } + if m.nom_champ != nil { + fields = append(fields, champpersonnalise.FieldNomChamp) + } + if m.type_champ != nil { + fields = append(fields, champpersonnalise.FieldTypeChamp) + } + if m.valeur != nil { + fields = append(fields, champpersonnalise.FieldValeur) + } + if m.unite != nil { + fields = append(fields, champpersonnalise.FieldUnite) + } + if m.created_at != nil { + fields = append(fields, champpersonnalise.FieldCreatedAt) + } + if m.updated_at != nil { + fields = append(fields, champpersonnalise.FieldUpdatedAt) + } + return fields +} + +// Field returns the value of a field with the given name. The second boolean +// return value indicates that this field was not set, or was not defined in the +// schema. +func (m *ChampPersonnaliseMutation) Field(name string) (ent.Value, bool) { + switch name { + case champpersonnalise.FieldObjetID: + return m.ObjetID() + case champpersonnalise.FieldNomChamp: + return m.NomChamp() + case champpersonnalise.FieldTypeChamp: + return m.TypeChamp() + case champpersonnalise.FieldValeur: + return m.Valeur() + case champpersonnalise.FieldUnite: + return m.Unite() + case champpersonnalise.FieldCreatedAt: + return m.CreatedAt() + case champpersonnalise.FieldUpdatedAt: + return m.UpdatedAt() + } + return nil, false +} + +// OldField returns the old value of the field from the database. An error is +// returned if the mutation operation is not UpdateOne, or the query to the +// database failed. +func (m *ChampPersonnaliseMutation) OldField(ctx context.Context, name string) (ent.Value, error) { + switch name { + case champpersonnalise.FieldObjetID: + return m.OldObjetID(ctx) + case champpersonnalise.FieldNomChamp: + return m.OldNomChamp(ctx) + case champpersonnalise.FieldTypeChamp: + return m.OldTypeChamp(ctx) + case champpersonnalise.FieldValeur: + return m.OldValeur(ctx) + case champpersonnalise.FieldUnite: + return m.OldUnite(ctx) + case champpersonnalise.FieldCreatedAt: + return m.OldCreatedAt(ctx) + case champpersonnalise.FieldUpdatedAt: + return m.OldUpdatedAt(ctx) + } + return nil, fmt.Errorf("unknown ChampPersonnalise field %s", name) +} + +// SetField sets the value of a field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *ChampPersonnaliseMutation) SetField(name string, value ent.Value) error { + switch name { + case champpersonnalise.FieldObjetID: + v, ok := value.(uuid.UUID) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetObjetID(v) + return nil + case champpersonnalise.FieldNomChamp: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetNomChamp(v) + return nil + case champpersonnalise.FieldTypeChamp: + v, ok := value.(champpersonnalise.TypeChamp) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetTypeChamp(v) + return nil + case champpersonnalise.FieldValeur: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetValeur(v) + return nil + case champpersonnalise.FieldUnite: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetUnite(v) + return nil + case champpersonnalise.FieldCreatedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetCreatedAt(v) + return nil + case champpersonnalise.FieldUpdatedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetUpdatedAt(v) + return nil + } + return fmt.Errorf("unknown ChampPersonnalise field %s", name) +} + +// AddedFields returns all numeric fields that were incremented/decremented during +// this mutation. +func (m *ChampPersonnaliseMutation) AddedFields() []string { + return nil +} + +// AddedField returns the numeric value that was incremented/decremented on a field +// with the given name. The second boolean return value indicates that this field +// was not set, or was not defined in the schema. +func (m *ChampPersonnaliseMutation) AddedField(name string) (ent.Value, bool) { + return nil, false +} + +// AddField adds the value to the field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *ChampPersonnaliseMutation) AddField(name string, value ent.Value) error { + switch name { + } + return fmt.Errorf("unknown ChampPersonnalise numeric field %s", name) +} + +// ClearedFields returns all nullable fields that were cleared during this +// mutation. +func (m *ChampPersonnaliseMutation) ClearedFields() []string { + var fields []string + if m.FieldCleared(champpersonnalise.FieldValeur) { + fields = append(fields, champpersonnalise.FieldValeur) + } + if m.FieldCleared(champpersonnalise.FieldUnite) { + fields = append(fields, champpersonnalise.FieldUnite) + } + return fields +} + +// FieldCleared returns a boolean indicating if a field with the given name was +// cleared in this mutation. +func (m *ChampPersonnaliseMutation) FieldCleared(name string) bool { + _, ok := m.clearedFields[name] + return ok +} + +// ClearField clears the value of the field with the given name. It returns an +// error if the field is not defined in the schema. +func (m *ChampPersonnaliseMutation) ClearField(name string) error { + switch name { + case champpersonnalise.FieldValeur: + m.ClearValeur() + return nil + case champpersonnalise.FieldUnite: + m.ClearUnite() + return nil + } + return fmt.Errorf("unknown ChampPersonnalise nullable field %s", name) +} + +// ResetField resets all changes in the mutation for the field with the given name. +// It returns an error if the field is not defined in the schema. +func (m *ChampPersonnaliseMutation) ResetField(name string) error { + switch name { + case champpersonnalise.FieldObjetID: + m.ResetObjetID() + return nil + case champpersonnalise.FieldNomChamp: + m.ResetNomChamp() + return nil + case champpersonnalise.FieldTypeChamp: + m.ResetTypeChamp() + return nil + case champpersonnalise.FieldValeur: + m.ResetValeur() + return nil + case champpersonnalise.FieldUnite: + m.ResetUnite() + return nil + case champpersonnalise.FieldCreatedAt: + m.ResetCreatedAt() + return nil + case champpersonnalise.FieldUpdatedAt: + m.ResetUpdatedAt() + return nil + } + return fmt.Errorf("unknown ChampPersonnalise field %s", name) +} + +// AddedEdges returns all edge names that were set/added in this mutation. +func (m *ChampPersonnaliseMutation) AddedEdges() []string { + edges := make([]string, 0, 1) + if m.objet != nil { + edges = append(edges, champpersonnalise.EdgeObjet) + } + return edges +} + +// AddedIDs returns all IDs (to other nodes) that were added for the given edge +// name in this mutation. +func (m *ChampPersonnaliseMutation) AddedIDs(name string) []ent.Value { + switch name { + case champpersonnalise.EdgeObjet: + if id := m.objet; id != nil { + return []ent.Value{*id} + } + } + return nil +} + +// RemovedEdges returns all edge names that were removed in this mutation. +func (m *ChampPersonnaliseMutation) RemovedEdges() []string { + edges := make([]string, 0, 1) + return edges +} + +// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with +// the given name in this mutation. +func (m *ChampPersonnaliseMutation) RemovedIDs(name string) []ent.Value { + return nil +} + +// ClearedEdges returns all edge names that were cleared in this mutation. +func (m *ChampPersonnaliseMutation) ClearedEdges() []string { + edges := make([]string, 0, 1) + if m.clearedobjet { + edges = append(edges, champpersonnalise.EdgeObjet) + } + return edges +} + +// EdgeCleared returns a boolean which indicates if the edge with the given name +// was cleared in this mutation. +func (m *ChampPersonnaliseMutation) EdgeCleared(name string) bool { + switch name { + case champpersonnalise.EdgeObjet: + return m.clearedobjet + } + return false +} + +// ClearEdge clears the value of the edge with the given name. It returns an error +// if that edge is not defined in the schema. +func (m *ChampPersonnaliseMutation) ClearEdge(name string) error { + switch name { + case champpersonnalise.EdgeObjet: + m.ClearObjet() + return nil + } + return fmt.Errorf("unknown ChampPersonnalise unique edge %s", name) +} + +// ResetEdge resets all changes to the edge with the given name in this mutation. +// It returns an error if the edge is not defined in the schema. +func (m *ChampPersonnaliseMutation) ResetEdge(name string) error { + switch name { + case champpersonnalise.EdgeObjet: + m.ResetObjet() + return nil + } + return fmt.Errorf("unknown ChampPersonnalise edge %s", name) +} + +// EmplacementMutation represents an operation that mutates the Emplacement nodes in the graph. +type EmplacementMutation struct { + config + op Op + typ string + id *uuid.UUID + nom *string + slug *string + piece *string + meuble *string + numero_boite *string + icone *string + created_at *time.Time + updated_at *time.Time + clearedFields map[string]struct{} + parent *uuid.UUID + clearedparent bool + enfants map[uuid.UUID]struct{} + removedenfants map[uuid.UUID]struct{} + clearedenfants bool + liens_objets map[uuid.UUID]struct{} + removedliens_objets map[uuid.UUID]struct{} + clearedliens_objets bool + done bool + oldValue func(context.Context) (*Emplacement, error) + predicates []predicate.Emplacement +} + +var _ ent.Mutation = (*EmplacementMutation)(nil) + +// emplacementOption allows management of the mutation configuration using functional options. +type emplacementOption func(*EmplacementMutation) + +// newEmplacementMutation creates new mutation for the Emplacement entity. +func newEmplacementMutation(c config, op Op, opts ...emplacementOption) *EmplacementMutation { + m := &EmplacementMutation{ + config: c, + op: op, + typ: TypeEmplacement, + clearedFields: make(map[string]struct{}), + } + for _, opt := range opts { + opt(m) + } + return m +} + +// withEmplacementID sets the ID field of the mutation. +func withEmplacementID(id uuid.UUID) emplacementOption { + return func(m *EmplacementMutation) { + var ( + err error + once sync.Once + value *Emplacement + ) + m.oldValue = func(ctx context.Context) (*Emplacement, error) { + once.Do(func() { + if m.done { + err = errors.New("querying old values post mutation is not allowed") + } else { + value, err = m.Client().Emplacement.Get(ctx, id) + } + }) + return value, err + } + m.id = &id + } +} + +// withEmplacement sets the old Emplacement of the mutation. +func withEmplacement(node *Emplacement) emplacementOption { + return func(m *EmplacementMutation) { + m.oldValue = func(context.Context) (*Emplacement, error) { + return node, nil + } + m.id = &node.ID + } +} + +// Client returns a new `ent.Client` from the mutation. If the mutation was +// executed in a transaction (ent.Tx), a transactional client is returned. +func (m EmplacementMutation) Client() *Client { + client := &Client{config: m.config} + client.init() + return client +} + +// Tx returns an `ent.Tx` for mutations that were executed in transactions; +// it returns an error otherwise. +func (m EmplacementMutation) Tx() (*Tx, error) { + if _, ok := m.driver.(*txDriver); !ok { + return nil, errors.New("ent: mutation is not running in a transaction") + } + tx := &Tx{config: m.config} + tx.init() + return tx, nil +} + +// SetID sets the value of the id field. Note that this +// operation is only accepted on creation of Emplacement entities. +func (m *EmplacementMutation) SetID(id uuid.UUID) { + m.id = &id +} + +// ID returns the ID value in the mutation. Note that the ID is only available +// if it was provided to the builder or after it was returned from the database. +func (m *EmplacementMutation) ID() (id uuid.UUID, exists bool) { + if m.id == nil { + return + } + return *m.id, true +} + +// IDs queries the database and returns the entity ids that match the mutation's predicate. +// That means, if the mutation is applied within a transaction with an isolation level such +// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated +// or updated by the mutation. +func (m *EmplacementMutation) IDs(ctx context.Context) ([]uuid.UUID, error) { + switch { + case m.op.Is(OpUpdateOne | OpDeleteOne): + id, exists := m.ID() + if exists { + return []uuid.UUID{id}, nil + } + fallthrough + case m.op.Is(OpUpdate | OpDelete): + return m.Client().Emplacement.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) + } +} + +// SetNom sets the "nom" field. +func (m *EmplacementMutation) SetNom(s string) { + m.nom = &s +} + +// Nom returns the value of the "nom" field in the mutation. +func (m *EmplacementMutation) Nom() (r string, exists bool) { + v := m.nom + if v == nil { + return + } + return *v, true +} + +// OldNom returns the old "nom" field's value of the Emplacement entity. +// If the Emplacement object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *EmplacementMutation) OldNom(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldNom is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldNom requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldNom: %w", err) + } + return oldValue.Nom, nil +} + +// ResetNom resets all changes to the "nom" field. +func (m *EmplacementMutation) ResetNom() { + m.nom = nil +} + +// SetParentID sets the "parent_id" field. +func (m *EmplacementMutation) SetParentID(u uuid.UUID) { + m.parent = &u +} + +// ParentID returns the value of the "parent_id" field in the mutation. +func (m *EmplacementMutation) ParentID() (r uuid.UUID, exists bool) { + v := m.parent + if v == nil { + return + } + return *v, true +} + +// OldParentID returns the old "parent_id" field's value of the Emplacement entity. +// If the Emplacement object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *EmplacementMutation) OldParentID(ctx context.Context) (v *uuid.UUID, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldParentID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldParentID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldParentID: %w", err) + } + return oldValue.ParentID, nil +} + +// ClearParentID clears the value of the "parent_id" field. +func (m *EmplacementMutation) ClearParentID() { + m.parent = nil + m.clearedFields[emplacement.FieldParentID] = struct{}{} +} + +// ParentIDCleared returns if the "parent_id" field was cleared in this mutation. +func (m *EmplacementMutation) ParentIDCleared() bool { + _, ok := m.clearedFields[emplacement.FieldParentID] + return ok +} + +// ResetParentID resets all changes to the "parent_id" field. +func (m *EmplacementMutation) ResetParentID() { + m.parent = nil + delete(m.clearedFields, emplacement.FieldParentID) +} + +// SetSlug sets the "slug" field. +func (m *EmplacementMutation) SetSlug(s string) { + m.slug = &s +} + +// Slug returns the value of the "slug" field in the mutation. +func (m *EmplacementMutation) Slug() (r string, exists bool) { + v := m.slug + if v == nil { + return + } + return *v, true +} + +// OldSlug returns the old "slug" field's value of the Emplacement entity. +// If the Emplacement object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *EmplacementMutation) OldSlug(ctx context.Context) (v *string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldSlug is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldSlug requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldSlug: %w", err) + } + return oldValue.Slug, nil +} + +// ClearSlug clears the value of the "slug" field. +func (m *EmplacementMutation) ClearSlug() { + m.slug = nil + m.clearedFields[emplacement.FieldSlug] = struct{}{} +} + +// SlugCleared returns if the "slug" field was cleared in this mutation. +func (m *EmplacementMutation) SlugCleared() bool { + _, ok := m.clearedFields[emplacement.FieldSlug] + return ok +} + +// ResetSlug resets all changes to the "slug" field. +func (m *EmplacementMutation) ResetSlug() { + m.slug = nil + delete(m.clearedFields, emplacement.FieldSlug) +} + +// SetPiece sets the "piece" field. +func (m *EmplacementMutation) SetPiece(s string) { + m.piece = &s +} + +// Piece returns the value of the "piece" field in the mutation. +func (m *EmplacementMutation) Piece() (r string, exists bool) { + v := m.piece + if v == nil { + return + } + return *v, true +} + +// OldPiece returns the old "piece" field's value of the Emplacement entity. +// If the Emplacement object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *EmplacementMutation) OldPiece(ctx context.Context) (v *string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldPiece is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldPiece requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldPiece: %w", err) + } + return oldValue.Piece, nil +} + +// ClearPiece clears the value of the "piece" field. +func (m *EmplacementMutation) ClearPiece() { + m.piece = nil + m.clearedFields[emplacement.FieldPiece] = struct{}{} +} + +// PieceCleared returns if the "piece" field was cleared in this mutation. +func (m *EmplacementMutation) PieceCleared() bool { + _, ok := m.clearedFields[emplacement.FieldPiece] + return ok +} + +// ResetPiece resets all changes to the "piece" field. +func (m *EmplacementMutation) ResetPiece() { + m.piece = nil + delete(m.clearedFields, emplacement.FieldPiece) +} + +// SetMeuble sets the "meuble" field. +func (m *EmplacementMutation) SetMeuble(s string) { + m.meuble = &s +} + +// Meuble returns the value of the "meuble" field in the mutation. +func (m *EmplacementMutation) Meuble() (r string, exists bool) { + v := m.meuble + if v == nil { + return + } + return *v, true +} + +// OldMeuble returns the old "meuble" field's value of the Emplacement entity. +// If the Emplacement object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *EmplacementMutation) OldMeuble(ctx context.Context) (v *string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldMeuble is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldMeuble requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldMeuble: %w", err) + } + return oldValue.Meuble, nil +} + +// ClearMeuble clears the value of the "meuble" field. +func (m *EmplacementMutation) ClearMeuble() { + m.meuble = nil + m.clearedFields[emplacement.FieldMeuble] = struct{}{} +} + +// MeubleCleared returns if the "meuble" field was cleared in this mutation. +func (m *EmplacementMutation) MeubleCleared() bool { + _, ok := m.clearedFields[emplacement.FieldMeuble] + return ok +} + +// ResetMeuble resets all changes to the "meuble" field. +func (m *EmplacementMutation) ResetMeuble() { + m.meuble = nil + delete(m.clearedFields, emplacement.FieldMeuble) +} + +// SetNumeroBoite sets the "numero_boite" field. +func (m *EmplacementMutation) SetNumeroBoite(s string) { + m.numero_boite = &s +} + +// NumeroBoite returns the value of the "numero_boite" field in the mutation. +func (m *EmplacementMutation) NumeroBoite() (r string, exists bool) { + v := m.numero_boite + if v == nil { + return + } + return *v, true +} + +// OldNumeroBoite returns the old "numero_boite" field's value of the Emplacement entity. +// If the Emplacement object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *EmplacementMutation) OldNumeroBoite(ctx context.Context) (v *string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldNumeroBoite is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldNumeroBoite requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldNumeroBoite: %w", err) + } + return oldValue.NumeroBoite, nil +} + +// ClearNumeroBoite clears the value of the "numero_boite" field. +func (m *EmplacementMutation) ClearNumeroBoite() { + m.numero_boite = nil + m.clearedFields[emplacement.FieldNumeroBoite] = struct{}{} +} + +// NumeroBoiteCleared returns if the "numero_boite" field was cleared in this mutation. +func (m *EmplacementMutation) NumeroBoiteCleared() bool { + _, ok := m.clearedFields[emplacement.FieldNumeroBoite] + return ok +} + +// ResetNumeroBoite resets all changes to the "numero_boite" field. +func (m *EmplacementMutation) ResetNumeroBoite() { + m.numero_boite = nil + delete(m.clearedFields, emplacement.FieldNumeroBoite) +} + +// SetIcone sets the "icone" field. +func (m *EmplacementMutation) SetIcone(s string) { + m.icone = &s +} + +// Icone returns the value of the "icone" field in the mutation. +func (m *EmplacementMutation) Icone() (r string, exists bool) { + v := m.icone + if v == nil { + return + } + return *v, true +} + +// OldIcone returns the old "icone" field's value of the Emplacement entity. +// If the Emplacement object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *EmplacementMutation) OldIcone(ctx context.Context) (v *string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldIcone is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldIcone requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldIcone: %w", err) + } + return oldValue.Icone, nil +} + +// ClearIcone clears the value of the "icone" field. +func (m *EmplacementMutation) ClearIcone() { + m.icone = nil + m.clearedFields[emplacement.FieldIcone] = struct{}{} +} + +// IconeCleared returns if the "icone" field was cleared in this mutation. +func (m *EmplacementMutation) IconeCleared() bool { + _, ok := m.clearedFields[emplacement.FieldIcone] + return ok +} + +// ResetIcone resets all changes to the "icone" field. +func (m *EmplacementMutation) ResetIcone() { + m.icone = nil + delete(m.clearedFields, emplacement.FieldIcone) +} + +// SetCreatedAt sets the "created_at" field. +func (m *EmplacementMutation) SetCreatedAt(t time.Time) { + m.created_at = &t +} + +// CreatedAt returns the value of the "created_at" field in the mutation. +func (m *EmplacementMutation) CreatedAt() (r time.Time, exists bool) { + v := m.created_at + if v == nil { + return + } + return *v, true +} + +// OldCreatedAt returns the old "created_at" field's value of the Emplacement entity. +// If the Emplacement object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *EmplacementMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldCreatedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) + } + return oldValue.CreatedAt, nil +} + +// ResetCreatedAt resets all changes to the "created_at" field. +func (m *EmplacementMutation) ResetCreatedAt() { + m.created_at = nil +} + +// SetUpdatedAt sets the "updated_at" field. +func (m *EmplacementMutation) SetUpdatedAt(t time.Time) { + m.updated_at = &t +} + +// UpdatedAt returns the value of the "updated_at" field in the mutation. +func (m *EmplacementMutation) UpdatedAt() (r time.Time, exists bool) { + v := m.updated_at + if v == nil { + return + } + return *v, true +} + +// OldUpdatedAt returns the old "updated_at" field's value of the Emplacement entity. +// If the Emplacement object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *EmplacementMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldUpdatedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) + } + return oldValue.UpdatedAt, nil +} + +// ResetUpdatedAt resets all changes to the "updated_at" field. +func (m *EmplacementMutation) ResetUpdatedAt() { + m.updated_at = nil +} + +// ClearParent clears the "parent" edge to the Emplacement entity. +func (m *EmplacementMutation) ClearParent() { + m.clearedparent = true + m.clearedFields[emplacement.FieldParentID] = struct{}{} +} + +// ParentCleared reports if the "parent" edge to the Emplacement entity was cleared. +func (m *EmplacementMutation) ParentCleared() bool { + return m.ParentIDCleared() || m.clearedparent +} + +// ParentIDs returns the "parent" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// ParentID instead. It exists only for internal usage by the builders. +func (m *EmplacementMutation) ParentIDs() (ids []uuid.UUID) { + if id := m.parent; id != nil { + ids = append(ids, *id) + } + return +} + +// ResetParent resets all changes to the "parent" edge. +func (m *EmplacementMutation) ResetParent() { + m.parent = nil + m.clearedparent = false +} + +// AddEnfantIDs adds the "enfants" edge to the Emplacement entity by ids. +func (m *EmplacementMutation) AddEnfantIDs(ids ...uuid.UUID) { + if m.enfants == nil { + m.enfants = make(map[uuid.UUID]struct{}) + } + for i := range ids { + m.enfants[ids[i]] = struct{}{} + } +} + +// ClearEnfants clears the "enfants" edge to the Emplacement entity. +func (m *EmplacementMutation) ClearEnfants() { + m.clearedenfants = true +} + +// EnfantsCleared reports if the "enfants" edge to the Emplacement entity was cleared. +func (m *EmplacementMutation) EnfantsCleared() bool { + return m.clearedenfants +} + +// RemoveEnfantIDs removes the "enfants" edge to the Emplacement entity by IDs. +func (m *EmplacementMutation) RemoveEnfantIDs(ids ...uuid.UUID) { + if m.removedenfants == nil { + m.removedenfants = make(map[uuid.UUID]struct{}) + } + for i := range ids { + delete(m.enfants, ids[i]) + m.removedenfants[ids[i]] = struct{}{} + } +} + +// RemovedEnfants returns the removed IDs of the "enfants" edge to the Emplacement entity. +func (m *EmplacementMutation) RemovedEnfantsIDs() (ids []uuid.UUID) { + for id := range m.removedenfants { + ids = append(ids, id) + } + return +} + +// EnfantsIDs returns the "enfants" edge IDs in the mutation. +func (m *EmplacementMutation) EnfantsIDs() (ids []uuid.UUID) { + for id := range m.enfants { + ids = append(ids, id) + } + return +} + +// ResetEnfants resets all changes to the "enfants" edge. +func (m *EmplacementMutation) ResetEnfants() { + m.enfants = nil + m.clearedenfants = false + m.removedenfants = nil +} + +// AddLiensObjetIDs adds the "liens_objets" edge to the LienObjetEmplacement entity by ids. +func (m *EmplacementMutation) AddLiensObjetIDs(ids ...uuid.UUID) { + if m.liens_objets == nil { + m.liens_objets = make(map[uuid.UUID]struct{}) + } + for i := range ids { + m.liens_objets[ids[i]] = struct{}{} + } +} + +// ClearLiensObjets clears the "liens_objets" edge to the LienObjetEmplacement entity. +func (m *EmplacementMutation) ClearLiensObjets() { + m.clearedliens_objets = true +} + +// LiensObjetsCleared reports if the "liens_objets" edge to the LienObjetEmplacement entity was cleared. +func (m *EmplacementMutation) LiensObjetsCleared() bool { + return m.clearedliens_objets +} + +// RemoveLiensObjetIDs removes the "liens_objets" edge to the LienObjetEmplacement entity by IDs. +func (m *EmplacementMutation) RemoveLiensObjetIDs(ids ...uuid.UUID) { + if m.removedliens_objets == nil { + m.removedliens_objets = make(map[uuid.UUID]struct{}) + } + for i := range ids { + delete(m.liens_objets, ids[i]) + m.removedliens_objets[ids[i]] = struct{}{} + } +} + +// RemovedLiensObjets returns the removed IDs of the "liens_objets" edge to the LienObjetEmplacement entity. +func (m *EmplacementMutation) RemovedLiensObjetsIDs() (ids []uuid.UUID) { + for id := range m.removedliens_objets { + ids = append(ids, id) + } + return +} + +// LiensObjetsIDs returns the "liens_objets" edge IDs in the mutation. +func (m *EmplacementMutation) LiensObjetsIDs() (ids []uuid.UUID) { + for id := range m.liens_objets { + ids = append(ids, id) + } + return +} + +// ResetLiensObjets resets all changes to the "liens_objets" edge. +func (m *EmplacementMutation) ResetLiensObjets() { + m.liens_objets = nil + m.clearedliens_objets = false + m.removedliens_objets = nil +} + +// Where appends a list predicates to the EmplacementMutation builder. +func (m *EmplacementMutation) Where(ps ...predicate.Emplacement) { + m.predicates = append(m.predicates, ps...) +} + +// WhereP appends storage-level predicates to the EmplacementMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *EmplacementMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.Emplacement, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + +// Op returns the operation name. +func (m *EmplacementMutation) Op() Op { + return m.op +} + +// SetOp allows setting the mutation operation. +func (m *EmplacementMutation) SetOp(op Op) { + m.op = op +} + +// Type returns the node type of this mutation (Emplacement). +func (m *EmplacementMutation) Type() string { + return m.typ +} + +// Fields returns all fields that were changed during this mutation. Note that in +// order to get all numeric fields that were incremented/decremented, call +// AddedFields(). +func (m *EmplacementMutation) Fields() []string { + fields := make([]string, 0, 9) + if m.nom != nil { + fields = append(fields, emplacement.FieldNom) + } + if m.parent != nil { + fields = append(fields, emplacement.FieldParentID) + } + if m.slug != nil { + fields = append(fields, emplacement.FieldSlug) + } + if m.piece != nil { + fields = append(fields, emplacement.FieldPiece) + } + if m.meuble != nil { + fields = append(fields, emplacement.FieldMeuble) + } + if m.numero_boite != nil { + fields = append(fields, emplacement.FieldNumeroBoite) + } + if m.icone != nil { + fields = append(fields, emplacement.FieldIcone) + } + if m.created_at != nil { + fields = append(fields, emplacement.FieldCreatedAt) + } + if m.updated_at != nil { + fields = append(fields, emplacement.FieldUpdatedAt) + } + return fields +} + +// Field returns the value of a field with the given name. The second boolean +// return value indicates that this field was not set, or was not defined in the +// schema. +func (m *EmplacementMutation) Field(name string) (ent.Value, bool) { + switch name { + case emplacement.FieldNom: + return m.Nom() + case emplacement.FieldParentID: + return m.ParentID() + case emplacement.FieldSlug: + return m.Slug() + case emplacement.FieldPiece: + return m.Piece() + case emplacement.FieldMeuble: + return m.Meuble() + case emplacement.FieldNumeroBoite: + return m.NumeroBoite() + case emplacement.FieldIcone: + return m.Icone() + case emplacement.FieldCreatedAt: + return m.CreatedAt() + case emplacement.FieldUpdatedAt: + return m.UpdatedAt() + } + return nil, false +} + +// OldField returns the old value of the field from the database. An error is +// returned if the mutation operation is not UpdateOne, or the query to the +// database failed. +func (m *EmplacementMutation) OldField(ctx context.Context, name string) (ent.Value, error) { + switch name { + case emplacement.FieldNom: + return m.OldNom(ctx) + case emplacement.FieldParentID: + return m.OldParentID(ctx) + case emplacement.FieldSlug: + return m.OldSlug(ctx) + case emplacement.FieldPiece: + return m.OldPiece(ctx) + case emplacement.FieldMeuble: + return m.OldMeuble(ctx) + case emplacement.FieldNumeroBoite: + return m.OldNumeroBoite(ctx) + case emplacement.FieldIcone: + return m.OldIcone(ctx) + case emplacement.FieldCreatedAt: + return m.OldCreatedAt(ctx) + case emplacement.FieldUpdatedAt: + return m.OldUpdatedAt(ctx) + } + return nil, fmt.Errorf("unknown Emplacement field %s", name) +} + +// SetField sets the value of a field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *EmplacementMutation) SetField(name string, value ent.Value) error { + switch name { + case emplacement.FieldNom: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetNom(v) + return nil + case emplacement.FieldParentID: + v, ok := value.(uuid.UUID) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetParentID(v) + return nil + case emplacement.FieldSlug: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetSlug(v) + return nil + case emplacement.FieldPiece: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetPiece(v) + return nil + case emplacement.FieldMeuble: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetMeuble(v) + return nil + case emplacement.FieldNumeroBoite: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetNumeroBoite(v) + return nil + case emplacement.FieldIcone: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetIcone(v) + return nil + case emplacement.FieldCreatedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetCreatedAt(v) + return nil + case emplacement.FieldUpdatedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetUpdatedAt(v) + return nil + } + return fmt.Errorf("unknown Emplacement field %s", name) +} + +// AddedFields returns all numeric fields that were incremented/decremented during +// this mutation. +func (m *EmplacementMutation) AddedFields() []string { + return nil +} + +// AddedField returns the numeric value that was incremented/decremented on a field +// with the given name. The second boolean return value indicates that this field +// was not set, or was not defined in the schema. +func (m *EmplacementMutation) AddedField(name string) (ent.Value, bool) { + return nil, false +} + +// AddField adds the value to the field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *EmplacementMutation) AddField(name string, value ent.Value) error { + switch name { + } + return fmt.Errorf("unknown Emplacement numeric field %s", name) +} + +// ClearedFields returns all nullable fields that were cleared during this +// mutation. +func (m *EmplacementMutation) ClearedFields() []string { + var fields []string + if m.FieldCleared(emplacement.FieldParentID) { + fields = append(fields, emplacement.FieldParentID) + } + if m.FieldCleared(emplacement.FieldSlug) { + fields = append(fields, emplacement.FieldSlug) + } + if m.FieldCleared(emplacement.FieldPiece) { + fields = append(fields, emplacement.FieldPiece) + } + if m.FieldCleared(emplacement.FieldMeuble) { + fields = append(fields, emplacement.FieldMeuble) + } + if m.FieldCleared(emplacement.FieldNumeroBoite) { + fields = append(fields, emplacement.FieldNumeroBoite) + } + if m.FieldCleared(emplacement.FieldIcone) { + fields = append(fields, emplacement.FieldIcone) + } + return fields +} + +// FieldCleared returns a boolean indicating if a field with the given name was +// cleared in this mutation. +func (m *EmplacementMutation) FieldCleared(name string) bool { + _, ok := m.clearedFields[name] + return ok +} + +// ClearField clears the value of the field with the given name. It returns an +// error if the field is not defined in the schema. +func (m *EmplacementMutation) ClearField(name string) error { + switch name { + case emplacement.FieldParentID: + m.ClearParentID() + return nil + case emplacement.FieldSlug: + m.ClearSlug() + return nil + case emplacement.FieldPiece: + m.ClearPiece() + return nil + case emplacement.FieldMeuble: + m.ClearMeuble() + return nil + case emplacement.FieldNumeroBoite: + m.ClearNumeroBoite() + return nil + case emplacement.FieldIcone: + m.ClearIcone() + return nil + } + return fmt.Errorf("unknown Emplacement nullable field %s", name) +} + +// ResetField resets all changes in the mutation for the field with the given name. +// It returns an error if the field is not defined in the schema. +func (m *EmplacementMutation) ResetField(name string) error { + switch name { + case emplacement.FieldNom: + m.ResetNom() + return nil + case emplacement.FieldParentID: + m.ResetParentID() + return nil + case emplacement.FieldSlug: + m.ResetSlug() + return nil + case emplacement.FieldPiece: + m.ResetPiece() + return nil + case emplacement.FieldMeuble: + m.ResetMeuble() + return nil + case emplacement.FieldNumeroBoite: + m.ResetNumeroBoite() + return nil + case emplacement.FieldIcone: + m.ResetIcone() + return nil + case emplacement.FieldCreatedAt: + m.ResetCreatedAt() + return nil + case emplacement.FieldUpdatedAt: + m.ResetUpdatedAt() + return nil + } + return fmt.Errorf("unknown Emplacement field %s", name) +} + +// AddedEdges returns all edge names that were set/added in this mutation. +func (m *EmplacementMutation) AddedEdges() []string { + edges := make([]string, 0, 3) + if m.parent != nil { + edges = append(edges, emplacement.EdgeParent) + } + if m.enfants != nil { + edges = append(edges, emplacement.EdgeEnfants) + } + if m.liens_objets != nil { + edges = append(edges, emplacement.EdgeLiensObjets) + } + return edges +} + +// AddedIDs returns all IDs (to other nodes) that were added for the given edge +// name in this mutation. +func (m *EmplacementMutation) AddedIDs(name string) []ent.Value { + switch name { + case emplacement.EdgeParent: + if id := m.parent; id != nil { + return []ent.Value{*id} + } + case emplacement.EdgeEnfants: + ids := make([]ent.Value, 0, len(m.enfants)) + for id := range m.enfants { + ids = append(ids, id) + } + return ids + case emplacement.EdgeLiensObjets: + ids := make([]ent.Value, 0, len(m.liens_objets)) + for id := range m.liens_objets { + ids = append(ids, id) + } + return ids + } + return nil +} + +// RemovedEdges returns all edge names that were removed in this mutation. +func (m *EmplacementMutation) RemovedEdges() []string { + edges := make([]string, 0, 3) + if m.removedenfants != nil { + edges = append(edges, emplacement.EdgeEnfants) + } + if m.removedliens_objets != nil { + edges = append(edges, emplacement.EdgeLiensObjets) + } + return edges +} + +// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with +// the given name in this mutation. +func (m *EmplacementMutation) RemovedIDs(name string) []ent.Value { + switch name { + case emplacement.EdgeEnfants: + ids := make([]ent.Value, 0, len(m.removedenfants)) + for id := range m.removedenfants { + ids = append(ids, id) + } + return ids + case emplacement.EdgeLiensObjets: + ids := make([]ent.Value, 0, len(m.removedliens_objets)) + for id := range m.removedliens_objets { + ids = append(ids, id) + } + return ids + } + return nil +} + +// ClearedEdges returns all edge names that were cleared in this mutation. +func (m *EmplacementMutation) ClearedEdges() []string { + edges := make([]string, 0, 3) + if m.clearedparent { + edges = append(edges, emplacement.EdgeParent) + } + if m.clearedenfants { + edges = append(edges, emplacement.EdgeEnfants) + } + if m.clearedliens_objets { + edges = append(edges, emplacement.EdgeLiensObjets) + } + return edges +} + +// EdgeCleared returns a boolean which indicates if the edge with the given name +// was cleared in this mutation. +func (m *EmplacementMutation) EdgeCleared(name string) bool { + switch name { + case emplacement.EdgeParent: + return m.clearedparent + case emplacement.EdgeEnfants: + return m.clearedenfants + case emplacement.EdgeLiensObjets: + return m.clearedliens_objets + } + return false +} + +// ClearEdge clears the value of the edge with the given name. It returns an error +// if that edge is not defined in the schema. +func (m *EmplacementMutation) ClearEdge(name string) error { + switch name { + case emplacement.EdgeParent: + m.ClearParent() + return nil + } + return fmt.Errorf("unknown Emplacement unique edge %s", name) +} + +// ResetEdge resets all changes to the edge with the given name in this mutation. +// It returns an error if the edge is not defined in the schema. +func (m *EmplacementMutation) ResetEdge(name string) error { + switch name { + case emplacement.EdgeParent: + m.ResetParent() + return nil + case emplacement.EdgeEnfants: + m.ResetEnfants() + return nil + case emplacement.EdgeLiensObjets: + m.ResetLiensObjets() + return nil + } + return fmt.Errorf("unknown Emplacement edge %s", name) +} + +// LienObjetEmplacementMutation represents an operation that mutates the LienObjetEmplacement nodes in the graph. +type LienObjetEmplacementMutation struct { + config + op Op + typ string + id *uuid.UUID + _type *lienobjetemplacement.Type + created_at *time.Time + updated_at *time.Time + clearedFields map[string]struct{} + objet *uuid.UUID + clearedobjet bool + emplacement *uuid.UUID + clearedemplacement bool + done bool + oldValue func(context.Context) (*LienObjetEmplacement, error) + predicates []predicate.LienObjetEmplacement +} + +var _ ent.Mutation = (*LienObjetEmplacementMutation)(nil) + +// lienobjetemplacementOption allows management of the mutation configuration using functional options. +type lienobjetemplacementOption func(*LienObjetEmplacementMutation) + +// newLienObjetEmplacementMutation creates new mutation for the LienObjetEmplacement entity. +func newLienObjetEmplacementMutation(c config, op Op, opts ...lienobjetemplacementOption) *LienObjetEmplacementMutation { + m := &LienObjetEmplacementMutation{ + config: c, + op: op, + typ: TypeLienObjetEmplacement, + clearedFields: make(map[string]struct{}), + } + for _, opt := range opts { + opt(m) + } + return m +} + +// withLienObjetEmplacementID sets the ID field of the mutation. +func withLienObjetEmplacementID(id uuid.UUID) lienobjetemplacementOption { + return func(m *LienObjetEmplacementMutation) { + var ( + err error + once sync.Once + value *LienObjetEmplacement + ) + m.oldValue = func(ctx context.Context) (*LienObjetEmplacement, error) { + once.Do(func() { + if m.done { + err = errors.New("querying old values post mutation is not allowed") + } else { + value, err = m.Client().LienObjetEmplacement.Get(ctx, id) + } + }) + return value, err + } + m.id = &id + } +} + +// withLienObjetEmplacement sets the old LienObjetEmplacement of the mutation. +func withLienObjetEmplacement(node *LienObjetEmplacement) lienobjetemplacementOption { + return func(m *LienObjetEmplacementMutation) { + m.oldValue = func(context.Context) (*LienObjetEmplacement, error) { + return node, nil + } + m.id = &node.ID + } +} + +// Client returns a new `ent.Client` from the mutation. If the mutation was +// executed in a transaction (ent.Tx), a transactional client is returned. +func (m LienObjetEmplacementMutation) Client() *Client { + client := &Client{config: m.config} + client.init() + return client +} + +// Tx returns an `ent.Tx` for mutations that were executed in transactions; +// it returns an error otherwise. +func (m LienObjetEmplacementMutation) Tx() (*Tx, error) { + if _, ok := m.driver.(*txDriver); !ok { + return nil, errors.New("ent: mutation is not running in a transaction") + } + tx := &Tx{config: m.config} + tx.init() + return tx, nil +} + +// SetID sets the value of the id field. Note that this +// operation is only accepted on creation of LienObjetEmplacement entities. +func (m *LienObjetEmplacementMutation) SetID(id uuid.UUID) { + m.id = &id +} + +// ID returns the ID value in the mutation. Note that the ID is only available +// if it was provided to the builder or after it was returned from the database. +func (m *LienObjetEmplacementMutation) ID() (id uuid.UUID, exists bool) { + if m.id == nil { + return + } + return *m.id, true +} + +// IDs queries the database and returns the entity ids that match the mutation's predicate. +// That means, if the mutation is applied within a transaction with an isolation level such +// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated +// or updated by the mutation. +func (m *LienObjetEmplacementMutation) IDs(ctx context.Context) ([]uuid.UUID, error) { + switch { + case m.op.Is(OpUpdateOne | OpDeleteOne): + id, exists := m.ID() + if exists { + return []uuid.UUID{id}, nil + } + fallthrough + case m.op.Is(OpUpdate | OpDelete): + return m.Client().LienObjetEmplacement.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) + } +} + +// SetObjetID sets the "objet_id" field. +func (m *LienObjetEmplacementMutation) SetObjetID(u uuid.UUID) { + m.objet = &u +} + +// ObjetID returns the value of the "objet_id" field in the mutation. +func (m *LienObjetEmplacementMutation) ObjetID() (r uuid.UUID, exists bool) { + v := m.objet + if v == nil { + return + } + return *v, true +} + +// OldObjetID returns the old "objet_id" field's value of the LienObjetEmplacement entity. +// If the LienObjetEmplacement object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *LienObjetEmplacementMutation) OldObjetID(ctx context.Context) (v uuid.UUID, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldObjetID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldObjetID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldObjetID: %w", err) + } + return oldValue.ObjetID, nil +} + +// ResetObjetID resets all changes to the "objet_id" field. +func (m *LienObjetEmplacementMutation) ResetObjetID() { + m.objet = nil +} + +// SetEmplacementID sets the "emplacement_id" field. +func (m *LienObjetEmplacementMutation) SetEmplacementID(u uuid.UUID) { + m.emplacement = &u +} + +// EmplacementID returns the value of the "emplacement_id" field in the mutation. +func (m *LienObjetEmplacementMutation) EmplacementID() (r uuid.UUID, exists bool) { + v := m.emplacement + if v == nil { + return + } + return *v, true +} + +// OldEmplacementID returns the old "emplacement_id" field's value of the LienObjetEmplacement entity. +// If the LienObjetEmplacement object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *LienObjetEmplacementMutation) OldEmplacementID(ctx context.Context) (v uuid.UUID, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldEmplacementID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldEmplacementID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldEmplacementID: %w", err) + } + return oldValue.EmplacementID, nil +} + +// ResetEmplacementID resets all changes to the "emplacement_id" field. +func (m *LienObjetEmplacementMutation) ResetEmplacementID() { + m.emplacement = nil +} + +// SetType sets the "type" field. +func (m *LienObjetEmplacementMutation) SetType(l lienobjetemplacement.Type) { + m._type = &l +} + +// GetType returns the value of the "type" field in the mutation. +func (m *LienObjetEmplacementMutation) GetType() (r lienobjetemplacement.Type, exists bool) { + v := m._type + if v == nil { + return + } + return *v, true +} + +// OldType returns the old "type" field's value of the LienObjetEmplacement entity. +// If the LienObjetEmplacement object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *LienObjetEmplacementMutation) OldType(ctx context.Context) (v lienobjetemplacement.Type, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldType is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldType requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldType: %w", err) + } + return oldValue.Type, nil +} + +// ResetType resets all changes to the "type" field. +func (m *LienObjetEmplacementMutation) ResetType() { + m._type = nil +} + +// SetCreatedAt sets the "created_at" field. +func (m *LienObjetEmplacementMutation) SetCreatedAt(t time.Time) { + m.created_at = &t +} + +// CreatedAt returns the value of the "created_at" field in the mutation. +func (m *LienObjetEmplacementMutation) CreatedAt() (r time.Time, exists bool) { + v := m.created_at + if v == nil { + return + } + return *v, true +} + +// OldCreatedAt returns the old "created_at" field's value of the LienObjetEmplacement entity. +// If the LienObjetEmplacement object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *LienObjetEmplacementMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldCreatedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) + } + return oldValue.CreatedAt, nil +} + +// ResetCreatedAt resets all changes to the "created_at" field. +func (m *LienObjetEmplacementMutation) ResetCreatedAt() { + m.created_at = nil +} + +// SetUpdatedAt sets the "updated_at" field. +func (m *LienObjetEmplacementMutation) SetUpdatedAt(t time.Time) { + m.updated_at = &t +} + +// UpdatedAt returns the value of the "updated_at" field in the mutation. +func (m *LienObjetEmplacementMutation) UpdatedAt() (r time.Time, exists bool) { + v := m.updated_at + if v == nil { + return + } + return *v, true +} + +// OldUpdatedAt returns the old "updated_at" field's value of the LienObjetEmplacement entity. +// If the LienObjetEmplacement object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *LienObjetEmplacementMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldUpdatedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) + } + return oldValue.UpdatedAt, nil +} + +// ResetUpdatedAt resets all changes to the "updated_at" field. +func (m *LienObjetEmplacementMutation) ResetUpdatedAt() { + m.updated_at = nil +} + +// ClearObjet clears the "objet" edge to the Objet entity. +func (m *LienObjetEmplacementMutation) ClearObjet() { + m.clearedobjet = true + m.clearedFields[lienobjetemplacement.FieldObjetID] = struct{}{} +} + +// ObjetCleared reports if the "objet" edge to the Objet entity was cleared. +func (m *LienObjetEmplacementMutation) ObjetCleared() bool { + return m.clearedobjet +} + +// ObjetIDs returns the "objet" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// ObjetID instead. It exists only for internal usage by the builders. +func (m *LienObjetEmplacementMutation) ObjetIDs() (ids []uuid.UUID) { + if id := m.objet; id != nil { + ids = append(ids, *id) + } + return +} + +// ResetObjet resets all changes to the "objet" edge. +func (m *LienObjetEmplacementMutation) ResetObjet() { + m.objet = nil + m.clearedobjet = false +} + +// ClearEmplacement clears the "emplacement" edge to the Emplacement entity. +func (m *LienObjetEmplacementMutation) ClearEmplacement() { + m.clearedemplacement = true + m.clearedFields[lienobjetemplacement.FieldEmplacementID] = struct{}{} +} + +// EmplacementCleared reports if the "emplacement" edge to the Emplacement entity was cleared. +func (m *LienObjetEmplacementMutation) EmplacementCleared() bool { + return m.clearedemplacement +} + +// EmplacementIDs returns the "emplacement" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// EmplacementID instead. It exists only for internal usage by the builders. +func (m *LienObjetEmplacementMutation) EmplacementIDs() (ids []uuid.UUID) { + if id := m.emplacement; id != nil { + ids = append(ids, *id) + } + return +} + +// ResetEmplacement resets all changes to the "emplacement" edge. +func (m *LienObjetEmplacementMutation) ResetEmplacement() { + m.emplacement = nil + m.clearedemplacement = false +} + +// Where appends a list predicates to the LienObjetEmplacementMutation builder. +func (m *LienObjetEmplacementMutation) Where(ps ...predicate.LienObjetEmplacement) { + m.predicates = append(m.predicates, ps...) +} + +// WhereP appends storage-level predicates to the LienObjetEmplacementMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *LienObjetEmplacementMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.LienObjetEmplacement, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + +// Op returns the operation name. +func (m *LienObjetEmplacementMutation) Op() Op { + return m.op +} + +// SetOp allows setting the mutation operation. +func (m *LienObjetEmplacementMutation) SetOp(op Op) { + m.op = op +} + +// Type returns the node type of this mutation (LienObjetEmplacement). +func (m *LienObjetEmplacementMutation) Type() string { + return m.typ +} + +// Fields returns all fields that were changed during this mutation. Note that in +// order to get all numeric fields that were incremented/decremented, call +// AddedFields(). +func (m *LienObjetEmplacementMutation) Fields() []string { + fields := make([]string, 0, 5) + if m.objet != nil { + fields = append(fields, lienobjetemplacement.FieldObjetID) + } + if m.emplacement != nil { + fields = append(fields, lienobjetemplacement.FieldEmplacementID) + } + if m._type != nil { + fields = append(fields, lienobjetemplacement.FieldType) + } + if m.created_at != nil { + fields = append(fields, lienobjetemplacement.FieldCreatedAt) + } + if m.updated_at != nil { + fields = append(fields, lienobjetemplacement.FieldUpdatedAt) + } + return fields +} + +// Field returns the value of a field with the given name. The second boolean +// return value indicates that this field was not set, or was not defined in the +// schema. +func (m *LienObjetEmplacementMutation) Field(name string) (ent.Value, bool) { + switch name { + case lienobjetemplacement.FieldObjetID: + return m.ObjetID() + case lienobjetemplacement.FieldEmplacementID: + return m.EmplacementID() + case lienobjetemplacement.FieldType: + return m.GetType() + case lienobjetemplacement.FieldCreatedAt: + return m.CreatedAt() + case lienobjetemplacement.FieldUpdatedAt: + return m.UpdatedAt() + } + return nil, false +} + +// OldField returns the old value of the field from the database. An error is +// returned if the mutation operation is not UpdateOne, or the query to the +// database failed. +func (m *LienObjetEmplacementMutation) OldField(ctx context.Context, name string) (ent.Value, error) { + switch name { + case lienobjetemplacement.FieldObjetID: + return m.OldObjetID(ctx) + case lienobjetemplacement.FieldEmplacementID: + return m.OldEmplacementID(ctx) + case lienobjetemplacement.FieldType: + return m.OldType(ctx) + case lienobjetemplacement.FieldCreatedAt: + return m.OldCreatedAt(ctx) + case lienobjetemplacement.FieldUpdatedAt: + return m.OldUpdatedAt(ctx) + } + return nil, fmt.Errorf("unknown LienObjetEmplacement field %s", name) +} + +// SetField sets the value of a field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *LienObjetEmplacementMutation) SetField(name string, value ent.Value) error { + switch name { + case lienobjetemplacement.FieldObjetID: + v, ok := value.(uuid.UUID) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetObjetID(v) + return nil + case lienobjetemplacement.FieldEmplacementID: + v, ok := value.(uuid.UUID) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetEmplacementID(v) + return nil + case lienobjetemplacement.FieldType: + v, ok := value.(lienobjetemplacement.Type) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetType(v) + return nil + case lienobjetemplacement.FieldCreatedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetCreatedAt(v) + return nil + case lienobjetemplacement.FieldUpdatedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetUpdatedAt(v) + return nil + } + return fmt.Errorf("unknown LienObjetEmplacement field %s", name) +} + +// AddedFields returns all numeric fields that were incremented/decremented during +// this mutation. +func (m *LienObjetEmplacementMutation) AddedFields() []string { + return nil +} + +// AddedField returns the numeric value that was incremented/decremented on a field +// with the given name. The second boolean return value indicates that this field +// was not set, or was not defined in the schema. +func (m *LienObjetEmplacementMutation) AddedField(name string) (ent.Value, bool) { + return nil, false +} + +// AddField adds the value to the field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *LienObjetEmplacementMutation) AddField(name string, value ent.Value) error { + switch name { + } + return fmt.Errorf("unknown LienObjetEmplacement numeric field %s", name) +} + +// ClearedFields returns all nullable fields that were cleared during this +// mutation. +func (m *LienObjetEmplacementMutation) ClearedFields() []string { + return nil +} + +// FieldCleared returns a boolean indicating if a field with the given name was +// cleared in this mutation. +func (m *LienObjetEmplacementMutation) FieldCleared(name string) bool { + _, ok := m.clearedFields[name] + return ok +} + +// ClearField clears the value of the field with the given name. It returns an +// error if the field is not defined in the schema. +func (m *LienObjetEmplacementMutation) ClearField(name string) error { + return fmt.Errorf("unknown LienObjetEmplacement nullable field %s", name) +} + +// ResetField resets all changes in the mutation for the field with the given name. +// It returns an error if the field is not defined in the schema. +func (m *LienObjetEmplacementMutation) ResetField(name string) error { + switch name { + case lienobjetemplacement.FieldObjetID: + m.ResetObjetID() + return nil + case lienobjetemplacement.FieldEmplacementID: + m.ResetEmplacementID() + return nil + case lienobjetemplacement.FieldType: + m.ResetType() + return nil + case lienobjetemplacement.FieldCreatedAt: + m.ResetCreatedAt() + return nil + case lienobjetemplacement.FieldUpdatedAt: + m.ResetUpdatedAt() + return nil + } + return fmt.Errorf("unknown LienObjetEmplacement field %s", name) +} + +// AddedEdges returns all edge names that were set/added in this mutation. +func (m *LienObjetEmplacementMutation) AddedEdges() []string { + edges := make([]string, 0, 2) + if m.objet != nil { + edges = append(edges, lienobjetemplacement.EdgeObjet) + } + if m.emplacement != nil { + edges = append(edges, lienobjetemplacement.EdgeEmplacement) + } + return edges +} + +// AddedIDs returns all IDs (to other nodes) that were added for the given edge +// name in this mutation. +func (m *LienObjetEmplacementMutation) AddedIDs(name string) []ent.Value { + switch name { + case lienobjetemplacement.EdgeObjet: + if id := m.objet; id != nil { + return []ent.Value{*id} + } + case lienobjetemplacement.EdgeEmplacement: + if id := m.emplacement; id != nil { + return []ent.Value{*id} + } + } + return nil +} + +// RemovedEdges returns all edge names that were removed in this mutation. +func (m *LienObjetEmplacementMutation) RemovedEdges() []string { + edges := make([]string, 0, 2) + return edges +} + +// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with +// the given name in this mutation. +func (m *LienObjetEmplacementMutation) RemovedIDs(name string) []ent.Value { + return nil +} + +// ClearedEdges returns all edge names that were cleared in this mutation. +func (m *LienObjetEmplacementMutation) ClearedEdges() []string { + edges := make([]string, 0, 2) + if m.clearedobjet { + edges = append(edges, lienobjetemplacement.EdgeObjet) + } + if m.clearedemplacement { + edges = append(edges, lienobjetemplacement.EdgeEmplacement) + } + return edges +} + +// EdgeCleared returns a boolean which indicates if the edge with the given name +// was cleared in this mutation. +func (m *LienObjetEmplacementMutation) EdgeCleared(name string) bool { + switch name { + case lienobjetemplacement.EdgeObjet: + return m.clearedobjet + case lienobjetemplacement.EdgeEmplacement: + return m.clearedemplacement + } + return false +} + +// ClearEdge clears the value of the edge with the given name. It returns an error +// if that edge is not defined in the schema. +func (m *LienObjetEmplacementMutation) ClearEdge(name string) error { + switch name { + case lienobjetemplacement.EdgeObjet: + m.ClearObjet() + return nil + case lienobjetemplacement.EdgeEmplacement: + m.ClearEmplacement() + return nil + } + return fmt.Errorf("unknown LienObjetEmplacement unique edge %s", name) +} + +// ResetEdge resets all changes to the edge with the given name in this mutation. +// It returns an error if the edge is not defined in the schema. +func (m *LienObjetEmplacementMutation) ResetEdge(name string) error { + switch name { + case lienobjetemplacement.EdgeObjet: + m.ResetObjet() + return nil + case lienobjetemplacement.EdgeEmplacement: + m.ResetEmplacement() + return nil + } + return fmt.Errorf("unknown LienObjetEmplacement edge %s", name) +} + +// ObjetMutation represents an operation that mutates the Objet nodes in the graph. +type ObjetMutation struct { + config + op Op + typ string + id *uuid.UUID + nom *string + description *string + quantite *int + addquantite *int + prix_achat *float64 + addprix_achat *float64 + date_achat *time.Time + boutique *string + numero_serie *string + numero_modele *string + fabricant *string + statut *objet.Statut + caracteristiques *map[string]interface{} + created_at *time.Time + updated_at *time.Time + clearedFields map[string]struct{} + liens_emplacements map[uuid.UUID]struct{} + removedliens_emplacements map[uuid.UUID]struct{} + clearedliens_emplacements bool + champs_personnalises map[uuid.UUID]struct{} + removedchamps_personnalises map[uuid.UUID]struct{} + clearedchamps_personnalises bool + pieces_jointes map[uuid.UUID]struct{} + removedpieces_jointes map[uuid.UUID]struct{} + clearedpieces_jointes bool + done bool + oldValue func(context.Context) (*Objet, error) + predicates []predicate.Objet +} + +var _ ent.Mutation = (*ObjetMutation)(nil) + +// objetOption allows management of the mutation configuration using functional options. +type objetOption func(*ObjetMutation) + +// newObjetMutation creates new mutation for the Objet entity. +func newObjetMutation(c config, op Op, opts ...objetOption) *ObjetMutation { + m := &ObjetMutation{ + config: c, + op: op, + typ: TypeObjet, + clearedFields: make(map[string]struct{}), + } + for _, opt := range opts { + opt(m) + } + return m +} + +// withObjetID sets the ID field of the mutation. +func withObjetID(id uuid.UUID) objetOption { + return func(m *ObjetMutation) { + var ( + err error + once sync.Once + value *Objet + ) + m.oldValue = func(ctx context.Context) (*Objet, error) { + once.Do(func() { + if m.done { + err = errors.New("querying old values post mutation is not allowed") + } else { + value, err = m.Client().Objet.Get(ctx, id) + } + }) + return value, err + } + m.id = &id + } +} + +// withObjet sets the old Objet of the mutation. +func withObjet(node *Objet) objetOption { + return func(m *ObjetMutation) { + m.oldValue = func(context.Context) (*Objet, error) { + return node, nil + } + m.id = &node.ID + } +} + +// Client returns a new `ent.Client` from the mutation. If the mutation was +// executed in a transaction (ent.Tx), a transactional client is returned. +func (m ObjetMutation) Client() *Client { + client := &Client{config: m.config} + client.init() + return client +} + +// Tx returns an `ent.Tx` for mutations that were executed in transactions; +// it returns an error otherwise. +func (m ObjetMutation) Tx() (*Tx, error) { + if _, ok := m.driver.(*txDriver); !ok { + return nil, errors.New("ent: mutation is not running in a transaction") + } + tx := &Tx{config: m.config} + tx.init() + return tx, nil +} + +// SetID sets the value of the id field. Note that this +// operation is only accepted on creation of Objet entities. +func (m *ObjetMutation) SetID(id uuid.UUID) { + m.id = &id +} + +// ID returns the ID value in the mutation. Note that the ID is only available +// if it was provided to the builder or after it was returned from the database. +func (m *ObjetMutation) ID() (id uuid.UUID, exists bool) { + if m.id == nil { + return + } + return *m.id, true +} + +// IDs queries the database and returns the entity ids that match the mutation's predicate. +// That means, if the mutation is applied within a transaction with an isolation level such +// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated +// or updated by the mutation. +func (m *ObjetMutation) IDs(ctx context.Context) ([]uuid.UUID, error) { + switch { + case m.op.Is(OpUpdateOne | OpDeleteOne): + id, exists := m.ID() + if exists { + return []uuid.UUID{id}, nil + } + fallthrough + case m.op.Is(OpUpdate | OpDelete): + return m.Client().Objet.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) + } +} + +// SetNom sets the "nom" field. +func (m *ObjetMutation) SetNom(s string) { + m.nom = &s +} + +// Nom returns the value of the "nom" field in the mutation. +func (m *ObjetMutation) Nom() (r string, exists bool) { + v := m.nom + if v == nil { + return + } + return *v, true +} + +// OldNom returns the old "nom" field's value of the Objet entity. +// If the Objet object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ObjetMutation) OldNom(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldNom is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldNom requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldNom: %w", err) + } + return oldValue.Nom, nil +} + +// ResetNom resets all changes to the "nom" field. +func (m *ObjetMutation) ResetNom() { + m.nom = nil +} + +// SetDescription sets the "description" field. +func (m *ObjetMutation) SetDescription(s string) { + m.description = &s +} + +// Description returns the value of the "description" field in the mutation. +func (m *ObjetMutation) Description() (r string, exists bool) { + v := m.description + if v == nil { + return + } + return *v, true +} + +// OldDescription returns the old "description" field's value of the Objet entity. +// If the Objet object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ObjetMutation) OldDescription(ctx context.Context) (v *string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldDescription is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldDescription requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldDescription: %w", err) + } + return oldValue.Description, nil +} + +// ClearDescription clears the value of the "description" field. +func (m *ObjetMutation) ClearDescription() { + m.description = nil + m.clearedFields[objet.FieldDescription] = struct{}{} +} + +// DescriptionCleared returns if the "description" field was cleared in this mutation. +func (m *ObjetMutation) DescriptionCleared() bool { + _, ok := m.clearedFields[objet.FieldDescription] + return ok +} + +// ResetDescription resets all changes to the "description" field. +func (m *ObjetMutation) ResetDescription() { + m.description = nil + delete(m.clearedFields, objet.FieldDescription) +} + +// SetQuantite sets the "quantite" field. +func (m *ObjetMutation) SetQuantite(i int) { + m.quantite = &i + m.addquantite = nil +} + +// Quantite returns the value of the "quantite" field in the mutation. +func (m *ObjetMutation) Quantite() (r int, exists bool) { + v := m.quantite + if v == nil { + return + } + return *v, true +} + +// OldQuantite returns the old "quantite" field's value of the Objet entity. +// If the Objet object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ObjetMutation) OldQuantite(ctx context.Context) (v int, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldQuantite is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldQuantite requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldQuantite: %w", err) + } + return oldValue.Quantite, nil +} + +// AddQuantite adds i to the "quantite" field. +func (m *ObjetMutation) AddQuantite(i int) { + if m.addquantite != nil { + *m.addquantite += i + } else { + m.addquantite = &i + } +} + +// AddedQuantite returns the value that was added to the "quantite" field in this mutation. +func (m *ObjetMutation) AddedQuantite() (r int, exists bool) { + v := m.addquantite + if v == nil { + return + } + return *v, true +} + +// ResetQuantite resets all changes to the "quantite" field. +func (m *ObjetMutation) ResetQuantite() { + m.quantite = nil + m.addquantite = nil +} + +// SetPrixAchat sets the "prix_achat" field. +func (m *ObjetMutation) SetPrixAchat(f float64) { + m.prix_achat = &f + m.addprix_achat = nil +} + +// PrixAchat returns the value of the "prix_achat" field in the mutation. +func (m *ObjetMutation) PrixAchat() (r float64, exists bool) { + v := m.prix_achat + if v == nil { + return + } + return *v, true +} + +// OldPrixAchat returns the old "prix_achat" field's value of the Objet entity. +// If the Objet object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ObjetMutation) OldPrixAchat(ctx context.Context) (v *float64, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldPrixAchat is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldPrixAchat requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldPrixAchat: %w", err) + } + return oldValue.PrixAchat, nil +} + +// AddPrixAchat adds f to the "prix_achat" field. +func (m *ObjetMutation) AddPrixAchat(f float64) { + if m.addprix_achat != nil { + *m.addprix_achat += f + } else { + m.addprix_achat = &f + } +} + +// AddedPrixAchat returns the value that was added to the "prix_achat" field in this mutation. +func (m *ObjetMutation) AddedPrixAchat() (r float64, exists bool) { + v := m.addprix_achat + if v == nil { + return + } + return *v, true +} + +// ClearPrixAchat clears the value of the "prix_achat" field. +func (m *ObjetMutation) ClearPrixAchat() { + m.prix_achat = nil + m.addprix_achat = nil + m.clearedFields[objet.FieldPrixAchat] = struct{}{} +} + +// PrixAchatCleared returns if the "prix_achat" field was cleared in this mutation. +func (m *ObjetMutation) PrixAchatCleared() bool { + _, ok := m.clearedFields[objet.FieldPrixAchat] + return ok +} + +// ResetPrixAchat resets all changes to the "prix_achat" field. +func (m *ObjetMutation) ResetPrixAchat() { + m.prix_achat = nil + m.addprix_achat = nil + delete(m.clearedFields, objet.FieldPrixAchat) +} + +// SetDateAchat sets the "date_achat" field. +func (m *ObjetMutation) SetDateAchat(t time.Time) { + m.date_achat = &t +} + +// DateAchat returns the value of the "date_achat" field in the mutation. +func (m *ObjetMutation) DateAchat() (r time.Time, exists bool) { + v := m.date_achat + if v == nil { + return + } + return *v, true +} + +// OldDateAchat returns the old "date_achat" field's value of the Objet entity. +// If the Objet object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ObjetMutation) OldDateAchat(ctx context.Context) (v *time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldDateAchat is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldDateAchat requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldDateAchat: %w", err) + } + return oldValue.DateAchat, nil +} + +// ClearDateAchat clears the value of the "date_achat" field. +func (m *ObjetMutation) ClearDateAchat() { + m.date_achat = nil + m.clearedFields[objet.FieldDateAchat] = struct{}{} +} + +// DateAchatCleared returns if the "date_achat" field was cleared in this mutation. +func (m *ObjetMutation) DateAchatCleared() bool { + _, ok := m.clearedFields[objet.FieldDateAchat] + return ok +} + +// ResetDateAchat resets all changes to the "date_achat" field. +func (m *ObjetMutation) ResetDateAchat() { + m.date_achat = nil + delete(m.clearedFields, objet.FieldDateAchat) +} + +// SetBoutique sets the "boutique" field. +func (m *ObjetMutation) SetBoutique(s string) { + m.boutique = &s +} + +// Boutique returns the value of the "boutique" field in the mutation. +func (m *ObjetMutation) Boutique() (r string, exists bool) { + v := m.boutique + if v == nil { + return + } + return *v, true +} + +// OldBoutique returns the old "boutique" field's value of the Objet entity. +// If the Objet object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ObjetMutation) OldBoutique(ctx context.Context) (v *string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldBoutique is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldBoutique requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldBoutique: %w", err) + } + return oldValue.Boutique, nil +} + +// ClearBoutique clears the value of the "boutique" field. +func (m *ObjetMutation) ClearBoutique() { + m.boutique = nil + m.clearedFields[objet.FieldBoutique] = struct{}{} +} + +// BoutiqueCleared returns if the "boutique" field was cleared in this mutation. +func (m *ObjetMutation) BoutiqueCleared() bool { + _, ok := m.clearedFields[objet.FieldBoutique] + return ok +} + +// ResetBoutique resets all changes to the "boutique" field. +func (m *ObjetMutation) ResetBoutique() { + m.boutique = nil + delete(m.clearedFields, objet.FieldBoutique) +} + +// SetNumeroSerie sets the "numero_serie" field. +func (m *ObjetMutation) SetNumeroSerie(s string) { + m.numero_serie = &s +} + +// NumeroSerie returns the value of the "numero_serie" field in the mutation. +func (m *ObjetMutation) NumeroSerie() (r string, exists bool) { + v := m.numero_serie + if v == nil { + return + } + return *v, true +} + +// OldNumeroSerie returns the old "numero_serie" field's value of the Objet entity. +// If the Objet object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ObjetMutation) OldNumeroSerie(ctx context.Context) (v *string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldNumeroSerie is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldNumeroSerie requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldNumeroSerie: %w", err) + } + return oldValue.NumeroSerie, nil +} + +// ClearNumeroSerie clears the value of the "numero_serie" field. +func (m *ObjetMutation) ClearNumeroSerie() { + m.numero_serie = nil + m.clearedFields[objet.FieldNumeroSerie] = struct{}{} +} + +// NumeroSerieCleared returns if the "numero_serie" field was cleared in this mutation. +func (m *ObjetMutation) NumeroSerieCleared() bool { + _, ok := m.clearedFields[objet.FieldNumeroSerie] + return ok +} + +// ResetNumeroSerie resets all changes to the "numero_serie" field. +func (m *ObjetMutation) ResetNumeroSerie() { + m.numero_serie = nil + delete(m.clearedFields, objet.FieldNumeroSerie) +} + +// SetNumeroModele sets the "numero_modele" field. +func (m *ObjetMutation) SetNumeroModele(s string) { + m.numero_modele = &s +} + +// NumeroModele returns the value of the "numero_modele" field in the mutation. +func (m *ObjetMutation) NumeroModele() (r string, exists bool) { + v := m.numero_modele + if v == nil { + return + } + return *v, true +} + +// OldNumeroModele returns the old "numero_modele" field's value of the Objet entity. +// If the Objet object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ObjetMutation) OldNumeroModele(ctx context.Context) (v *string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldNumeroModele is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldNumeroModele requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldNumeroModele: %w", err) + } + return oldValue.NumeroModele, nil +} + +// ClearNumeroModele clears the value of the "numero_modele" field. +func (m *ObjetMutation) ClearNumeroModele() { + m.numero_modele = nil + m.clearedFields[objet.FieldNumeroModele] = struct{}{} +} + +// NumeroModeleCleared returns if the "numero_modele" field was cleared in this mutation. +func (m *ObjetMutation) NumeroModeleCleared() bool { + _, ok := m.clearedFields[objet.FieldNumeroModele] + return ok +} + +// ResetNumeroModele resets all changes to the "numero_modele" field. +func (m *ObjetMutation) ResetNumeroModele() { + m.numero_modele = nil + delete(m.clearedFields, objet.FieldNumeroModele) +} + +// SetFabricant sets the "fabricant" field. +func (m *ObjetMutation) SetFabricant(s string) { + m.fabricant = &s +} + +// Fabricant returns the value of the "fabricant" field in the mutation. +func (m *ObjetMutation) Fabricant() (r string, exists bool) { + v := m.fabricant + if v == nil { + return + } + return *v, true +} + +// OldFabricant returns the old "fabricant" field's value of the Objet entity. +// If the Objet object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ObjetMutation) OldFabricant(ctx context.Context) (v *string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldFabricant is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldFabricant requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldFabricant: %w", err) + } + return oldValue.Fabricant, nil +} + +// ClearFabricant clears the value of the "fabricant" field. +func (m *ObjetMutation) ClearFabricant() { + m.fabricant = nil + m.clearedFields[objet.FieldFabricant] = struct{}{} +} + +// FabricantCleared returns if the "fabricant" field was cleared in this mutation. +func (m *ObjetMutation) FabricantCleared() bool { + _, ok := m.clearedFields[objet.FieldFabricant] + return ok +} + +// ResetFabricant resets all changes to the "fabricant" field. +func (m *ObjetMutation) ResetFabricant() { + m.fabricant = nil + delete(m.clearedFields, objet.FieldFabricant) +} + +// SetStatut sets the "statut" field. +func (m *ObjetMutation) SetStatut(o objet.Statut) { + m.statut = &o +} + +// Statut returns the value of the "statut" field in the mutation. +func (m *ObjetMutation) Statut() (r objet.Statut, exists bool) { + v := m.statut + if v == nil { + return + } + return *v, true +} + +// OldStatut returns the old "statut" field's value of the Objet entity. +// If the Objet object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ObjetMutation) OldStatut(ctx context.Context) (v objet.Statut, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldStatut is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldStatut requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldStatut: %w", err) + } + return oldValue.Statut, nil +} + +// ResetStatut resets all changes to the "statut" field. +func (m *ObjetMutation) ResetStatut() { + m.statut = nil +} + +// SetCaracteristiques sets the "caracteristiques" field. +func (m *ObjetMutation) SetCaracteristiques(value map[string]interface{}) { + m.caracteristiques = &value +} + +// Caracteristiques returns the value of the "caracteristiques" field in the mutation. +func (m *ObjetMutation) Caracteristiques() (r map[string]interface{}, exists bool) { + v := m.caracteristiques + if v == nil { + return + } + return *v, true +} + +// OldCaracteristiques returns the old "caracteristiques" field's value of the Objet entity. +// If the Objet object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ObjetMutation) OldCaracteristiques(ctx context.Context) (v map[string]interface{}, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldCaracteristiques is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldCaracteristiques requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldCaracteristiques: %w", err) + } + return oldValue.Caracteristiques, nil +} + +// ClearCaracteristiques clears the value of the "caracteristiques" field. +func (m *ObjetMutation) ClearCaracteristiques() { + m.caracteristiques = nil + m.clearedFields[objet.FieldCaracteristiques] = struct{}{} +} + +// CaracteristiquesCleared returns if the "caracteristiques" field was cleared in this mutation. +func (m *ObjetMutation) CaracteristiquesCleared() bool { + _, ok := m.clearedFields[objet.FieldCaracteristiques] + return ok +} + +// ResetCaracteristiques resets all changes to the "caracteristiques" field. +func (m *ObjetMutation) ResetCaracteristiques() { + m.caracteristiques = nil + delete(m.clearedFields, objet.FieldCaracteristiques) +} + +// SetCreatedAt sets the "created_at" field. +func (m *ObjetMutation) SetCreatedAt(t time.Time) { + m.created_at = &t +} + +// CreatedAt returns the value of the "created_at" field in the mutation. +func (m *ObjetMutation) CreatedAt() (r time.Time, exists bool) { + v := m.created_at + if v == nil { + return + } + return *v, true +} + +// OldCreatedAt returns the old "created_at" field's value of the Objet entity. +// If the Objet object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ObjetMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldCreatedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) + } + return oldValue.CreatedAt, nil +} + +// ResetCreatedAt resets all changes to the "created_at" field. +func (m *ObjetMutation) ResetCreatedAt() { + m.created_at = nil +} + +// SetUpdatedAt sets the "updated_at" field. +func (m *ObjetMutation) SetUpdatedAt(t time.Time) { + m.updated_at = &t +} + +// UpdatedAt returns the value of the "updated_at" field in the mutation. +func (m *ObjetMutation) UpdatedAt() (r time.Time, exists bool) { + v := m.updated_at + if v == nil { + return + } + return *v, true +} + +// OldUpdatedAt returns the old "updated_at" field's value of the Objet entity. +// If the Objet object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ObjetMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldUpdatedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) + } + return oldValue.UpdatedAt, nil +} + +// ResetUpdatedAt resets all changes to the "updated_at" field. +func (m *ObjetMutation) ResetUpdatedAt() { + m.updated_at = nil +} + +// AddLiensEmplacementIDs adds the "liens_emplacements" edge to the LienObjetEmplacement entity by ids. +func (m *ObjetMutation) AddLiensEmplacementIDs(ids ...uuid.UUID) { + if m.liens_emplacements == nil { + m.liens_emplacements = make(map[uuid.UUID]struct{}) + } + for i := range ids { + m.liens_emplacements[ids[i]] = struct{}{} + } +} + +// ClearLiensEmplacements clears the "liens_emplacements" edge to the LienObjetEmplacement entity. +func (m *ObjetMutation) ClearLiensEmplacements() { + m.clearedliens_emplacements = true +} + +// LiensEmplacementsCleared reports if the "liens_emplacements" edge to the LienObjetEmplacement entity was cleared. +func (m *ObjetMutation) LiensEmplacementsCleared() bool { + return m.clearedliens_emplacements +} + +// RemoveLiensEmplacementIDs removes the "liens_emplacements" edge to the LienObjetEmplacement entity by IDs. +func (m *ObjetMutation) RemoveLiensEmplacementIDs(ids ...uuid.UUID) { + if m.removedliens_emplacements == nil { + m.removedliens_emplacements = make(map[uuid.UUID]struct{}) + } + for i := range ids { + delete(m.liens_emplacements, ids[i]) + m.removedliens_emplacements[ids[i]] = struct{}{} + } +} + +// RemovedLiensEmplacements returns the removed IDs of the "liens_emplacements" edge to the LienObjetEmplacement entity. +func (m *ObjetMutation) RemovedLiensEmplacementsIDs() (ids []uuid.UUID) { + for id := range m.removedliens_emplacements { + ids = append(ids, id) + } + return +} + +// LiensEmplacementsIDs returns the "liens_emplacements" edge IDs in the mutation. +func (m *ObjetMutation) LiensEmplacementsIDs() (ids []uuid.UUID) { + for id := range m.liens_emplacements { + ids = append(ids, id) + } + return +} + +// ResetLiensEmplacements resets all changes to the "liens_emplacements" edge. +func (m *ObjetMutation) ResetLiensEmplacements() { + m.liens_emplacements = nil + m.clearedliens_emplacements = false + m.removedliens_emplacements = nil +} + +// AddChampsPersonnaliseIDs adds the "champs_personnalises" edge to the ChampPersonnalise entity by ids. +func (m *ObjetMutation) AddChampsPersonnaliseIDs(ids ...uuid.UUID) { + if m.champs_personnalises == nil { + m.champs_personnalises = make(map[uuid.UUID]struct{}) + } + for i := range ids { + m.champs_personnalises[ids[i]] = struct{}{} + } +} + +// ClearChampsPersonnalises clears the "champs_personnalises" edge to the ChampPersonnalise entity. +func (m *ObjetMutation) ClearChampsPersonnalises() { + m.clearedchamps_personnalises = true +} + +// ChampsPersonnalisesCleared reports if the "champs_personnalises" edge to the ChampPersonnalise entity was cleared. +func (m *ObjetMutation) ChampsPersonnalisesCleared() bool { + return m.clearedchamps_personnalises +} + +// RemoveChampsPersonnaliseIDs removes the "champs_personnalises" edge to the ChampPersonnalise entity by IDs. +func (m *ObjetMutation) RemoveChampsPersonnaliseIDs(ids ...uuid.UUID) { + if m.removedchamps_personnalises == nil { + m.removedchamps_personnalises = make(map[uuid.UUID]struct{}) + } + for i := range ids { + delete(m.champs_personnalises, ids[i]) + m.removedchamps_personnalises[ids[i]] = struct{}{} + } +} + +// RemovedChampsPersonnalises returns the removed IDs of the "champs_personnalises" edge to the ChampPersonnalise entity. +func (m *ObjetMutation) RemovedChampsPersonnalisesIDs() (ids []uuid.UUID) { + for id := range m.removedchamps_personnalises { + ids = append(ids, id) + } + return +} + +// ChampsPersonnalisesIDs returns the "champs_personnalises" edge IDs in the mutation. +func (m *ObjetMutation) ChampsPersonnalisesIDs() (ids []uuid.UUID) { + for id := range m.champs_personnalises { + ids = append(ids, id) + } + return +} + +// ResetChampsPersonnalises resets all changes to the "champs_personnalises" edge. +func (m *ObjetMutation) ResetChampsPersonnalises() { + m.champs_personnalises = nil + m.clearedchamps_personnalises = false + m.removedchamps_personnalises = nil +} + +// AddPiecesJointeIDs adds the "pieces_jointes" edge to the PieceJointe entity by ids. +func (m *ObjetMutation) AddPiecesJointeIDs(ids ...uuid.UUID) { + if m.pieces_jointes == nil { + m.pieces_jointes = make(map[uuid.UUID]struct{}) + } + for i := range ids { + m.pieces_jointes[ids[i]] = struct{}{} + } +} + +// ClearPiecesJointes clears the "pieces_jointes" edge to the PieceJointe entity. +func (m *ObjetMutation) ClearPiecesJointes() { + m.clearedpieces_jointes = true +} + +// PiecesJointesCleared reports if the "pieces_jointes" edge to the PieceJointe entity was cleared. +func (m *ObjetMutation) PiecesJointesCleared() bool { + return m.clearedpieces_jointes +} + +// RemovePiecesJointeIDs removes the "pieces_jointes" edge to the PieceJointe entity by IDs. +func (m *ObjetMutation) RemovePiecesJointeIDs(ids ...uuid.UUID) { + if m.removedpieces_jointes == nil { + m.removedpieces_jointes = make(map[uuid.UUID]struct{}) + } + for i := range ids { + delete(m.pieces_jointes, ids[i]) + m.removedpieces_jointes[ids[i]] = struct{}{} + } +} + +// RemovedPiecesJointes returns the removed IDs of the "pieces_jointes" edge to the PieceJointe entity. +func (m *ObjetMutation) RemovedPiecesJointesIDs() (ids []uuid.UUID) { + for id := range m.removedpieces_jointes { + ids = append(ids, id) + } + return +} + +// PiecesJointesIDs returns the "pieces_jointes" edge IDs in the mutation. +func (m *ObjetMutation) PiecesJointesIDs() (ids []uuid.UUID) { + for id := range m.pieces_jointes { + ids = append(ids, id) + } + return +} + +// ResetPiecesJointes resets all changes to the "pieces_jointes" edge. +func (m *ObjetMutation) ResetPiecesJointes() { + m.pieces_jointes = nil + m.clearedpieces_jointes = false + m.removedpieces_jointes = nil +} + +// Where appends a list predicates to the ObjetMutation builder. +func (m *ObjetMutation) Where(ps ...predicate.Objet) { + m.predicates = append(m.predicates, ps...) +} + +// WhereP appends storage-level predicates to the ObjetMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *ObjetMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.Objet, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + +// Op returns the operation name. +func (m *ObjetMutation) Op() Op { + return m.op +} + +// SetOp allows setting the mutation operation. +func (m *ObjetMutation) SetOp(op Op) { + m.op = op +} + +// Type returns the node type of this mutation (Objet). +func (m *ObjetMutation) Type() string { + return m.typ +} + +// Fields returns all fields that were changed during this mutation. Note that in +// order to get all numeric fields that were incremented/decremented, call +// AddedFields(). +func (m *ObjetMutation) Fields() []string { + fields := make([]string, 0, 13) + if m.nom != nil { + fields = append(fields, objet.FieldNom) + } + if m.description != nil { + fields = append(fields, objet.FieldDescription) + } + if m.quantite != nil { + fields = append(fields, objet.FieldQuantite) + } + if m.prix_achat != nil { + fields = append(fields, objet.FieldPrixAchat) + } + if m.date_achat != nil { + fields = append(fields, objet.FieldDateAchat) + } + if m.boutique != nil { + fields = append(fields, objet.FieldBoutique) + } + if m.numero_serie != nil { + fields = append(fields, objet.FieldNumeroSerie) + } + if m.numero_modele != nil { + fields = append(fields, objet.FieldNumeroModele) + } + if m.fabricant != nil { + fields = append(fields, objet.FieldFabricant) + } + if m.statut != nil { + fields = append(fields, objet.FieldStatut) + } + if m.caracteristiques != nil { + fields = append(fields, objet.FieldCaracteristiques) + } + if m.created_at != nil { + fields = append(fields, objet.FieldCreatedAt) + } + if m.updated_at != nil { + fields = append(fields, objet.FieldUpdatedAt) + } + return fields +} + +// Field returns the value of a field with the given name. The second boolean +// return value indicates that this field was not set, or was not defined in the +// schema. +func (m *ObjetMutation) Field(name string) (ent.Value, bool) { + switch name { + case objet.FieldNom: + return m.Nom() + case objet.FieldDescription: + return m.Description() + case objet.FieldQuantite: + return m.Quantite() + case objet.FieldPrixAchat: + return m.PrixAchat() + case objet.FieldDateAchat: + return m.DateAchat() + case objet.FieldBoutique: + return m.Boutique() + case objet.FieldNumeroSerie: + return m.NumeroSerie() + case objet.FieldNumeroModele: + return m.NumeroModele() + case objet.FieldFabricant: + return m.Fabricant() + case objet.FieldStatut: + return m.Statut() + case objet.FieldCaracteristiques: + return m.Caracteristiques() + case objet.FieldCreatedAt: + return m.CreatedAt() + case objet.FieldUpdatedAt: + return m.UpdatedAt() + } + return nil, false +} + +// OldField returns the old value of the field from the database. An error is +// returned if the mutation operation is not UpdateOne, or the query to the +// database failed. +func (m *ObjetMutation) OldField(ctx context.Context, name string) (ent.Value, error) { + switch name { + case objet.FieldNom: + return m.OldNom(ctx) + case objet.FieldDescription: + return m.OldDescription(ctx) + case objet.FieldQuantite: + return m.OldQuantite(ctx) + case objet.FieldPrixAchat: + return m.OldPrixAchat(ctx) + case objet.FieldDateAchat: + return m.OldDateAchat(ctx) + case objet.FieldBoutique: + return m.OldBoutique(ctx) + case objet.FieldNumeroSerie: + return m.OldNumeroSerie(ctx) + case objet.FieldNumeroModele: + return m.OldNumeroModele(ctx) + case objet.FieldFabricant: + return m.OldFabricant(ctx) + case objet.FieldStatut: + return m.OldStatut(ctx) + case objet.FieldCaracteristiques: + return m.OldCaracteristiques(ctx) + case objet.FieldCreatedAt: + return m.OldCreatedAt(ctx) + case objet.FieldUpdatedAt: + return m.OldUpdatedAt(ctx) + } + return nil, fmt.Errorf("unknown Objet field %s", name) +} + +// SetField sets the value of a field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *ObjetMutation) SetField(name string, value ent.Value) error { + switch name { + case objet.FieldNom: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetNom(v) + return nil + case objet.FieldDescription: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetDescription(v) + return nil + case objet.FieldQuantite: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetQuantite(v) + return nil + case objet.FieldPrixAchat: + v, ok := value.(float64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetPrixAchat(v) + return nil + case objet.FieldDateAchat: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetDateAchat(v) + return nil + case objet.FieldBoutique: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetBoutique(v) + return nil + case objet.FieldNumeroSerie: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetNumeroSerie(v) + return nil + case objet.FieldNumeroModele: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetNumeroModele(v) + return nil + case objet.FieldFabricant: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetFabricant(v) + return nil + case objet.FieldStatut: + v, ok := value.(objet.Statut) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetStatut(v) + return nil + case objet.FieldCaracteristiques: + v, ok := value.(map[string]interface{}) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetCaracteristiques(v) + return nil + case objet.FieldCreatedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetCreatedAt(v) + return nil + case objet.FieldUpdatedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetUpdatedAt(v) + return nil + } + return fmt.Errorf("unknown Objet field %s", name) +} + +// AddedFields returns all numeric fields that were incremented/decremented during +// this mutation. +func (m *ObjetMutation) AddedFields() []string { + var fields []string + if m.addquantite != nil { + fields = append(fields, objet.FieldQuantite) + } + if m.addprix_achat != nil { + fields = append(fields, objet.FieldPrixAchat) + } + return fields +} + +// AddedField returns the numeric value that was incremented/decremented on a field +// with the given name. The second boolean return value indicates that this field +// was not set, or was not defined in the schema. +func (m *ObjetMutation) AddedField(name string) (ent.Value, bool) { + switch name { + case objet.FieldQuantite: + return m.AddedQuantite() + case objet.FieldPrixAchat: + return m.AddedPrixAchat() + } + return nil, false +} + +// AddField adds the value to the field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *ObjetMutation) AddField(name string, value ent.Value) error { + switch name { + case objet.FieldQuantite: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddQuantite(v) + return nil + case objet.FieldPrixAchat: + v, ok := value.(float64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddPrixAchat(v) + return nil + } + return fmt.Errorf("unknown Objet numeric field %s", name) +} + +// ClearedFields returns all nullable fields that were cleared during this +// mutation. +func (m *ObjetMutation) ClearedFields() []string { + var fields []string + if m.FieldCleared(objet.FieldDescription) { + fields = append(fields, objet.FieldDescription) + } + if m.FieldCleared(objet.FieldPrixAchat) { + fields = append(fields, objet.FieldPrixAchat) + } + if m.FieldCleared(objet.FieldDateAchat) { + fields = append(fields, objet.FieldDateAchat) + } + if m.FieldCleared(objet.FieldBoutique) { + fields = append(fields, objet.FieldBoutique) + } + if m.FieldCleared(objet.FieldNumeroSerie) { + fields = append(fields, objet.FieldNumeroSerie) + } + if m.FieldCleared(objet.FieldNumeroModele) { + fields = append(fields, objet.FieldNumeroModele) + } + if m.FieldCleared(objet.FieldFabricant) { + fields = append(fields, objet.FieldFabricant) + } + if m.FieldCleared(objet.FieldCaracteristiques) { + fields = append(fields, objet.FieldCaracteristiques) + } + return fields +} + +// FieldCleared returns a boolean indicating if a field with the given name was +// cleared in this mutation. +func (m *ObjetMutation) FieldCleared(name string) bool { + _, ok := m.clearedFields[name] + return ok +} + +// ClearField clears the value of the field with the given name. It returns an +// error if the field is not defined in the schema. +func (m *ObjetMutation) ClearField(name string) error { + switch name { + case objet.FieldDescription: + m.ClearDescription() + return nil + case objet.FieldPrixAchat: + m.ClearPrixAchat() + return nil + case objet.FieldDateAchat: + m.ClearDateAchat() + return nil + case objet.FieldBoutique: + m.ClearBoutique() + return nil + case objet.FieldNumeroSerie: + m.ClearNumeroSerie() + return nil + case objet.FieldNumeroModele: + m.ClearNumeroModele() + return nil + case objet.FieldFabricant: + m.ClearFabricant() + return nil + case objet.FieldCaracteristiques: + m.ClearCaracteristiques() + return nil + } + return fmt.Errorf("unknown Objet nullable field %s", name) +} + +// ResetField resets all changes in the mutation for the field with the given name. +// It returns an error if the field is not defined in the schema. +func (m *ObjetMutation) ResetField(name string) error { + switch name { + case objet.FieldNom: + m.ResetNom() + return nil + case objet.FieldDescription: + m.ResetDescription() + return nil + case objet.FieldQuantite: + m.ResetQuantite() + return nil + case objet.FieldPrixAchat: + m.ResetPrixAchat() + return nil + case objet.FieldDateAchat: + m.ResetDateAchat() + return nil + case objet.FieldBoutique: + m.ResetBoutique() + return nil + case objet.FieldNumeroSerie: + m.ResetNumeroSerie() + return nil + case objet.FieldNumeroModele: + m.ResetNumeroModele() + return nil + case objet.FieldFabricant: + m.ResetFabricant() + return nil + case objet.FieldStatut: + m.ResetStatut() + return nil + case objet.FieldCaracteristiques: + m.ResetCaracteristiques() + return nil + case objet.FieldCreatedAt: + m.ResetCreatedAt() + return nil + case objet.FieldUpdatedAt: + m.ResetUpdatedAt() + return nil + } + return fmt.Errorf("unknown Objet field %s", name) +} + +// AddedEdges returns all edge names that were set/added in this mutation. +func (m *ObjetMutation) AddedEdges() []string { + edges := make([]string, 0, 3) + if m.liens_emplacements != nil { + edges = append(edges, objet.EdgeLiensEmplacements) + } + if m.champs_personnalises != nil { + edges = append(edges, objet.EdgeChampsPersonnalises) + } + if m.pieces_jointes != nil { + edges = append(edges, objet.EdgePiecesJointes) + } + return edges +} + +// AddedIDs returns all IDs (to other nodes) that were added for the given edge +// name in this mutation. +func (m *ObjetMutation) AddedIDs(name string) []ent.Value { + switch name { + case objet.EdgeLiensEmplacements: + ids := make([]ent.Value, 0, len(m.liens_emplacements)) + for id := range m.liens_emplacements { + ids = append(ids, id) + } + return ids + case objet.EdgeChampsPersonnalises: + ids := make([]ent.Value, 0, len(m.champs_personnalises)) + for id := range m.champs_personnalises { + ids = append(ids, id) + } + return ids + case objet.EdgePiecesJointes: + ids := make([]ent.Value, 0, len(m.pieces_jointes)) + for id := range m.pieces_jointes { + ids = append(ids, id) + } + return ids + } + return nil +} + +// RemovedEdges returns all edge names that were removed in this mutation. +func (m *ObjetMutation) RemovedEdges() []string { + edges := make([]string, 0, 3) + if m.removedliens_emplacements != nil { + edges = append(edges, objet.EdgeLiensEmplacements) + } + if m.removedchamps_personnalises != nil { + edges = append(edges, objet.EdgeChampsPersonnalises) + } + if m.removedpieces_jointes != nil { + edges = append(edges, objet.EdgePiecesJointes) + } + return edges +} + +// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with +// the given name in this mutation. +func (m *ObjetMutation) RemovedIDs(name string) []ent.Value { + switch name { + case objet.EdgeLiensEmplacements: + ids := make([]ent.Value, 0, len(m.removedliens_emplacements)) + for id := range m.removedliens_emplacements { + ids = append(ids, id) + } + return ids + case objet.EdgeChampsPersonnalises: + ids := make([]ent.Value, 0, len(m.removedchamps_personnalises)) + for id := range m.removedchamps_personnalises { + ids = append(ids, id) + } + return ids + case objet.EdgePiecesJointes: + ids := make([]ent.Value, 0, len(m.removedpieces_jointes)) + for id := range m.removedpieces_jointes { + ids = append(ids, id) + } + return ids + } + return nil +} + +// ClearedEdges returns all edge names that were cleared in this mutation. +func (m *ObjetMutation) ClearedEdges() []string { + edges := make([]string, 0, 3) + if m.clearedliens_emplacements { + edges = append(edges, objet.EdgeLiensEmplacements) + } + if m.clearedchamps_personnalises { + edges = append(edges, objet.EdgeChampsPersonnalises) + } + if m.clearedpieces_jointes { + edges = append(edges, objet.EdgePiecesJointes) + } + return edges +} + +// EdgeCleared returns a boolean which indicates if the edge with the given name +// was cleared in this mutation. +func (m *ObjetMutation) EdgeCleared(name string) bool { + switch name { + case objet.EdgeLiensEmplacements: + return m.clearedliens_emplacements + case objet.EdgeChampsPersonnalises: + return m.clearedchamps_personnalises + case objet.EdgePiecesJointes: + return m.clearedpieces_jointes + } + return false +} + +// ClearEdge clears the value of the edge with the given name. It returns an error +// if that edge is not defined in the schema. +func (m *ObjetMutation) ClearEdge(name string) error { + switch name { + } + return fmt.Errorf("unknown Objet unique edge %s", name) +} + +// ResetEdge resets all changes to the edge with the given name in this mutation. +// It returns an error if the edge is not defined in the schema. +func (m *ObjetMutation) ResetEdge(name string) error { + switch name { + case objet.EdgeLiensEmplacements: + m.ResetLiensEmplacements() + return nil + case objet.EdgeChampsPersonnalises: + m.ResetChampsPersonnalises() + return nil + case objet.EdgePiecesJointes: + m.ResetPiecesJointes() + return nil + } + return fmt.Errorf("unknown Objet edge %s", name) +} + +// PieceJointeMutation represents an operation that mutates the PieceJointe nodes in the graph. +type PieceJointeMutation struct { + config + op Op + typ string + id *uuid.UUID + nom_fichier *string + chemin *string + type_mime *string + est_principale *bool + categorie *piecejointe.Categorie + created_at *time.Time + updated_at *time.Time + clearedFields map[string]struct{} + objet *uuid.UUID + clearedobjet bool + done bool + oldValue func(context.Context) (*PieceJointe, error) + predicates []predicate.PieceJointe +} + +var _ ent.Mutation = (*PieceJointeMutation)(nil) + +// piecejointeOption allows management of the mutation configuration using functional options. +type piecejointeOption func(*PieceJointeMutation) + +// newPieceJointeMutation creates new mutation for the PieceJointe entity. +func newPieceJointeMutation(c config, op Op, opts ...piecejointeOption) *PieceJointeMutation { + m := &PieceJointeMutation{ + config: c, + op: op, + typ: TypePieceJointe, + clearedFields: make(map[string]struct{}), + } + for _, opt := range opts { + opt(m) + } + return m +} + +// withPieceJointeID sets the ID field of the mutation. +func withPieceJointeID(id uuid.UUID) piecejointeOption { + return func(m *PieceJointeMutation) { + var ( + err error + once sync.Once + value *PieceJointe + ) + m.oldValue = func(ctx context.Context) (*PieceJointe, error) { + once.Do(func() { + if m.done { + err = errors.New("querying old values post mutation is not allowed") + } else { + value, err = m.Client().PieceJointe.Get(ctx, id) + } + }) + return value, err + } + m.id = &id + } +} + +// withPieceJointe sets the old PieceJointe of the mutation. +func withPieceJointe(node *PieceJointe) piecejointeOption { + return func(m *PieceJointeMutation) { + m.oldValue = func(context.Context) (*PieceJointe, error) { + return node, nil + } + m.id = &node.ID + } +} + +// Client returns a new `ent.Client` from the mutation. If the mutation was +// executed in a transaction (ent.Tx), a transactional client is returned. +func (m PieceJointeMutation) Client() *Client { + client := &Client{config: m.config} + client.init() + return client +} + +// Tx returns an `ent.Tx` for mutations that were executed in transactions; +// it returns an error otherwise. +func (m PieceJointeMutation) Tx() (*Tx, error) { + if _, ok := m.driver.(*txDriver); !ok { + return nil, errors.New("ent: mutation is not running in a transaction") + } + tx := &Tx{config: m.config} + tx.init() + return tx, nil +} + +// SetID sets the value of the id field. Note that this +// operation is only accepted on creation of PieceJointe entities. +func (m *PieceJointeMutation) SetID(id uuid.UUID) { + m.id = &id +} + +// ID returns the ID value in the mutation. Note that the ID is only available +// if it was provided to the builder or after it was returned from the database. +func (m *PieceJointeMutation) ID() (id uuid.UUID, exists bool) { + if m.id == nil { + return + } + return *m.id, true +} + +// IDs queries the database and returns the entity ids that match the mutation's predicate. +// That means, if the mutation is applied within a transaction with an isolation level such +// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated +// or updated by the mutation. +func (m *PieceJointeMutation) IDs(ctx context.Context) ([]uuid.UUID, error) { + switch { + case m.op.Is(OpUpdateOne | OpDeleteOne): + id, exists := m.ID() + if exists { + return []uuid.UUID{id}, nil + } + fallthrough + case m.op.Is(OpUpdate | OpDelete): + return m.Client().PieceJointe.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) + } +} + +// SetObjetID sets the "objet_id" field. +func (m *PieceJointeMutation) SetObjetID(u uuid.UUID) { + m.objet = &u +} + +// ObjetID returns the value of the "objet_id" field in the mutation. +func (m *PieceJointeMutation) ObjetID() (r uuid.UUID, exists bool) { + v := m.objet + if v == nil { + return + } + return *v, true +} + +// OldObjetID returns the old "objet_id" field's value of the PieceJointe entity. +// If the PieceJointe object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *PieceJointeMutation) OldObjetID(ctx context.Context) (v uuid.UUID, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldObjetID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldObjetID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldObjetID: %w", err) + } + return oldValue.ObjetID, nil +} + +// ResetObjetID resets all changes to the "objet_id" field. +func (m *PieceJointeMutation) ResetObjetID() { + m.objet = nil +} + +// SetNomFichier sets the "nom_fichier" field. +func (m *PieceJointeMutation) SetNomFichier(s string) { + m.nom_fichier = &s +} + +// NomFichier returns the value of the "nom_fichier" field in the mutation. +func (m *PieceJointeMutation) NomFichier() (r string, exists bool) { + v := m.nom_fichier + if v == nil { + return + } + return *v, true +} + +// OldNomFichier returns the old "nom_fichier" field's value of the PieceJointe entity. +// If the PieceJointe object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *PieceJointeMutation) OldNomFichier(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldNomFichier is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldNomFichier requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldNomFichier: %w", err) + } + return oldValue.NomFichier, nil +} + +// ResetNomFichier resets all changes to the "nom_fichier" field. +func (m *PieceJointeMutation) ResetNomFichier() { + m.nom_fichier = nil +} + +// SetChemin sets the "chemin" field. +func (m *PieceJointeMutation) SetChemin(s string) { + m.chemin = &s +} + +// Chemin returns the value of the "chemin" field in the mutation. +func (m *PieceJointeMutation) Chemin() (r string, exists bool) { + v := m.chemin + if v == nil { + return + } + return *v, true +} + +// OldChemin returns the old "chemin" field's value of the PieceJointe entity. +// If the PieceJointe object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *PieceJointeMutation) OldChemin(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldChemin is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldChemin requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldChemin: %w", err) + } + return oldValue.Chemin, nil +} + +// ResetChemin resets all changes to the "chemin" field. +func (m *PieceJointeMutation) ResetChemin() { + m.chemin = nil +} + +// SetTypeMime sets the "type_mime" field. +func (m *PieceJointeMutation) SetTypeMime(s string) { + m.type_mime = &s +} + +// TypeMime returns the value of the "type_mime" field in the mutation. +func (m *PieceJointeMutation) TypeMime() (r string, exists bool) { + v := m.type_mime + if v == nil { + return + } + return *v, true +} + +// OldTypeMime returns the old "type_mime" field's value of the PieceJointe entity. +// If the PieceJointe object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *PieceJointeMutation) OldTypeMime(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldTypeMime is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldTypeMime requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldTypeMime: %w", err) + } + return oldValue.TypeMime, nil +} + +// ResetTypeMime resets all changes to the "type_mime" field. +func (m *PieceJointeMutation) ResetTypeMime() { + m.type_mime = nil +} + +// SetEstPrincipale sets the "est_principale" field. +func (m *PieceJointeMutation) SetEstPrincipale(b bool) { + m.est_principale = &b +} + +// EstPrincipale returns the value of the "est_principale" field in the mutation. +func (m *PieceJointeMutation) EstPrincipale() (r bool, exists bool) { + v := m.est_principale + if v == nil { + return + } + return *v, true +} + +// OldEstPrincipale returns the old "est_principale" field's value of the PieceJointe entity. +// If the PieceJointe object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *PieceJointeMutation) OldEstPrincipale(ctx context.Context) (v bool, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldEstPrincipale is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldEstPrincipale requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldEstPrincipale: %w", err) + } + return oldValue.EstPrincipale, nil +} + +// ResetEstPrincipale resets all changes to the "est_principale" field. +func (m *PieceJointeMutation) ResetEstPrincipale() { + m.est_principale = nil +} + +// SetCategorie sets the "categorie" field. +func (m *PieceJointeMutation) SetCategorie(pi piecejointe.Categorie) { + m.categorie = &pi +} + +// Categorie returns the value of the "categorie" field in the mutation. +func (m *PieceJointeMutation) Categorie() (r piecejointe.Categorie, exists bool) { + v := m.categorie + if v == nil { + return + } + return *v, true +} + +// OldCategorie returns the old "categorie" field's value of the PieceJointe entity. +// If the PieceJointe object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *PieceJointeMutation) OldCategorie(ctx context.Context) (v piecejointe.Categorie, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldCategorie is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldCategorie requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldCategorie: %w", err) + } + return oldValue.Categorie, nil +} + +// ResetCategorie resets all changes to the "categorie" field. +func (m *PieceJointeMutation) ResetCategorie() { + m.categorie = nil +} + +// SetCreatedAt sets the "created_at" field. +func (m *PieceJointeMutation) SetCreatedAt(t time.Time) { + m.created_at = &t +} + +// CreatedAt returns the value of the "created_at" field in the mutation. +func (m *PieceJointeMutation) CreatedAt() (r time.Time, exists bool) { + v := m.created_at + if v == nil { + return + } + return *v, true +} + +// OldCreatedAt returns the old "created_at" field's value of the PieceJointe entity. +// If the PieceJointe object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *PieceJointeMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldCreatedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) + } + return oldValue.CreatedAt, nil +} + +// ResetCreatedAt resets all changes to the "created_at" field. +func (m *PieceJointeMutation) ResetCreatedAt() { + m.created_at = nil +} + +// SetUpdatedAt sets the "updated_at" field. +func (m *PieceJointeMutation) SetUpdatedAt(t time.Time) { + m.updated_at = &t +} + +// UpdatedAt returns the value of the "updated_at" field in the mutation. +func (m *PieceJointeMutation) UpdatedAt() (r time.Time, exists bool) { + v := m.updated_at + if v == nil { + return + } + return *v, true +} + +// OldUpdatedAt returns the old "updated_at" field's value of the PieceJointe entity. +// If the PieceJointe object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *PieceJointeMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldUpdatedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) + } + return oldValue.UpdatedAt, nil +} + +// ResetUpdatedAt resets all changes to the "updated_at" field. +func (m *PieceJointeMutation) ResetUpdatedAt() { + m.updated_at = nil +} + +// ClearObjet clears the "objet" edge to the Objet entity. +func (m *PieceJointeMutation) ClearObjet() { + m.clearedobjet = true + m.clearedFields[piecejointe.FieldObjetID] = struct{}{} +} + +// ObjetCleared reports if the "objet" edge to the Objet entity was cleared. +func (m *PieceJointeMutation) ObjetCleared() bool { + return m.clearedobjet +} + +// ObjetIDs returns the "objet" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// ObjetID instead. It exists only for internal usage by the builders. +func (m *PieceJointeMutation) ObjetIDs() (ids []uuid.UUID) { + if id := m.objet; id != nil { + ids = append(ids, *id) + } + return +} + +// ResetObjet resets all changes to the "objet" edge. +func (m *PieceJointeMutation) ResetObjet() { + m.objet = nil + m.clearedobjet = false +} + +// Where appends a list predicates to the PieceJointeMutation builder. +func (m *PieceJointeMutation) Where(ps ...predicate.PieceJointe) { + m.predicates = append(m.predicates, ps...) +} + +// WhereP appends storage-level predicates to the PieceJointeMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *PieceJointeMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.PieceJointe, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + +// Op returns the operation name. +func (m *PieceJointeMutation) Op() Op { + return m.op +} + +// SetOp allows setting the mutation operation. +func (m *PieceJointeMutation) SetOp(op Op) { + m.op = op +} + +// Type returns the node type of this mutation (PieceJointe). +func (m *PieceJointeMutation) Type() string { + return m.typ +} + +// Fields returns all fields that were changed during this mutation. Note that in +// order to get all numeric fields that were incremented/decremented, call +// AddedFields(). +func (m *PieceJointeMutation) Fields() []string { + fields := make([]string, 0, 8) + if m.objet != nil { + fields = append(fields, piecejointe.FieldObjetID) + } + if m.nom_fichier != nil { + fields = append(fields, piecejointe.FieldNomFichier) + } + if m.chemin != nil { + fields = append(fields, piecejointe.FieldChemin) + } + if m.type_mime != nil { + fields = append(fields, piecejointe.FieldTypeMime) + } + if m.est_principale != nil { + fields = append(fields, piecejointe.FieldEstPrincipale) + } + if m.categorie != nil { + fields = append(fields, piecejointe.FieldCategorie) + } + if m.created_at != nil { + fields = append(fields, piecejointe.FieldCreatedAt) + } + if m.updated_at != nil { + fields = append(fields, piecejointe.FieldUpdatedAt) + } + return fields +} + +// Field returns the value of a field with the given name. The second boolean +// return value indicates that this field was not set, or was not defined in the +// schema. +func (m *PieceJointeMutation) Field(name string) (ent.Value, bool) { + switch name { + case piecejointe.FieldObjetID: + return m.ObjetID() + case piecejointe.FieldNomFichier: + return m.NomFichier() + case piecejointe.FieldChemin: + return m.Chemin() + case piecejointe.FieldTypeMime: + return m.TypeMime() + case piecejointe.FieldEstPrincipale: + return m.EstPrincipale() + case piecejointe.FieldCategorie: + return m.Categorie() + case piecejointe.FieldCreatedAt: + return m.CreatedAt() + case piecejointe.FieldUpdatedAt: + return m.UpdatedAt() + } + return nil, false +} + +// OldField returns the old value of the field from the database. An error is +// returned if the mutation operation is not UpdateOne, or the query to the +// database failed. +func (m *PieceJointeMutation) OldField(ctx context.Context, name string) (ent.Value, error) { + switch name { + case piecejointe.FieldObjetID: + return m.OldObjetID(ctx) + case piecejointe.FieldNomFichier: + return m.OldNomFichier(ctx) + case piecejointe.FieldChemin: + return m.OldChemin(ctx) + case piecejointe.FieldTypeMime: + return m.OldTypeMime(ctx) + case piecejointe.FieldEstPrincipale: + return m.OldEstPrincipale(ctx) + case piecejointe.FieldCategorie: + return m.OldCategorie(ctx) + case piecejointe.FieldCreatedAt: + return m.OldCreatedAt(ctx) + case piecejointe.FieldUpdatedAt: + return m.OldUpdatedAt(ctx) + } + return nil, fmt.Errorf("unknown PieceJointe field %s", name) +} + +// SetField sets the value of a field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *PieceJointeMutation) SetField(name string, value ent.Value) error { + switch name { + case piecejointe.FieldObjetID: + v, ok := value.(uuid.UUID) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetObjetID(v) + return nil + case piecejointe.FieldNomFichier: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetNomFichier(v) + return nil + case piecejointe.FieldChemin: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetChemin(v) + return nil + case piecejointe.FieldTypeMime: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetTypeMime(v) + return nil + case piecejointe.FieldEstPrincipale: + v, ok := value.(bool) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetEstPrincipale(v) + return nil + case piecejointe.FieldCategorie: + v, ok := value.(piecejointe.Categorie) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetCategorie(v) + return nil + case piecejointe.FieldCreatedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetCreatedAt(v) + return nil + case piecejointe.FieldUpdatedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetUpdatedAt(v) + return nil + } + return fmt.Errorf("unknown PieceJointe field %s", name) +} + +// AddedFields returns all numeric fields that were incremented/decremented during +// this mutation. +func (m *PieceJointeMutation) AddedFields() []string { + return nil +} + +// AddedField returns the numeric value that was incremented/decremented on a field +// with the given name. The second boolean return value indicates that this field +// was not set, or was not defined in the schema. +func (m *PieceJointeMutation) AddedField(name string) (ent.Value, bool) { + return nil, false +} + +// AddField adds the value to the field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *PieceJointeMutation) AddField(name string, value ent.Value) error { + switch name { + } + return fmt.Errorf("unknown PieceJointe numeric field %s", name) +} + +// ClearedFields returns all nullable fields that were cleared during this +// mutation. +func (m *PieceJointeMutation) ClearedFields() []string { + return nil +} + +// FieldCleared returns a boolean indicating if a field with the given name was +// cleared in this mutation. +func (m *PieceJointeMutation) FieldCleared(name string) bool { + _, ok := m.clearedFields[name] + return ok +} + +// ClearField clears the value of the field with the given name. It returns an +// error if the field is not defined in the schema. +func (m *PieceJointeMutation) ClearField(name string) error { + return fmt.Errorf("unknown PieceJointe nullable field %s", name) +} + +// ResetField resets all changes in the mutation for the field with the given name. +// It returns an error if the field is not defined in the schema. +func (m *PieceJointeMutation) ResetField(name string) error { + switch name { + case piecejointe.FieldObjetID: + m.ResetObjetID() + return nil + case piecejointe.FieldNomFichier: + m.ResetNomFichier() + return nil + case piecejointe.FieldChemin: + m.ResetChemin() + return nil + case piecejointe.FieldTypeMime: + m.ResetTypeMime() + return nil + case piecejointe.FieldEstPrincipale: + m.ResetEstPrincipale() + return nil + case piecejointe.FieldCategorie: + m.ResetCategorie() + return nil + case piecejointe.FieldCreatedAt: + m.ResetCreatedAt() + return nil + case piecejointe.FieldUpdatedAt: + m.ResetUpdatedAt() + return nil + } + return fmt.Errorf("unknown PieceJointe field %s", name) +} + +// AddedEdges returns all edge names that were set/added in this mutation. +func (m *PieceJointeMutation) AddedEdges() []string { + edges := make([]string, 0, 1) + if m.objet != nil { + edges = append(edges, piecejointe.EdgeObjet) + } + return edges +} + +// AddedIDs returns all IDs (to other nodes) that were added for the given edge +// name in this mutation. +func (m *PieceJointeMutation) AddedIDs(name string) []ent.Value { + switch name { + case piecejointe.EdgeObjet: + if id := m.objet; id != nil { + return []ent.Value{*id} + } + } + return nil +} + +// RemovedEdges returns all edge names that were removed in this mutation. +func (m *PieceJointeMutation) RemovedEdges() []string { + edges := make([]string, 0, 1) + return edges +} + +// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with +// the given name in this mutation. +func (m *PieceJointeMutation) RemovedIDs(name string) []ent.Value { + return nil +} + +// ClearedEdges returns all edge names that were cleared in this mutation. +func (m *PieceJointeMutation) ClearedEdges() []string { + edges := make([]string, 0, 1) + if m.clearedobjet { + edges = append(edges, piecejointe.EdgeObjet) + } + return edges +} + +// EdgeCleared returns a boolean which indicates if the edge with the given name +// was cleared in this mutation. +func (m *PieceJointeMutation) EdgeCleared(name string) bool { + switch name { + case piecejointe.EdgeObjet: + return m.clearedobjet + } + return false +} + +// ClearEdge clears the value of the edge with the given name. It returns an error +// if that edge is not defined in the schema. +func (m *PieceJointeMutation) ClearEdge(name string) error { + switch name { + case piecejointe.EdgeObjet: + m.ClearObjet() + return nil + } + return fmt.Errorf("unknown PieceJointe unique edge %s", name) +} + +// ResetEdge resets all changes to the edge with the given name in this mutation. +// It returns an error if the edge is not defined in the schema. +func (m *PieceJointeMutation) ResetEdge(name string) error { + switch name { + case piecejointe.EdgeObjet: + m.ResetObjet() + return nil + } + return fmt.Errorf("unknown PieceJointe edge %s", name) +} diff --git a/backend/internal/data/ent/objet.go b/backend/internal/data/ent/objet.go new file mode 100644 index 0000000..bab9255 --- /dev/null +++ b/backend/internal/data/ent/objet.go @@ -0,0 +1,328 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "encoding/json" + "fmt" + "strings" + "time" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/objet" + "github.com/google/uuid" +) + +// Objet is the model entity for the Objet schema. +type Objet struct { + config `json:"-"` + // ID of the ent. + // Identifiant unique de l'objet + ID uuid.UUID `json:"id,omitempty"` + // Nom de l'objet + Nom string `json:"nom,omitempty"` + // Description libre + Description *string `json:"description,omitempty"` + // Quantite en stock + Quantite int `json:"quantite,omitempty"` + // Prix d'achat + PrixAchat *float64 `json:"prix_achat,omitempty"` + // Date d'achat + DateAchat *time.Time `json:"date_achat,omitempty"` + // Boutique ou fournisseur + Boutique *string `json:"boutique,omitempty"` + // Numero de serie + NumeroSerie *string `json:"numero_serie,omitempty"` + // Numero de modele + NumeroModele *string `json:"numero_modele,omitempty"` + // Fabricant + Fabricant *string `json:"fabricant,omitempty"` + // Statut de l'objet + Statut objet.Statut `json:"statut,omitempty"` + // Caracteristiques personnalisees + Caracteristiques map[string]interface{} `json:"caracteristiques,omitempty"` + // Date de creation + CreatedAt time.Time `json:"created_at,omitempty"` + // Date de derniere mise a jour + UpdatedAt time.Time `json:"updated_at,omitempty"` + // Edges holds the relations/edges for other nodes in the graph. + // The values are being populated by the ObjetQuery when eager-loading is set. + Edges ObjetEdges `json:"edges"` + selectValues sql.SelectValues +} + +// ObjetEdges holds the relations/edges for other nodes in the graph. +type ObjetEdges struct { + // LiensEmplacements holds the value of the liens_emplacements edge. + LiensEmplacements []*LienObjetEmplacement `json:"liens_emplacements,omitempty"` + // ChampsPersonnalises holds the value of the champs_personnalises edge. + ChampsPersonnalises []*ChampPersonnalise `json:"champs_personnalises,omitempty"` + // PiecesJointes holds the value of the pieces_jointes edge. + PiecesJointes []*PieceJointe `json:"pieces_jointes,omitempty"` + // loadedTypes holds the information for reporting if a + // type was loaded (or requested) in eager-loading or not. + loadedTypes [3]bool +} + +// LiensEmplacementsOrErr returns the LiensEmplacements value or an error if the edge +// was not loaded in eager-loading. +func (e ObjetEdges) LiensEmplacementsOrErr() ([]*LienObjetEmplacement, error) { + if e.loadedTypes[0] { + return e.LiensEmplacements, nil + } + return nil, &NotLoadedError{edge: "liens_emplacements"} +} + +// ChampsPersonnalisesOrErr returns the ChampsPersonnalises value or an error if the edge +// was not loaded in eager-loading. +func (e ObjetEdges) ChampsPersonnalisesOrErr() ([]*ChampPersonnalise, error) { + if e.loadedTypes[1] { + return e.ChampsPersonnalises, nil + } + return nil, &NotLoadedError{edge: "champs_personnalises"} +} + +// PiecesJointesOrErr returns the PiecesJointes value or an error if the edge +// was not loaded in eager-loading. +func (e ObjetEdges) PiecesJointesOrErr() ([]*PieceJointe, error) { + if e.loadedTypes[2] { + return e.PiecesJointes, nil + } + return nil, &NotLoadedError{edge: "pieces_jointes"} +} + +// scanValues returns the types for scanning values from sql.Rows. +func (*Objet) scanValues(columns []string) ([]any, error) { + values := make([]any, len(columns)) + for i := range columns { + switch columns[i] { + case objet.FieldCaracteristiques: + values[i] = new([]byte) + case objet.FieldPrixAchat: + values[i] = new(sql.NullFloat64) + case objet.FieldQuantite: + values[i] = new(sql.NullInt64) + case objet.FieldNom, objet.FieldDescription, objet.FieldBoutique, objet.FieldNumeroSerie, objet.FieldNumeroModele, objet.FieldFabricant, objet.FieldStatut: + values[i] = new(sql.NullString) + case objet.FieldDateAchat, objet.FieldCreatedAt, objet.FieldUpdatedAt: + values[i] = new(sql.NullTime) + case objet.FieldID: + values[i] = new(uuid.UUID) + default: + values[i] = new(sql.UnknownType) + } + } + return values, nil +} + +// assignValues assigns the values that were returned from sql.Rows (after scanning) +// to the Objet fields. +func (_m *Objet) assignValues(columns []string, values []any) error { + if m, n := len(values), len(columns); m < n { + return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) + } + for i := range columns { + switch columns[i] { + case objet.FieldID: + if value, ok := values[i].(*uuid.UUID); !ok { + return fmt.Errorf("unexpected type %T for field id", values[i]) + } else if value != nil { + _m.ID = *value + } + case objet.FieldNom: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field nom", values[i]) + } else if value.Valid { + _m.Nom = value.String + } + case objet.FieldDescription: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field description", values[i]) + } else if value.Valid { + _m.Description = new(string) + *_m.Description = value.String + } + case objet.FieldQuantite: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field quantite", values[i]) + } else if value.Valid { + _m.Quantite = int(value.Int64) + } + case objet.FieldPrixAchat: + if value, ok := values[i].(*sql.NullFloat64); !ok { + return fmt.Errorf("unexpected type %T for field prix_achat", values[i]) + } else if value.Valid { + _m.PrixAchat = new(float64) + *_m.PrixAchat = value.Float64 + } + case objet.FieldDateAchat: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field date_achat", values[i]) + } else if value.Valid { + _m.DateAchat = new(time.Time) + *_m.DateAchat = value.Time + } + case objet.FieldBoutique: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field boutique", values[i]) + } else if value.Valid { + _m.Boutique = new(string) + *_m.Boutique = value.String + } + case objet.FieldNumeroSerie: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field numero_serie", values[i]) + } else if value.Valid { + _m.NumeroSerie = new(string) + *_m.NumeroSerie = value.String + } + case objet.FieldNumeroModele: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field numero_modele", values[i]) + } else if value.Valid { + _m.NumeroModele = new(string) + *_m.NumeroModele = value.String + } + case objet.FieldFabricant: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field fabricant", values[i]) + } else if value.Valid { + _m.Fabricant = new(string) + *_m.Fabricant = value.String + } + case objet.FieldStatut: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field statut", values[i]) + } else if value.Valid { + _m.Statut = objet.Statut(value.String) + } + case objet.FieldCaracteristiques: + if value, ok := values[i].(*[]byte); !ok { + return fmt.Errorf("unexpected type %T for field caracteristiques", values[i]) + } else if value != nil && len(*value) > 0 { + if err := json.Unmarshal(*value, &_m.Caracteristiques); err != nil { + return fmt.Errorf("unmarshal field caracteristiques: %w", err) + } + } + case objet.FieldCreatedAt: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field created_at", values[i]) + } else if value.Valid { + _m.CreatedAt = value.Time + } + case objet.FieldUpdatedAt: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field updated_at", values[i]) + } else if value.Valid { + _m.UpdatedAt = value.Time + } + default: + _m.selectValues.Set(columns[i], values[i]) + } + } + return nil +} + +// Value returns the ent.Value that was dynamically selected and assigned to the Objet. +// This includes values selected through modifiers, order, etc. +func (_m *Objet) Value(name string) (ent.Value, error) { + return _m.selectValues.Get(name) +} + +// QueryLiensEmplacements queries the "liens_emplacements" edge of the Objet entity. +func (_m *Objet) QueryLiensEmplacements() *LienObjetEmplacementQuery { + return NewObjetClient(_m.config).QueryLiensEmplacements(_m) +} + +// QueryChampsPersonnalises queries the "champs_personnalises" edge of the Objet entity. +func (_m *Objet) QueryChampsPersonnalises() *ChampPersonnaliseQuery { + return NewObjetClient(_m.config).QueryChampsPersonnalises(_m) +} + +// QueryPiecesJointes queries the "pieces_jointes" edge of the Objet entity. +func (_m *Objet) QueryPiecesJointes() *PieceJointeQuery { + return NewObjetClient(_m.config).QueryPiecesJointes(_m) +} + +// Update returns a builder for updating this Objet. +// Note that you need to call Objet.Unwrap() before calling this method if this Objet +// was returned from a transaction, and the transaction was committed or rolled back. +func (_m *Objet) Update() *ObjetUpdateOne { + return NewObjetClient(_m.config).UpdateOne(_m) +} + +// Unwrap unwraps the Objet entity that was returned from a transaction after it was closed, +// so that all future queries will be executed through the driver which created the transaction. +func (_m *Objet) Unwrap() *Objet { + _tx, ok := _m.config.driver.(*txDriver) + if !ok { + panic("ent: Objet is not a transactional entity") + } + _m.config.driver = _tx.drv + return _m +} + +// String implements the fmt.Stringer. +func (_m *Objet) String() string { + var builder strings.Builder + builder.WriteString("Objet(") + builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID)) + builder.WriteString("nom=") + builder.WriteString(_m.Nom) + builder.WriteString(", ") + if v := _m.Description; v != nil { + builder.WriteString("description=") + builder.WriteString(*v) + } + builder.WriteString(", ") + builder.WriteString("quantite=") + builder.WriteString(fmt.Sprintf("%v", _m.Quantite)) + builder.WriteString(", ") + if v := _m.PrixAchat; v != nil { + builder.WriteString("prix_achat=") + builder.WriteString(fmt.Sprintf("%v", *v)) + } + builder.WriteString(", ") + if v := _m.DateAchat; v != nil { + builder.WriteString("date_achat=") + builder.WriteString(v.Format(time.ANSIC)) + } + builder.WriteString(", ") + if v := _m.Boutique; v != nil { + builder.WriteString("boutique=") + builder.WriteString(*v) + } + builder.WriteString(", ") + if v := _m.NumeroSerie; v != nil { + builder.WriteString("numero_serie=") + builder.WriteString(*v) + } + builder.WriteString(", ") + if v := _m.NumeroModele; v != nil { + builder.WriteString("numero_modele=") + builder.WriteString(*v) + } + builder.WriteString(", ") + if v := _m.Fabricant; v != nil { + builder.WriteString("fabricant=") + builder.WriteString(*v) + } + builder.WriteString(", ") + builder.WriteString("statut=") + builder.WriteString(fmt.Sprintf("%v", _m.Statut)) + builder.WriteString(", ") + builder.WriteString("caracteristiques=") + builder.WriteString(fmt.Sprintf("%v", _m.Caracteristiques)) + builder.WriteString(", ") + builder.WriteString("created_at=") + builder.WriteString(_m.CreatedAt.Format(time.ANSIC)) + builder.WriteString(", ") + builder.WriteString("updated_at=") + builder.WriteString(_m.UpdatedAt.Format(time.ANSIC)) + builder.WriteByte(')') + return builder.String() +} + +// Objets is a parsable slice of Objet. +type Objets []*Objet diff --git a/backend/internal/data/ent/objet/objet.go b/backend/internal/data/ent/objet/objet.go new file mode 100644 index 0000000..2dafc31 --- /dev/null +++ b/backend/internal/data/ent/objet/objet.go @@ -0,0 +1,276 @@ +// Code generated by ent, DO NOT EDIT. + +package objet + +import ( + "fmt" + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "github.com/google/uuid" +) + +const ( + // Label holds the string label denoting the objet type in the database. + Label = "objet" + // FieldID holds the string denoting the id field in the database. + FieldID = "id" + // FieldNom holds the string denoting the nom field in the database. + FieldNom = "nom" + // FieldDescription holds the string denoting the description field in the database. + FieldDescription = "description" + // FieldQuantite holds the string denoting the quantite field in the database. + FieldQuantite = "quantite" + // FieldPrixAchat holds the string denoting the prix_achat field in the database. + FieldPrixAchat = "prix_achat" + // FieldDateAchat holds the string denoting the date_achat field in the database. + FieldDateAchat = "date_achat" + // FieldBoutique holds the string denoting the boutique field in the database. + FieldBoutique = "boutique" + // FieldNumeroSerie holds the string denoting the numero_serie field in the database. + FieldNumeroSerie = "numero_serie" + // FieldNumeroModele holds the string denoting the numero_modele field in the database. + FieldNumeroModele = "numero_modele" + // FieldFabricant holds the string denoting the fabricant field in the database. + FieldFabricant = "fabricant" + // FieldStatut holds the string denoting the statut field in the database. + FieldStatut = "statut" + // FieldCaracteristiques holds the string denoting the caracteristiques field in the database. + FieldCaracteristiques = "caracteristiques" + // FieldCreatedAt holds the string denoting the created_at field in the database. + FieldCreatedAt = "created_at" + // FieldUpdatedAt holds the string denoting the updated_at field in the database. + FieldUpdatedAt = "updated_at" + // EdgeLiensEmplacements holds the string denoting the liens_emplacements edge name in mutations. + EdgeLiensEmplacements = "liens_emplacements" + // EdgeChampsPersonnalises holds the string denoting the champs_personnalises edge name in mutations. + EdgeChampsPersonnalises = "champs_personnalises" + // EdgePiecesJointes holds the string denoting the pieces_jointes edge name in mutations. + EdgePiecesJointes = "pieces_jointes" + // Table holds the table name of the objet in the database. + Table = "objet" + // LiensEmplacementsTable is the table that holds the liens_emplacements relation/edge. + LiensEmplacementsTable = "lien_objet_emplacement" + // LiensEmplacementsInverseTable is the table name for the LienObjetEmplacement entity. + // It exists in this package in order to avoid circular dependency with the "lienobjetemplacement" package. + LiensEmplacementsInverseTable = "lien_objet_emplacement" + // LiensEmplacementsColumn is the table column denoting the liens_emplacements relation/edge. + LiensEmplacementsColumn = "objet_id" + // ChampsPersonnalisesTable is the table that holds the champs_personnalises relation/edge. + ChampsPersonnalisesTable = "champ_personnalise" + // ChampsPersonnalisesInverseTable is the table name for the ChampPersonnalise entity. + // It exists in this package in order to avoid circular dependency with the "champpersonnalise" package. + ChampsPersonnalisesInverseTable = "champ_personnalise" + // ChampsPersonnalisesColumn is the table column denoting the champs_personnalises relation/edge. + ChampsPersonnalisesColumn = "objet_id" + // PiecesJointesTable is the table that holds the pieces_jointes relation/edge. + PiecesJointesTable = "piece_jointe" + // PiecesJointesInverseTable is the table name for the PieceJointe entity. + // It exists in this package in order to avoid circular dependency with the "piecejointe" package. + PiecesJointesInverseTable = "piece_jointe" + // PiecesJointesColumn is the table column denoting the pieces_jointes relation/edge. + PiecesJointesColumn = "objet_id" +) + +// Columns holds all SQL columns for objet fields. +var Columns = []string{ + FieldID, + FieldNom, + FieldDescription, + FieldQuantite, + FieldPrixAchat, + FieldDateAchat, + FieldBoutique, + FieldNumeroSerie, + FieldNumeroModele, + FieldFabricant, + FieldStatut, + FieldCaracteristiques, + FieldCreatedAt, + FieldUpdatedAt, +} + +// ValidColumn reports if the column name is valid (part of the table columns). +func ValidColumn(column string) bool { + for i := range Columns { + if column == Columns[i] { + return true + } + } + return false +} + +var ( + // NomValidator is a validator for the "nom" field. It is called by the builders before save. + NomValidator func(string) error + // DefaultQuantite holds the default value on creation for the "quantite" field. + DefaultQuantite int + // DefaultCreatedAt holds the default value on creation for the "created_at" field. + DefaultCreatedAt func() time.Time + // DefaultUpdatedAt holds the default value on creation for the "updated_at" field. + DefaultUpdatedAt func() time.Time + // UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field. + UpdateDefaultUpdatedAt func() time.Time + // DefaultID holds the default value on creation for the "id" field. + DefaultID func() uuid.UUID +) + +// Statut defines the type for the "statut" enum field. +type Statut string + +// StatutEnStock is the default value of the Statut enum. +const DefaultStatut = StatutEnStock + +// Statut values. +const ( + StatutEnStock Statut = "en_stock" + StatutPret Statut = "pret" + StatutHorsService Statut = "hors_service" + StatutArchive Statut = "archive" +) + +func (s Statut) String() string { + return string(s) +} + +// StatutValidator is a validator for the "statut" field enum values. It is called by the builders before save. +func StatutValidator(s Statut) error { + switch s { + case StatutEnStock, StatutPret, StatutHorsService, StatutArchive: + return nil + default: + return fmt.Errorf("objet: invalid enum value for statut field: %q", s) + } +} + +// OrderOption defines the ordering options for the Objet queries. +type OrderOption func(*sql.Selector) + +// ByID orders the results by the id field. +func ByID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldID, opts...).ToFunc() +} + +// ByNom orders the results by the nom field. +func ByNom(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldNom, opts...).ToFunc() +} + +// ByDescription orders the results by the description field. +func ByDescription(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldDescription, opts...).ToFunc() +} + +// ByQuantite orders the results by the quantite field. +func ByQuantite(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldQuantite, opts...).ToFunc() +} + +// ByPrixAchat orders the results by the prix_achat field. +func ByPrixAchat(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldPrixAchat, opts...).ToFunc() +} + +// ByDateAchat orders the results by the date_achat field. +func ByDateAchat(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldDateAchat, opts...).ToFunc() +} + +// ByBoutique orders the results by the boutique field. +func ByBoutique(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldBoutique, opts...).ToFunc() +} + +// ByNumeroSerie orders the results by the numero_serie field. +func ByNumeroSerie(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldNumeroSerie, opts...).ToFunc() +} + +// ByNumeroModele orders the results by the numero_modele field. +func ByNumeroModele(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldNumeroModele, opts...).ToFunc() +} + +// ByFabricant orders the results by the fabricant field. +func ByFabricant(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldFabricant, opts...).ToFunc() +} + +// ByStatut orders the results by the statut field. +func ByStatut(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldStatut, opts...).ToFunc() +} + +// ByCreatedAt orders the results by the created_at field. +func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() +} + +// ByUpdatedAt orders the results by the updated_at field. +func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc() +} + +// ByLiensEmplacementsCount orders the results by liens_emplacements count. +func ByLiensEmplacementsCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newLiensEmplacementsStep(), opts...) + } +} + +// ByLiensEmplacements orders the results by liens_emplacements terms. +func ByLiensEmplacements(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newLiensEmplacementsStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} + +// ByChampsPersonnalisesCount orders the results by champs_personnalises count. +func ByChampsPersonnalisesCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newChampsPersonnalisesStep(), opts...) + } +} + +// ByChampsPersonnalises orders the results by champs_personnalises terms. +func ByChampsPersonnalises(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newChampsPersonnalisesStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} + +// ByPiecesJointesCount orders the results by pieces_jointes count. +func ByPiecesJointesCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newPiecesJointesStep(), opts...) + } +} + +// ByPiecesJointes orders the results by pieces_jointes terms. +func ByPiecesJointes(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newPiecesJointesStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} +func newLiensEmplacementsStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(LiensEmplacementsInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, LiensEmplacementsTable, LiensEmplacementsColumn), + ) +} +func newChampsPersonnalisesStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(ChampsPersonnalisesInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, ChampsPersonnalisesTable, ChampsPersonnalisesColumn), + ) +} +func newPiecesJointesStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(PiecesJointesInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, PiecesJointesTable, PiecesJointesColumn), + ) +} diff --git a/backend/internal/data/ent/objet/where.go b/backend/internal/data/ent/objet/where.go new file mode 100644 index 0000000..0538bc3 --- /dev/null +++ b/backend/internal/data/ent/objet/where.go @@ -0,0 +1,886 @@ +// Code generated by ent, DO NOT EDIT. + +package objet + +import ( + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/predicate" + "github.com/google/uuid" +) + +// ID filters vertices based on their ID field. +func ID(id uuid.UUID) predicate.Objet { + return predicate.Objet(sql.FieldEQ(FieldID, id)) +} + +// IDEQ applies the EQ predicate on the ID field. +func IDEQ(id uuid.UUID) predicate.Objet { + return predicate.Objet(sql.FieldEQ(FieldID, id)) +} + +// IDNEQ applies the NEQ predicate on the ID field. +func IDNEQ(id uuid.UUID) predicate.Objet { + return predicate.Objet(sql.FieldNEQ(FieldID, id)) +} + +// IDIn applies the In predicate on the ID field. +func IDIn(ids ...uuid.UUID) predicate.Objet { + return predicate.Objet(sql.FieldIn(FieldID, ids...)) +} + +// IDNotIn applies the NotIn predicate on the ID field. +func IDNotIn(ids ...uuid.UUID) predicate.Objet { + return predicate.Objet(sql.FieldNotIn(FieldID, ids...)) +} + +// IDGT applies the GT predicate on the ID field. +func IDGT(id uuid.UUID) predicate.Objet { + return predicate.Objet(sql.FieldGT(FieldID, id)) +} + +// IDGTE applies the GTE predicate on the ID field. +func IDGTE(id uuid.UUID) predicate.Objet { + return predicate.Objet(sql.FieldGTE(FieldID, id)) +} + +// IDLT applies the LT predicate on the ID field. +func IDLT(id uuid.UUID) predicate.Objet { + return predicate.Objet(sql.FieldLT(FieldID, id)) +} + +// IDLTE applies the LTE predicate on the ID field. +func IDLTE(id uuid.UUID) predicate.Objet { + return predicate.Objet(sql.FieldLTE(FieldID, id)) +} + +// Nom applies equality check predicate on the "nom" field. It's identical to NomEQ. +func Nom(v string) predicate.Objet { + return predicate.Objet(sql.FieldEQ(FieldNom, v)) +} + +// Description applies equality check predicate on the "description" field. It's identical to DescriptionEQ. +func Description(v string) predicate.Objet { + return predicate.Objet(sql.FieldEQ(FieldDescription, v)) +} + +// Quantite applies equality check predicate on the "quantite" field. It's identical to QuantiteEQ. +func Quantite(v int) predicate.Objet { + return predicate.Objet(sql.FieldEQ(FieldQuantite, v)) +} + +// PrixAchat applies equality check predicate on the "prix_achat" field. It's identical to PrixAchatEQ. +func PrixAchat(v float64) predicate.Objet { + return predicate.Objet(sql.FieldEQ(FieldPrixAchat, v)) +} + +// DateAchat applies equality check predicate on the "date_achat" field. It's identical to DateAchatEQ. +func DateAchat(v time.Time) predicate.Objet { + return predicate.Objet(sql.FieldEQ(FieldDateAchat, v)) +} + +// Boutique applies equality check predicate on the "boutique" field. It's identical to BoutiqueEQ. +func Boutique(v string) predicate.Objet { + return predicate.Objet(sql.FieldEQ(FieldBoutique, v)) +} + +// NumeroSerie applies equality check predicate on the "numero_serie" field. It's identical to NumeroSerieEQ. +func NumeroSerie(v string) predicate.Objet { + return predicate.Objet(sql.FieldEQ(FieldNumeroSerie, v)) +} + +// NumeroModele applies equality check predicate on the "numero_modele" field. It's identical to NumeroModeleEQ. +func NumeroModele(v string) predicate.Objet { + return predicate.Objet(sql.FieldEQ(FieldNumeroModele, v)) +} + +// Fabricant applies equality check predicate on the "fabricant" field. It's identical to FabricantEQ. +func Fabricant(v string) predicate.Objet { + return predicate.Objet(sql.FieldEQ(FieldFabricant, v)) +} + +// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. +func CreatedAt(v time.Time) predicate.Objet { + return predicate.Objet(sql.FieldEQ(FieldCreatedAt, v)) +} + +// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ. +func UpdatedAt(v time.Time) predicate.Objet { + return predicate.Objet(sql.FieldEQ(FieldUpdatedAt, v)) +} + +// NomEQ applies the EQ predicate on the "nom" field. +func NomEQ(v string) predicate.Objet { + return predicate.Objet(sql.FieldEQ(FieldNom, v)) +} + +// NomNEQ applies the NEQ predicate on the "nom" field. +func NomNEQ(v string) predicate.Objet { + return predicate.Objet(sql.FieldNEQ(FieldNom, v)) +} + +// NomIn applies the In predicate on the "nom" field. +func NomIn(vs ...string) predicate.Objet { + return predicate.Objet(sql.FieldIn(FieldNom, vs...)) +} + +// NomNotIn applies the NotIn predicate on the "nom" field. +func NomNotIn(vs ...string) predicate.Objet { + return predicate.Objet(sql.FieldNotIn(FieldNom, vs...)) +} + +// NomGT applies the GT predicate on the "nom" field. +func NomGT(v string) predicate.Objet { + return predicate.Objet(sql.FieldGT(FieldNom, v)) +} + +// NomGTE applies the GTE predicate on the "nom" field. +func NomGTE(v string) predicate.Objet { + return predicate.Objet(sql.FieldGTE(FieldNom, v)) +} + +// NomLT applies the LT predicate on the "nom" field. +func NomLT(v string) predicate.Objet { + return predicate.Objet(sql.FieldLT(FieldNom, v)) +} + +// NomLTE applies the LTE predicate on the "nom" field. +func NomLTE(v string) predicate.Objet { + return predicate.Objet(sql.FieldLTE(FieldNom, v)) +} + +// NomContains applies the Contains predicate on the "nom" field. +func NomContains(v string) predicate.Objet { + return predicate.Objet(sql.FieldContains(FieldNom, v)) +} + +// NomHasPrefix applies the HasPrefix predicate on the "nom" field. +func NomHasPrefix(v string) predicate.Objet { + return predicate.Objet(sql.FieldHasPrefix(FieldNom, v)) +} + +// NomHasSuffix applies the HasSuffix predicate on the "nom" field. +func NomHasSuffix(v string) predicate.Objet { + return predicate.Objet(sql.FieldHasSuffix(FieldNom, v)) +} + +// NomEqualFold applies the EqualFold predicate on the "nom" field. +func NomEqualFold(v string) predicate.Objet { + return predicate.Objet(sql.FieldEqualFold(FieldNom, v)) +} + +// NomContainsFold applies the ContainsFold predicate on the "nom" field. +func NomContainsFold(v string) predicate.Objet { + return predicate.Objet(sql.FieldContainsFold(FieldNom, v)) +} + +// DescriptionEQ applies the EQ predicate on the "description" field. +func DescriptionEQ(v string) predicate.Objet { + return predicate.Objet(sql.FieldEQ(FieldDescription, v)) +} + +// DescriptionNEQ applies the NEQ predicate on the "description" field. +func DescriptionNEQ(v string) predicate.Objet { + return predicate.Objet(sql.FieldNEQ(FieldDescription, v)) +} + +// DescriptionIn applies the In predicate on the "description" field. +func DescriptionIn(vs ...string) predicate.Objet { + return predicate.Objet(sql.FieldIn(FieldDescription, vs...)) +} + +// DescriptionNotIn applies the NotIn predicate on the "description" field. +func DescriptionNotIn(vs ...string) predicate.Objet { + return predicate.Objet(sql.FieldNotIn(FieldDescription, vs...)) +} + +// DescriptionGT applies the GT predicate on the "description" field. +func DescriptionGT(v string) predicate.Objet { + return predicate.Objet(sql.FieldGT(FieldDescription, v)) +} + +// DescriptionGTE applies the GTE predicate on the "description" field. +func DescriptionGTE(v string) predicate.Objet { + return predicate.Objet(sql.FieldGTE(FieldDescription, v)) +} + +// DescriptionLT applies the LT predicate on the "description" field. +func DescriptionLT(v string) predicate.Objet { + return predicate.Objet(sql.FieldLT(FieldDescription, v)) +} + +// DescriptionLTE applies the LTE predicate on the "description" field. +func DescriptionLTE(v string) predicate.Objet { + return predicate.Objet(sql.FieldLTE(FieldDescription, v)) +} + +// DescriptionContains applies the Contains predicate on the "description" field. +func DescriptionContains(v string) predicate.Objet { + return predicate.Objet(sql.FieldContains(FieldDescription, v)) +} + +// DescriptionHasPrefix applies the HasPrefix predicate on the "description" field. +func DescriptionHasPrefix(v string) predicate.Objet { + return predicate.Objet(sql.FieldHasPrefix(FieldDescription, v)) +} + +// DescriptionHasSuffix applies the HasSuffix predicate on the "description" field. +func DescriptionHasSuffix(v string) predicate.Objet { + return predicate.Objet(sql.FieldHasSuffix(FieldDescription, v)) +} + +// DescriptionIsNil applies the IsNil predicate on the "description" field. +func DescriptionIsNil() predicate.Objet { + return predicate.Objet(sql.FieldIsNull(FieldDescription)) +} + +// DescriptionNotNil applies the NotNil predicate on the "description" field. +func DescriptionNotNil() predicate.Objet { + return predicate.Objet(sql.FieldNotNull(FieldDescription)) +} + +// DescriptionEqualFold applies the EqualFold predicate on the "description" field. +func DescriptionEqualFold(v string) predicate.Objet { + return predicate.Objet(sql.FieldEqualFold(FieldDescription, v)) +} + +// DescriptionContainsFold applies the ContainsFold predicate on the "description" field. +func DescriptionContainsFold(v string) predicate.Objet { + return predicate.Objet(sql.FieldContainsFold(FieldDescription, v)) +} + +// QuantiteEQ applies the EQ predicate on the "quantite" field. +func QuantiteEQ(v int) predicate.Objet { + return predicate.Objet(sql.FieldEQ(FieldQuantite, v)) +} + +// QuantiteNEQ applies the NEQ predicate on the "quantite" field. +func QuantiteNEQ(v int) predicate.Objet { + return predicate.Objet(sql.FieldNEQ(FieldQuantite, v)) +} + +// QuantiteIn applies the In predicate on the "quantite" field. +func QuantiteIn(vs ...int) predicate.Objet { + return predicate.Objet(sql.FieldIn(FieldQuantite, vs...)) +} + +// QuantiteNotIn applies the NotIn predicate on the "quantite" field. +func QuantiteNotIn(vs ...int) predicate.Objet { + return predicate.Objet(sql.FieldNotIn(FieldQuantite, vs...)) +} + +// QuantiteGT applies the GT predicate on the "quantite" field. +func QuantiteGT(v int) predicate.Objet { + return predicate.Objet(sql.FieldGT(FieldQuantite, v)) +} + +// QuantiteGTE applies the GTE predicate on the "quantite" field. +func QuantiteGTE(v int) predicate.Objet { + return predicate.Objet(sql.FieldGTE(FieldQuantite, v)) +} + +// QuantiteLT applies the LT predicate on the "quantite" field. +func QuantiteLT(v int) predicate.Objet { + return predicate.Objet(sql.FieldLT(FieldQuantite, v)) +} + +// QuantiteLTE applies the LTE predicate on the "quantite" field. +func QuantiteLTE(v int) predicate.Objet { + return predicate.Objet(sql.FieldLTE(FieldQuantite, v)) +} + +// PrixAchatEQ applies the EQ predicate on the "prix_achat" field. +func PrixAchatEQ(v float64) predicate.Objet { + return predicate.Objet(sql.FieldEQ(FieldPrixAchat, v)) +} + +// PrixAchatNEQ applies the NEQ predicate on the "prix_achat" field. +func PrixAchatNEQ(v float64) predicate.Objet { + return predicate.Objet(sql.FieldNEQ(FieldPrixAchat, v)) +} + +// PrixAchatIn applies the In predicate on the "prix_achat" field. +func PrixAchatIn(vs ...float64) predicate.Objet { + return predicate.Objet(sql.FieldIn(FieldPrixAchat, vs...)) +} + +// PrixAchatNotIn applies the NotIn predicate on the "prix_achat" field. +func PrixAchatNotIn(vs ...float64) predicate.Objet { + return predicate.Objet(sql.FieldNotIn(FieldPrixAchat, vs...)) +} + +// PrixAchatGT applies the GT predicate on the "prix_achat" field. +func PrixAchatGT(v float64) predicate.Objet { + return predicate.Objet(sql.FieldGT(FieldPrixAchat, v)) +} + +// PrixAchatGTE applies the GTE predicate on the "prix_achat" field. +func PrixAchatGTE(v float64) predicate.Objet { + return predicate.Objet(sql.FieldGTE(FieldPrixAchat, v)) +} + +// PrixAchatLT applies the LT predicate on the "prix_achat" field. +func PrixAchatLT(v float64) predicate.Objet { + return predicate.Objet(sql.FieldLT(FieldPrixAchat, v)) +} + +// PrixAchatLTE applies the LTE predicate on the "prix_achat" field. +func PrixAchatLTE(v float64) predicate.Objet { + return predicate.Objet(sql.FieldLTE(FieldPrixAchat, v)) +} + +// PrixAchatIsNil applies the IsNil predicate on the "prix_achat" field. +func PrixAchatIsNil() predicate.Objet { + return predicate.Objet(sql.FieldIsNull(FieldPrixAchat)) +} + +// PrixAchatNotNil applies the NotNil predicate on the "prix_achat" field. +func PrixAchatNotNil() predicate.Objet { + return predicate.Objet(sql.FieldNotNull(FieldPrixAchat)) +} + +// DateAchatEQ applies the EQ predicate on the "date_achat" field. +func DateAchatEQ(v time.Time) predicate.Objet { + return predicate.Objet(sql.FieldEQ(FieldDateAchat, v)) +} + +// DateAchatNEQ applies the NEQ predicate on the "date_achat" field. +func DateAchatNEQ(v time.Time) predicate.Objet { + return predicate.Objet(sql.FieldNEQ(FieldDateAchat, v)) +} + +// DateAchatIn applies the In predicate on the "date_achat" field. +func DateAchatIn(vs ...time.Time) predicate.Objet { + return predicate.Objet(sql.FieldIn(FieldDateAchat, vs...)) +} + +// DateAchatNotIn applies the NotIn predicate on the "date_achat" field. +func DateAchatNotIn(vs ...time.Time) predicate.Objet { + return predicate.Objet(sql.FieldNotIn(FieldDateAchat, vs...)) +} + +// DateAchatGT applies the GT predicate on the "date_achat" field. +func DateAchatGT(v time.Time) predicate.Objet { + return predicate.Objet(sql.FieldGT(FieldDateAchat, v)) +} + +// DateAchatGTE applies the GTE predicate on the "date_achat" field. +func DateAchatGTE(v time.Time) predicate.Objet { + return predicate.Objet(sql.FieldGTE(FieldDateAchat, v)) +} + +// DateAchatLT applies the LT predicate on the "date_achat" field. +func DateAchatLT(v time.Time) predicate.Objet { + return predicate.Objet(sql.FieldLT(FieldDateAchat, v)) +} + +// DateAchatLTE applies the LTE predicate on the "date_achat" field. +func DateAchatLTE(v time.Time) predicate.Objet { + return predicate.Objet(sql.FieldLTE(FieldDateAchat, v)) +} + +// DateAchatIsNil applies the IsNil predicate on the "date_achat" field. +func DateAchatIsNil() predicate.Objet { + return predicate.Objet(sql.FieldIsNull(FieldDateAchat)) +} + +// DateAchatNotNil applies the NotNil predicate on the "date_achat" field. +func DateAchatNotNil() predicate.Objet { + return predicate.Objet(sql.FieldNotNull(FieldDateAchat)) +} + +// BoutiqueEQ applies the EQ predicate on the "boutique" field. +func BoutiqueEQ(v string) predicate.Objet { + return predicate.Objet(sql.FieldEQ(FieldBoutique, v)) +} + +// BoutiqueNEQ applies the NEQ predicate on the "boutique" field. +func BoutiqueNEQ(v string) predicate.Objet { + return predicate.Objet(sql.FieldNEQ(FieldBoutique, v)) +} + +// BoutiqueIn applies the In predicate on the "boutique" field. +func BoutiqueIn(vs ...string) predicate.Objet { + return predicate.Objet(sql.FieldIn(FieldBoutique, vs...)) +} + +// BoutiqueNotIn applies the NotIn predicate on the "boutique" field. +func BoutiqueNotIn(vs ...string) predicate.Objet { + return predicate.Objet(sql.FieldNotIn(FieldBoutique, vs...)) +} + +// BoutiqueGT applies the GT predicate on the "boutique" field. +func BoutiqueGT(v string) predicate.Objet { + return predicate.Objet(sql.FieldGT(FieldBoutique, v)) +} + +// BoutiqueGTE applies the GTE predicate on the "boutique" field. +func BoutiqueGTE(v string) predicate.Objet { + return predicate.Objet(sql.FieldGTE(FieldBoutique, v)) +} + +// BoutiqueLT applies the LT predicate on the "boutique" field. +func BoutiqueLT(v string) predicate.Objet { + return predicate.Objet(sql.FieldLT(FieldBoutique, v)) +} + +// BoutiqueLTE applies the LTE predicate on the "boutique" field. +func BoutiqueLTE(v string) predicate.Objet { + return predicate.Objet(sql.FieldLTE(FieldBoutique, v)) +} + +// BoutiqueContains applies the Contains predicate on the "boutique" field. +func BoutiqueContains(v string) predicate.Objet { + return predicate.Objet(sql.FieldContains(FieldBoutique, v)) +} + +// BoutiqueHasPrefix applies the HasPrefix predicate on the "boutique" field. +func BoutiqueHasPrefix(v string) predicate.Objet { + return predicate.Objet(sql.FieldHasPrefix(FieldBoutique, v)) +} + +// BoutiqueHasSuffix applies the HasSuffix predicate on the "boutique" field. +func BoutiqueHasSuffix(v string) predicate.Objet { + return predicate.Objet(sql.FieldHasSuffix(FieldBoutique, v)) +} + +// BoutiqueIsNil applies the IsNil predicate on the "boutique" field. +func BoutiqueIsNil() predicate.Objet { + return predicate.Objet(sql.FieldIsNull(FieldBoutique)) +} + +// BoutiqueNotNil applies the NotNil predicate on the "boutique" field. +func BoutiqueNotNil() predicate.Objet { + return predicate.Objet(sql.FieldNotNull(FieldBoutique)) +} + +// BoutiqueEqualFold applies the EqualFold predicate on the "boutique" field. +func BoutiqueEqualFold(v string) predicate.Objet { + return predicate.Objet(sql.FieldEqualFold(FieldBoutique, v)) +} + +// BoutiqueContainsFold applies the ContainsFold predicate on the "boutique" field. +func BoutiqueContainsFold(v string) predicate.Objet { + return predicate.Objet(sql.FieldContainsFold(FieldBoutique, v)) +} + +// NumeroSerieEQ applies the EQ predicate on the "numero_serie" field. +func NumeroSerieEQ(v string) predicate.Objet { + return predicate.Objet(sql.FieldEQ(FieldNumeroSerie, v)) +} + +// NumeroSerieNEQ applies the NEQ predicate on the "numero_serie" field. +func NumeroSerieNEQ(v string) predicate.Objet { + return predicate.Objet(sql.FieldNEQ(FieldNumeroSerie, v)) +} + +// NumeroSerieIn applies the In predicate on the "numero_serie" field. +func NumeroSerieIn(vs ...string) predicate.Objet { + return predicate.Objet(sql.FieldIn(FieldNumeroSerie, vs...)) +} + +// NumeroSerieNotIn applies the NotIn predicate on the "numero_serie" field. +func NumeroSerieNotIn(vs ...string) predicate.Objet { + return predicate.Objet(sql.FieldNotIn(FieldNumeroSerie, vs...)) +} + +// NumeroSerieGT applies the GT predicate on the "numero_serie" field. +func NumeroSerieGT(v string) predicate.Objet { + return predicate.Objet(sql.FieldGT(FieldNumeroSerie, v)) +} + +// NumeroSerieGTE applies the GTE predicate on the "numero_serie" field. +func NumeroSerieGTE(v string) predicate.Objet { + return predicate.Objet(sql.FieldGTE(FieldNumeroSerie, v)) +} + +// NumeroSerieLT applies the LT predicate on the "numero_serie" field. +func NumeroSerieLT(v string) predicate.Objet { + return predicate.Objet(sql.FieldLT(FieldNumeroSerie, v)) +} + +// NumeroSerieLTE applies the LTE predicate on the "numero_serie" field. +func NumeroSerieLTE(v string) predicate.Objet { + return predicate.Objet(sql.FieldLTE(FieldNumeroSerie, v)) +} + +// NumeroSerieContains applies the Contains predicate on the "numero_serie" field. +func NumeroSerieContains(v string) predicate.Objet { + return predicate.Objet(sql.FieldContains(FieldNumeroSerie, v)) +} + +// NumeroSerieHasPrefix applies the HasPrefix predicate on the "numero_serie" field. +func NumeroSerieHasPrefix(v string) predicate.Objet { + return predicate.Objet(sql.FieldHasPrefix(FieldNumeroSerie, v)) +} + +// NumeroSerieHasSuffix applies the HasSuffix predicate on the "numero_serie" field. +func NumeroSerieHasSuffix(v string) predicate.Objet { + return predicate.Objet(sql.FieldHasSuffix(FieldNumeroSerie, v)) +} + +// NumeroSerieIsNil applies the IsNil predicate on the "numero_serie" field. +func NumeroSerieIsNil() predicate.Objet { + return predicate.Objet(sql.FieldIsNull(FieldNumeroSerie)) +} + +// NumeroSerieNotNil applies the NotNil predicate on the "numero_serie" field. +func NumeroSerieNotNil() predicate.Objet { + return predicate.Objet(sql.FieldNotNull(FieldNumeroSerie)) +} + +// NumeroSerieEqualFold applies the EqualFold predicate on the "numero_serie" field. +func NumeroSerieEqualFold(v string) predicate.Objet { + return predicate.Objet(sql.FieldEqualFold(FieldNumeroSerie, v)) +} + +// NumeroSerieContainsFold applies the ContainsFold predicate on the "numero_serie" field. +func NumeroSerieContainsFold(v string) predicate.Objet { + return predicate.Objet(sql.FieldContainsFold(FieldNumeroSerie, v)) +} + +// NumeroModeleEQ applies the EQ predicate on the "numero_modele" field. +func NumeroModeleEQ(v string) predicate.Objet { + return predicate.Objet(sql.FieldEQ(FieldNumeroModele, v)) +} + +// NumeroModeleNEQ applies the NEQ predicate on the "numero_modele" field. +func NumeroModeleNEQ(v string) predicate.Objet { + return predicate.Objet(sql.FieldNEQ(FieldNumeroModele, v)) +} + +// NumeroModeleIn applies the In predicate on the "numero_modele" field. +func NumeroModeleIn(vs ...string) predicate.Objet { + return predicate.Objet(sql.FieldIn(FieldNumeroModele, vs...)) +} + +// NumeroModeleNotIn applies the NotIn predicate on the "numero_modele" field. +func NumeroModeleNotIn(vs ...string) predicate.Objet { + return predicate.Objet(sql.FieldNotIn(FieldNumeroModele, vs...)) +} + +// NumeroModeleGT applies the GT predicate on the "numero_modele" field. +func NumeroModeleGT(v string) predicate.Objet { + return predicate.Objet(sql.FieldGT(FieldNumeroModele, v)) +} + +// NumeroModeleGTE applies the GTE predicate on the "numero_modele" field. +func NumeroModeleGTE(v string) predicate.Objet { + return predicate.Objet(sql.FieldGTE(FieldNumeroModele, v)) +} + +// NumeroModeleLT applies the LT predicate on the "numero_modele" field. +func NumeroModeleLT(v string) predicate.Objet { + return predicate.Objet(sql.FieldLT(FieldNumeroModele, v)) +} + +// NumeroModeleLTE applies the LTE predicate on the "numero_modele" field. +func NumeroModeleLTE(v string) predicate.Objet { + return predicate.Objet(sql.FieldLTE(FieldNumeroModele, v)) +} + +// NumeroModeleContains applies the Contains predicate on the "numero_modele" field. +func NumeroModeleContains(v string) predicate.Objet { + return predicate.Objet(sql.FieldContains(FieldNumeroModele, v)) +} + +// NumeroModeleHasPrefix applies the HasPrefix predicate on the "numero_modele" field. +func NumeroModeleHasPrefix(v string) predicate.Objet { + return predicate.Objet(sql.FieldHasPrefix(FieldNumeroModele, v)) +} + +// NumeroModeleHasSuffix applies the HasSuffix predicate on the "numero_modele" field. +func NumeroModeleHasSuffix(v string) predicate.Objet { + return predicate.Objet(sql.FieldHasSuffix(FieldNumeroModele, v)) +} + +// NumeroModeleIsNil applies the IsNil predicate on the "numero_modele" field. +func NumeroModeleIsNil() predicate.Objet { + return predicate.Objet(sql.FieldIsNull(FieldNumeroModele)) +} + +// NumeroModeleNotNil applies the NotNil predicate on the "numero_modele" field. +func NumeroModeleNotNil() predicate.Objet { + return predicate.Objet(sql.FieldNotNull(FieldNumeroModele)) +} + +// NumeroModeleEqualFold applies the EqualFold predicate on the "numero_modele" field. +func NumeroModeleEqualFold(v string) predicate.Objet { + return predicate.Objet(sql.FieldEqualFold(FieldNumeroModele, v)) +} + +// NumeroModeleContainsFold applies the ContainsFold predicate on the "numero_modele" field. +func NumeroModeleContainsFold(v string) predicate.Objet { + return predicate.Objet(sql.FieldContainsFold(FieldNumeroModele, v)) +} + +// FabricantEQ applies the EQ predicate on the "fabricant" field. +func FabricantEQ(v string) predicate.Objet { + return predicate.Objet(sql.FieldEQ(FieldFabricant, v)) +} + +// FabricantNEQ applies the NEQ predicate on the "fabricant" field. +func FabricantNEQ(v string) predicate.Objet { + return predicate.Objet(sql.FieldNEQ(FieldFabricant, v)) +} + +// FabricantIn applies the In predicate on the "fabricant" field. +func FabricantIn(vs ...string) predicate.Objet { + return predicate.Objet(sql.FieldIn(FieldFabricant, vs...)) +} + +// FabricantNotIn applies the NotIn predicate on the "fabricant" field. +func FabricantNotIn(vs ...string) predicate.Objet { + return predicate.Objet(sql.FieldNotIn(FieldFabricant, vs...)) +} + +// FabricantGT applies the GT predicate on the "fabricant" field. +func FabricantGT(v string) predicate.Objet { + return predicate.Objet(sql.FieldGT(FieldFabricant, v)) +} + +// FabricantGTE applies the GTE predicate on the "fabricant" field. +func FabricantGTE(v string) predicate.Objet { + return predicate.Objet(sql.FieldGTE(FieldFabricant, v)) +} + +// FabricantLT applies the LT predicate on the "fabricant" field. +func FabricantLT(v string) predicate.Objet { + return predicate.Objet(sql.FieldLT(FieldFabricant, v)) +} + +// FabricantLTE applies the LTE predicate on the "fabricant" field. +func FabricantLTE(v string) predicate.Objet { + return predicate.Objet(sql.FieldLTE(FieldFabricant, v)) +} + +// FabricantContains applies the Contains predicate on the "fabricant" field. +func FabricantContains(v string) predicate.Objet { + return predicate.Objet(sql.FieldContains(FieldFabricant, v)) +} + +// FabricantHasPrefix applies the HasPrefix predicate on the "fabricant" field. +func FabricantHasPrefix(v string) predicate.Objet { + return predicate.Objet(sql.FieldHasPrefix(FieldFabricant, v)) +} + +// FabricantHasSuffix applies the HasSuffix predicate on the "fabricant" field. +func FabricantHasSuffix(v string) predicate.Objet { + return predicate.Objet(sql.FieldHasSuffix(FieldFabricant, v)) +} + +// FabricantIsNil applies the IsNil predicate on the "fabricant" field. +func FabricantIsNil() predicate.Objet { + return predicate.Objet(sql.FieldIsNull(FieldFabricant)) +} + +// FabricantNotNil applies the NotNil predicate on the "fabricant" field. +func FabricantNotNil() predicate.Objet { + return predicate.Objet(sql.FieldNotNull(FieldFabricant)) +} + +// FabricantEqualFold applies the EqualFold predicate on the "fabricant" field. +func FabricantEqualFold(v string) predicate.Objet { + return predicate.Objet(sql.FieldEqualFold(FieldFabricant, v)) +} + +// FabricantContainsFold applies the ContainsFold predicate on the "fabricant" field. +func FabricantContainsFold(v string) predicate.Objet { + return predicate.Objet(sql.FieldContainsFold(FieldFabricant, v)) +} + +// StatutEQ applies the EQ predicate on the "statut" field. +func StatutEQ(v Statut) predicate.Objet { + return predicate.Objet(sql.FieldEQ(FieldStatut, v)) +} + +// StatutNEQ applies the NEQ predicate on the "statut" field. +func StatutNEQ(v Statut) predicate.Objet { + return predicate.Objet(sql.FieldNEQ(FieldStatut, v)) +} + +// StatutIn applies the In predicate on the "statut" field. +func StatutIn(vs ...Statut) predicate.Objet { + return predicate.Objet(sql.FieldIn(FieldStatut, vs...)) +} + +// StatutNotIn applies the NotIn predicate on the "statut" field. +func StatutNotIn(vs ...Statut) predicate.Objet { + return predicate.Objet(sql.FieldNotIn(FieldStatut, vs...)) +} + +// CaracteristiquesIsNil applies the IsNil predicate on the "caracteristiques" field. +func CaracteristiquesIsNil() predicate.Objet { + return predicate.Objet(sql.FieldIsNull(FieldCaracteristiques)) +} + +// CaracteristiquesNotNil applies the NotNil predicate on the "caracteristiques" field. +func CaracteristiquesNotNil() predicate.Objet { + return predicate.Objet(sql.FieldNotNull(FieldCaracteristiques)) +} + +// CreatedAtEQ applies the EQ predicate on the "created_at" field. +func CreatedAtEQ(v time.Time) predicate.Objet { + return predicate.Objet(sql.FieldEQ(FieldCreatedAt, v)) +} + +// CreatedAtNEQ applies the NEQ predicate on the "created_at" field. +func CreatedAtNEQ(v time.Time) predicate.Objet { + return predicate.Objet(sql.FieldNEQ(FieldCreatedAt, v)) +} + +// CreatedAtIn applies the In predicate on the "created_at" field. +func CreatedAtIn(vs ...time.Time) predicate.Objet { + return predicate.Objet(sql.FieldIn(FieldCreatedAt, vs...)) +} + +// CreatedAtNotIn applies the NotIn predicate on the "created_at" field. +func CreatedAtNotIn(vs ...time.Time) predicate.Objet { + return predicate.Objet(sql.FieldNotIn(FieldCreatedAt, vs...)) +} + +// CreatedAtGT applies the GT predicate on the "created_at" field. +func CreatedAtGT(v time.Time) predicate.Objet { + return predicate.Objet(sql.FieldGT(FieldCreatedAt, v)) +} + +// CreatedAtGTE applies the GTE predicate on the "created_at" field. +func CreatedAtGTE(v time.Time) predicate.Objet { + return predicate.Objet(sql.FieldGTE(FieldCreatedAt, v)) +} + +// CreatedAtLT applies the LT predicate on the "created_at" field. +func CreatedAtLT(v time.Time) predicate.Objet { + return predicate.Objet(sql.FieldLT(FieldCreatedAt, v)) +} + +// CreatedAtLTE applies the LTE predicate on the "created_at" field. +func CreatedAtLTE(v time.Time) predicate.Objet { + return predicate.Objet(sql.FieldLTE(FieldCreatedAt, v)) +} + +// UpdatedAtEQ applies the EQ predicate on the "updated_at" field. +func UpdatedAtEQ(v time.Time) predicate.Objet { + return predicate.Objet(sql.FieldEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field. +func UpdatedAtNEQ(v time.Time) predicate.Objet { + return predicate.Objet(sql.FieldNEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtIn applies the In predicate on the "updated_at" field. +func UpdatedAtIn(vs ...time.Time) predicate.Objet { + return predicate.Objet(sql.FieldIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field. +func UpdatedAtNotIn(vs ...time.Time) predicate.Objet { + return predicate.Objet(sql.FieldNotIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtGT applies the GT predicate on the "updated_at" field. +func UpdatedAtGT(v time.Time) predicate.Objet { + return predicate.Objet(sql.FieldGT(FieldUpdatedAt, v)) +} + +// UpdatedAtGTE applies the GTE predicate on the "updated_at" field. +func UpdatedAtGTE(v time.Time) predicate.Objet { + return predicate.Objet(sql.FieldGTE(FieldUpdatedAt, v)) +} + +// UpdatedAtLT applies the LT predicate on the "updated_at" field. +func UpdatedAtLT(v time.Time) predicate.Objet { + return predicate.Objet(sql.FieldLT(FieldUpdatedAt, v)) +} + +// UpdatedAtLTE applies the LTE predicate on the "updated_at" field. +func UpdatedAtLTE(v time.Time) predicate.Objet { + return predicate.Objet(sql.FieldLTE(FieldUpdatedAt, v)) +} + +// HasLiensEmplacements applies the HasEdge predicate on the "liens_emplacements" edge. +func HasLiensEmplacements() predicate.Objet { + return predicate.Objet(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, LiensEmplacementsTable, LiensEmplacementsColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasLiensEmplacementsWith applies the HasEdge predicate on the "liens_emplacements" edge with a given conditions (other predicates). +func HasLiensEmplacementsWith(preds ...predicate.LienObjetEmplacement) predicate.Objet { + return predicate.Objet(func(s *sql.Selector) { + step := newLiensEmplacementsStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + +// HasChampsPersonnalises applies the HasEdge predicate on the "champs_personnalises" edge. +func HasChampsPersonnalises() predicate.Objet { + return predicate.Objet(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, ChampsPersonnalisesTable, ChampsPersonnalisesColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasChampsPersonnalisesWith applies the HasEdge predicate on the "champs_personnalises" edge with a given conditions (other predicates). +func HasChampsPersonnalisesWith(preds ...predicate.ChampPersonnalise) predicate.Objet { + return predicate.Objet(func(s *sql.Selector) { + step := newChampsPersonnalisesStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + +// HasPiecesJointes applies the HasEdge predicate on the "pieces_jointes" edge. +func HasPiecesJointes() predicate.Objet { + return predicate.Objet(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, PiecesJointesTable, PiecesJointesColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasPiecesJointesWith applies the HasEdge predicate on the "pieces_jointes" edge with a given conditions (other predicates). +func HasPiecesJointesWith(preds ...predicate.PieceJointe) predicate.Objet { + return predicate.Objet(func(s *sql.Selector) { + step := newPiecesJointesStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + +// And groups predicates with the AND operator between them. +func And(predicates ...predicate.Objet) predicate.Objet { + return predicate.Objet(sql.AndPredicates(predicates...)) +} + +// Or groups predicates with the OR operator between them. +func Or(predicates ...predicate.Objet) predicate.Objet { + return predicate.Objet(sql.OrPredicates(predicates...)) +} + +// Not applies the not operator on the given predicate. +func Not(p predicate.Objet) predicate.Objet { + return predicate.Objet(sql.NotPredicates(p)) +} diff --git a/backend/internal/data/ent/objet_create.go b/backend/internal/data/ent/objet_create.go new file mode 100644 index 0000000..93afe47 --- /dev/null +++ b/backend/internal/data/ent/objet_create.go @@ -0,0 +1,556 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + "time" + + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/champpersonnalise" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/lienobjetemplacement" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/objet" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/piecejointe" + "github.com/google/uuid" +) + +// ObjetCreate is the builder for creating a Objet entity. +type ObjetCreate struct { + config + mutation *ObjetMutation + hooks []Hook +} + +// SetNom sets the "nom" field. +func (_c *ObjetCreate) SetNom(v string) *ObjetCreate { + _c.mutation.SetNom(v) + return _c +} + +// SetDescription sets the "description" field. +func (_c *ObjetCreate) SetDescription(v string) *ObjetCreate { + _c.mutation.SetDescription(v) + return _c +} + +// SetNillableDescription sets the "description" field if the given value is not nil. +func (_c *ObjetCreate) SetNillableDescription(v *string) *ObjetCreate { + if v != nil { + _c.SetDescription(*v) + } + return _c +} + +// SetQuantite sets the "quantite" field. +func (_c *ObjetCreate) SetQuantite(v int) *ObjetCreate { + _c.mutation.SetQuantite(v) + return _c +} + +// SetNillableQuantite sets the "quantite" field if the given value is not nil. +func (_c *ObjetCreate) SetNillableQuantite(v *int) *ObjetCreate { + if v != nil { + _c.SetQuantite(*v) + } + return _c +} + +// SetPrixAchat sets the "prix_achat" field. +func (_c *ObjetCreate) SetPrixAchat(v float64) *ObjetCreate { + _c.mutation.SetPrixAchat(v) + return _c +} + +// SetNillablePrixAchat sets the "prix_achat" field if the given value is not nil. +func (_c *ObjetCreate) SetNillablePrixAchat(v *float64) *ObjetCreate { + if v != nil { + _c.SetPrixAchat(*v) + } + return _c +} + +// SetDateAchat sets the "date_achat" field. +func (_c *ObjetCreate) SetDateAchat(v time.Time) *ObjetCreate { + _c.mutation.SetDateAchat(v) + return _c +} + +// SetNillableDateAchat sets the "date_achat" field if the given value is not nil. +func (_c *ObjetCreate) SetNillableDateAchat(v *time.Time) *ObjetCreate { + if v != nil { + _c.SetDateAchat(*v) + } + return _c +} + +// SetBoutique sets the "boutique" field. +func (_c *ObjetCreate) SetBoutique(v string) *ObjetCreate { + _c.mutation.SetBoutique(v) + return _c +} + +// SetNillableBoutique sets the "boutique" field if the given value is not nil. +func (_c *ObjetCreate) SetNillableBoutique(v *string) *ObjetCreate { + if v != nil { + _c.SetBoutique(*v) + } + return _c +} + +// SetNumeroSerie sets the "numero_serie" field. +func (_c *ObjetCreate) SetNumeroSerie(v string) *ObjetCreate { + _c.mutation.SetNumeroSerie(v) + return _c +} + +// SetNillableNumeroSerie sets the "numero_serie" field if the given value is not nil. +func (_c *ObjetCreate) SetNillableNumeroSerie(v *string) *ObjetCreate { + if v != nil { + _c.SetNumeroSerie(*v) + } + return _c +} + +// SetNumeroModele sets the "numero_modele" field. +func (_c *ObjetCreate) SetNumeroModele(v string) *ObjetCreate { + _c.mutation.SetNumeroModele(v) + return _c +} + +// SetNillableNumeroModele sets the "numero_modele" field if the given value is not nil. +func (_c *ObjetCreate) SetNillableNumeroModele(v *string) *ObjetCreate { + if v != nil { + _c.SetNumeroModele(*v) + } + return _c +} + +// SetFabricant sets the "fabricant" field. +func (_c *ObjetCreate) SetFabricant(v string) *ObjetCreate { + _c.mutation.SetFabricant(v) + return _c +} + +// SetNillableFabricant sets the "fabricant" field if the given value is not nil. +func (_c *ObjetCreate) SetNillableFabricant(v *string) *ObjetCreate { + if v != nil { + _c.SetFabricant(*v) + } + return _c +} + +// SetStatut sets the "statut" field. +func (_c *ObjetCreate) SetStatut(v objet.Statut) *ObjetCreate { + _c.mutation.SetStatut(v) + return _c +} + +// SetNillableStatut sets the "statut" field if the given value is not nil. +func (_c *ObjetCreate) SetNillableStatut(v *objet.Statut) *ObjetCreate { + if v != nil { + _c.SetStatut(*v) + } + return _c +} + +// SetCaracteristiques sets the "caracteristiques" field. +func (_c *ObjetCreate) SetCaracteristiques(v map[string]interface{}) *ObjetCreate { + _c.mutation.SetCaracteristiques(v) + return _c +} + +// SetCreatedAt sets the "created_at" field. +func (_c *ObjetCreate) SetCreatedAt(v time.Time) *ObjetCreate { + _c.mutation.SetCreatedAt(v) + return _c +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (_c *ObjetCreate) SetNillableCreatedAt(v *time.Time) *ObjetCreate { + if v != nil { + _c.SetCreatedAt(*v) + } + return _c +} + +// SetUpdatedAt sets the "updated_at" field. +func (_c *ObjetCreate) SetUpdatedAt(v time.Time) *ObjetCreate { + _c.mutation.SetUpdatedAt(v) + return _c +} + +// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. +func (_c *ObjetCreate) SetNillableUpdatedAt(v *time.Time) *ObjetCreate { + if v != nil { + _c.SetUpdatedAt(*v) + } + return _c +} + +// SetID sets the "id" field. +func (_c *ObjetCreate) SetID(v uuid.UUID) *ObjetCreate { + _c.mutation.SetID(v) + return _c +} + +// SetNillableID sets the "id" field if the given value is not nil. +func (_c *ObjetCreate) SetNillableID(v *uuid.UUID) *ObjetCreate { + if v != nil { + _c.SetID(*v) + } + return _c +} + +// AddLiensEmplacementIDs adds the "liens_emplacements" edge to the LienObjetEmplacement entity by IDs. +func (_c *ObjetCreate) AddLiensEmplacementIDs(ids ...uuid.UUID) *ObjetCreate { + _c.mutation.AddLiensEmplacementIDs(ids...) + return _c +} + +// AddLiensEmplacements adds the "liens_emplacements" edges to the LienObjetEmplacement entity. +func (_c *ObjetCreate) AddLiensEmplacements(v ...*LienObjetEmplacement) *ObjetCreate { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _c.AddLiensEmplacementIDs(ids...) +} + +// AddChampsPersonnaliseIDs adds the "champs_personnalises" edge to the ChampPersonnalise entity by IDs. +func (_c *ObjetCreate) AddChampsPersonnaliseIDs(ids ...uuid.UUID) *ObjetCreate { + _c.mutation.AddChampsPersonnaliseIDs(ids...) + return _c +} + +// AddChampsPersonnalises adds the "champs_personnalises" edges to the ChampPersonnalise entity. +func (_c *ObjetCreate) AddChampsPersonnalises(v ...*ChampPersonnalise) *ObjetCreate { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _c.AddChampsPersonnaliseIDs(ids...) +} + +// AddPiecesJointeIDs adds the "pieces_jointes" edge to the PieceJointe entity by IDs. +func (_c *ObjetCreate) AddPiecesJointeIDs(ids ...uuid.UUID) *ObjetCreate { + _c.mutation.AddPiecesJointeIDs(ids...) + return _c +} + +// AddPiecesJointes adds the "pieces_jointes" edges to the PieceJointe entity. +func (_c *ObjetCreate) AddPiecesJointes(v ...*PieceJointe) *ObjetCreate { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _c.AddPiecesJointeIDs(ids...) +} + +// Mutation returns the ObjetMutation object of the builder. +func (_c *ObjetCreate) Mutation() *ObjetMutation { + return _c.mutation +} + +// Save creates the Objet in the database. +func (_c *ObjetCreate) Save(ctx context.Context) (*Objet, error) { + _c.defaults() + return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks) +} + +// SaveX calls Save and panics if Save returns an error. +func (_c *ObjetCreate) SaveX(ctx context.Context) *Objet { + v, err := _c.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (_c *ObjetCreate) Exec(ctx context.Context) error { + _, err := _c.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_c *ObjetCreate) ExecX(ctx context.Context) { + if err := _c.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (_c *ObjetCreate) defaults() { + if _, ok := _c.mutation.Quantite(); !ok { + v := objet.DefaultQuantite + _c.mutation.SetQuantite(v) + } + if _, ok := _c.mutation.Statut(); !ok { + v := objet.DefaultStatut + _c.mutation.SetStatut(v) + } + if _, ok := _c.mutation.CreatedAt(); !ok { + v := objet.DefaultCreatedAt() + _c.mutation.SetCreatedAt(v) + } + if _, ok := _c.mutation.UpdatedAt(); !ok { + v := objet.DefaultUpdatedAt() + _c.mutation.SetUpdatedAt(v) + } + if _, ok := _c.mutation.ID(); !ok { + v := objet.DefaultID() + _c.mutation.SetID(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_c *ObjetCreate) check() error { + if _, ok := _c.mutation.Nom(); !ok { + return &ValidationError{Name: "nom", err: errors.New(`ent: missing required field "Objet.nom"`)} + } + if v, ok := _c.mutation.Nom(); ok { + if err := objet.NomValidator(v); err != nil { + return &ValidationError{Name: "nom", err: fmt.Errorf(`ent: validator failed for field "Objet.nom": %w`, err)} + } + } + if _, ok := _c.mutation.Quantite(); !ok { + return &ValidationError{Name: "quantite", err: errors.New(`ent: missing required field "Objet.quantite"`)} + } + if _, ok := _c.mutation.Statut(); !ok { + return &ValidationError{Name: "statut", err: errors.New(`ent: missing required field "Objet.statut"`)} + } + if v, ok := _c.mutation.Statut(); ok { + if err := objet.StatutValidator(v); err != nil { + return &ValidationError{Name: "statut", err: fmt.Errorf(`ent: validator failed for field "Objet.statut": %w`, err)} + } + } + if _, ok := _c.mutation.CreatedAt(); !ok { + return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Objet.created_at"`)} + } + if _, ok := _c.mutation.UpdatedAt(); !ok { + return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "Objet.updated_at"`)} + } + return nil +} + +func (_c *ObjetCreate) sqlSave(ctx context.Context) (*Objet, error) { + if err := _c.check(); err != nil { + return nil, err + } + _node, _spec := _c.createSpec() + if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + if _spec.ID.Value != nil { + if id, ok := _spec.ID.Value.(*uuid.UUID); ok { + _node.ID = *id + } else if err := _node.ID.Scan(_spec.ID.Value); err != nil { + return nil, err + } + } + _c.mutation.id = &_node.ID + _c.mutation.done = true + return _node, nil +} + +func (_c *ObjetCreate) createSpec() (*Objet, *sqlgraph.CreateSpec) { + var ( + _node = &Objet{config: _c.config} + _spec = sqlgraph.NewCreateSpec(objet.Table, sqlgraph.NewFieldSpec(objet.FieldID, field.TypeUUID)) + ) + if id, ok := _c.mutation.ID(); ok { + _node.ID = id + _spec.ID.Value = &id + } + if value, ok := _c.mutation.Nom(); ok { + _spec.SetField(objet.FieldNom, field.TypeString, value) + _node.Nom = value + } + if value, ok := _c.mutation.Description(); ok { + _spec.SetField(objet.FieldDescription, field.TypeString, value) + _node.Description = &value + } + if value, ok := _c.mutation.Quantite(); ok { + _spec.SetField(objet.FieldQuantite, field.TypeInt, value) + _node.Quantite = value + } + if value, ok := _c.mutation.PrixAchat(); ok { + _spec.SetField(objet.FieldPrixAchat, field.TypeFloat64, value) + _node.PrixAchat = &value + } + if value, ok := _c.mutation.DateAchat(); ok { + _spec.SetField(objet.FieldDateAchat, field.TypeTime, value) + _node.DateAchat = &value + } + if value, ok := _c.mutation.Boutique(); ok { + _spec.SetField(objet.FieldBoutique, field.TypeString, value) + _node.Boutique = &value + } + if value, ok := _c.mutation.NumeroSerie(); ok { + _spec.SetField(objet.FieldNumeroSerie, field.TypeString, value) + _node.NumeroSerie = &value + } + if value, ok := _c.mutation.NumeroModele(); ok { + _spec.SetField(objet.FieldNumeroModele, field.TypeString, value) + _node.NumeroModele = &value + } + if value, ok := _c.mutation.Fabricant(); ok { + _spec.SetField(objet.FieldFabricant, field.TypeString, value) + _node.Fabricant = &value + } + if value, ok := _c.mutation.Statut(); ok { + _spec.SetField(objet.FieldStatut, field.TypeEnum, value) + _node.Statut = value + } + if value, ok := _c.mutation.Caracteristiques(); ok { + _spec.SetField(objet.FieldCaracteristiques, field.TypeJSON, value) + _node.Caracteristiques = value + } + if value, ok := _c.mutation.CreatedAt(); ok { + _spec.SetField(objet.FieldCreatedAt, field.TypeTime, value) + _node.CreatedAt = value + } + if value, ok := _c.mutation.UpdatedAt(); ok { + _spec.SetField(objet.FieldUpdatedAt, field.TypeTime, value) + _node.UpdatedAt = value + } + if nodes := _c.mutation.LiensEmplacementsIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: objet.LiensEmplacementsTable, + Columns: []string{objet.LiensEmplacementsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(lienobjetemplacement.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges = append(_spec.Edges, edge) + } + if nodes := _c.mutation.ChampsPersonnalisesIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: objet.ChampsPersonnalisesTable, + Columns: []string{objet.ChampsPersonnalisesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(champpersonnalise.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges = append(_spec.Edges, edge) + } + if nodes := _c.mutation.PiecesJointesIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: objet.PiecesJointesTable, + Columns: []string{objet.PiecesJointesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(piecejointe.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges = append(_spec.Edges, edge) + } + return _node, _spec +} + +// ObjetCreateBulk is the builder for creating many Objet entities in bulk. +type ObjetCreateBulk struct { + config + err error + builders []*ObjetCreate +} + +// Save creates the Objet entities in the database. +func (_c *ObjetCreateBulk) Save(ctx context.Context) ([]*Objet, error) { + if _c.err != nil { + return nil, _c.err + } + specs := make([]*sqlgraph.CreateSpec, len(_c.builders)) + nodes := make([]*Objet, len(_c.builders)) + mutators := make([]Mutator, len(_c.builders)) + for i := range _c.builders { + func(i int, root context.Context) { + builder := _c.builders[i] + builder.defaults() + var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { + mutation, ok := m.(*ObjetMutation) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T", m) + } + if err := builder.check(); err != nil { + return nil, err + } + builder.mutation = mutation + var err error + nodes[i], specs[i] = builder.createSpec() + if i < len(mutators)-1 { + _, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation) + } else { + spec := &sqlgraph.BatchCreateSpec{Nodes: specs} + // Invoke the actual operation on the latest mutation in the chain. + if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + } + } + if err != nil { + return nil, err + } + mutation.id = &nodes[i].ID + mutation.done = true + return nodes[i], nil + }) + for i := len(builder.hooks) - 1; i >= 0; i-- { + mut = builder.hooks[i](mut) + } + mutators[i] = mut + }(i, ctx) + } + if len(mutators) > 0 { + if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil { + return nil, err + } + } + return nodes, nil +} + +// SaveX is like Save, but panics if an error occurs. +func (_c *ObjetCreateBulk) SaveX(ctx context.Context) []*Objet { + v, err := _c.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (_c *ObjetCreateBulk) Exec(ctx context.Context) error { + _, err := _c.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_c *ObjetCreateBulk) ExecX(ctx context.Context) { + if err := _c.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/backend/internal/data/ent/objet_delete.go b/backend/internal/data/ent/objet_delete.go new file mode 100644 index 0000000..a74e907 --- /dev/null +++ b/backend/internal/data/ent/objet_delete.go @@ -0,0 +1,88 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/objet" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/predicate" +) + +// ObjetDelete is the builder for deleting a Objet entity. +type ObjetDelete struct { + config + hooks []Hook + mutation *ObjetMutation +} + +// Where appends a list predicates to the ObjetDelete builder. +func (_d *ObjetDelete) Where(ps ...predicate.Objet) *ObjetDelete { + _d.mutation.Where(ps...) + return _d +} + +// Exec executes the deletion query and returns how many vertices were deleted. +func (_d *ObjetDelete) Exec(ctx context.Context) (int, error) { + return withHooks(ctx, _d.sqlExec, _d.mutation, _d.hooks) +} + +// ExecX is like Exec, but panics if an error occurs. +func (_d *ObjetDelete) ExecX(ctx context.Context) int { + n, err := _d.Exec(ctx) + if err != nil { + panic(err) + } + return n +} + +func (_d *ObjetDelete) sqlExec(ctx context.Context) (int, error) { + _spec := sqlgraph.NewDeleteSpec(objet.Table, sqlgraph.NewFieldSpec(objet.FieldID, field.TypeUUID)) + if ps := _d.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + affected, err := sqlgraph.DeleteNodes(ctx, _d.driver, _spec) + if err != nil && sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + _d.mutation.done = true + return affected, err +} + +// ObjetDeleteOne is the builder for deleting a single Objet entity. +type ObjetDeleteOne struct { + _d *ObjetDelete +} + +// Where appends a list predicates to the ObjetDelete builder. +func (_d *ObjetDeleteOne) Where(ps ...predicate.Objet) *ObjetDeleteOne { + _d._d.mutation.Where(ps...) + return _d +} + +// Exec executes the deletion query. +func (_d *ObjetDeleteOne) Exec(ctx context.Context) error { + n, err := _d._d.Exec(ctx) + switch { + case err != nil: + return err + case n == 0: + return &NotFoundError{objet.Label} + default: + return nil + } +} + +// ExecX is like Exec, but panics if an error occurs. +func (_d *ObjetDeleteOne) ExecX(ctx context.Context) { + if err := _d.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/backend/internal/data/ent/objet_query.go b/backend/internal/data/ent/objet_query.go new file mode 100644 index 0000000..314f7d2 --- /dev/null +++ b/backend/internal/data/ent/objet_query.go @@ -0,0 +1,759 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "database/sql/driver" + "fmt" + "math" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/champpersonnalise" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/lienobjetemplacement" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/objet" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/piecejointe" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/predicate" + "github.com/google/uuid" +) + +// ObjetQuery is the builder for querying Objet entities. +type ObjetQuery struct { + config + ctx *QueryContext + order []objet.OrderOption + inters []Interceptor + predicates []predicate.Objet + withLiensEmplacements *LienObjetEmplacementQuery + withChampsPersonnalises *ChampPersonnaliseQuery + withPiecesJointes *PieceJointeQuery + // intermediate query (i.e. traversal path). + sql *sql.Selector + path func(context.Context) (*sql.Selector, error) +} + +// Where adds a new predicate for the ObjetQuery builder. +func (_q *ObjetQuery) Where(ps ...predicate.Objet) *ObjetQuery { + _q.predicates = append(_q.predicates, ps...) + return _q +} + +// Limit the number of records to be returned by this query. +func (_q *ObjetQuery) Limit(limit int) *ObjetQuery { + _q.ctx.Limit = &limit + return _q +} + +// Offset to start from. +func (_q *ObjetQuery) Offset(offset int) *ObjetQuery { + _q.ctx.Offset = &offset + return _q +} + +// Unique configures the query builder to filter duplicate records on query. +// By default, unique is set to true, and can be disabled using this method. +func (_q *ObjetQuery) Unique(unique bool) *ObjetQuery { + _q.ctx.Unique = &unique + return _q +} + +// Order specifies how the records should be ordered. +func (_q *ObjetQuery) Order(o ...objet.OrderOption) *ObjetQuery { + _q.order = append(_q.order, o...) + return _q +} + +// QueryLiensEmplacements chains the current query on the "liens_emplacements" edge. +func (_q *ObjetQuery) QueryLiensEmplacements() *LienObjetEmplacementQuery { + query := (&LienObjetEmplacementClient{config: _q.config}).Query() + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + selector := _q.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(objet.Table, objet.FieldID, selector), + sqlgraph.To(lienobjetemplacement.Table, lienobjetemplacement.FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, objet.LiensEmplacementsTable, objet.LiensEmplacementsColumn), + ) + fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) + return fromU, nil + } + return query +} + +// QueryChampsPersonnalises chains the current query on the "champs_personnalises" edge. +func (_q *ObjetQuery) QueryChampsPersonnalises() *ChampPersonnaliseQuery { + query := (&ChampPersonnaliseClient{config: _q.config}).Query() + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + selector := _q.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(objet.Table, objet.FieldID, selector), + sqlgraph.To(champpersonnalise.Table, champpersonnalise.FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, objet.ChampsPersonnalisesTable, objet.ChampsPersonnalisesColumn), + ) + fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) + return fromU, nil + } + return query +} + +// QueryPiecesJointes chains the current query on the "pieces_jointes" edge. +func (_q *ObjetQuery) QueryPiecesJointes() *PieceJointeQuery { + query := (&PieceJointeClient{config: _q.config}).Query() + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + selector := _q.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(objet.Table, objet.FieldID, selector), + sqlgraph.To(piecejointe.Table, piecejointe.FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, objet.PiecesJointesTable, objet.PiecesJointesColumn), + ) + fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) + return fromU, nil + } + return query +} + +// First returns the first Objet entity from the query. +// Returns a *NotFoundError when no Objet was found. +func (_q *ObjetQuery) First(ctx context.Context) (*Objet, error) { + nodes, err := _q.Limit(1).All(setContextOp(ctx, _q.ctx, ent.OpQueryFirst)) + if err != nil { + return nil, err + } + if len(nodes) == 0 { + return nil, &NotFoundError{objet.Label} + } + return nodes[0], nil +} + +// FirstX is like First, but panics if an error occurs. +func (_q *ObjetQuery) FirstX(ctx context.Context) *Objet { + node, err := _q.First(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return node +} + +// FirstID returns the first Objet ID from the query. +// Returns a *NotFoundError when no Objet ID was found. +func (_q *ObjetQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { + var ids []uuid.UUID + if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil { + return + } + if len(ids) == 0 { + err = &NotFoundError{objet.Label} + return + } + return ids[0], nil +} + +// FirstIDX is like FirstID, but panics if an error occurs. +func (_q *ObjetQuery) FirstIDX(ctx context.Context) uuid.UUID { + id, err := _q.FirstID(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return id +} + +// Only returns a single Objet entity found by the query, ensuring it only returns one. +// Returns a *NotSingularError when more than one Objet entity is found. +// Returns a *NotFoundError when no Objet entities are found. +func (_q *ObjetQuery) Only(ctx context.Context) (*Objet, error) { + nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly)) + if err != nil { + return nil, err + } + switch len(nodes) { + case 1: + return nodes[0], nil + case 0: + return nil, &NotFoundError{objet.Label} + default: + return nil, &NotSingularError{objet.Label} + } +} + +// OnlyX is like Only, but panics if an error occurs. +func (_q *ObjetQuery) OnlyX(ctx context.Context) *Objet { + node, err := _q.Only(ctx) + if err != nil { + panic(err) + } + return node +} + +// OnlyID is like Only, but returns the only Objet ID in the query. +// Returns a *NotSingularError when more than one Objet ID is found. +// Returns a *NotFoundError when no entities are found. +func (_q *ObjetQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { + var ids []uuid.UUID + if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryOnlyID)); err != nil { + return + } + switch len(ids) { + case 1: + id = ids[0] + case 0: + err = &NotFoundError{objet.Label} + default: + err = &NotSingularError{objet.Label} + } + return +} + +// OnlyIDX is like OnlyID, but panics if an error occurs. +func (_q *ObjetQuery) OnlyIDX(ctx context.Context) uuid.UUID { + id, err := _q.OnlyID(ctx) + if err != nil { + panic(err) + } + return id +} + +// All executes the query and returns a list of Objets. +func (_q *ObjetQuery) All(ctx context.Context) ([]*Objet, error) { + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll) + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + qr := querierAll[[]*Objet, *ObjetQuery]() + return withInterceptors[[]*Objet](ctx, _q, qr, _q.inters) +} + +// AllX is like All, but panics if an error occurs. +func (_q *ObjetQuery) AllX(ctx context.Context) []*Objet { + nodes, err := _q.All(ctx) + if err != nil { + panic(err) + } + return nodes +} + +// IDs executes the query and returns a list of Objet IDs. +func (_q *ObjetQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) { + if _q.ctx.Unique == nil && _q.path != nil { + _q.Unique(true) + } + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryIDs) + if err = _q.Select(objet.FieldID).Scan(ctx, &ids); err != nil { + return nil, err + } + return ids, nil +} + +// IDsX is like IDs, but panics if an error occurs. +func (_q *ObjetQuery) IDsX(ctx context.Context) []uuid.UUID { + ids, err := _q.IDs(ctx) + if err != nil { + panic(err) + } + return ids +} + +// Count returns the count of the given query. +func (_q *ObjetQuery) Count(ctx context.Context) (int, error) { + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryCount) + if err := _q.prepareQuery(ctx); err != nil { + return 0, err + } + return withInterceptors[int](ctx, _q, querierCount[*ObjetQuery](), _q.inters) +} + +// CountX is like Count, but panics if an error occurs. +func (_q *ObjetQuery) CountX(ctx context.Context) int { + count, err := _q.Count(ctx) + if err != nil { + panic(err) + } + return count +} + +// Exist returns true if the query has elements in the graph. +func (_q *ObjetQuery) Exist(ctx context.Context) (bool, error) { + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryExist) + switch _, err := _q.FirstID(ctx); { + case IsNotFound(err): + return false, nil + case err != nil: + return false, fmt.Errorf("ent: check existence: %w", err) + default: + return true, nil + } +} + +// ExistX is like Exist, but panics if an error occurs. +func (_q *ObjetQuery) ExistX(ctx context.Context) bool { + exist, err := _q.Exist(ctx) + if err != nil { + panic(err) + } + return exist +} + +// Clone returns a duplicate of the ObjetQuery builder, including all associated steps. It can be +// used to prepare common query builders and use them differently after the clone is made. +func (_q *ObjetQuery) Clone() *ObjetQuery { + if _q == nil { + return nil + } + return &ObjetQuery{ + config: _q.config, + ctx: _q.ctx.Clone(), + order: append([]objet.OrderOption{}, _q.order...), + inters: append([]Interceptor{}, _q.inters...), + predicates: append([]predicate.Objet{}, _q.predicates...), + withLiensEmplacements: _q.withLiensEmplacements.Clone(), + withChampsPersonnalises: _q.withChampsPersonnalises.Clone(), + withPiecesJointes: _q.withPiecesJointes.Clone(), + // clone intermediate query. + sql: _q.sql.Clone(), + path: _q.path, + } +} + +// WithLiensEmplacements tells the query-builder to eager-load the nodes that are connected to +// the "liens_emplacements" edge. The optional arguments are used to configure the query builder of the edge. +func (_q *ObjetQuery) WithLiensEmplacements(opts ...func(*LienObjetEmplacementQuery)) *ObjetQuery { + query := (&LienObjetEmplacementClient{config: _q.config}).Query() + for _, opt := range opts { + opt(query) + } + _q.withLiensEmplacements = query + return _q +} + +// WithChampsPersonnalises tells the query-builder to eager-load the nodes that are connected to +// the "champs_personnalises" edge. The optional arguments are used to configure the query builder of the edge. +func (_q *ObjetQuery) WithChampsPersonnalises(opts ...func(*ChampPersonnaliseQuery)) *ObjetQuery { + query := (&ChampPersonnaliseClient{config: _q.config}).Query() + for _, opt := range opts { + opt(query) + } + _q.withChampsPersonnalises = query + return _q +} + +// WithPiecesJointes tells the query-builder to eager-load the nodes that are connected to +// the "pieces_jointes" edge. The optional arguments are used to configure the query builder of the edge. +func (_q *ObjetQuery) WithPiecesJointes(opts ...func(*PieceJointeQuery)) *ObjetQuery { + query := (&PieceJointeClient{config: _q.config}).Query() + for _, opt := range opts { + opt(query) + } + _q.withPiecesJointes = query + return _q +} + +// GroupBy is used to group vertices by one or more fields/columns. +// It is often used with aggregate functions, like: count, max, mean, min, sum. +// +// Example: +// +// var v []struct { +// Nom string `json:"nom,omitempty"` +// Count int `json:"count,omitempty"` +// } +// +// client.Objet.Query(). +// GroupBy(objet.FieldNom). +// Aggregate(ent.Count()). +// Scan(ctx, &v) +func (_q *ObjetQuery) GroupBy(field string, fields ...string) *ObjetGroupBy { + _q.ctx.Fields = append([]string{field}, fields...) + grbuild := &ObjetGroupBy{build: _q} + grbuild.flds = &_q.ctx.Fields + grbuild.label = objet.Label + grbuild.scan = grbuild.Scan + return grbuild +} + +// Select allows the selection one or more fields/columns for the given query, +// instead of selecting all fields in the entity. +// +// Example: +// +// var v []struct { +// Nom string `json:"nom,omitempty"` +// } +// +// client.Objet.Query(). +// Select(objet.FieldNom). +// Scan(ctx, &v) +func (_q *ObjetQuery) Select(fields ...string) *ObjetSelect { + _q.ctx.Fields = append(_q.ctx.Fields, fields...) + sbuild := &ObjetSelect{ObjetQuery: _q} + sbuild.label = objet.Label + sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan + return sbuild +} + +// Aggregate returns a ObjetSelect configured with the given aggregations. +func (_q *ObjetQuery) Aggregate(fns ...AggregateFunc) *ObjetSelect { + return _q.Select().Aggregate(fns...) +} + +func (_q *ObjetQuery) prepareQuery(ctx context.Context) error { + for _, inter := range _q.inters { + if inter == nil { + return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)") + } + if trv, ok := inter.(Traverser); ok { + if err := trv.Traverse(ctx, _q); err != nil { + return err + } + } + } + for _, f := range _q.ctx.Fields { + if !objet.ValidColumn(f) { + return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + } + if _q.path != nil { + prev, err := _q.path(ctx) + if err != nil { + return err + } + _q.sql = prev + } + return nil +} + +func (_q *ObjetQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Objet, error) { + var ( + nodes = []*Objet{} + _spec = _q.querySpec() + loadedTypes = [3]bool{ + _q.withLiensEmplacements != nil, + _q.withChampsPersonnalises != nil, + _q.withPiecesJointes != nil, + } + ) + _spec.ScanValues = func(columns []string) ([]any, error) { + return (*Objet).scanValues(nil, columns) + } + _spec.Assign = func(columns []string, values []any) error { + node := &Objet{config: _q.config} + nodes = append(nodes, node) + node.Edges.loadedTypes = loadedTypes + return node.assignValues(columns, values) + } + for i := range hooks { + hooks[i](ctx, _spec) + } + if err := sqlgraph.QueryNodes(ctx, _q.driver, _spec); err != nil { + return nil, err + } + if len(nodes) == 0 { + return nodes, nil + } + if query := _q.withLiensEmplacements; query != nil { + if err := _q.loadLiensEmplacements(ctx, query, nodes, + func(n *Objet) { n.Edges.LiensEmplacements = []*LienObjetEmplacement{} }, + func(n *Objet, e *LienObjetEmplacement) { + n.Edges.LiensEmplacements = append(n.Edges.LiensEmplacements, e) + }); err != nil { + return nil, err + } + } + if query := _q.withChampsPersonnalises; query != nil { + if err := _q.loadChampsPersonnalises(ctx, query, nodes, + func(n *Objet) { n.Edges.ChampsPersonnalises = []*ChampPersonnalise{} }, + func(n *Objet, e *ChampPersonnalise) { + n.Edges.ChampsPersonnalises = append(n.Edges.ChampsPersonnalises, e) + }); err != nil { + return nil, err + } + } + if query := _q.withPiecesJointes; query != nil { + if err := _q.loadPiecesJointes(ctx, query, nodes, + func(n *Objet) { n.Edges.PiecesJointes = []*PieceJointe{} }, + func(n *Objet, e *PieceJointe) { n.Edges.PiecesJointes = append(n.Edges.PiecesJointes, e) }); err != nil { + return nil, err + } + } + return nodes, nil +} + +func (_q *ObjetQuery) loadLiensEmplacements(ctx context.Context, query *LienObjetEmplacementQuery, nodes []*Objet, init func(*Objet), assign func(*Objet, *LienObjetEmplacement)) error { + fks := make([]driver.Value, 0, len(nodes)) + nodeids := make(map[uuid.UUID]*Objet) + for i := range nodes { + fks = append(fks, nodes[i].ID) + nodeids[nodes[i].ID] = nodes[i] + if init != nil { + init(nodes[i]) + } + } + if len(query.ctx.Fields) > 0 { + query.ctx.AppendFieldOnce(lienobjetemplacement.FieldObjetID) + } + query.Where(predicate.LienObjetEmplacement(func(s *sql.Selector) { + s.Where(sql.InValues(s.C(objet.LiensEmplacementsColumn), fks...)) + })) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + fk := n.ObjetID + node, ok := nodeids[fk] + if !ok { + return fmt.Errorf(`unexpected referenced foreign-key "objet_id" returned %v for node %v`, fk, n.ID) + } + assign(node, n) + } + return nil +} +func (_q *ObjetQuery) loadChampsPersonnalises(ctx context.Context, query *ChampPersonnaliseQuery, nodes []*Objet, init func(*Objet), assign func(*Objet, *ChampPersonnalise)) error { + fks := make([]driver.Value, 0, len(nodes)) + nodeids := make(map[uuid.UUID]*Objet) + for i := range nodes { + fks = append(fks, nodes[i].ID) + nodeids[nodes[i].ID] = nodes[i] + if init != nil { + init(nodes[i]) + } + } + if len(query.ctx.Fields) > 0 { + query.ctx.AppendFieldOnce(champpersonnalise.FieldObjetID) + } + query.Where(predicate.ChampPersonnalise(func(s *sql.Selector) { + s.Where(sql.InValues(s.C(objet.ChampsPersonnalisesColumn), fks...)) + })) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + fk := n.ObjetID + node, ok := nodeids[fk] + if !ok { + return fmt.Errorf(`unexpected referenced foreign-key "objet_id" returned %v for node %v`, fk, n.ID) + } + assign(node, n) + } + return nil +} +func (_q *ObjetQuery) loadPiecesJointes(ctx context.Context, query *PieceJointeQuery, nodes []*Objet, init func(*Objet), assign func(*Objet, *PieceJointe)) error { + fks := make([]driver.Value, 0, len(nodes)) + nodeids := make(map[uuid.UUID]*Objet) + for i := range nodes { + fks = append(fks, nodes[i].ID) + nodeids[nodes[i].ID] = nodes[i] + if init != nil { + init(nodes[i]) + } + } + if len(query.ctx.Fields) > 0 { + query.ctx.AppendFieldOnce(piecejointe.FieldObjetID) + } + query.Where(predicate.PieceJointe(func(s *sql.Selector) { + s.Where(sql.InValues(s.C(objet.PiecesJointesColumn), fks...)) + })) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + fk := n.ObjetID + node, ok := nodeids[fk] + if !ok { + return fmt.Errorf(`unexpected referenced foreign-key "objet_id" returned %v for node %v`, fk, n.ID) + } + assign(node, n) + } + return nil +} + +func (_q *ObjetQuery) sqlCount(ctx context.Context) (int, error) { + _spec := _q.querySpec() + _spec.Node.Columns = _q.ctx.Fields + if len(_q.ctx.Fields) > 0 { + _spec.Unique = _q.ctx.Unique != nil && *_q.ctx.Unique + } + return sqlgraph.CountNodes(ctx, _q.driver, _spec) +} + +func (_q *ObjetQuery) querySpec() *sqlgraph.QuerySpec { + _spec := sqlgraph.NewQuerySpec(objet.Table, objet.Columns, sqlgraph.NewFieldSpec(objet.FieldID, field.TypeUUID)) + _spec.From = _q.sql + if unique := _q.ctx.Unique; unique != nil { + _spec.Unique = *unique + } else if _q.path != nil { + _spec.Unique = true + } + if fields := _q.ctx.Fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, objet.FieldID) + for i := range fields { + if fields[i] != objet.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) + } + } + } + if ps := _q.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if limit := _q.ctx.Limit; limit != nil { + _spec.Limit = *limit + } + if offset := _q.ctx.Offset; offset != nil { + _spec.Offset = *offset + } + if ps := _q.order; len(ps) > 0 { + _spec.Order = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + return _spec +} + +func (_q *ObjetQuery) sqlQuery(ctx context.Context) *sql.Selector { + builder := sql.Dialect(_q.driver.Dialect()) + t1 := builder.Table(objet.Table) + columns := _q.ctx.Fields + if len(columns) == 0 { + columns = objet.Columns + } + selector := builder.Select(t1.Columns(columns...)...).From(t1) + if _q.sql != nil { + selector = _q.sql + selector.Select(selector.Columns(columns...)...) + } + if _q.ctx.Unique != nil && *_q.ctx.Unique { + selector.Distinct() + } + for _, p := range _q.predicates { + p(selector) + } + for _, p := range _q.order { + p(selector) + } + if offset := _q.ctx.Offset; offset != nil { + // limit is mandatory for offset clause. We start + // with default value, and override it below if needed. + selector.Offset(*offset).Limit(math.MaxInt32) + } + if limit := _q.ctx.Limit; limit != nil { + selector.Limit(*limit) + } + return selector +} + +// ObjetGroupBy is the group-by builder for Objet entities. +type ObjetGroupBy struct { + selector + build *ObjetQuery +} + +// Aggregate adds the given aggregation functions to the group-by query. +func (_g *ObjetGroupBy) Aggregate(fns ...AggregateFunc) *ObjetGroupBy { + _g.fns = append(_g.fns, fns...) + return _g +} + +// Scan applies the selector query and scans the result into the given value. +func (_g *ObjetGroupBy) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, _g.build.ctx, ent.OpQueryGroupBy) + if err := _g.build.prepareQuery(ctx); err != nil { + return err + } + return scanWithInterceptors[*ObjetQuery, *ObjetGroupBy](ctx, _g.build, _g, _g.build.inters, v) +} + +func (_g *ObjetGroupBy) sqlScan(ctx context.Context, root *ObjetQuery, v any) error { + selector := root.sqlQuery(ctx).Select() + aggregation := make([]string, 0, len(_g.fns)) + for _, fn := range _g.fns { + aggregation = append(aggregation, fn(selector)) + } + if len(selector.SelectedColumns()) == 0 { + columns := make([]string, 0, len(*_g.flds)+len(_g.fns)) + for _, f := range *_g.flds { + columns = append(columns, selector.C(f)) + } + columns = append(columns, aggregation...) + selector.Select(columns...) + } + selector.GroupBy(selector.Columns(*_g.flds...)...) + if err := selector.Err(); err != nil { + return err + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := _g.build.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} + +// ObjetSelect is the builder for selecting fields of Objet entities. +type ObjetSelect struct { + *ObjetQuery + selector +} + +// Aggregate adds the given aggregation functions to the selector query. +func (_s *ObjetSelect) Aggregate(fns ...AggregateFunc) *ObjetSelect { + _s.fns = append(_s.fns, fns...) + return _s +} + +// Scan applies the selector query and scans the result into the given value. +func (_s *ObjetSelect) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, _s.ctx, ent.OpQuerySelect) + if err := _s.prepareQuery(ctx); err != nil { + return err + } + return scanWithInterceptors[*ObjetQuery, *ObjetSelect](ctx, _s.ObjetQuery, _s, _s.inters, v) +} + +func (_s *ObjetSelect) sqlScan(ctx context.Context, root *ObjetQuery, v any) error { + selector := root.sqlQuery(ctx) + aggregation := make([]string, 0, len(_s.fns)) + for _, fn := range _s.fns { + aggregation = append(aggregation, fn(selector)) + } + switch n := len(*_s.selector.flds); { + case n == 0 && len(aggregation) > 0: + selector.Select(aggregation...) + case n != 0 && len(aggregation) > 0: + selector.AppendSelect(aggregation...) + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := _s.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} diff --git a/backend/internal/data/ent/objet_update.go b/backend/internal/data/ent/objet_update.go new file mode 100644 index 0000000..d01d666 --- /dev/null +++ b/backend/internal/data/ent/objet_update.go @@ -0,0 +1,1314 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/champpersonnalise" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/lienobjetemplacement" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/objet" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/piecejointe" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/predicate" + "github.com/google/uuid" +) + +// ObjetUpdate is the builder for updating Objet entities. +type ObjetUpdate struct { + config + hooks []Hook + mutation *ObjetMutation +} + +// Where appends a list predicates to the ObjetUpdate builder. +func (_u *ObjetUpdate) Where(ps ...predicate.Objet) *ObjetUpdate { + _u.mutation.Where(ps...) + return _u +} + +// SetNom sets the "nom" field. +func (_u *ObjetUpdate) SetNom(v string) *ObjetUpdate { + _u.mutation.SetNom(v) + return _u +} + +// SetNillableNom sets the "nom" field if the given value is not nil. +func (_u *ObjetUpdate) SetNillableNom(v *string) *ObjetUpdate { + if v != nil { + _u.SetNom(*v) + } + return _u +} + +// SetDescription sets the "description" field. +func (_u *ObjetUpdate) SetDescription(v string) *ObjetUpdate { + _u.mutation.SetDescription(v) + return _u +} + +// SetNillableDescription sets the "description" field if the given value is not nil. +func (_u *ObjetUpdate) SetNillableDescription(v *string) *ObjetUpdate { + if v != nil { + _u.SetDescription(*v) + } + return _u +} + +// ClearDescription clears the value of the "description" field. +func (_u *ObjetUpdate) ClearDescription() *ObjetUpdate { + _u.mutation.ClearDescription() + return _u +} + +// SetQuantite sets the "quantite" field. +func (_u *ObjetUpdate) SetQuantite(v int) *ObjetUpdate { + _u.mutation.ResetQuantite() + _u.mutation.SetQuantite(v) + return _u +} + +// SetNillableQuantite sets the "quantite" field if the given value is not nil. +func (_u *ObjetUpdate) SetNillableQuantite(v *int) *ObjetUpdate { + if v != nil { + _u.SetQuantite(*v) + } + return _u +} + +// AddQuantite adds value to the "quantite" field. +func (_u *ObjetUpdate) AddQuantite(v int) *ObjetUpdate { + _u.mutation.AddQuantite(v) + return _u +} + +// SetPrixAchat sets the "prix_achat" field. +func (_u *ObjetUpdate) SetPrixAchat(v float64) *ObjetUpdate { + _u.mutation.ResetPrixAchat() + _u.mutation.SetPrixAchat(v) + return _u +} + +// SetNillablePrixAchat sets the "prix_achat" field if the given value is not nil. +func (_u *ObjetUpdate) SetNillablePrixAchat(v *float64) *ObjetUpdate { + if v != nil { + _u.SetPrixAchat(*v) + } + return _u +} + +// AddPrixAchat adds value to the "prix_achat" field. +func (_u *ObjetUpdate) AddPrixAchat(v float64) *ObjetUpdate { + _u.mutation.AddPrixAchat(v) + return _u +} + +// ClearPrixAchat clears the value of the "prix_achat" field. +func (_u *ObjetUpdate) ClearPrixAchat() *ObjetUpdate { + _u.mutation.ClearPrixAchat() + return _u +} + +// SetDateAchat sets the "date_achat" field. +func (_u *ObjetUpdate) SetDateAchat(v time.Time) *ObjetUpdate { + _u.mutation.SetDateAchat(v) + return _u +} + +// SetNillableDateAchat sets the "date_achat" field if the given value is not nil. +func (_u *ObjetUpdate) SetNillableDateAchat(v *time.Time) *ObjetUpdate { + if v != nil { + _u.SetDateAchat(*v) + } + return _u +} + +// ClearDateAchat clears the value of the "date_achat" field. +func (_u *ObjetUpdate) ClearDateAchat() *ObjetUpdate { + _u.mutation.ClearDateAchat() + return _u +} + +// SetBoutique sets the "boutique" field. +func (_u *ObjetUpdate) SetBoutique(v string) *ObjetUpdate { + _u.mutation.SetBoutique(v) + return _u +} + +// SetNillableBoutique sets the "boutique" field if the given value is not nil. +func (_u *ObjetUpdate) SetNillableBoutique(v *string) *ObjetUpdate { + if v != nil { + _u.SetBoutique(*v) + } + return _u +} + +// ClearBoutique clears the value of the "boutique" field. +func (_u *ObjetUpdate) ClearBoutique() *ObjetUpdate { + _u.mutation.ClearBoutique() + return _u +} + +// SetNumeroSerie sets the "numero_serie" field. +func (_u *ObjetUpdate) SetNumeroSerie(v string) *ObjetUpdate { + _u.mutation.SetNumeroSerie(v) + return _u +} + +// SetNillableNumeroSerie sets the "numero_serie" field if the given value is not nil. +func (_u *ObjetUpdate) SetNillableNumeroSerie(v *string) *ObjetUpdate { + if v != nil { + _u.SetNumeroSerie(*v) + } + return _u +} + +// ClearNumeroSerie clears the value of the "numero_serie" field. +func (_u *ObjetUpdate) ClearNumeroSerie() *ObjetUpdate { + _u.mutation.ClearNumeroSerie() + return _u +} + +// SetNumeroModele sets the "numero_modele" field. +func (_u *ObjetUpdate) SetNumeroModele(v string) *ObjetUpdate { + _u.mutation.SetNumeroModele(v) + return _u +} + +// SetNillableNumeroModele sets the "numero_modele" field if the given value is not nil. +func (_u *ObjetUpdate) SetNillableNumeroModele(v *string) *ObjetUpdate { + if v != nil { + _u.SetNumeroModele(*v) + } + return _u +} + +// ClearNumeroModele clears the value of the "numero_modele" field. +func (_u *ObjetUpdate) ClearNumeroModele() *ObjetUpdate { + _u.mutation.ClearNumeroModele() + return _u +} + +// SetFabricant sets the "fabricant" field. +func (_u *ObjetUpdate) SetFabricant(v string) *ObjetUpdate { + _u.mutation.SetFabricant(v) + return _u +} + +// SetNillableFabricant sets the "fabricant" field if the given value is not nil. +func (_u *ObjetUpdate) SetNillableFabricant(v *string) *ObjetUpdate { + if v != nil { + _u.SetFabricant(*v) + } + return _u +} + +// ClearFabricant clears the value of the "fabricant" field. +func (_u *ObjetUpdate) ClearFabricant() *ObjetUpdate { + _u.mutation.ClearFabricant() + return _u +} + +// SetStatut sets the "statut" field. +func (_u *ObjetUpdate) SetStatut(v objet.Statut) *ObjetUpdate { + _u.mutation.SetStatut(v) + return _u +} + +// SetNillableStatut sets the "statut" field if the given value is not nil. +func (_u *ObjetUpdate) SetNillableStatut(v *objet.Statut) *ObjetUpdate { + if v != nil { + _u.SetStatut(*v) + } + return _u +} + +// SetCaracteristiques sets the "caracteristiques" field. +func (_u *ObjetUpdate) SetCaracteristiques(v map[string]interface{}) *ObjetUpdate { + _u.mutation.SetCaracteristiques(v) + return _u +} + +// ClearCaracteristiques clears the value of the "caracteristiques" field. +func (_u *ObjetUpdate) ClearCaracteristiques() *ObjetUpdate { + _u.mutation.ClearCaracteristiques() + return _u +} + +// SetCreatedAt sets the "created_at" field. +func (_u *ObjetUpdate) SetCreatedAt(v time.Time) *ObjetUpdate { + _u.mutation.SetCreatedAt(v) + return _u +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (_u *ObjetUpdate) SetNillableCreatedAt(v *time.Time) *ObjetUpdate { + if v != nil { + _u.SetCreatedAt(*v) + } + return _u +} + +// SetUpdatedAt sets the "updated_at" field. +func (_u *ObjetUpdate) SetUpdatedAt(v time.Time) *ObjetUpdate { + _u.mutation.SetUpdatedAt(v) + return _u +} + +// AddLiensEmplacementIDs adds the "liens_emplacements" edge to the LienObjetEmplacement entity by IDs. +func (_u *ObjetUpdate) AddLiensEmplacementIDs(ids ...uuid.UUID) *ObjetUpdate { + _u.mutation.AddLiensEmplacementIDs(ids...) + return _u +} + +// AddLiensEmplacements adds the "liens_emplacements" edges to the LienObjetEmplacement entity. +func (_u *ObjetUpdate) AddLiensEmplacements(v ...*LienObjetEmplacement) *ObjetUpdate { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.AddLiensEmplacementIDs(ids...) +} + +// AddChampsPersonnaliseIDs adds the "champs_personnalises" edge to the ChampPersonnalise entity by IDs. +func (_u *ObjetUpdate) AddChampsPersonnaliseIDs(ids ...uuid.UUID) *ObjetUpdate { + _u.mutation.AddChampsPersonnaliseIDs(ids...) + return _u +} + +// AddChampsPersonnalises adds the "champs_personnalises" edges to the ChampPersonnalise entity. +func (_u *ObjetUpdate) AddChampsPersonnalises(v ...*ChampPersonnalise) *ObjetUpdate { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.AddChampsPersonnaliseIDs(ids...) +} + +// AddPiecesJointeIDs adds the "pieces_jointes" edge to the PieceJointe entity by IDs. +func (_u *ObjetUpdate) AddPiecesJointeIDs(ids ...uuid.UUID) *ObjetUpdate { + _u.mutation.AddPiecesJointeIDs(ids...) + return _u +} + +// AddPiecesJointes adds the "pieces_jointes" edges to the PieceJointe entity. +func (_u *ObjetUpdate) AddPiecesJointes(v ...*PieceJointe) *ObjetUpdate { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.AddPiecesJointeIDs(ids...) +} + +// Mutation returns the ObjetMutation object of the builder. +func (_u *ObjetUpdate) Mutation() *ObjetMutation { + return _u.mutation +} + +// ClearLiensEmplacements clears all "liens_emplacements" edges to the LienObjetEmplacement entity. +func (_u *ObjetUpdate) ClearLiensEmplacements() *ObjetUpdate { + _u.mutation.ClearLiensEmplacements() + return _u +} + +// RemoveLiensEmplacementIDs removes the "liens_emplacements" edge to LienObjetEmplacement entities by IDs. +func (_u *ObjetUpdate) RemoveLiensEmplacementIDs(ids ...uuid.UUID) *ObjetUpdate { + _u.mutation.RemoveLiensEmplacementIDs(ids...) + return _u +} + +// RemoveLiensEmplacements removes "liens_emplacements" edges to LienObjetEmplacement entities. +func (_u *ObjetUpdate) RemoveLiensEmplacements(v ...*LienObjetEmplacement) *ObjetUpdate { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.RemoveLiensEmplacementIDs(ids...) +} + +// ClearChampsPersonnalises clears all "champs_personnalises" edges to the ChampPersonnalise entity. +func (_u *ObjetUpdate) ClearChampsPersonnalises() *ObjetUpdate { + _u.mutation.ClearChampsPersonnalises() + return _u +} + +// RemoveChampsPersonnaliseIDs removes the "champs_personnalises" edge to ChampPersonnalise entities by IDs. +func (_u *ObjetUpdate) RemoveChampsPersonnaliseIDs(ids ...uuid.UUID) *ObjetUpdate { + _u.mutation.RemoveChampsPersonnaliseIDs(ids...) + return _u +} + +// RemoveChampsPersonnalises removes "champs_personnalises" edges to ChampPersonnalise entities. +func (_u *ObjetUpdate) RemoveChampsPersonnalises(v ...*ChampPersonnalise) *ObjetUpdate { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.RemoveChampsPersonnaliseIDs(ids...) +} + +// ClearPiecesJointes clears all "pieces_jointes" edges to the PieceJointe entity. +func (_u *ObjetUpdate) ClearPiecesJointes() *ObjetUpdate { + _u.mutation.ClearPiecesJointes() + return _u +} + +// RemovePiecesJointeIDs removes the "pieces_jointes" edge to PieceJointe entities by IDs. +func (_u *ObjetUpdate) RemovePiecesJointeIDs(ids ...uuid.UUID) *ObjetUpdate { + _u.mutation.RemovePiecesJointeIDs(ids...) + return _u +} + +// RemovePiecesJointes removes "pieces_jointes" edges to PieceJointe entities. +func (_u *ObjetUpdate) RemovePiecesJointes(v ...*PieceJointe) *ObjetUpdate { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.RemovePiecesJointeIDs(ids...) +} + +// Save executes the query and returns the number of nodes affected by the update operation. +func (_u *ObjetUpdate) Save(ctx context.Context) (int, error) { + _u.defaults() + return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (_u *ObjetUpdate) SaveX(ctx context.Context) int { + affected, err := _u.Save(ctx) + if err != nil { + panic(err) + } + return affected +} + +// Exec executes the query. +func (_u *ObjetUpdate) Exec(ctx context.Context) error { + _, err := _u.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_u *ObjetUpdate) ExecX(ctx context.Context) { + if err := _u.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (_u *ObjetUpdate) defaults() { + if _, ok := _u.mutation.UpdatedAt(); !ok { + v := objet.UpdateDefaultUpdatedAt() + _u.mutation.SetUpdatedAt(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_u *ObjetUpdate) check() error { + if v, ok := _u.mutation.Nom(); ok { + if err := objet.NomValidator(v); err != nil { + return &ValidationError{Name: "nom", err: fmt.Errorf(`ent: validator failed for field "Objet.nom": %w`, err)} + } + } + if v, ok := _u.mutation.Statut(); ok { + if err := objet.StatutValidator(v); err != nil { + return &ValidationError{Name: "statut", err: fmt.Errorf(`ent: validator failed for field "Objet.statut": %w`, err)} + } + } + return nil +} + +func (_u *ObjetUpdate) sqlSave(ctx context.Context) (_node int, err error) { + if err := _u.check(); err != nil { + return _node, err + } + _spec := sqlgraph.NewUpdateSpec(objet.Table, objet.Columns, sqlgraph.NewFieldSpec(objet.FieldID, field.TypeUUID)) + if ps := _u.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := _u.mutation.Nom(); ok { + _spec.SetField(objet.FieldNom, field.TypeString, value) + } + if value, ok := _u.mutation.Description(); ok { + _spec.SetField(objet.FieldDescription, field.TypeString, value) + } + if _u.mutation.DescriptionCleared() { + _spec.ClearField(objet.FieldDescription, field.TypeString) + } + if value, ok := _u.mutation.Quantite(); ok { + _spec.SetField(objet.FieldQuantite, field.TypeInt, value) + } + if value, ok := _u.mutation.AddedQuantite(); ok { + _spec.AddField(objet.FieldQuantite, field.TypeInt, value) + } + if value, ok := _u.mutation.PrixAchat(); ok { + _spec.SetField(objet.FieldPrixAchat, field.TypeFloat64, value) + } + if value, ok := _u.mutation.AddedPrixAchat(); ok { + _spec.AddField(objet.FieldPrixAchat, field.TypeFloat64, value) + } + if _u.mutation.PrixAchatCleared() { + _spec.ClearField(objet.FieldPrixAchat, field.TypeFloat64) + } + if value, ok := _u.mutation.DateAchat(); ok { + _spec.SetField(objet.FieldDateAchat, field.TypeTime, value) + } + if _u.mutation.DateAchatCleared() { + _spec.ClearField(objet.FieldDateAchat, field.TypeTime) + } + if value, ok := _u.mutation.Boutique(); ok { + _spec.SetField(objet.FieldBoutique, field.TypeString, value) + } + if _u.mutation.BoutiqueCleared() { + _spec.ClearField(objet.FieldBoutique, field.TypeString) + } + if value, ok := _u.mutation.NumeroSerie(); ok { + _spec.SetField(objet.FieldNumeroSerie, field.TypeString, value) + } + if _u.mutation.NumeroSerieCleared() { + _spec.ClearField(objet.FieldNumeroSerie, field.TypeString) + } + if value, ok := _u.mutation.NumeroModele(); ok { + _spec.SetField(objet.FieldNumeroModele, field.TypeString, value) + } + if _u.mutation.NumeroModeleCleared() { + _spec.ClearField(objet.FieldNumeroModele, field.TypeString) + } + if value, ok := _u.mutation.Fabricant(); ok { + _spec.SetField(objet.FieldFabricant, field.TypeString, value) + } + if _u.mutation.FabricantCleared() { + _spec.ClearField(objet.FieldFabricant, field.TypeString) + } + if value, ok := _u.mutation.Statut(); ok { + _spec.SetField(objet.FieldStatut, field.TypeEnum, value) + } + if value, ok := _u.mutation.Caracteristiques(); ok { + _spec.SetField(objet.FieldCaracteristiques, field.TypeJSON, value) + } + if _u.mutation.CaracteristiquesCleared() { + _spec.ClearField(objet.FieldCaracteristiques, field.TypeJSON) + } + if value, ok := _u.mutation.CreatedAt(); ok { + _spec.SetField(objet.FieldCreatedAt, field.TypeTime, value) + } + if value, ok := _u.mutation.UpdatedAt(); ok { + _spec.SetField(objet.FieldUpdatedAt, field.TypeTime, value) + } + if _u.mutation.LiensEmplacementsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: objet.LiensEmplacementsTable, + Columns: []string{objet.LiensEmplacementsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(lienobjetemplacement.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.RemovedLiensEmplacementsIDs(); len(nodes) > 0 && !_u.mutation.LiensEmplacementsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: objet.LiensEmplacementsTable, + Columns: []string{objet.LiensEmplacementsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(lienobjetemplacement.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.LiensEmplacementsIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: objet.LiensEmplacementsTable, + Columns: []string{objet.LiensEmplacementsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(lienobjetemplacement.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if _u.mutation.ChampsPersonnalisesCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: objet.ChampsPersonnalisesTable, + Columns: []string{objet.ChampsPersonnalisesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(champpersonnalise.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.RemovedChampsPersonnalisesIDs(); len(nodes) > 0 && !_u.mutation.ChampsPersonnalisesCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: objet.ChampsPersonnalisesTable, + Columns: []string{objet.ChampsPersonnalisesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(champpersonnalise.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.ChampsPersonnalisesIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: objet.ChampsPersonnalisesTable, + Columns: []string{objet.ChampsPersonnalisesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(champpersonnalise.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if _u.mutation.PiecesJointesCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: objet.PiecesJointesTable, + Columns: []string{objet.PiecesJointesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(piecejointe.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.RemovedPiecesJointesIDs(); len(nodes) > 0 && !_u.mutation.PiecesJointesCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: objet.PiecesJointesTable, + Columns: []string{objet.PiecesJointesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(piecejointe.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.PiecesJointesIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: objet.PiecesJointesTable, + Columns: []string{objet.PiecesJointesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(piecejointe.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{objet.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return 0, err + } + _u.mutation.done = true + return _node, nil +} + +// ObjetUpdateOne is the builder for updating a single Objet entity. +type ObjetUpdateOne struct { + config + fields []string + hooks []Hook + mutation *ObjetMutation +} + +// SetNom sets the "nom" field. +func (_u *ObjetUpdateOne) SetNom(v string) *ObjetUpdateOne { + _u.mutation.SetNom(v) + return _u +} + +// SetNillableNom sets the "nom" field if the given value is not nil. +func (_u *ObjetUpdateOne) SetNillableNom(v *string) *ObjetUpdateOne { + if v != nil { + _u.SetNom(*v) + } + return _u +} + +// SetDescription sets the "description" field. +func (_u *ObjetUpdateOne) SetDescription(v string) *ObjetUpdateOne { + _u.mutation.SetDescription(v) + return _u +} + +// SetNillableDescription sets the "description" field if the given value is not nil. +func (_u *ObjetUpdateOne) SetNillableDescription(v *string) *ObjetUpdateOne { + if v != nil { + _u.SetDescription(*v) + } + return _u +} + +// ClearDescription clears the value of the "description" field. +func (_u *ObjetUpdateOne) ClearDescription() *ObjetUpdateOne { + _u.mutation.ClearDescription() + return _u +} + +// SetQuantite sets the "quantite" field. +func (_u *ObjetUpdateOne) SetQuantite(v int) *ObjetUpdateOne { + _u.mutation.ResetQuantite() + _u.mutation.SetQuantite(v) + return _u +} + +// SetNillableQuantite sets the "quantite" field if the given value is not nil. +func (_u *ObjetUpdateOne) SetNillableQuantite(v *int) *ObjetUpdateOne { + if v != nil { + _u.SetQuantite(*v) + } + return _u +} + +// AddQuantite adds value to the "quantite" field. +func (_u *ObjetUpdateOne) AddQuantite(v int) *ObjetUpdateOne { + _u.mutation.AddQuantite(v) + return _u +} + +// SetPrixAchat sets the "prix_achat" field. +func (_u *ObjetUpdateOne) SetPrixAchat(v float64) *ObjetUpdateOne { + _u.mutation.ResetPrixAchat() + _u.mutation.SetPrixAchat(v) + return _u +} + +// SetNillablePrixAchat sets the "prix_achat" field if the given value is not nil. +func (_u *ObjetUpdateOne) SetNillablePrixAchat(v *float64) *ObjetUpdateOne { + if v != nil { + _u.SetPrixAchat(*v) + } + return _u +} + +// AddPrixAchat adds value to the "prix_achat" field. +func (_u *ObjetUpdateOne) AddPrixAchat(v float64) *ObjetUpdateOne { + _u.mutation.AddPrixAchat(v) + return _u +} + +// ClearPrixAchat clears the value of the "prix_achat" field. +func (_u *ObjetUpdateOne) ClearPrixAchat() *ObjetUpdateOne { + _u.mutation.ClearPrixAchat() + return _u +} + +// SetDateAchat sets the "date_achat" field. +func (_u *ObjetUpdateOne) SetDateAchat(v time.Time) *ObjetUpdateOne { + _u.mutation.SetDateAchat(v) + return _u +} + +// SetNillableDateAchat sets the "date_achat" field if the given value is not nil. +func (_u *ObjetUpdateOne) SetNillableDateAchat(v *time.Time) *ObjetUpdateOne { + if v != nil { + _u.SetDateAchat(*v) + } + return _u +} + +// ClearDateAchat clears the value of the "date_achat" field. +func (_u *ObjetUpdateOne) ClearDateAchat() *ObjetUpdateOne { + _u.mutation.ClearDateAchat() + return _u +} + +// SetBoutique sets the "boutique" field. +func (_u *ObjetUpdateOne) SetBoutique(v string) *ObjetUpdateOne { + _u.mutation.SetBoutique(v) + return _u +} + +// SetNillableBoutique sets the "boutique" field if the given value is not nil. +func (_u *ObjetUpdateOne) SetNillableBoutique(v *string) *ObjetUpdateOne { + if v != nil { + _u.SetBoutique(*v) + } + return _u +} + +// ClearBoutique clears the value of the "boutique" field. +func (_u *ObjetUpdateOne) ClearBoutique() *ObjetUpdateOne { + _u.mutation.ClearBoutique() + return _u +} + +// SetNumeroSerie sets the "numero_serie" field. +func (_u *ObjetUpdateOne) SetNumeroSerie(v string) *ObjetUpdateOne { + _u.mutation.SetNumeroSerie(v) + return _u +} + +// SetNillableNumeroSerie sets the "numero_serie" field if the given value is not nil. +func (_u *ObjetUpdateOne) SetNillableNumeroSerie(v *string) *ObjetUpdateOne { + if v != nil { + _u.SetNumeroSerie(*v) + } + return _u +} + +// ClearNumeroSerie clears the value of the "numero_serie" field. +func (_u *ObjetUpdateOne) ClearNumeroSerie() *ObjetUpdateOne { + _u.mutation.ClearNumeroSerie() + return _u +} + +// SetNumeroModele sets the "numero_modele" field. +func (_u *ObjetUpdateOne) SetNumeroModele(v string) *ObjetUpdateOne { + _u.mutation.SetNumeroModele(v) + return _u +} + +// SetNillableNumeroModele sets the "numero_modele" field if the given value is not nil. +func (_u *ObjetUpdateOne) SetNillableNumeroModele(v *string) *ObjetUpdateOne { + if v != nil { + _u.SetNumeroModele(*v) + } + return _u +} + +// ClearNumeroModele clears the value of the "numero_modele" field. +func (_u *ObjetUpdateOne) ClearNumeroModele() *ObjetUpdateOne { + _u.mutation.ClearNumeroModele() + return _u +} + +// SetFabricant sets the "fabricant" field. +func (_u *ObjetUpdateOne) SetFabricant(v string) *ObjetUpdateOne { + _u.mutation.SetFabricant(v) + return _u +} + +// SetNillableFabricant sets the "fabricant" field if the given value is not nil. +func (_u *ObjetUpdateOne) SetNillableFabricant(v *string) *ObjetUpdateOne { + if v != nil { + _u.SetFabricant(*v) + } + return _u +} + +// ClearFabricant clears the value of the "fabricant" field. +func (_u *ObjetUpdateOne) ClearFabricant() *ObjetUpdateOne { + _u.mutation.ClearFabricant() + return _u +} + +// SetStatut sets the "statut" field. +func (_u *ObjetUpdateOne) SetStatut(v objet.Statut) *ObjetUpdateOne { + _u.mutation.SetStatut(v) + return _u +} + +// SetNillableStatut sets the "statut" field if the given value is not nil. +func (_u *ObjetUpdateOne) SetNillableStatut(v *objet.Statut) *ObjetUpdateOne { + if v != nil { + _u.SetStatut(*v) + } + return _u +} + +// SetCaracteristiques sets the "caracteristiques" field. +func (_u *ObjetUpdateOne) SetCaracteristiques(v map[string]interface{}) *ObjetUpdateOne { + _u.mutation.SetCaracteristiques(v) + return _u +} + +// ClearCaracteristiques clears the value of the "caracteristiques" field. +func (_u *ObjetUpdateOne) ClearCaracteristiques() *ObjetUpdateOne { + _u.mutation.ClearCaracteristiques() + return _u +} + +// SetCreatedAt sets the "created_at" field. +func (_u *ObjetUpdateOne) SetCreatedAt(v time.Time) *ObjetUpdateOne { + _u.mutation.SetCreatedAt(v) + return _u +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (_u *ObjetUpdateOne) SetNillableCreatedAt(v *time.Time) *ObjetUpdateOne { + if v != nil { + _u.SetCreatedAt(*v) + } + return _u +} + +// SetUpdatedAt sets the "updated_at" field. +func (_u *ObjetUpdateOne) SetUpdatedAt(v time.Time) *ObjetUpdateOne { + _u.mutation.SetUpdatedAt(v) + return _u +} + +// AddLiensEmplacementIDs adds the "liens_emplacements" edge to the LienObjetEmplacement entity by IDs. +func (_u *ObjetUpdateOne) AddLiensEmplacementIDs(ids ...uuid.UUID) *ObjetUpdateOne { + _u.mutation.AddLiensEmplacementIDs(ids...) + return _u +} + +// AddLiensEmplacements adds the "liens_emplacements" edges to the LienObjetEmplacement entity. +func (_u *ObjetUpdateOne) AddLiensEmplacements(v ...*LienObjetEmplacement) *ObjetUpdateOne { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.AddLiensEmplacementIDs(ids...) +} + +// AddChampsPersonnaliseIDs adds the "champs_personnalises" edge to the ChampPersonnalise entity by IDs. +func (_u *ObjetUpdateOne) AddChampsPersonnaliseIDs(ids ...uuid.UUID) *ObjetUpdateOne { + _u.mutation.AddChampsPersonnaliseIDs(ids...) + return _u +} + +// AddChampsPersonnalises adds the "champs_personnalises" edges to the ChampPersonnalise entity. +func (_u *ObjetUpdateOne) AddChampsPersonnalises(v ...*ChampPersonnalise) *ObjetUpdateOne { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.AddChampsPersonnaliseIDs(ids...) +} + +// AddPiecesJointeIDs adds the "pieces_jointes" edge to the PieceJointe entity by IDs. +func (_u *ObjetUpdateOne) AddPiecesJointeIDs(ids ...uuid.UUID) *ObjetUpdateOne { + _u.mutation.AddPiecesJointeIDs(ids...) + return _u +} + +// AddPiecesJointes adds the "pieces_jointes" edges to the PieceJointe entity. +func (_u *ObjetUpdateOne) AddPiecesJointes(v ...*PieceJointe) *ObjetUpdateOne { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.AddPiecesJointeIDs(ids...) +} + +// Mutation returns the ObjetMutation object of the builder. +func (_u *ObjetUpdateOne) Mutation() *ObjetMutation { + return _u.mutation +} + +// ClearLiensEmplacements clears all "liens_emplacements" edges to the LienObjetEmplacement entity. +func (_u *ObjetUpdateOne) ClearLiensEmplacements() *ObjetUpdateOne { + _u.mutation.ClearLiensEmplacements() + return _u +} + +// RemoveLiensEmplacementIDs removes the "liens_emplacements" edge to LienObjetEmplacement entities by IDs. +func (_u *ObjetUpdateOne) RemoveLiensEmplacementIDs(ids ...uuid.UUID) *ObjetUpdateOne { + _u.mutation.RemoveLiensEmplacementIDs(ids...) + return _u +} + +// RemoveLiensEmplacements removes "liens_emplacements" edges to LienObjetEmplacement entities. +func (_u *ObjetUpdateOne) RemoveLiensEmplacements(v ...*LienObjetEmplacement) *ObjetUpdateOne { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.RemoveLiensEmplacementIDs(ids...) +} + +// ClearChampsPersonnalises clears all "champs_personnalises" edges to the ChampPersonnalise entity. +func (_u *ObjetUpdateOne) ClearChampsPersonnalises() *ObjetUpdateOne { + _u.mutation.ClearChampsPersonnalises() + return _u +} + +// RemoveChampsPersonnaliseIDs removes the "champs_personnalises" edge to ChampPersonnalise entities by IDs. +func (_u *ObjetUpdateOne) RemoveChampsPersonnaliseIDs(ids ...uuid.UUID) *ObjetUpdateOne { + _u.mutation.RemoveChampsPersonnaliseIDs(ids...) + return _u +} + +// RemoveChampsPersonnalises removes "champs_personnalises" edges to ChampPersonnalise entities. +func (_u *ObjetUpdateOne) RemoveChampsPersonnalises(v ...*ChampPersonnalise) *ObjetUpdateOne { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.RemoveChampsPersonnaliseIDs(ids...) +} + +// ClearPiecesJointes clears all "pieces_jointes" edges to the PieceJointe entity. +func (_u *ObjetUpdateOne) ClearPiecesJointes() *ObjetUpdateOne { + _u.mutation.ClearPiecesJointes() + return _u +} + +// RemovePiecesJointeIDs removes the "pieces_jointes" edge to PieceJointe entities by IDs. +func (_u *ObjetUpdateOne) RemovePiecesJointeIDs(ids ...uuid.UUID) *ObjetUpdateOne { + _u.mutation.RemovePiecesJointeIDs(ids...) + return _u +} + +// RemovePiecesJointes removes "pieces_jointes" edges to PieceJointe entities. +func (_u *ObjetUpdateOne) RemovePiecesJointes(v ...*PieceJointe) *ObjetUpdateOne { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.RemovePiecesJointeIDs(ids...) +} + +// Where appends a list predicates to the ObjetUpdate builder. +func (_u *ObjetUpdateOne) Where(ps ...predicate.Objet) *ObjetUpdateOne { + _u.mutation.Where(ps...) + return _u +} + +// Select allows selecting one or more fields (columns) of the returned entity. +// The default is selecting all fields defined in the entity schema. +func (_u *ObjetUpdateOne) Select(field string, fields ...string) *ObjetUpdateOne { + _u.fields = append([]string{field}, fields...) + return _u +} + +// Save executes the query and returns the updated Objet entity. +func (_u *ObjetUpdateOne) Save(ctx context.Context) (*Objet, error) { + _u.defaults() + return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (_u *ObjetUpdateOne) SaveX(ctx context.Context) *Objet { + node, err := _u.Save(ctx) + if err != nil { + panic(err) + } + return node +} + +// Exec executes the query on the entity. +func (_u *ObjetUpdateOne) Exec(ctx context.Context) error { + _, err := _u.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_u *ObjetUpdateOne) ExecX(ctx context.Context) { + if err := _u.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (_u *ObjetUpdateOne) defaults() { + if _, ok := _u.mutation.UpdatedAt(); !ok { + v := objet.UpdateDefaultUpdatedAt() + _u.mutation.SetUpdatedAt(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_u *ObjetUpdateOne) check() error { + if v, ok := _u.mutation.Nom(); ok { + if err := objet.NomValidator(v); err != nil { + return &ValidationError{Name: "nom", err: fmt.Errorf(`ent: validator failed for field "Objet.nom": %w`, err)} + } + } + if v, ok := _u.mutation.Statut(); ok { + if err := objet.StatutValidator(v); err != nil { + return &ValidationError{Name: "statut", err: fmt.Errorf(`ent: validator failed for field "Objet.statut": %w`, err)} + } + } + return nil +} + +func (_u *ObjetUpdateOne) sqlSave(ctx context.Context) (_node *Objet, err error) { + if err := _u.check(); err != nil { + return _node, err + } + _spec := sqlgraph.NewUpdateSpec(objet.Table, objet.Columns, sqlgraph.NewFieldSpec(objet.FieldID, field.TypeUUID)) + id, ok := _u.mutation.ID() + if !ok { + return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Objet.id" for update`)} + } + _spec.Node.ID.Value = id + if fields := _u.fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, objet.FieldID) + for _, f := range fields { + if !objet.ValidColumn(f) { + return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + if f != objet.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, f) + } + } + } + if ps := _u.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := _u.mutation.Nom(); ok { + _spec.SetField(objet.FieldNom, field.TypeString, value) + } + if value, ok := _u.mutation.Description(); ok { + _spec.SetField(objet.FieldDescription, field.TypeString, value) + } + if _u.mutation.DescriptionCleared() { + _spec.ClearField(objet.FieldDescription, field.TypeString) + } + if value, ok := _u.mutation.Quantite(); ok { + _spec.SetField(objet.FieldQuantite, field.TypeInt, value) + } + if value, ok := _u.mutation.AddedQuantite(); ok { + _spec.AddField(objet.FieldQuantite, field.TypeInt, value) + } + if value, ok := _u.mutation.PrixAchat(); ok { + _spec.SetField(objet.FieldPrixAchat, field.TypeFloat64, value) + } + if value, ok := _u.mutation.AddedPrixAchat(); ok { + _spec.AddField(objet.FieldPrixAchat, field.TypeFloat64, value) + } + if _u.mutation.PrixAchatCleared() { + _spec.ClearField(objet.FieldPrixAchat, field.TypeFloat64) + } + if value, ok := _u.mutation.DateAchat(); ok { + _spec.SetField(objet.FieldDateAchat, field.TypeTime, value) + } + if _u.mutation.DateAchatCleared() { + _spec.ClearField(objet.FieldDateAchat, field.TypeTime) + } + if value, ok := _u.mutation.Boutique(); ok { + _spec.SetField(objet.FieldBoutique, field.TypeString, value) + } + if _u.mutation.BoutiqueCleared() { + _spec.ClearField(objet.FieldBoutique, field.TypeString) + } + if value, ok := _u.mutation.NumeroSerie(); ok { + _spec.SetField(objet.FieldNumeroSerie, field.TypeString, value) + } + if _u.mutation.NumeroSerieCleared() { + _spec.ClearField(objet.FieldNumeroSerie, field.TypeString) + } + if value, ok := _u.mutation.NumeroModele(); ok { + _spec.SetField(objet.FieldNumeroModele, field.TypeString, value) + } + if _u.mutation.NumeroModeleCleared() { + _spec.ClearField(objet.FieldNumeroModele, field.TypeString) + } + if value, ok := _u.mutation.Fabricant(); ok { + _spec.SetField(objet.FieldFabricant, field.TypeString, value) + } + if _u.mutation.FabricantCleared() { + _spec.ClearField(objet.FieldFabricant, field.TypeString) + } + if value, ok := _u.mutation.Statut(); ok { + _spec.SetField(objet.FieldStatut, field.TypeEnum, value) + } + if value, ok := _u.mutation.Caracteristiques(); ok { + _spec.SetField(objet.FieldCaracteristiques, field.TypeJSON, value) + } + if _u.mutation.CaracteristiquesCleared() { + _spec.ClearField(objet.FieldCaracteristiques, field.TypeJSON) + } + if value, ok := _u.mutation.CreatedAt(); ok { + _spec.SetField(objet.FieldCreatedAt, field.TypeTime, value) + } + if value, ok := _u.mutation.UpdatedAt(); ok { + _spec.SetField(objet.FieldUpdatedAt, field.TypeTime, value) + } + if _u.mutation.LiensEmplacementsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: objet.LiensEmplacementsTable, + Columns: []string{objet.LiensEmplacementsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(lienobjetemplacement.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.RemovedLiensEmplacementsIDs(); len(nodes) > 0 && !_u.mutation.LiensEmplacementsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: objet.LiensEmplacementsTable, + Columns: []string{objet.LiensEmplacementsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(lienobjetemplacement.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.LiensEmplacementsIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: objet.LiensEmplacementsTable, + Columns: []string{objet.LiensEmplacementsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(lienobjetemplacement.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if _u.mutation.ChampsPersonnalisesCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: objet.ChampsPersonnalisesTable, + Columns: []string{objet.ChampsPersonnalisesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(champpersonnalise.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.RemovedChampsPersonnalisesIDs(); len(nodes) > 0 && !_u.mutation.ChampsPersonnalisesCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: objet.ChampsPersonnalisesTable, + Columns: []string{objet.ChampsPersonnalisesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(champpersonnalise.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.ChampsPersonnalisesIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: objet.ChampsPersonnalisesTable, + Columns: []string{objet.ChampsPersonnalisesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(champpersonnalise.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if _u.mutation.PiecesJointesCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: objet.PiecesJointesTable, + Columns: []string{objet.PiecesJointesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(piecejointe.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.RemovedPiecesJointesIDs(); len(nodes) > 0 && !_u.mutation.PiecesJointesCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: objet.PiecesJointesTable, + Columns: []string{objet.PiecesJointesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(piecejointe.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.PiecesJointesIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: objet.PiecesJointesTable, + Columns: []string{objet.PiecesJointesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(piecejointe.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + _node = &Objet{config: _u.config} + _spec.Assign = _node.assignValues + _spec.ScanValues = _node.scanValues + if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{objet.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + _u.mutation.done = true + return _node, nil +} diff --git a/backend/internal/data/ent/piecejointe.go b/backend/internal/data/ent/piecejointe.go new file mode 100644 index 0000000..1bd68ef --- /dev/null +++ b/backend/internal/data/ent/piecejointe.go @@ -0,0 +1,216 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "fmt" + "strings" + "time" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/objet" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/piecejointe" + "github.com/google/uuid" +) + +// PieceJointe is the model entity for the PieceJointe schema. +type PieceJointe struct { + config `json:"-"` + // ID of the ent. + // Identifiant unique de la piece jointe + ID uuid.UUID `json:"id,omitempty"` + // Identifiant de l'objet + ObjetID uuid.UUID `json:"objet_id,omitempty"` + // Nom du fichier + NomFichier string `json:"nom_fichier,omitempty"` + // Chemin de stockage + Chemin string `json:"chemin,omitempty"` + // Type MIME + TypeMime string `json:"type_mime,omitempty"` + // Piece jointe principale + EstPrincipale bool `json:"est_principale,omitempty"` + // Categorie de la piece jointe + Categorie piecejointe.Categorie `json:"categorie,omitempty"` + // Date de creation + CreatedAt time.Time `json:"created_at,omitempty"` + // Date de derniere mise a jour + UpdatedAt time.Time `json:"updated_at,omitempty"` + // Edges holds the relations/edges for other nodes in the graph. + // The values are being populated by the PieceJointeQuery when eager-loading is set. + Edges PieceJointeEdges `json:"edges"` + selectValues sql.SelectValues +} + +// PieceJointeEdges holds the relations/edges for other nodes in the graph. +type PieceJointeEdges struct { + // Objet holds the value of the objet edge. + Objet *Objet `json:"objet,omitempty"` + // loadedTypes holds the information for reporting if a + // type was loaded (or requested) in eager-loading or not. + loadedTypes [1]bool +} + +// ObjetOrErr returns the Objet value or an error if the edge +// was not loaded in eager-loading, or loaded but was not found. +func (e PieceJointeEdges) ObjetOrErr() (*Objet, error) { + if e.Objet != nil { + return e.Objet, nil + } else if e.loadedTypes[0] { + return nil, &NotFoundError{label: objet.Label} + } + return nil, &NotLoadedError{edge: "objet"} +} + +// scanValues returns the types for scanning values from sql.Rows. +func (*PieceJointe) scanValues(columns []string) ([]any, error) { + values := make([]any, len(columns)) + for i := range columns { + switch columns[i] { + case piecejointe.FieldEstPrincipale: + values[i] = new(sql.NullBool) + case piecejointe.FieldNomFichier, piecejointe.FieldChemin, piecejointe.FieldTypeMime, piecejointe.FieldCategorie: + values[i] = new(sql.NullString) + case piecejointe.FieldCreatedAt, piecejointe.FieldUpdatedAt: + values[i] = new(sql.NullTime) + case piecejointe.FieldID, piecejointe.FieldObjetID: + values[i] = new(uuid.UUID) + default: + values[i] = new(sql.UnknownType) + } + } + return values, nil +} + +// assignValues assigns the values that were returned from sql.Rows (after scanning) +// to the PieceJointe fields. +func (_m *PieceJointe) assignValues(columns []string, values []any) error { + if m, n := len(values), len(columns); m < n { + return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) + } + for i := range columns { + switch columns[i] { + case piecejointe.FieldID: + if value, ok := values[i].(*uuid.UUID); !ok { + return fmt.Errorf("unexpected type %T for field id", values[i]) + } else if value != nil { + _m.ID = *value + } + case piecejointe.FieldObjetID: + if value, ok := values[i].(*uuid.UUID); !ok { + return fmt.Errorf("unexpected type %T for field objet_id", values[i]) + } else if value != nil { + _m.ObjetID = *value + } + case piecejointe.FieldNomFichier: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field nom_fichier", values[i]) + } else if value.Valid { + _m.NomFichier = value.String + } + case piecejointe.FieldChemin: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field chemin", values[i]) + } else if value.Valid { + _m.Chemin = value.String + } + case piecejointe.FieldTypeMime: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field type_mime", values[i]) + } else if value.Valid { + _m.TypeMime = value.String + } + case piecejointe.FieldEstPrincipale: + if value, ok := values[i].(*sql.NullBool); !ok { + return fmt.Errorf("unexpected type %T for field est_principale", values[i]) + } else if value.Valid { + _m.EstPrincipale = value.Bool + } + case piecejointe.FieldCategorie: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field categorie", values[i]) + } else if value.Valid { + _m.Categorie = piecejointe.Categorie(value.String) + } + case piecejointe.FieldCreatedAt: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field created_at", values[i]) + } else if value.Valid { + _m.CreatedAt = value.Time + } + case piecejointe.FieldUpdatedAt: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field updated_at", values[i]) + } else if value.Valid { + _m.UpdatedAt = value.Time + } + default: + _m.selectValues.Set(columns[i], values[i]) + } + } + return nil +} + +// Value returns the ent.Value that was dynamically selected and assigned to the PieceJointe. +// This includes values selected through modifiers, order, etc. +func (_m *PieceJointe) Value(name string) (ent.Value, error) { + return _m.selectValues.Get(name) +} + +// QueryObjet queries the "objet" edge of the PieceJointe entity. +func (_m *PieceJointe) QueryObjet() *ObjetQuery { + return NewPieceJointeClient(_m.config).QueryObjet(_m) +} + +// Update returns a builder for updating this PieceJointe. +// Note that you need to call PieceJointe.Unwrap() before calling this method if this PieceJointe +// was returned from a transaction, and the transaction was committed or rolled back. +func (_m *PieceJointe) Update() *PieceJointeUpdateOne { + return NewPieceJointeClient(_m.config).UpdateOne(_m) +} + +// Unwrap unwraps the PieceJointe entity that was returned from a transaction after it was closed, +// so that all future queries will be executed through the driver which created the transaction. +func (_m *PieceJointe) Unwrap() *PieceJointe { + _tx, ok := _m.config.driver.(*txDriver) + if !ok { + panic("ent: PieceJointe is not a transactional entity") + } + _m.config.driver = _tx.drv + return _m +} + +// String implements the fmt.Stringer. +func (_m *PieceJointe) String() string { + var builder strings.Builder + builder.WriteString("PieceJointe(") + builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID)) + builder.WriteString("objet_id=") + builder.WriteString(fmt.Sprintf("%v", _m.ObjetID)) + builder.WriteString(", ") + builder.WriteString("nom_fichier=") + builder.WriteString(_m.NomFichier) + builder.WriteString(", ") + builder.WriteString("chemin=") + builder.WriteString(_m.Chemin) + builder.WriteString(", ") + builder.WriteString("type_mime=") + builder.WriteString(_m.TypeMime) + builder.WriteString(", ") + builder.WriteString("est_principale=") + builder.WriteString(fmt.Sprintf("%v", _m.EstPrincipale)) + builder.WriteString(", ") + builder.WriteString("categorie=") + builder.WriteString(fmt.Sprintf("%v", _m.Categorie)) + builder.WriteString(", ") + builder.WriteString("created_at=") + builder.WriteString(_m.CreatedAt.Format(time.ANSIC)) + builder.WriteString(", ") + builder.WriteString("updated_at=") + builder.WriteString(_m.UpdatedAt.Format(time.ANSIC)) + builder.WriteByte(')') + return builder.String() +} + +// PieceJointes is a parsable slice of PieceJointe. +type PieceJointes []*PieceJointe diff --git a/backend/internal/data/ent/piecejointe/piecejointe.go b/backend/internal/data/ent/piecejointe/piecejointe.go new file mode 100644 index 0000000..2d400a9 --- /dev/null +++ b/backend/internal/data/ent/piecejointe/piecejointe.go @@ -0,0 +1,177 @@ +// Code generated by ent, DO NOT EDIT. + +package piecejointe + +import ( + "fmt" + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "github.com/google/uuid" +) + +const ( + // Label holds the string label denoting the piecejointe type in the database. + Label = "piece_jointe" + // FieldID holds the string denoting the id field in the database. + FieldID = "id" + // FieldObjetID holds the string denoting the objet_id field in the database. + FieldObjetID = "objet_id" + // FieldNomFichier holds the string denoting the nom_fichier field in the database. + FieldNomFichier = "nom_fichier" + // FieldChemin holds the string denoting the chemin field in the database. + FieldChemin = "chemin" + // FieldTypeMime holds the string denoting the type_mime field in the database. + FieldTypeMime = "type_mime" + // FieldEstPrincipale holds the string denoting the est_principale field in the database. + FieldEstPrincipale = "est_principale" + // FieldCategorie holds the string denoting the categorie field in the database. + FieldCategorie = "categorie" + // FieldCreatedAt holds the string denoting the created_at field in the database. + FieldCreatedAt = "created_at" + // FieldUpdatedAt holds the string denoting the updated_at field in the database. + FieldUpdatedAt = "updated_at" + // EdgeObjet holds the string denoting the objet edge name in mutations. + EdgeObjet = "objet" + // Table holds the table name of the piecejointe in the database. + Table = "piece_jointe" + // ObjetTable is the table that holds the objet relation/edge. + ObjetTable = "piece_jointe" + // ObjetInverseTable is the table name for the Objet entity. + // It exists in this package in order to avoid circular dependency with the "objet" package. + ObjetInverseTable = "objet" + // ObjetColumn is the table column denoting the objet relation/edge. + ObjetColumn = "objet_id" +) + +// Columns holds all SQL columns for piecejointe fields. +var Columns = []string{ + FieldID, + FieldObjetID, + FieldNomFichier, + FieldChemin, + FieldTypeMime, + FieldEstPrincipale, + FieldCategorie, + FieldCreatedAt, + FieldUpdatedAt, +} + +// ValidColumn reports if the column name is valid (part of the table columns). +func ValidColumn(column string) bool { + for i := range Columns { + if column == Columns[i] { + return true + } + } + return false +} + +var ( + // NomFichierValidator is a validator for the "nom_fichier" field. It is called by the builders before save. + NomFichierValidator func(string) error + // CheminValidator is a validator for the "chemin" field. It is called by the builders before save. + CheminValidator func(string) error + // TypeMimeValidator is a validator for the "type_mime" field. It is called by the builders before save. + TypeMimeValidator func(string) error + // DefaultEstPrincipale holds the default value on creation for the "est_principale" field. + DefaultEstPrincipale bool + // DefaultCreatedAt holds the default value on creation for the "created_at" field. + DefaultCreatedAt func() time.Time + // DefaultUpdatedAt holds the default value on creation for the "updated_at" field. + DefaultUpdatedAt func() time.Time + // UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field. + UpdateDefaultUpdatedAt func() time.Time + // DefaultID holds the default value on creation for the "id" field. + DefaultID func() uuid.UUID +) + +// Categorie defines the type for the "categorie" enum field. +type Categorie string + +// CategorieImage is the default value of the Categorie enum. +const DefaultCategorie = CategorieImage + +// Categorie values. +const ( + CategorieImage Categorie = "image" + CategoriePdfNotice Categorie = "pdf_notice" + CategorieMarkdownTuto Categorie = "markdown_tuto" +) + +func (c Categorie) String() string { + return string(c) +} + +// CategorieValidator is a validator for the "categorie" field enum values. It is called by the builders before save. +func CategorieValidator(c Categorie) error { + switch c { + case CategorieImage, CategoriePdfNotice, CategorieMarkdownTuto: + return nil + default: + return fmt.Errorf("piecejointe: invalid enum value for categorie field: %q", c) + } +} + +// OrderOption defines the ordering options for the PieceJointe queries. +type OrderOption func(*sql.Selector) + +// ByID orders the results by the id field. +func ByID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldID, opts...).ToFunc() +} + +// ByObjetID orders the results by the objet_id field. +func ByObjetID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldObjetID, opts...).ToFunc() +} + +// ByNomFichier orders the results by the nom_fichier field. +func ByNomFichier(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldNomFichier, opts...).ToFunc() +} + +// ByChemin orders the results by the chemin field. +func ByChemin(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldChemin, opts...).ToFunc() +} + +// ByTypeMime orders the results by the type_mime field. +func ByTypeMime(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldTypeMime, opts...).ToFunc() +} + +// ByEstPrincipale orders the results by the est_principale field. +func ByEstPrincipale(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldEstPrincipale, opts...).ToFunc() +} + +// ByCategorie orders the results by the categorie field. +func ByCategorie(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCategorie, opts...).ToFunc() +} + +// ByCreatedAt orders the results by the created_at field. +func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() +} + +// ByUpdatedAt orders the results by the updated_at field. +func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc() +} + +// ByObjetField orders the results by objet field. +func ByObjetField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newObjetStep(), sql.OrderByField(field, opts...)) + } +} +func newObjetStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(ObjetInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, ObjetTable, ObjetColumn), + ) +} diff --git a/backend/internal/data/ent/piecejointe/where.go b/backend/internal/data/ent/piecejointe/where.go new file mode 100644 index 0000000..da278e2 --- /dev/null +++ b/backend/internal/data/ent/piecejointe/where.go @@ -0,0 +1,455 @@ +// Code generated by ent, DO NOT EDIT. + +package piecejointe + +import ( + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/predicate" + "github.com/google/uuid" +) + +// ID filters vertices based on their ID field. +func ID(id uuid.UUID) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldEQ(FieldID, id)) +} + +// IDEQ applies the EQ predicate on the ID field. +func IDEQ(id uuid.UUID) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldEQ(FieldID, id)) +} + +// IDNEQ applies the NEQ predicate on the ID field. +func IDNEQ(id uuid.UUID) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldNEQ(FieldID, id)) +} + +// IDIn applies the In predicate on the ID field. +func IDIn(ids ...uuid.UUID) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldIn(FieldID, ids...)) +} + +// IDNotIn applies the NotIn predicate on the ID field. +func IDNotIn(ids ...uuid.UUID) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldNotIn(FieldID, ids...)) +} + +// IDGT applies the GT predicate on the ID field. +func IDGT(id uuid.UUID) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldGT(FieldID, id)) +} + +// IDGTE applies the GTE predicate on the ID field. +func IDGTE(id uuid.UUID) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldGTE(FieldID, id)) +} + +// IDLT applies the LT predicate on the ID field. +func IDLT(id uuid.UUID) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldLT(FieldID, id)) +} + +// IDLTE applies the LTE predicate on the ID field. +func IDLTE(id uuid.UUID) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldLTE(FieldID, id)) +} + +// ObjetID applies equality check predicate on the "objet_id" field. It's identical to ObjetIDEQ. +func ObjetID(v uuid.UUID) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldEQ(FieldObjetID, v)) +} + +// NomFichier applies equality check predicate on the "nom_fichier" field. It's identical to NomFichierEQ. +func NomFichier(v string) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldEQ(FieldNomFichier, v)) +} + +// Chemin applies equality check predicate on the "chemin" field. It's identical to CheminEQ. +func Chemin(v string) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldEQ(FieldChemin, v)) +} + +// TypeMime applies equality check predicate on the "type_mime" field. It's identical to TypeMimeEQ. +func TypeMime(v string) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldEQ(FieldTypeMime, v)) +} + +// EstPrincipale applies equality check predicate on the "est_principale" field. It's identical to EstPrincipaleEQ. +func EstPrincipale(v bool) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldEQ(FieldEstPrincipale, v)) +} + +// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. +func CreatedAt(v time.Time) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldEQ(FieldCreatedAt, v)) +} + +// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ. +func UpdatedAt(v time.Time) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldEQ(FieldUpdatedAt, v)) +} + +// ObjetIDEQ applies the EQ predicate on the "objet_id" field. +func ObjetIDEQ(v uuid.UUID) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldEQ(FieldObjetID, v)) +} + +// ObjetIDNEQ applies the NEQ predicate on the "objet_id" field. +func ObjetIDNEQ(v uuid.UUID) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldNEQ(FieldObjetID, v)) +} + +// ObjetIDIn applies the In predicate on the "objet_id" field. +func ObjetIDIn(vs ...uuid.UUID) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldIn(FieldObjetID, vs...)) +} + +// ObjetIDNotIn applies the NotIn predicate on the "objet_id" field. +func ObjetIDNotIn(vs ...uuid.UUID) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldNotIn(FieldObjetID, vs...)) +} + +// NomFichierEQ applies the EQ predicate on the "nom_fichier" field. +func NomFichierEQ(v string) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldEQ(FieldNomFichier, v)) +} + +// NomFichierNEQ applies the NEQ predicate on the "nom_fichier" field. +func NomFichierNEQ(v string) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldNEQ(FieldNomFichier, v)) +} + +// NomFichierIn applies the In predicate on the "nom_fichier" field. +func NomFichierIn(vs ...string) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldIn(FieldNomFichier, vs...)) +} + +// NomFichierNotIn applies the NotIn predicate on the "nom_fichier" field. +func NomFichierNotIn(vs ...string) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldNotIn(FieldNomFichier, vs...)) +} + +// NomFichierGT applies the GT predicate on the "nom_fichier" field. +func NomFichierGT(v string) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldGT(FieldNomFichier, v)) +} + +// NomFichierGTE applies the GTE predicate on the "nom_fichier" field. +func NomFichierGTE(v string) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldGTE(FieldNomFichier, v)) +} + +// NomFichierLT applies the LT predicate on the "nom_fichier" field. +func NomFichierLT(v string) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldLT(FieldNomFichier, v)) +} + +// NomFichierLTE applies the LTE predicate on the "nom_fichier" field. +func NomFichierLTE(v string) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldLTE(FieldNomFichier, v)) +} + +// NomFichierContains applies the Contains predicate on the "nom_fichier" field. +func NomFichierContains(v string) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldContains(FieldNomFichier, v)) +} + +// NomFichierHasPrefix applies the HasPrefix predicate on the "nom_fichier" field. +func NomFichierHasPrefix(v string) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldHasPrefix(FieldNomFichier, v)) +} + +// NomFichierHasSuffix applies the HasSuffix predicate on the "nom_fichier" field. +func NomFichierHasSuffix(v string) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldHasSuffix(FieldNomFichier, v)) +} + +// NomFichierEqualFold applies the EqualFold predicate on the "nom_fichier" field. +func NomFichierEqualFold(v string) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldEqualFold(FieldNomFichier, v)) +} + +// NomFichierContainsFold applies the ContainsFold predicate on the "nom_fichier" field. +func NomFichierContainsFold(v string) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldContainsFold(FieldNomFichier, v)) +} + +// CheminEQ applies the EQ predicate on the "chemin" field. +func CheminEQ(v string) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldEQ(FieldChemin, v)) +} + +// CheminNEQ applies the NEQ predicate on the "chemin" field. +func CheminNEQ(v string) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldNEQ(FieldChemin, v)) +} + +// CheminIn applies the In predicate on the "chemin" field. +func CheminIn(vs ...string) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldIn(FieldChemin, vs...)) +} + +// CheminNotIn applies the NotIn predicate on the "chemin" field. +func CheminNotIn(vs ...string) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldNotIn(FieldChemin, vs...)) +} + +// CheminGT applies the GT predicate on the "chemin" field. +func CheminGT(v string) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldGT(FieldChemin, v)) +} + +// CheminGTE applies the GTE predicate on the "chemin" field. +func CheminGTE(v string) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldGTE(FieldChemin, v)) +} + +// CheminLT applies the LT predicate on the "chemin" field. +func CheminLT(v string) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldLT(FieldChemin, v)) +} + +// CheminLTE applies the LTE predicate on the "chemin" field. +func CheminLTE(v string) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldLTE(FieldChemin, v)) +} + +// CheminContains applies the Contains predicate on the "chemin" field. +func CheminContains(v string) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldContains(FieldChemin, v)) +} + +// CheminHasPrefix applies the HasPrefix predicate on the "chemin" field. +func CheminHasPrefix(v string) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldHasPrefix(FieldChemin, v)) +} + +// CheminHasSuffix applies the HasSuffix predicate on the "chemin" field. +func CheminHasSuffix(v string) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldHasSuffix(FieldChemin, v)) +} + +// CheminEqualFold applies the EqualFold predicate on the "chemin" field. +func CheminEqualFold(v string) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldEqualFold(FieldChemin, v)) +} + +// CheminContainsFold applies the ContainsFold predicate on the "chemin" field. +func CheminContainsFold(v string) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldContainsFold(FieldChemin, v)) +} + +// TypeMimeEQ applies the EQ predicate on the "type_mime" field. +func TypeMimeEQ(v string) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldEQ(FieldTypeMime, v)) +} + +// TypeMimeNEQ applies the NEQ predicate on the "type_mime" field. +func TypeMimeNEQ(v string) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldNEQ(FieldTypeMime, v)) +} + +// TypeMimeIn applies the In predicate on the "type_mime" field. +func TypeMimeIn(vs ...string) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldIn(FieldTypeMime, vs...)) +} + +// TypeMimeNotIn applies the NotIn predicate on the "type_mime" field. +func TypeMimeNotIn(vs ...string) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldNotIn(FieldTypeMime, vs...)) +} + +// TypeMimeGT applies the GT predicate on the "type_mime" field. +func TypeMimeGT(v string) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldGT(FieldTypeMime, v)) +} + +// TypeMimeGTE applies the GTE predicate on the "type_mime" field. +func TypeMimeGTE(v string) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldGTE(FieldTypeMime, v)) +} + +// TypeMimeLT applies the LT predicate on the "type_mime" field. +func TypeMimeLT(v string) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldLT(FieldTypeMime, v)) +} + +// TypeMimeLTE applies the LTE predicate on the "type_mime" field. +func TypeMimeLTE(v string) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldLTE(FieldTypeMime, v)) +} + +// TypeMimeContains applies the Contains predicate on the "type_mime" field. +func TypeMimeContains(v string) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldContains(FieldTypeMime, v)) +} + +// TypeMimeHasPrefix applies the HasPrefix predicate on the "type_mime" field. +func TypeMimeHasPrefix(v string) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldHasPrefix(FieldTypeMime, v)) +} + +// TypeMimeHasSuffix applies the HasSuffix predicate on the "type_mime" field. +func TypeMimeHasSuffix(v string) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldHasSuffix(FieldTypeMime, v)) +} + +// TypeMimeEqualFold applies the EqualFold predicate on the "type_mime" field. +func TypeMimeEqualFold(v string) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldEqualFold(FieldTypeMime, v)) +} + +// TypeMimeContainsFold applies the ContainsFold predicate on the "type_mime" field. +func TypeMimeContainsFold(v string) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldContainsFold(FieldTypeMime, v)) +} + +// EstPrincipaleEQ applies the EQ predicate on the "est_principale" field. +func EstPrincipaleEQ(v bool) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldEQ(FieldEstPrincipale, v)) +} + +// EstPrincipaleNEQ applies the NEQ predicate on the "est_principale" field. +func EstPrincipaleNEQ(v bool) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldNEQ(FieldEstPrincipale, v)) +} + +// CategorieEQ applies the EQ predicate on the "categorie" field. +func CategorieEQ(v Categorie) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldEQ(FieldCategorie, v)) +} + +// CategorieNEQ applies the NEQ predicate on the "categorie" field. +func CategorieNEQ(v Categorie) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldNEQ(FieldCategorie, v)) +} + +// CategorieIn applies the In predicate on the "categorie" field. +func CategorieIn(vs ...Categorie) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldIn(FieldCategorie, vs...)) +} + +// CategorieNotIn applies the NotIn predicate on the "categorie" field. +func CategorieNotIn(vs ...Categorie) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldNotIn(FieldCategorie, vs...)) +} + +// CreatedAtEQ applies the EQ predicate on the "created_at" field. +func CreatedAtEQ(v time.Time) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldEQ(FieldCreatedAt, v)) +} + +// CreatedAtNEQ applies the NEQ predicate on the "created_at" field. +func CreatedAtNEQ(v time.Time) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldNEQ(FieldCreatedAt, v)) +} + +// CreatedAtIn applies the In predicate on the "created_at" field. +func CreatedAtIn(vs ...time.Time) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldIn(FieldCreatedAt, vs...)) +} + +// CreatedAtNotIn applies the NotIn predicate on the "created_at" field. +func CreatedAtNotIn(vs ...time.Time) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldNotIn(FieldCreatedAt, vs...)) +} + +// CreatedAtGT applies the GT predicate on the "created_at" field. +func CreatedAtGT(v time.Time) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldGT(FieldCreatedAt, v)) +} + +// CreatedAtGTE applies the GTE predicate on the "created_at" field. +func CreatedAtGTE(v time.Time) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldGTE(FieldCreatedAt, v)) +} + +// CreatedAtLT applies the LT predicate on the "created_at" field. +func CreatedAtLT(v time.Time) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldLT(FieldCreatedAt, v)) +} + +// CreatedAtLTE applies the LTE predicate on the "created_at" field. +func CreatedAtLTE(v time.Time) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldLTE(FieldCreatedAt, v)) +} + +// UpdatedAtEQ applies the EQ predicate on the "updated_at" field. +func UpdatedAtEQ(v time.Time) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field. +func UpdatedAtNEQ(v time.Time) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldNEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtIn applies the In predicate on the "updated_at" field. +func UpdatedAtIn(vs ...time.Time) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field. +func UpdatedAtNotIn(vs ...time.Time) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldNotIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtGT applies the GT predicate on the "updated_at" field. +func UpdatedAtGT(v time.Time) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldGT(FieldUpdatedAt, v)) +} + +// UpdatedAtGTE applies the GTE predicate on the "updated_at" field. +func UpdatedAtGTE(v time.Time) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldGTE(FieldUpdatedAt, v)) +} + +// UpdatedAtLT applies the LT predicate on the "updated_at" field. +func UpdatedAtLT(v time.Time) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldLT(FieldUpdatedAt, v)) +} + +// UpdatedAtLTE applies the LTE predicate on the "updated_at" field. +func UpdatedAtLTE(v time.Time) predicate.PieceJointe { + return predicate.PieceJointe(sql.FieldLTE(FieldUpdatedAt, v)) +} + +// HasObjet applies the HasEdge predicate on the "objet" edge. +func HasObjet() predicate.PieceJointe { + return predicate.PieceJointe(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, ObjetTable, ObjetColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasObjetWith applies the HasEdge predicate on the "objet" edge with a given conditions (other predicates). +func HasObjetWith(preds ...predicate.Objet) predicate.PieceJointe { + return predicate.PieceJointe(func(s *sql.Selector) { + step := newObjetStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + +// And groups predicates with the AND operator between them. +func And(predicates ...predicate.PieceJointe) predicate.PieceJointe { + return predicate.PieceJointe(sql.AndPredicates(predicates...)) +} + +// Or groups predicates with the OR operator between them. +func Or(predicates ...predicate.PieceJointe) predicate.PieceJointe { + return predicate.PieceJointe(sql.OrPredicates(predicates...)) +} + +// Not applies the not operator on the given predicate. +func Not(p predicate.PieceJointe) predicate.PieceJointe { + return predicate.PieceJointe(sql.NotPredicates(p)) +} diff --git a/backend/internal/data/ent/piecejointe_create.go b/backend/internal/data/ent/piecejointe_create.go new file mode 100644 index 0000000..9a5eea9 --- /dev/null +++ b/backend/internal/data/ent/piecejointe_create.go @@ -0,0 +1,395 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + "time" + + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/objet" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/piecejointe" + "github.com/google/uuid" +) + +// PieceJointeCreate is the builder for creating a PieceJointe entity. +type PieceJointeCreate struct { + config + mutation *PieceJointeMutation + hooks []Hook +} + +// SetObjetID sets the "objet_id" field. +func (_c *PieceJointeCreate) SetObjetID(v uuid.UUID) *PieceJointeCreate { + _c.mutation.SetObjetID(v) + return _c +} + +// SetNomFichier sets the "nom_fichier" field. +func (_c *PieceJointeCreate) SetNomFichier(v string) *PieceJointeCreate { + _c.mutation.SetNomFichier(v) + return _c +} + +// SetChemin sets the "chemin" field. +func (_c *PieceJointeCreate) SetChemin(v string) *PieceJointeCreate { + _c.mutation.SetChemin(v) + return _c +} + +// SetTypeMime sets the "type_mime" field. +func (_c *PieceJointeCreate) SetTypeMime(v string) *PieceJointeCreate { + _c.mutation.SetTypeMime(v) + return _c +} + +// SetEstPrincipale sets the "est_principale" field. +func (_c *PieceJointeCreate) SetEstPrincipale(v bool) *PieceJointeCreate { + _c.mutation.SetEstPrincipale(v) + return _c +} + +// SetNillableEstPrincipale sets the "est_principale" field if the given value is not nil. +func (_c *PieceJointeCreate) SetNillableEstPrincipale(v *bool) *PieceJointeCreate { + if v != nil { + _c.SetEstPrincipale(*v) + } + return _c +} + +// SetCategorie sets the "categorie" field. +func (_c *PieceJointeCreate) SetCategorie(v piecejointe.Categorie) *PieceJointeCreate { + _c.mutation.SetCategorie(v) + return _c +} + +// SetNillableCategorie sets the "categorie" field if the given value is not nil. +func (_c *PieceJointeCreate) SetNillableCategorie(v *piecejointe.Categorie) *PieceJointeCreate { + if v != nil { + _c.SetCategorie(*v) + } + return _c +} + +// SetCreatedAt sets the "created_at" field. +func (_c *PieceJointeCreate) SetCreatedAt(v time.Time) *PieceJointeCreate { + _c.mutation.SetCreatedAt(v) + return _c +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (_c *PieceJointeCreate) SetNillableCreatedAt(v *time.Time) *PieceJointeCreate { + if v != nil { + _c.SetCreatedAt(*v) + } + return _c +} + +// SetUpdatedAt sets the "updated_at" field. +func (_c *PieceJointeCreate) SetUpdatedAt(v time.Time) *PieceJointeCreate { + _c.mutation.SetUpdatedAt(v) + return _c +} + +// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. +func (_c *PieceJointeCreate) SetNillableUpdatedAt(v *time.Time) *PieceJointeCreate { + if v != nil { + _c.SetUpdatedAt(*v) + } + return _c +} + +// SetID sets the "id" field. +func (_c *PieceJointeCreate) SetID(v uuid.UUID) *PieceJointeCreate { + _c.mutation.SetID(v) + return _c +} + +// SetNillableID sets the "id" field if the given value is not nil. +func (_c *PieceJointeCreate) SetNillableID(v *uuid.UUID) *PieceJointeCreate { + if v != nil { + _c.SetID(*v) + } + return _c +} + +// SetObjet sets the "objet" edge to the Objet entity. +func (_c *PieceJointeCreate) SetObjet(v *Objet) *PieceJointeCreate { + return _c.SetObjetID(v.ID) +} + +// Mutation returns the PieceJointeMutation object of the builder. +func (_c *PieceJointeCreate) Mutation() *PieceJointeMutation { + return _c.mutation +} + +// Save creates the PieceJointe in the database. +func (_c *PieceJointeCreate) Save(ctx context.Context) (*PieceJointe, error) { + _c.defaults() + return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks) +} + +// SaveX calls Save and panics if Save returns an error. +func (_c *PieceJointeCreate) SaveX(ctx context.Context) *PieceJointe { + v, err := _c.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (_c *PieceJointeCreate) Exec(ctx context.Context) error { + _, err := _c.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_c *PieceJointeCreate) ExecX(ctx context.Context) { + if err := _c.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (_c *PieceJointeCreate) defaults() { + if _, ok := _c.mutation.EstPrincipale(); !ok { + v := piecejointe.DefaultEstPrincipale + _c.mutation.SetEstPrincipale(v) + } + if _, ok := _c.mutation.Categorie(); !ok { + v := piecejointe.DefaultCategorie + _c.mutation.SetCategorie(v) + } + if _, ok := _c.mutation.CreatedAt(); !ok { + v := piecejointe.DefaultCreatedAt() + _c.mutation.SetCreatedAt(v) + } + if _, ok := _c.mutation.UpdatedAt(); !ok { + v := piecejointe.DefaultUpdatedAt() + _c.mutation.SetUpdatedAt(v) + } + if _, ok := _c.mutation.ID(); !ok { + v := piecejointe.DefaultID() + _c.mutation.SetID(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_c *PieceJointeCreate) check() error { + if _, ok := _c.mutation.ObjetID(); !ok { + return &ValidationError{Name: "objet_id", err: errors.New(`ent: missing required field "PieceJointe.objet_id"`)} + } + if _, ok := _c.mutation.NomFichier(); !ok { + return &ValidationError{Name: "nom_fichier", err: errors.New(`ent: missing required field "PieceJointe.nom_fichier"`)} + } + if v, ok := _c.mutation.NomFichier(); ok { + if err := piecejointe.NomFichierValidator(v); err != nil { + return &ValidationError{Name: "nom_fichier", err: fmt.Errorf(`ent: validator failed for field "PieceJointe.nom_fichier": %w`, err)} + } + } + if _, ok := _c.mutation.Chemin(); !ok { + return &ValidationError{Name: "chemin", err: errors.New(`ent: missing required field "PieceJointe.chemin"`)} + } + if v, ok := _c.mutation.Chemin(); ok { + if err := piecejointe.CheminValidator(v); err != nil { + return &ValidationError{Name: "chemin", err: fmt.Errorf(`ent: validator failed for field "PieceJointe.chemin": %w`, err)} + } + } + if _, ok := _c.mutation.TypeMime(); !ok { + return &ValidationError{Name: "type_mime", err: errors.New(`ent: missing required field "PieceJointe.type_mime"`)} + } + if v, ok := _c.mutation.TypeMime(); ok { + if err := piecejointe.TypeMimeValidator(v); err != nil { + return &ValidationError{Name: "type_mime", err: fmt.Errorf(`ent: validator failed for field "PieceJointe.type_mime": %w`, err)} + } + } + if _, ok := _c.mutation.EstPrincipale(); !ok { + return &ValidationError{Name: "est_principale", err: errors.New(`ent: missing required field "PieceJointe.est_principale"`)} + } + if _, ok := _c.mutation.Categorie(); !ok { + return &ValidationError{Name: "categorie", err: errors.New(`ent: missing required field "PieceJointe.categorie"`)} + } + if v, ok := _c.mutation.Categorie(); ok { + if err := piecejointe.CategorieValidator(v); err != nil { + return &ValidationError{Name: "categorie", err: fmt.Errorf(`ent: validator failed for field "PieceJointe.categorie": %w`, err)} + } + } + if _, ok := _c.mutation.CreatedAt(); !ok { + return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "PieceJointe.created_at"`)} + } + if _, ok := _c.mutation.UpdatedAt(); !ok { + return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "PieceJointe.updated_at"`)} + } + if len(_c.mutation.ObjetIDs()) == 0 { + return &ValidationError{Name: "objet", err: errors.New(`ent: missing required edge "PieceJointe.objet"`)} + } + return nil +} + +func (_c *PieceJointeCreate) sqlSave(ctx context.Context) (*PieceJointe, error) { + if err := _c.check(); err != nil { + return nil, err + } + _node, _spec := _c.createSpec() + if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + if _spec.ID.Value != nil { + if id, ok := _spec.ID.Value.(*uuid.UUID); ok { + _node.ID = *id + } else if err := _node.ID.Scan(_spec.ID.Value); err != nil { + return nil, err + } + } + _c.mutation.id = &_node.ID + _c.mutation.done = true + return _node, nil +} + +func (_c *PieceJointeCreate) createSpec() (*PieceJointe, *sqlgraph.CreateSpec) { + var ( + _node = &PieceJointe{config: _c.config} + _spec = sqlgraph.NewCreateSpec(piecejointe.Table, sqlgraph.NewFieldSpec(piecejointe.FieldID, field.TypeUUID)) + ) + if id, ok := _c.mutation.ID(); ok { + _node.ID = id + _spec.ID.Value = &id + } + if value, ok := _c.mutation.NomFichier(); ok { + _spec.SetField(piecejointe.FieldNomFichier, field.TypeString, value) + _node.NomFichier = value + } + if value, ok := _c.mutation.Chemin(); ok { + _spec.SetField(piecejointe.FieldChemin, field.TypeString, value) + _node.Chemin = value + } + if value, ok := _c.mutation.TypeMime(); ok { + _spec.SetField(piecejointe.FieldTypeMime, field.TypeString, value) + _node.TypeMime = value + } + if value, ok := _c.mutation.EstPrincipale(); ok { + _spec.SetField(piecejointe.FieldEstPrincipale, field.TypeBool, value) + _node.EstPrincipale = value + } + if value, ok := _c.mutation.Categorie(); ok { + _spec.SetField(piecejointe.FieldCategorie, field.TypeEnum, value) + _node.Categorie = value + } + if value, ok := _c.mutation.CreatedAt(); ok { + _spec.SetField(piecejointe.FieldCreatedAt, field.TypeTime, value) + _node.CreatedAt = value + } + if value, ok := _c.mutation.UpdatedAt(); ok { + _spec.SetField(piecejointe.FieldUpdatedAt, field.TypeTime, value) + _node.UpdatedAt = value + } + if nodes := _c.mutation.ObjetIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: piecejointe.ObjetTable, + Columns: []string{piecejointe.ObjetColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(objet.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _node.ObjetID = nodes[0] + _spec.Edges = append(_spec.Edges, edge) + } + return _node, _spec +} + +// PieceJointeCreateBulk is the builder for creating many PieceJointe entities in bulk. +type PieceJointeCreateBulk struct { + config + err error + builders []*PieceJointeCreate +} + +// Save creates the PieceJointe entities in the database. +func (_c *PieceJointeCreateBulk) Save(ctx context.Context) ([]*PieceJointe, error) { + if _c.err != nil { + return nil, _c.err + } + specs := make([]*sqlgraph.CreateSpec, len(_c.builders)) + nodes := make([]*PieceJointe, len(_c.builders)) + mutators := make([]Mutator, len(_c.builders)) + for i := range _c.builders { + func(i int, root context.Context) { + builder := _c.builders[i] + builder.defaults() + var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { + mutation, ok := m.(*PieceJointeMutation) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T", m) + } + if err := builder.check(); err != nil { + return nil, err + } + builder.mutation = mutation + var err error + nodes[i], specs[i] = builder.createSpec() + if i < len(mutators)-1 { + _, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation) + } else { + spec := &sqlgraph.BatchCreateSpec{Nodes: specs} + // Invoke the actual operation on the latest mutation in the chain. + if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + } + } + if err != nil { + return nil, err + } + mutation.id = &nodes[i].ID + mutation.done = true + return nodes[i], nil + }) + for i := len(builder.hooks) - 1; i >= 0; i-- { + mut = builder.hooks[i](mut) + } + mutators[i] = mut + }(i, ctx) + } + if len(mutators) > 0 { + if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil { + return nil, err + } + } + return nodes, nil +} + +// SaveX is like Save, but panics if an error occurs. +func (_c *PieceJointeCreateBulk) SaveX(ctx context.Context) []*PieceJointe { + v, err := _c.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (_c *PieceJointeCreateBulk) Exec(ctx context.Context) error { + _, err := _c.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_c *PieceJointeCreateBulk) ExecX(ctx context.Context) { + if err := _c.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/backend/internal/data/ent/piecejointe_delete.go b/backend/internal/data/ent/piecejointe_delete.go new file mode 100644 index 0000000..dcde8d7 --- /dev/null +++ b/backend/internal/data/ent/piecejointe_delete.go @@ -0,0 +1,88 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/piecejointe" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/predicate" +) + +// PieceJointeDelete is the builder for deleting a PieceJointe entity. +type PieceJointeDelete struct { + config + hooks []Hook + mutation *PieceJointeMutation +} + +// Where appends a list predicates to the PieceJointeDelete builder. +func (_d *PieceJointeDelete) Where(ps ...predicate.PieceJointe) *PieceJointeDelete { + _d.mutation.Where(ps...) + return _d +} + +// Exec executes the deletion query and returns how many vertices were deleted. +func (_d *PieceJointeDelete) Exec(ctx context.Context) (int, error) { + return withHooks(ctx, _d.sqlExec, _d.mutation, _d.hooks) +} + +// ExecX is like Exec, but panics if an error occurs. +func (_d *PieceJointeDelete) ExecX(ctx context.Context) int { + n, err := _d.Exec(ctx) + if err != nil { + panic(err) + } + return n +} + +func (_d *PieceJointeDelete) sqlExec(ctx context.Context) (int, error) { + _spec := sqlgraph.NewDeleteSpec(piecejointe.Table, sqlgraph.NewFieldSpec(piecejointe.FieldID, field.TypeUUID)) + if ps := _d.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + affected, err := sqlgraph.DeleteNodes(ctx, _d.driver, _spec) + if err != nil && sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + _d.mutation.done = true + return affected, err +} + +// PieceJointeDeleteOne is the builder for deleting a single PieceJointe entity. +type PieceJointeDeleteOne struct { + _d *PieceJointeDelete +} + +// Where appends a list predicates to the PieceJointeDelete builder. +func (_d *PieceJointeDeleteOne) Where(ps ...predicate.PieceJointe) *PieceJointeDeleteOne { + _d._d.mutation.Where(ps...) + return _d +} + +// Exec executes the deletion query. +func (_d *PieceJointeDeleteOne) Exec(ctx context.Context) error { + n, err := _d._d.Exec(ctx) + switch { + case err != nil: + return err + case n == 0: + return &NotFoundError{piecejointe.Label} + default: + return nil + } +} + +// ExecX is like Exec, but panics if an error occurs. +func (_d *PieceJointeDeleteOne) ExecX(ctx context.Context) { + if err := _d.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/backend/internal/data/ent/piecejointe_query.go b/backend/internal/data/ent/piecejointe_query.go new file mode 100644 index 0000000..73d4ef4 --- /dev/null +++ b/backend/internal/data/ent/piecejointe_query.go @@ -0,0 +1,607 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "fmt" + "math" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/objet" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/piecejointe" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/predicate" + "github.com/google/uuid" +) + +// PieceJointeQuery is the builder for querying PieceJointe entities. +type PieceJointeQuery struct { + config + ctx *QueryContext + order []piecejointe.OrderOption + inters []Interceptor + predicates []predicate.PieceJointe + withObjet *ObjetQuery + // intermediate query (i.e. traversal path). + sql *sql.Selector + path func(context.Context) (*sql.Selector, error) +} + +// Where adds a new predicate for the PieceJointeQuery builder. +func (_q *PieceJointeQuery) Where(ps ...predicate.PieceJointe) *PieceJointeQuery { + _q.predicates = append(_q.predicates, ps...) + return _q +} + +// Limit the number of records to be returned by this query. +func (_q *PieceJointeQuery) Limit(limit int) *PieceJointeQuery { + _q.ctx.Limit = &limit + return _q +} + +// Offset to start from. +func (_q *PieceJointeQuery) Offset(offset int) *PieceJointeQuery { + _q.ctx.Offset = &offset + return _q +} + +// Unique configures the query builder to filter duplicate records on query. +// By default, unique is set to true, and can be disabled using this method. +func (_q *PieceJointeQuery) Unique(unique bool) *PieceJointeQuery { + _q.ctx.Unique = &unique + return _q +} + +// Order specifies how the records should be ordered. +func (_q *PieceJointeQuery) Order(o ...piecejointe.OrderOption) *PieceJointeQuery { + _q.order = append(_q.order, o...) + return _q +} + +// QueryObjet chains the current query on the "objet" edge. +func (_q *PieceJointeQuery) QueryObjet() *ObjetQuery { + query := (&ObjetClient{config: _q.config}).Query() + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + selector := _q.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(piecejointe.Table, piecejointe.FieldID, selector), + sqlgraph.To(objet.Table, objet.FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, piecejointe.ObjetTable, piecejointe.ObjetColumn), + ) + fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) + return fromU, nil + } + return query +} + +// First returns the first PieceJointe entity from the query. +// Returns a *NotFoundError when no PieceJointe was found. +func (_q *PieceJointeQuery) First(ctx context.Context) (*PieceJointe, error) { + nodes, err := _q.Limit(1).All(setContextOp(ctx, _q.ctx, ent.OpQueryFirst)) + if err != nil { + return nil, err + } + if len(nodes) == 0 { + return nil, &NotFoundError{piecejointe.Label} + } + return nodes[0], nil +} + +// FirstX is like First, but panics if an error occurs. +func (_q *PieceJointeQuery) FirstX(ctx context.Context) *PieceJointe { + node, err := _q.First(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return node +} + +// FirstID returns the first PieceJointe ID from the query. +// Returns a *NotFoundError when no PieceJointe ID was found. +func (_q *PieceJointeQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { + var ids []uuid.UUID + if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil { + return + } + if len(ids) == 0 { + err = &NotFoundError{piecejointe.Label} + return + } + return ids[0], nil +} + +// FirstIDX is like FirstID, but panics if an error occurs. +func (_q *PieceJointeQuery) FirstIDX(ctx context.Context) uuid.UUID { + id, err := _q.FirstID(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return id +} + +// Only returns a single PieceJointe entity found by the query, ensuring it only returns one. +// Returns a *NotSingularError when more than one PieceJointe entity is found. +// Returns a *NotFoundError when no PieceJointe entities are found. +func (_q *PieceJointeQuery) Only(ctx context.Context) (*PieceJointe, error) { + nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly)) + if err != nil { + return nil, err + } + switch len(nodes) { + case 1: + return nodes[0], nil + case 0: + return nil, &NotFoundError{piecejointe.Label} + default: + return nil, &NotSingularError{piecejointe.Label} + } +} + +// OnlyX is like Only, but panics if an error occurs. +func (_q *PieceJointeQuery) OnlyX(ctx context.Context) *PieceJointe { + node, err := _q.Only(ctx) + if err != nil { + panic(err) + } + return node +} + +// OnlyID is like Only, but returns the only PieceJointe ID in the query. +// Returns a *NotSingularError when more than one PieceJointe ID is found. +// Returns a *NotFoundError when no entities are found. +func (_q *PieceJointeQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { + var ids []uuid.UUID + if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryOnlyID)); err != nil { + return + } + switch len(ids) { + case 1: + id = ids[0] + case 0: + err = &NotFoundError{piecejointe.Label} + default: + err = &NotSingularError{piecejointe.Label} + } + return +} + +// OnlyIDX is like OnlyID, but panics if an error occurs. +func (_q *PieceJointeQuery) OnlyIDX(ctx context.Context) uuid.UUID { + id, err := _q.OnlyID(ctx) + if err != nil { + panic(err) + } + return id +} + +// All executes the query and returns a list of PieceJointes. +func (_q *PieceJointeQuery) All(ctx context.Context) ([]*PieceJointe, error) { + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll) + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + qr := querierAll[[]*PieceJointe, *PieceJointeQuery]() + return withInterceptors[[]*PieceJointe](ctx, _q, qr, _q.inters) +} + +// AllX is like All, but panics if an error occurs. +func (_q *PieceJointeQuery) AllX(ctx context.Context) []*PieceJointe { + nodes, err := _q.All(ctx) + if err != nil { + panic(err) + } + return nodes +} + +// IDs executes the query and returns a list of PieceJointe IDs. +func (_q *PieceJointeQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) { + if _q.ctx.Unique == nil && _q.path != nil { + _q.Unique(true) + } + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryIDs) + if err = _q.Select(piecejointe.FieldID).Scan(ctx, &ids); err != nil { + return nil, err + } + return ids, nil +} + +// IDsX is like IDs, but panics if an error occurs. +func (_q *PieceJointeQuery) IDsX(ctx context.Context) []uuid.UUID { + ids, err := _q.IDs(ctx) + if err != nil { + panic(err) + } + return ids +} + +// Count returns the count of the given query. +func (_q *PieceJointeQuery) Count(ctx context.Context) (int, error) { + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryCount) + if err := _q.prepareQuery(ctx); err != nil { + return 0, err + } + return withInterceptors[int](ctx, _q, querierCount[*PieceJointeQuery](), _q.inters) +} + +// CountX is like Count, but panics if an error occurs. +func (_q *PieceJointeQuery) CountX(ctx context.Context) int { + count, err := _q.Count(ctx) + if err != nil { + panic(err) + } + return count +} + +// Exist returns true if the query has elements in the graph. +func (_q *PieceJointeQuery) Exist(ctx context.Context) (bool, error) { + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryExist) + switch _, err := _q.FirstID(ctx); { + case IsNotFound(err): + return false, nil + case err != nil: + return false, fmt.Errorf("ent: check existence: %w", err) + default: + return true, nil + } +} + +// ExistX is like Exist, but panics if an error occurs. +func (_q *PieceJointeQuery) ExistX(ctx context.Context) bool { + exist, err := _q.Exist(ctx) + if err != nil { + panic(err) + } + return exist +} + +// Clone returns a duplicate of the PieceJointeQuery builder, including all associated steps. It can be +// used to prepare common query builders and use them differently after the clone is made. +func (_q *PieceJointeQuery) Clone() *PieceJointeQuery { + if _q == nil { + return nil + } + return &PieceJointeQuery{ + config: _q.config, + ctx: _q.ctx.Clone(), + order: append([]piecejointe.OrderOption{}, _q.order...), + inters: append([]Interceptor{}, _q.inters...), + predicates: append([]predicate.PieceJointe{}, _q.predicates...), + withObjet: _q.withObjet.Clone(), + // clone intermediate query. + sql: _q.sql.Clone(), + path: _q.path, + } +} + +// WithObjet tells the query-builder to eager-load the nodes that are connected to +// the "objet" edge. The optional arguments are used to configure the query builder of the edge. +func (_q *PieceJointeQuery) WithObjet(opts ...func(*ObjetQuery)) *PieceJointeQuery { + query := (&ObjetClient{config: _q.config}).Query() + for _, opt := range opts { + opt(query) + } + _q.withObjet = query + return _q +} + +// GroupBy is used to group vertices by one or more fields/columns. +// It is often used with aggregate functions, like: count, max, mean, min, sum. +// +// Example: +// +// var v []struct { +// ObjetID uuid.UUID `json:"objet_id,omitempty"` +// Count int `json:"count,omitempty"` +// } +// +// client.PieceJointe.Query(). +// GroupBy(piecejointe.FieldObjetID). +// Aggregate(ent.Count()). +// Scan(ctx, &v) +func (_q *PieceJointeQuery) GroupBy(field string, fields ...string) *PieceJointeGroupBy { + _q.ctx.Fields = append([]string{field}, fields...) + grbuild := &PieceJointeGroupBy{build: _q} + grbuild.flds = &_q.ctx.Fields + grbuild.label = piecejointe.Label + grbuild.scan = grbuild.Scan + return grbuild +} + +// Select allows the selection one or more fields/columns for the given query, +// instead of selecting all fields in the entity. +// +// Example: +// +// var v []struct { +// ObjetID uuid.UUID `json:"objet_id,omitempty"` +// } +// +// client.PieceJointe.Query(). +// Select(piecejointe.FieldObjetID). +// Scan(ctx, &v) +func (_q *PieceJointeQuery) Select(fields ...string) *PieceJointeSelect { + _q.ctx.Fields = append(_q.ctx.Fields, fields...) + sbuild := &PieceJointeSelect{PieceJointeQuery: _q} + sbuild.label = piecejointe.Label + sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan + return sbuild +} + +// Aggregate returns a PieceJointeSelect configured with the given aggregations. +func (_q *PieceJointeQuery) Aggregate(fns ...AggregateFunc) *PieceJointeSelect { + return _q.Select().Aggregate(fns...) +} + +func (_q *PieceJointeQuery) prepareQuery(ctx context.Context) error { + for _, inter := range _q.inters { + if inter == nil { + return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)") + } + if trv, ok := inter.(Traverser); ok { + if err := trv.Traverse(ctx, _q); err != nil { + return err + } + } + } + for _, f := range _q.ctx.Fields { + if !piecejointe.ValidColumn(f) { + return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + } + if _q.path != nil { + prev, err := _q.path(ctx) + if err != nil { + return err + } + _q.sql = prev + } + return nil +} + +func (_q *PieceJointeQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*PieceJointe, error) { + var ( + nodes = []*PieceJointe{} + _spec = _q.querySpec() + loadedTypes = [1]bool{ + _q.withObjet != nil, + } + ) + _spec.ScanValues = func(columns []string) ([]any, error) { + return (*PieceJointe).scanValues(nil, columns) + } + _spec.Assign = func(columns []string, values []any) error { + node := &PieceJointe{config: _q.config} + nodes = append(nodes, node) + node.Edges.loadedTypes = loadedTypes + return node.assignValues(columns, values) + } + for i := range hooks { + hooks[i](ctx, _spec) + } + if err := sqlgraph.QueryNodes(ctx, _q.driver, _spec); err != nil { + return nil, err + } + if len(nodes) == 0 { + return nodes, nil + } + if query := _q.withObjet; query != nil { + if err := _q.loadObjet(ctx, query, nodes, nil, + func(n *PieceJointe, e *Objet) { n.Edges.Objet = e }); err != nil { + return nil, err + } + } + return nodes, nil +} + +func (_q *PieceJointeQuery) loadObjet(ctx context.Context, query *ObjetQuery, nodes []*PieceJointe, init func(*PieceJointe), assign func(*PieceJointe, *Objet)) error { + ids := make([]uuid.UUID, 0, len(nodes)) + nodeids := make(map[uuid.UUID][]*PieceJointe) + for i := range nodes { + fk := nodes[i].ObjetID + if _, ok := nodeids[fk]; !ok { + ids = append(ids, fk) + } + nodeids[fk] = append(nodeids[fk], nodes[i]) + } + if len(ids) == 0 { + return nil + } + query.Where(objet.IDIn(ids...)) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + nodes, ok := nodeids[n.ID] + if !ok { + return fmt.Errorf(`unexpected foreign-key "objet_id" returned %v`, n.ID) + } + for i := range nodes { + assign(nodes[i], n) + } + } + return nil +} + +func (_q *PieceJointeQuery) sqlCount(ctx context.Context) (int, error) { + _spec := _q.querySpec() + _spec.Node.Columns = _q.ctx.Fields + if len(_q.ctx.Fields) > 0 { + _spec.Unique = _q.ctx.Unique != nil && *_q.ctx.Unique + } + return sqlgraph.CountNodes(ctx, _q.driver, _spec) +} + +func (_q *PieceJointeQuery) querySpec() *sqlgraph.QuerySpec { + _spec := sqlgraph.NewQuerySpec(piecejointe.Table, piecejointe.Columns, sqlgraph.NewFieldSpec(piecejointe.FieldID, field.TypeUUID)) + _spec.From = _q.sql + if unique := _q.ctx.Unique; unique != nil { + _spec.Unique = *unique + } else if _q.path != nil { + _spec.Unique = true + } + if fields := _q.ctx.Fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, piecejointe.FieldID) + for i := range fields { + if fields[i] != piecejointe.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) + } + } + if _q.withObjet != nil { + _spec.Node.AddColumnOnce(piecejointe.FieldObjetID) + } + } + if ps := _q.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if limit := _q.ctx.Limit; limit != nil { + _spec.Limit = *limit + } + if offset := _q.ctx.Offset; offset != nil { + _spec.Offset = *offset + } + if ps := _q.order; len(ps) > 0 { + _spec.Order = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + return _spec +} + +func (_q *PieceJointeQuery) sqlQuery(ctx context.Context) *sql.Selector { + builder := sql.Dialect(_q.driver.Dialect()) + t1 := builder.Table(piecejointe.Table) + columns := _q.ctx.Fields + if len(columns) == 0 { + columns = piecejointe.Columns + } + selector := builder.Select(t1.Columns(columns...)...).From(t1) + if _q.sql != nil { + selector = _q.sql + selector.Select(selector.Columns(columns...)...) + } + if _q.ctx.Unique != nil && *_q.ctx.Unique { + selector.Distinct() + } + for _, p := range _q.predicates { + p(selector) + } + for _, p := range _q.order { + p(selector) + } + if offset := _q.ctx.Offset; offset != nil { + // limit is mandatory for offset clause. We start + // with default value, and override it below if needed. + selector.Offset(*offset).Limit(math.MaxInt32) + } + if limit := _q.ctx.Limit; limit != nil { + selector.Limit(*limit) + } + return selector +} + +// PieceJointeGroupBy is the group-by builder for PieceJointe entities. +type PieceJointeGroupBy struct { + selector + build *PieceJointeQuery +} + +// Aggregate adds the given aggregation functions to the group-by query. +func (_g *PieceJointeGroupBy) Aggregate(fns ...AggregateFunc) *PieceJointeGroupBy { + _g.fns = append(_g.fns, fns...) + return _g +} + +// Scan applies the selector query and scans the result into the given value. +func (_g *PieceJointeGroupBy) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, _g.build.ctx, ent.OpQueryGroupBy) + if err := _g.build.prepareQuery(ctx); err != nil { + return err + } + return scanWithInterceptors[*PieceJointeQuery, *PieceJointeGroupBy](ctx, _g.build, _g, _g.build.inters, v) +} + +func (_g *PieceJointeGroupBy) sqlScan(ctx context.Context, root *PieceJointeQuery, v any) error { + selector := root.sqlQuery(ctx).Select() + aggregation := make([]string, 0, len(_g.fns)) + for _, fn := range _g.fns { + aggregation = append(aggregation, fn(selector)) + } + if len(selector.SelectedColumns()) == 0 { + columns := make([]string, 0, len(*_g.flds)+len(_g.fns)) + for _, f := range *_g.flds { + columns = append(columns, selector.C(f)) + } + columns = append(columns, aggregation...) + selector.Select(columns...) + } + selector.GroupBy(selector.Columns(*_g.flds...)...) + if err := selector.Err(); err != nil { + return err + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := _g.build.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} + +// PieceJointeSelect is the builder for selecting fields of PieceJointe entities. +type PieceJointeSelect struct { + *PieceJointeQuery + selector +} + +// Aggregate adds the given aggregation functions to the selector query. +func (_s *PieceJointeSelect) Aggregate(fns ...AggregateFunc) *PieceJointeSelect { + _s.fns = append(_s.fns, fns...) + return _s +} + +// Scan applies the selector query and scans the result into the given value. +func (_s *PieceJointeSelect) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, _s.ctx, ent.OpQuerySelect) + if err := _s.prepareQuery(ctx); err != nil { + return err + } + return scanWithInterceptors[*PieceJointeQuery, *PieceJointeSelect](ctx, _s.PieceJointeQuery, _s, _s.inters, v) +} + +func (_s *PieceJointeSelect) sqlScan(ctx context.Context, root *PieceJointeQuery, v any) error { + selector := root.sqlQuery(ctx) + aggregation := make([]string, 0, len(_s.fns)) + for _, fn := range _s.fns { + aggregation = append(aggregation, fn(selector)) + } + switch n := len(*_s.selector.flds); { + case n == 0 && len(aggregation) > 0: + selector.Select(aggregation...) + case n != 0 && len(aggregation) > 0: + selector.AppendSelect(aggregation...) + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := _s.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} diff --git a/backend/internal/data/ent/piecejointe_update.go b/backend/internal/data/ent/piecejointe_update.go new file mode 100644 index 0000000..94d0590 --- /dev/null +++ b/backend/internal/data/ent/piecejointe_update.go @@ -0,0 +1,588 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/objet" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/piecejointe" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/predicate" + "github.com/google/uuid" +) + +// PieceJointeUpdate is the builder for updating PieceJointe entities. +type PieceJointeUpdate struct { + config + hooks []Hook + mutation *PieceJointeMutation +} + +// Where appends a list predicates to the PieceJointeUpdate builder. +func (_u *PieceJointeUpdate) Where(ps ...predicate.PieceJointe) *PieceJointeUpdate { + _u.mutation.Where(ps...) + return _u +} + +// SetObjetID sets the "objet_id" field. +func (_u *PieceJointeUpdate) SetObjetID(v uuid.UUID) *PieceJointeUpdate { + _u.mutation.SetObjetID(v) + return _u +} + +// SetNillableObjetID sets the "objet_id" field if the given value is not nil. +func (_u *PieceJointeUpdate) SetNillableObjetID(v *uuid.UUID) *PieceJointeUpdate { + if v != nil { + _u.SetObjetID(*v) + } + return _u +} + +// SetNomFichier sets the "nom_fichier" field. +func (_u *PieceJointeUpdate) SetNomFichier(v string) *PieceJointeUpdate { + _u.mutation.SetNomFichier(v) + return _u +} + +// SetNillableNomFichier sets the "nom_fichier" field if the given value is not nil. +func (_u *PieceJointeUpdate) SetNillableNomFichier(v *string) *PieceJointeUpdate { + if v != nil { + _u.SetNomFichier(*v) + } + return _u +} + +// SetChemin sets the "chemin" field. +func (_u *PieceJointeUpdate) SetChemin(v string) *PieceJointeUpdate { + _u.mutation.SetChemin(v) + return _u +} + +// SetNillableChemin sets the "chemin" field if the given value is not nil. +func (_u *PieceJointeUpdate) SetNillableChemin(v *string) *PieceJointeUpdate { + if v != nil { + _u.SetChemin(*v) + } + return _u +} + +// SetTypeMime sets the "type_mime" field. +func (_u *PieceJointeUpdate) SetTypeMime(v string) *PieceJointeUpdate { + _u.mutation.SetTypeMime(v) + return _u +} + +// SetNillableTypeMime sets the "type_mime" field if the given value is not nil. +func (_u *PieceJointeUpdate) SetNillableTypeMime(v *string) *PieceJointeUpdate { + if v != nil { + _u.SetTypeMime(*v) + } + return _u +} + +// SetEstPrincipale sets the "est_principale" field. +func (_u *PieceJointeUpdate) SetEstPrincipale(v bool) *PieceJointeUpdate { + _u.mutation.SetEstPrincipale(v) + return _u +} + +// SetNillableEstPrincipale sets the "est_principale" field if the given value is not nil. +func (_u *PieceJointeUpdate) SetNillableEstPrincipale(v *bool) *PieceJointeUpdate { + if v != nil { + _u.SetEstPrincipale(*v) + } + return _u +} + +// SetCategorie sets the "categorie" field. +func (_u *PieceJointeUpdate) SetCategorie(v piecejointe.Categorie) *PieceJointeUpdate { + _u.mutation.SetCategorie(v) + return _u +} + +// SetNillableCategorie sets the "categorie" field if the given value is not nil. +func (_u *PieceJointeUpdate) SetNillableCategorie(v *piecejointe.Categorie) *PieceJointeUpdate { + if v != nil { + _u.SetCategorie(*v) + } + return _u +} + +// SetCreatedAt sets the "created_at" field. +func (_u *PieceJointeUpdate) SetCreatedAt(v time.Time) *PieceJointeUpdate { + _u.mutation.SetCreatedAt(v) + return _u +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (_u *PieceJointeUpdate) SetNillableCreatedAt(v *time.Time) *PieceJointeUpdate { + if v != nil { + _u.SetCreatedAt(*v) + } + return _u +} + +// SetUpdatedAt sets the "updated_at" field. +func (_u *PieceJointeUpdate) SetUpdatedAt(v time.Time) *PieceJointeUpdate { + _u.mutation.SetUpdatedAt(v) + return _u +} + +// SetObjet sets the "objet" edge to the Objet entity. +func (_u *PieceJointeUpdate) SetObjet(v *Objet) *PieceJointeUpdate { + return _u.SetObjetID(v.ID) +} + +// Mutation returns the PieceJointeMutation object of the builder. +func (_u *PieceJointeUpdate) Mutation() *PieceJointeMutation { + return _u.mutation +} + +// ClearObjet clears the "objet" edge to the Objet entity. +func (_u *PieceJointeUpdate) ClearObjet() *PieceJointeUpdate { + _u.mutation.ClearObjet() + return _u +} + +// Save executes the query and returns the number of nodes affected by the update operation. +func (_u *PieceJointeUpdate) Save(ctx context.Context) (int, error) { + _u.defaults() + return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (_u *PieceJointeUpdate) SaveX(ctx context.Context) int { + affected, err := _u.Save(ctx) + if err != nil { + panic(err) + } + return affected +} + +// Exec executes the query. +func (_u *PieceJointeUpdate) Exec(ctx context.Context) error { + _, err := _u.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_u *PieceJointeUpdate) ExecX(ctx context.Context) { + if err := _u.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (_u *PieceJointeUpdate) defaults() { + if _, ok := _u.mutation.UpdatedAt(); !ok { + v := piecejointe.UpdateDefaultUpdatedAt() + _u.mutation.SetUpdatedAt(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_u *PieceJointeUpdate) check() error { + if v, ok := _u.mutation.NomFichier(); ok { + if err := piecejointe.NomFichierValidator(v); err != nil { + return &ValidationError{Name: "nom_fichier", err: fmt.Errorf(`ent: validator failed for field "PieceJointe.nom_fichier": %w`, err)} + } + } + if v, ok := _u.mutation.Chemin(); ok { + if err := piecejointe.CheminValidator(v); err != nil { + return &ValidationError{Name: "chemin", err: fmt.Errorf(`ent: validator failed for field "PieceJointe.chemin": %w`, err)} + } + } + if v, ok := _u.mutation.TypeMime(); ok { + if err := piecejointe.TypeMimeValidator(v); err != nil { + return &ValidationError{Name: "type_mime", err: fmt.Errorf(`ent: validator failed for field "PieceJointe.type_mime": %w`, err)} + } + } + if v, ok := _u.mutation.Categorie(); ok { + if err := piecejointe.CategorieValidator(v); err != nil { + return &ValidationError{Name: "categorie", err: fmt.Errorf(`ent: validator failed for field "PieceJointe.categorie": %w`, err)} + } + } + if _u.mutation.ObjetCleared() && len(_u.mutation.ObjetIDs()) > 0 { + return errors.New(`ent: clearing a required unique edge "PieceJointe.objet"`) + } + return nil +} + +func (_u *PieceJointeUpdate) sqlSave(ctx context.Context) (_node int, err error) { + if err := _u.check(); err != nil { + return _node, err + } + _spec := sqlgraph.NewUpdateSpec(piecejointe.Table, piecejointe.Columns, sqlgraph.NewFieldSpec(piecejointe.FieldID, field.TypeUUID)) + if ps := _u.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := _u.mutation.NomFichier(); ok { + _spec.SetField(piecejointe.FieldNomFichier, field.TypeString, value) + } + if value, ok := _u.mutation.Chemin(); ok { + _spec.SetField(piecejointe.FieldChemin, field.TypeString, value) + } + if value, ok := _u.mutation.TypeMime(); ok { + _spec.SetField(piecejointe.FieldTypeMime, field.TypeString, value) + } + if value, ok := _u.mutation.EstPrincipale(); ok { + _spec.SetField(piecejointe.FieldEstPrincipale, field.TypeBool, value) + } + if value, ok := _u.mutation.Categorie(); ok { + _spec.SetField(piecejointe.FieldCategorie, field.TypeEnum, value) + } + if value, ok := _u.mutation.CreatedAt(); ok { + _spec.SetField(piecejointe.FieldCreatedAt, field.TypeTime, value) + } + if value, ok := _u.mutation.UpdatedAt(); ok { + _spec.SetField(piecejointe.FieldUpdatedAt, field.TypeTime, value) + } + if _u.mutation.ObjetCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: piecejointe.ObjetTable, + Columns: []string{piecejointe.ObjetColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(objet.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.ObjetIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: piecejointe.ObjetTable, + Columns: []string{piecejointe.ObjetColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(objet.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{piecejointe.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return 0, err + } + _u.mutation.done = true + return _node, nil +} + +// PieceJointeUpdateOne is the builder for updating a single PieceJointe entity. +type PieceJointeUpdateOne struct { + config + fields []string + hooks []Hook + mutation *PieceJointeMutation +} + +// SetObjetID sets the "objet_id" field. +func (_u *PieceJointeUpdateOne) SetObjetID(v uuid.UUID) *PieceJointeUpdateOne { + _u.mutation.SetObjetID(v) + return _u +} + +// SetNillableObjetID sets the "objet_id" field if the given value is not nil. +func (_u *PieceJointeUpdateOne) SetNillableObjetID(v *uuid.UUID) *PieceJointeUpdateOne { + if v != nil { + _u.SetObjetID(*v) + } + return _u +} + +// SetNomFichier sets the "nom_fichier" field. +func (_u *PieceJointeUpdateOne) SetNomFichier(v string) *PieceJointeUpdateOne { + _u.mutation.SetNomFichier(v) + return _u +} + +// SetNillableNomFichier sets the "nom_fichier" field if the given value is not nil. +func (_u *PieceJointeUpdateOne) SetNillableNomFichier(v *string) *PieceJointeUpdateOne { + if v != nil { + _u.SetNomFichier(*v) + } + return _u +} + +// SetChemin sets the "chemin" field. +func (_u *PieceJointeUpdateOne) SetChemin(v string) *PieceJointeUpdateOne { + _u.mutation.SetChemin(v) + return _u +} + +// SetNillableChemin sets the "chemin" field if the given value is not nil. +func (_u *PieceJointeUpdateOne) SetNillableChemin(v *string) *PieceJointeUpdateOne { + if v != nil { + _u.SetChemin(*v) + } + return _u +} + +// SetTypeMime sets the "type_mime" field. +func (_u *PieceJointeUpdateOne) SetTypeMime(v string) *PieceJointeUpdateOne { + _u.mutation.SetTypeMime(v) + return _u +} + +// SetNillableTypeMime sets the "type_mime" field if the given value is not nil. +func (_u *PieceJointeUpdateOne) SetNillableTypeMime(v *string) *PieceJointeUpdateOne { + if v != nil { + _u.SetTypeMime(*v) + } + return _u +} + +// SetEstPrincipale sets the "est_principale" field. +func (_u *PieceJointeUpdateOne) SetEstPrincipale(v bool) *PieceJointeUpdateOne { + _u.mutation.SetEstPrincipale(v) + return _u +} + +// SetNillableEstPrincipale sets the "est_principale" field if the given value is not nil. +func (_u *PieceJointeUpdateOne) SetNillableEstPrincipale(v *bool) *PieceJointeUpdateOne { + if v != nil { + _u.SetEstPrincipale(*v) + } + return _u +} + +// SetCategorie sets the "categorie" field. +func (_u *PieceJointeUpdateOne) SetCategorie(v piecejointe.Categorie) *PieceJointeUpdateOne { + _u.mutation.SetCategorie(v) + return _u +} + +// SetNillableCategorie sets the "categorie" field if the given value is not nil. +func (_u *PieceJointeUpdateOne) SetNillableCategorie(v *piecejointe.Categorie) *PieceJointeUpdateOne { + if v != nil { + _u.SetCategorie(*v) + } + return _u +} + +// SetCreatedAt sets the "created_at" field. +func (_u *PieceJointeUpdateOne) SetCreatedAt(v time.Time) *PieceJointeUpdateOne { + _u.mutation.SetCreatedAt(v) + return _u +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (_u *PieceJointeUpdateOne) SetNillableCreatedAt(v *time.Time) *PieceJointeUpdateOne { + if v != nil { + _u.SetCreatedAt(*v) + } + return _u +} + +// SetUpdatedAt sets the "updated_at" field. +func (_u *PieceJointeUpdateOne) SetUpdatedAt(v time.Time) *PieceJointeUpdateOne { + _u.mutation.SetUpdatedAt(v) + return _u +} + +// SetObjet sets the "objet" edge to the Objet entity. +func (_u *PieceJointeUpdateOne) SetObjet(v *Objet) *PieceJointeUpdateOne { + return _u.SetObjetID(v.ID) +} + +// Mutation returns the PieceJointeMutation object of the builder. +func (_u *PieceJointeUpdateOne) Mutation() *PieceJointeMutation { + return _u.mutation +} + +// ClearObjet clears the "objet" edge to the Objet entity. +func (_u *PieceJointeUpdateOne) ClearObjet() *PieceJointeUpdateOne { + _u.mutation.ClearObjet() + return _u +} + +// Where appends a list predicates to the PieceJointeUpdate builder. +func (_u *PieceJointeUpdateOne) Where(ps ...predicate.PieceJointe) *PieceJointeUpdateOne { + _u.mutation.Where(ps...) + return _u +} + +// Select allows selecting one or more fields (columns) of the returned entity. +// The default is selecting all fields defined in the entity schema. +func (_u *PieceJointeUpdateOne) Select(field string, fields ...string) *PieceJointeUpdateOne { + _u.fields = append([]string{field}, fields...) + return _u +} + +// Save executes the query and returns the updated PieceJointe entity. +func (_u *PieceJointeUpdateOne) Save(ctx context.Context) (*PieceJointe, error) { + _u.defaults() + return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (_u *PieceJointeUpdateOne) SaveX(ctx context.Context) *PieceJointe { + node, err := _u.Save(ctx) + if err != nil { + panic(err) + } + return node +} + +// Exec executes the query on the entity. +func (_u *PieceJointeUpdateOne) Exec(ctx context.Context) error { + _, err := _u.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_u *PieceJointeUpdateOne) ExecX(ctx context.Context) { + if err := _u.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (_u *PieceJointeUpdateOne) defaults() { + if _, ok := _u.mutation.UpdatedAt(); !ok { + v := piecejointe.UpdateDefaultUpdatedAt() + _u.mutation.SetUpdatedAt(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_u *PieceJointeUpdateOne) check() error { + if v, ok := _u.mutation.NomFichier(); ok { + if err := piecejointe.NomFichierValidator(v); err != nil { + return &ValidationError{Name: "nom_fichier", err: fmt.Errorf(`ent: validator failed for field "PieceJointe.nom_fichier": %w`, err)} + } + } + if v, ok := _u.mutation.Chemin(); ok { + if err := piecejointe.CheminValidator(v); err != nil { + return &ValidationError{Name: "chemin", err: fmt.Errorf(`ent: validator failed for field "PieceJointe.chemin": %w`, err)} + } + } + if v, ok := _u.mutation.TypeMime(); ok { + if err := piecejointe.TypeMimeValidator(v); err != nil { + return &ValidationError{Name: "type_mime", err: fmt.Errorf(`ent: validator failed for field "PieceJointe.type_mime": %w`, err)} + } + } + if v, ok := _u.mutation.Categorie(); ok { + if err := piecejointe.CategorieValidator(v); err != nil { + return &ValidationError{Name: "categorie", err: fmt.Errorf(`ent: validator failed for field "PieceJointe.categorie": %w`, err)} + } + } + if _u.mutation.ObjetCleared() && len(_u.mutation.ObjetIDs()) > 0 { + return errors.New(`ent: clearing a required unique edge "PieceJointe.objet"`) + } + return nil +} + +func (_u *PieceJointeUpdateOne) sqlSave(ctx context.Context) (_node *PieceJointe, err error) { + if err := _u.check(); err != nil { + return _node, err + } + _spec := sqlgraph.NewUpdateSpec(piecejointe.Table, piecejointe.Columns, sqlgraph.NewFieldSpec(piecejointe.FieldID, field.TypeUUID)) + id, ok := _u.mutation.ID() + if !ok { + return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "PieceJointe.id" for update`)} + } + _spec.Node.ID.Value = id + if fields := _u.fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, piecejointe.FieldID) + for _, f := range fields { + if !piecejointe.ValidColumn(f) { + return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + if f != piecejointe.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, f) + } + } + } + if ps := _u.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := _u.mutation.NomFichier(); ok { + _spec.SetField(piecejointe.FieldNomFichier, field.TypeString, value) + } + if value, ok := _u.mutation.Chemin(); ok { + _spec.SetField(piecejointe.FieldChemin, field.TypeString, value) + } + if value, ok := _u.mutation.TypeMime(); ok { + _spec.SetField(piecejointe.FieldTypeMime, field.TypeString, value) + } + if value, ok := _u.mutation.EstPrincipale(); ok { + _spec.SetField(piecejointe.FieldEstPrincipale, field.TypeBool, value) + } + if value, ok := _u.mutation.Categorie(); ok { + _spec.SetField(piecejointe.FieldCategorie, field.TypeEnum, value) + } + if value, ok := _u.mutation.CreatedAt(); ok { + _spec.SetField(piecejointe.FieldCreatedAt, field.TypeTime, value) + } + if value, ok := _u.mutation.UpdatedAt(); ok { + _spec.SetField(piecejointe.FieldUpdatedAt, field.TypeTime, value) + } + if _u.mutation.ObjetCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: piecejointe.ObjetTable, + Columns: []string{piecejointe.ObjetColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(objet.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.ObjetIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: piecejointe.ObjetTable, + Columns: []string{piecejointe.ObjetColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(objet.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + _node = &PieceJointe{config: _u.config} + _spec.Assign = _node.assignValues + _spec.ScanValues = _node.scanValues + if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{piecejointe.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + _u.mutation.done = true + return _node, nil +} diff --git a/backend/internal/data/ent/predicate/predicate.go b/backend/internal/data/ent/predicate/predicate.go new file mode 100644 index 0000000..c9d34e5 --- /dev/null +++ b/backend/internal/data/ent/predicate/predicate.go @@ -0,0 +1,25 @@ +// Code generated by ent, DO NOT EDIT. + +package predicate + +import ( + "entgo.io/ent/dialect/sql" +) + +// Categorie is the predicate function for categorie builders. +type Categorie func(*sql.Selector) + +// ChampPersonnalise is the predicate function for champpersonnalise builders. +type ChampPersonnalise func(*sql.Selector) + +// Emplacement is the predicate function for emplacement builders. +type Emplacement func(*sql.Selector) + +// LienObjetEmplacement is the predicate function for lienobjetemplacement builders. +type LienObjetEmplacement func(*sql.Selector) + +// Objet is the predicate function for objet builders. +type Objet func(*sql.Selector) + +// PieceJointe is the predicate function for piecejointe builders. +type PieceJointe func(*sql.Selector) diff --git a/backend/internal/data/ent/runtime.go b/backend/internal/data/ent/runtime.go new file mode 100644 index 0000000..ab63ce0 --- /dev/null +++ b/backend/internal/data/ent/runtime.go @@ -0,0 +1,154 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "time" + + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/categorie" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/champpersonnalise" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/emplacement" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/lienobjetemplacement" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/objet" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/piecejointe" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/schema" + "github.com/google/uuid" +) + +// The init function reads all schema descriptors with runtime code +// (default values, validators, hooks and policies) and stitches it +// to their package variables. +func init() { + categorieFields := schema.Categorie{}.Fields() + _ = categorieFields + // categorieDescNom is the schema descriptor for nom field. + categorieDescNom := categorieFields[1].Descriptor() + // categorie.NomValidator is a validator for the "nom" field. It is called by the builders before save. + categorie.NomValidator = categorieDescNom.Validators[0].(func(string) error) + // categorieDescCreatedAt is the schema descriptor for created_at field. + categorieDescCreatedAt := categorieFields[5].Descriptor() + // categorie.DefaultCreatedAt holds the default value on creation for the created_at field. + categorie.DefaultCreatedAt = categorieDescCreatedAt.Default.(func() time.Time) + // categorieDescUpdatedAt is the schema descriptor for updated_at field. + categorieDescUpdatedAt := categorieFields[6].Descriptor() + // categorie.DefaultUpdatedAt holds the default value on creation for the updated_at field. + categorie.DefaultUpdatedAt = categorieDescUpdatedAt.Default.(func() time.Time) + // categorie.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field. + categorie.UpdateDefaultUpdatedAt = categorieDescUpdatedAt.UpdateDefault.(func() time.Time) + // categorieDescID is the schema descriptor for id field. + categorieDescID := categorieFields[0].Descriptor() + // categorie.DefaultID holds the default value on creation for the id field. + categorie.DefaultID = categorieDescID.Default.(func() uuid.UUID) + champpersonnaliseFields := schema.ChampPersonnalise{}.Fields() + _ = champpersonnaliseFields + // champpersonnaliseDescNomChamp is the schema descriptor for nom_champ field. + champpersonnaliseDescNomChamp := champpersonnaliseFields[2].Descriptor() + // champpersonnalise.NomChampValidator is a validator for the "nom_champ" field. It is called by the builders before save. + champpersonnalise.NomChampValidator = champpersonnaliseDescNomChamp.Validators[0].(func(string) error) + // champpersonnaliseDescCreatedAt is the schema descriptor for created_at field. + champpersonnaliseDescCreatedAt := champpersonnaliseFields[6].Descriptor() + // champpersonnalise.DefaultCreatedAt holds the default value on creation for the created_at field. + champpersonnalise.DefaultCreatedAt = champpersonnaliseDescCreatedAt.Default.(func() time.Time) + // champpersonnaliseDescUpdatedAt is the schema descriptor for updated_at field. + champpersonnaliseDescUpdatedAt := champpersonnaliseFields[7].Descriptor() + // champpersonnalise.DefaultUpdatedAt holds the default value on creation for the updated_at field. + champpersonnalise.DefaultUpdatedAt = champpersonnaliseDescUpdatedAt.Default.(func() time.Time) + // champpersonnalise.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field. + champpersonnalise.UpdateDefaultUpdatedAt = champpersonnaliseDescUpdatedAt.UpdateDefault.(func() time.Time) + // champpersonnaliseDescID is the schema descriptor for id field. + champpersonnaliseDescID := champpersonnaliseFields[0].Descriptor() + // champpersonnalise.DefaultID holds the default value on creation for the id field. + champpersonnalise.DefaultID = champpersonnaliseDescID.Default.(func() uuid.UUID) + emplacementFields := schema.Emplacement{}.Fields() + _ = emplacementFields + // emplacementDescNom is the schema descriptor for nom field. + emplacementDescNom := emplacementFields[1].Descriptor() + // emplacement.NomValidator is a validator for the "nom" field. It is called by the builders before save. + emplacement.NomValidator = emplacementDescNom.Validators[0].(func(string) error) + // emplacementDescCreatedAt is the schema descriptor for created_at field. + emplacementDescCreatedAt := emplacementFields[8].Descriptor() + // emplacement.DefaultCreatedAt holds the default value on creation for the created_at field. + emplacement.DefaultCreatedAt = emplacementDescCreatedAt.Default.(func() time.Time) + // emplacementDescUpdatedAt is the schema descriptor for updated_at field. + emplacementDescUpdatedAt := emplacementFields[9].Descriptor() + // emplacement.DefaultUpdatedAt holds the default value on creation for the updated_at field. + emplacement.DefaultUpdatedAt = emplacementDescUpdatedAt.Default.(func() time.Time) + // emplacement.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field. + emplacement.UpdateDefaultUpdatedAt = emplacementDescUpdatedAt.UpdateDefault.(func() time.Time) + // emplacementDescID is the schema descriptor for id field. + emplacementDescID := emplacementFields[0].Descriptor() + // emplacement.DefaultID holds the default value on creation for the id field. + emplacement.DefaultID = emplacementDescID.Default.(func() uuid.UUID) + lienobjetemplacementFields := schema.LienObjetEmplacement{}.Fields() + _ = lienobjetemplacementFields + // lienobjetemplacementDescCreatedAt is the schema descriptor for created_at field. + lienobjetemplacementDescCreatedAt := lienobjetemplacementFields[4].Descriptor() + // lienobjetemplacement.DefaultCreatedAt holds the default value on creation for the created_at field. + lienobjetemplacement.DefaultCreatedAt = lienobjetemplacementDescCreatedAt.Default.(func() time.Time) + // lienobjetemplacementDescUpdatedAt is the schema descriptor for updated_at field. + lienobjetemplacementDescUpdatedAt := lienobjetemplacementFields[5].Descriptor() + // lienobjetemplacement.DefaultUpdatedAt holds the default value on creation for the updated_at field. + lienobjetemplacement.DefaultUpdatedAt = lienobjetemplacementDescUpdatedAt.Default.(func() time.Time) + // lienobjetemplacement.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field. + lienobjetemplacement.UpdateDefaultUpdatedAt = lienobjetemplacementDescUpdatedAt.UpdateDefault.(func() time.Time) + // lienobjetemplacementDescID is the schema descriptor for id field. + lienobjetemplacementDescID := lienobjetemplacementFields[0].Descriptor() + // lienobjetemplacement.DefaultID holds the default value on creation for the id field. + lienobjetemplacement.DefaultID = lienobjetemplacementDescID.Default.(func() uuid.UUID) + objetFields := schema.Objet{}.Fields() + _ = objetFields + // objetDescNom is the schema descriptor for nom field. + objetDescNom := objetFields[1].Descriptor() + // objet.NomValidator is a validator for the "nom" field. It is called by the builders before save. + objet.NomValidator = objetDescNom.Validators[0].(func(string) error) + // objetDescQuantite is the schema descriptor for quantite field. + objetDescQuantite := objetFields[3].Descriptor() + // objet.DefaultQuantite holds the default value on creation for the quantite field. + objet.DefaultQuantite = objetDescQuantite.Default.(int) + // objetDescCreatedAt is the schema descriptor for created_at field. + objetDescCreatedAt := objetFields[12].Descriptor() + // objet.DefaultCreatedAt holds the default value on creation for the created_at field. + objet.DefaultCreatedAt = objetDescCreatedAt.Default.(func() time.Time) + // objetDescUpdatedAt is the schema descriptor for updated_at field. + objetDescUpdatedAt := objetFields[13].Descriptor() + // objet.DefaultUpdatedAt holds the default value on creation for the updated_at field. + objet.DefaultUpdatedAt = objetDescUpdatedAt.Default.(func() time.Time) + // objet.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field. + objet.UpdateDefaultUpdatedAt = objetDescUpdatedAt.UpdateDefault.(func() time.Time) + // objetDescID is the schema descriptor for id field. + objetDescID := objetFields[0].Descriptor() + // objet.DefaultID holds the default value on creation for the id field. + objet.DefaultID = objetDescID.Default.(func() uuid.UUID) + piecejointeFields := schema.PieceJointe{}.Fields() + _ = piecejointeFields + // piecejointeDescNomFichier is the schema descriptor for nom_fichier field. + piecejointeDescNomFichier := piecejointeFields[2].Descriptor() + // piecejointe.NomFichierValidator is a validator for the "nom_fichier" field. It is called by the builders before save. + piecejointe.NomFichierValidator = piecejointeDescNomFichier.Validators[0].(func(string) error) + // piecejointeDescChemin is the schema descriptor for chemin field. + piecejointeDescChemin := piecejointeFields[3].Descriptor() + // piecejointe.CheminValidator is a validator for the "chemin" field. It is called by the builders before save. + piecejointe.CheminValidator = piecejointeDescChemin.Validators[0].(func(string) error) + // piecejointeDescTypeMime is the schema descriptor for type_mime field. + piecejointeDescTypeMime := piecejointeFields[4].Descriptor() + // piecejointe.TypeMimeValidator is a validator for the "type_mime" field. It is called by the builders before save. + piecejointe.TypeMimeValidator = piecejointeDescTypeMime.Validators[0].(func(string) error) + // piecejointeDescEstPrincipale is the schema descriptor for est_principale field. + piecejointeDescEstPrincipale := piecejointeFields[5].Descriptor() + // piecejointe.DefaultEstPrincipale holds the default value on creation for the est_principale field. + piecejointe.DefaultEstPrincipale = piecejointeDescEstPrincipale.Default.(bool) + // piecejointeDescCreatedAt is the schema descriptor for created_at field. + piecejointeDescCreatedAt := piecejointeFields[7].Descriptor() + // piecejointe.DefaultCreatedAt holds the default value on creation for the created_at field. + piecejointe.DefaultCreatedAt = piecejointeDescCreatedAt.Default.(func() time.Time) + // piecejointeDescUpdatedAt is the schema descriptor for updated_at field. + piecejointeDescUpdatedAt := piecejointeFields[8].Descriptor() + // piecejointe.DefaultUpdatedAt holds the default value on creation for the updated_at field. + piecejointe.DefaultUpdatedAt = piecejointeDescUpdatedAt.Default.(func() time.Time) + // piecejointe.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field. + piecejointe.UpdateDefaultUpdatedAt = piecejointeDescUpdatedAt.UpdateDefault.(func() time.Time) + // piecejointeDescID is the schema descriptor for id field. + piecejointeDescID := piecejointeFields[0].Descriptor() + // piecejointe.DefaultID holds the default value on creation for the id field. + piecejointe.DefaultID = piecejointeDescID.Default.(func() uuid.UUID) +} diff --git a/backend/internal/data/ent/runtime/runtime.go b/backend/internal/data/ent/runtime/runtime.go new file mode 100644 index 0000000..711c49e --- /dev/null +++ b/backend/internal/data/ent/runtime/runtime.go @@ -0,0 +1,10 @@ +// Code generated by ent, DO NOT EDIT. + +package runtime + +// The schema-stitching logic is generated in gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/runtime.go + +const ( + Version = "v0.14.5" // Version of ent codegen. + Sum = "h1:Rj2WOYJtCkWyFo6a+5wB3EfBRP0rnx1fMk6gGA0UUe4=" // Sum of ent codegen. +) diff --git a/backend/internal/data/ent/schema/categorie.go b/backend/internal/data/ent/schema/categorie.go index bb12cf6..7e9f274 100644 --- a/backend/internal/data/ent/schema/categorie.go +++ b/backend/internal/data/ent/schema/categorie.go @@ -4,6 +4,8 @@ import ( "time" "entgo.io/ent" + "entgo.io/ent/dialect/entsql" + "entgo.io/ent/schema" "entgo.io/ent/schema/edge" "entgo.io/ent/schema/field" "github.com/google/uuid" @@ -45,6 +47,13 @@ func (Categorie) Fields() []ent.Field { } } +// Annotations pour le nom de table. +func (Categorie) Annotations() []schema.Annotation { + return []schema.Annotation{ + entsql.Annotation{Table: "categorie"}, + } +} + // Edges de l'entite Categorie. func (Categorie) Edges() []ent.Edge { return []ent.Edge{ diff --git a/backend/internal/data/ent/schema/champ_personnalise.go b/backend/internal/data/ent/schema/champ_personnalise.go index 92e234e..f091acf 100644 --- a/backend/internal/data/ent/schema/champ_personnalise.go +++ b/backend/internal/data/ent/schema/champ_personnalise.go @@ -4,6 +4,8 @@ import ( "time" "entgo.io/ent" + "entgo.io/ent/dialect/entsql" + "entgo.io/ent/schema" "entgo.io/ent/schema/edge" "entgo.io/ent/schema/field" "github.com/google/uuid" @@ -47,12 +49,20 @@ func (ChampPersonnalise) Fields() []ent.Field { } } +// Annotations pour le nom de table. +func (ChampPersonnalise) Annotations() []schema.Annotation { + return []schema.Annotation{ + entsql.Annotation{Table: "champ_personnalise"}, + } +} + // Edges de l'entite ChampPersonnalise. func (ChampPersonnalise) Edges() []ent.Edge { return []ent.Edge{ edge.From("objet", Objet.Type). Ref("champs_personnalises"). Unique(). - Field("objet_id"), + Field("objet_id"). + Required(), } } diff --git a/backend/internal/data/ent/schema/emplacement.go b/backend/internal/data/ent/schema/emplacement.go index 0ab959d..bc28163 100644 --- a/backend/internal/data/ent/schema/emplacement.go +++ b/backend/internal/data/ent/schema/emplacement.go @@ -4,6 +4,8 @@ import ( "time" "entgo.io/ent" + "entgo.io/ent/dialect/entsql" + "entgo.io/ent/schema" "entgo.io/ent/schema/edge" "entgo.io/ent/schema/field" "github.com/google/uuid" @@ -57,6 +59,13 @@ func (Emplacement) Fields() []ent.Field { } } +// Annotations pour le nom de table. +func (Emplacement) Annotations() []schema.Annotation { + return []schema.Annotation{ + entsql.Annotation{Table: "emplacement"}, + } +} + // Edges de l'entite Emplacement. func (Emplacement) Edges() []ent.Edge { return []ent.Edge{ @@ -65,5 +74,7 @@ func (Emplacement) Edges() []ent.Edge { Unique(). Field("parent_id"). Comment("Lien parent/enfants pour l'arbre des emplacements"), + edge.To("liens_objets", LienObjetEmplacement.Type). + Comment("Liens entre emplacements et objets"), } } diff --git a/backend/internal/data/ent/schema/lien_objet_emplacement.go b/backend/internal/data/ent/schema/lien_objet_emplacement.go index b40e770..b81270e 100644 --- a/backend/internal/data/ent/schema/lien_objet_emplacement.go +++ b/backend/internal/data/ent/schema/lien_objet_emplacement.go @@ -4,6 +4,8 @@ import ( "time" "entgo.io/ent" + "entgo.io/ent/dialect/entsql" + "entgo.io/ent/schema" "entgo.io/ent/schema/edge" "entgo.io/ent/schema/field" "github.com/google/uuid" @@ -38,16 +40,25 @@ func (LienObjetEmplacement) Fields() []ent.Field { } } +// Annotations pour le nom de table. +func (LienObjetEmplacement) Annotations() []schema.Annotation { + return []schema.Annotation{ + entsql.Annotation{Table: "lien_objet_emplacement"}, + } +} + // Edges de l'entite LienObjetEmplacement. func (LienObjetEmplacement) Edges() []ent.Edge { return []ent.Edge{ edge.From("objet", Objet.Type). Ref("liens_emplacements"). Unique(). - Field("objet_id"), + Field("objet_id"). + Required(), edge.From("emplacement", Emplacement.Type). Ref("liens_objets"). Unique(). - Field("emplacement_id"), + Field("emplacement_id"). + Required(), } } diff --git a/backend/internal/data/ent/schema/objet.go b/backend/internal/data/ent/schema/objet.go index e1a266c..2dc26d7 100644 --- a/backend/internal/data/ent/schema/objet.go +++ b/backend/internal/data/ent/schema/objet.go @@ -4,6 +4,8 @@ import ( "time" "entgo.io/ent" + "entgo.io/ent/dialect/entsql" + "entgo.io/ent/schema" "entgo.io/ent/schema/edge" "entgo.io/ent/schema/field" "github.com/google/uuid" @@ -60,7 +62,6 @@ func (Objet) Fields() []ent.Field { Comment("Statut de l'objet"), field.JSON("caracteristiques", map[string]any{}). Optional(). - Nillable(). Comment("Caracteristiques personnalisees"), field.Time("created_at"). Default(time.Now). @@ -72,6 +73,13 @@ func (Objet) Fields() []ent.Field { } } +// Annotations pour le nom de table. +func (Objet) Annotations() []schema.Annotation { + return []schema.Annotation{ + entsql.Annotation{Table: "objet"}, + } +} + // Edges de l'entite Objet. func (Objet) Edges() []ent.Edge { return []ent.Edge{ diff --git a/backend/internal/data/ent/schema/piece_jointe.go b/backend/internal/data/ent/schema/piece_jointe.go index cfb7b1c..2f93d78 100644 --- a/backend/internal/data/ent/schema/piece_jointe.go +++ b/backend/internal/data/ent/schema/piece_jointe.go @@ -4,6 +4,8 @@ import ( "time" "entgo.io/ent" + "entgo.io/ent/dialect/entsql" + "entgo.io/ent/schema" "entgo.io/ent/schema/edge" "entgo.io/ent/schema/field" "github.com/google/uuid" @@ -48,12 +50,20 @@ func (PieceJointe) Fields() []ent.Field { } } +// Annotations pour le nom de table. +func (PieceJointe) Annotations() []schema.Annotation { + return []schema.Annotation{ + entsql.Annotation{Table: "piece_jointe"}, + } +} + // Edges de l'entite PieceJointe. func (PieceJointe) Edges() []ent.Edge { return []ent.Edge{ edge.From("objet", Objet.Type). Ref("pieces_jointes"). Unique(). - Field("objet_id"), + Field("objet_id"). + Required(), } } diff --git a/backend/internal/data/ent/tx.go b/backend/internal/data/ent/tx.go new file mode 100644 index 0000000..5d318be --- /dev/null +++ b/backend/internal/data/ent/tx.go @@ -0,0 +1,225 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "sync" + + "entgo.io/ent/dialect" +) + +// Tx is a transactional client that is created by calling Client.Tx(). +type Tx struct { + config + // Categorie is the client for interacting with the Categorie builders. + Categorie *CategorieClient + // ChampPersonnalise is the client for interacting with the ChampPersonnalise builders. + ChampPersonnalise *ChampPersonnaliseClient + // Emplacement is the client for interacting with the Emplacement builders. + Emplacement *EmplacementClient + // LienObjetEmplacement is the client for interacting with the LienObjetEmplacement builders. + LienObjetEmplacement *LienObjetEmplacementClient + // Objet is the client for interacting with the Objet builders. + Objet *ObjetClient + // PieceJointe is the client for interacting with the PieceJointe builders. + PieceJointe *PieceJointeClient + + // lazily loaded. + client *Client + clientOnce sync.Once + // ctx lives for the life of the transaction. It is + // the same context used by the underlying connection. + ctx context.Context +} + +type ( + // Committer is the interface that wraps the Commit method. + Committer interface { + Commit(context.Context, *Tx) error + } + + // The CommitFunc type is an adapter to allow the use of ordinary + // function as a Committer. If f is a function with the appropriate + // signature, CommitFunc(f) is a Committer that calls f. + CommitFunc func(context.Context, *Tx) error + + // CommitHook defines the "commit middleware". A function that gets a Committer + // and returns a Committer. For example: + // + // hook := func(next ent.Committer) ent.Committer { + // return ent.CommitFunc(func(ctx context.Context, tx *ent.Tx) error { + // // Do some stuff before. + // if err := next.Commit(ctx, tx); err != nil { + // return err + // } + // // Do some stuff after. + // return nil + // }) + // } + // + CommitHook func(Committer) Committer +) + +// Commit calls f(ctx, m). +func (f CommitFunc) Commit(ctx context.Context, tx *Tx) error { + return f(ctx, tx) +} + +// Commit commits the transaction. +func (tx *Tx) Commit() error { + txDriver := tx.config.driver.(*txDriver) + var fn Committer = CommitFunc(func(context.Context, *Tx) error { + return txDriver.tx.Commit() + }) + txDriver.mu.Lock() + hooks := append([]CommitHook(nil), txDriver.onCommit...) + txDriver.mu.Unlock() + for i := len(hooks) - 1; i >= 0; i-- { + fn = hooks[i](fn) + } + return fn.Commit(tx.ctx, tx) +} + +// OnCommit adds a hook to call on commit. +func (tx *Tx) OnCommit(f CommitHook) { + txDriver := tx.config.driver.(*txDriver) + txDriver.mu.Lock() + txDriver.onCommit = append(txDriver.onCommit, f) + txDriver.mu.Unlock() +} + +type ( + // Rollbacker is the interface that wraps the Rollback method. + Rollbacker interface { + Rollback(context.Context, *Tx) error + } + + // The RollbackFunc type is an adapter to allow the use of ordinary + // function as a Rollbacker. If f is a function with the appropriate + // signature, RollbackFunc(f) is a Rollbacker that calls f. + RollbackFunc func(context.Context, *Tx) error + + // RollbackHook defines the "rollback middleware". A function that gets a Rollbacker + // and returns a Rollbacker. For example: + // + // hook := func(next ent.Rollbacker) ent.Rollbacker { + // return ent.RollbackFunc(func(ctx context.Context, tx *ent.Tx) error { + // // Do some stuff before. + // if err := next.Rollback(ctx, tx); err != nil { + // return err + // } + // // Do some stuff after. + // return nil + // }) + // } + // + RollbackHook func(Rollbacker) Rollbacker +) + +// Rollback calls f(ctx, m). +func (f RollbackFunc) Rollback(ctx context.Context, tx *Tx) error { + return f(ctx, tx) +} + +// Rollback rollbacks the transaction. +func (tx *Tx) Rollback() error { + txDriver := tx.config.driver.(*txDriver) + var fn Rollbacker = RollbackFunc(func(context.Context, *Tx) error { + return txDriver.tx.Rollback() + }) + txDriver.mu.Lock() + hooks := append([]RollbackHook(nil), txDriver.onRollback...) + txDriver.mu.Unlock() + for i := len(hooks) - 1; i >= 0; i-- { + fn = hooks[i](fn) + } + return fn.Rollback(tx.ctx, tx) +} + +// OnRollback adds a hook to call on rollback. +func (tx *Tx) OnRollback(f RollbackHook) { + txDriver := tx.config.driver.(*txDriver) + txDriver.mu.Lock() + txDriver.onRollback = append(txDriver.onRollback, f) + txDriver.mu.Unlock() +} + +// Client returns a Client that binds to current transaction. +func (tx *Tx) Client() *Client { + tx.clientOnce.Do(func() { + tx.client = &Client{config: tx.config} + tx.client.init() + }) + return tx.client +} + +func (tx *Tx) init() { + tx.Categorie = NewCategorieClient(tx.config) + tx.ChampPersonnalise = NewChampPersonnaliseClient(tx.config) + tx.Emplacement = NewEmplacementClient(tx.config) + tx.LienObjetEmplacement = NewLienObjetEmplacementClient(tx.config) + tx.Objet = NewObjetClient(tx.config) + tx.PieceJointe = NewPieceJointeClient(tx.config) +} + +// txDriver wraps the given dialect.Tx with a nop dialect.Driver implementation. +// The idea is to support transactions without adding any extra code to the builders. +// When a builder calls to driver.Tx(), it gets the same dialect.Tx instance. +// Commit and Rollback are nop for the internal builders and the user must call one +// of them in order to commit or rollback the transaction. +// +// If a closed transaction is embedded in one of the generated entities, and the entity +// applies a query, for example: Categorie.QueryXXX(), the query will be executed +// through the driver which created this transaction. +// +// Note that txDriver is not goroutine safe. +type txDriver struct { + // the driver we started the transaction from. + drv dialect.Driver + // tx is the underlying transaction. + tx dialect.Tx + // completion hooks. + mu sync.Mutex + onCommit []CommitHook + onRollback []RollbackHook +} + +// newTx creates a new transactional driver. +func newTx(ctx context.Context, drv dialect.Driver) (*txDriver, error) { + tx, err := drv.Tx(ctx) + if err != nil { + return nil, err + } + return &txDriver{tx: tx, drv: drv}, nil +} + +// Tx returns the transaction wrapper (txDriver) to avoid Commit or Rollback calls +// from the internal builders. Should be called only by the internal builders. +func (tx *txDriver) Tx(context.Context) (dialect.Tx, error) { return tx, nil } + +// Dialect returns the dialect of the driver we started the transaction from. +func (tx *txDriver) Dialect() string { return tx.drv.Dialect() } + +// Close is a nop close. +func (*txDriver) Close() error { return nil } + +// Commit is a nop commit for the internal builders. +// User must call `Tx.Commit` in order to commit the transaction. +func (*txDriver) Commit() error { return nil } + +// Rollback is a nop rollback for the internal builders. +// User must call `Tx.Rollback` in order to rollback the transaction. +func (*txDriver) Rollback() error { return nil } + +// Exec calls tx.Exec. +func (tx *txDriver) Exec(ctx context.Context, query string, args, v any) error { + return tx.tx.Exec(ctx, query, args, v) +} + +// Query calls tx.Query. +func (tx *txDriver) Query(ctx context.Context, query string, args, v any) error { + return tx.tx.Query(ctx, query, args, v) +} + +var _ dialect.Driver = (*txDriver)(nil) diff --git a/backend/internal/handlers/categories.go b/backend/internal/handlers/categories.go new file mode 100644 index 0000000..d23a4c6 --- /dev/null +++ b/backend/internal/handlers/categories.go @@ -0,0 +1,193 @@ +package handlers + +import ( + "net/http" + + "github.com/gin-gonic/gin" + "github.com/google/uuid" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/categorie" +) + +type categorieRequest struct { + Nom *string `json:"nom"` + ParentID *string `json:"parent_id"` + Slug *string `json:"slug"` + Icone *string `json:"icone"` +} + +// @Summary Lister les categories +// @Tags Categories +// @Produce json +// @Param page query int false "Page" +// @Param limit query int false "Limite" +// @Success 200 {object} map[string]any +// @Failure 500 {object} map[string]string +// @Router /categories [get] +func (h *Handler) ListCategories(c *gin.Context) { + limit, offset, page := parsePagination(c.Query("page"), c.Query("limit")) + query := h.client.Categorie.Query() + total, err := query.Count(c.Request.Context()) + if err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"erreur": "impossible de compter les categories"}) + return + } + + items, err := query. + Order(ent.Desc(categorie.FieldCreatedAt)). + Limit(limit). + Offset(offset). + All(c.Request.Context()) + if err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"erreur": "impossible de lister les categories"}) + return + } + respondPaginated(c, items, total, page, limit) +} + +// @Summary Creer une categorie +// @Tags Categories +// @Accept json +// @Produce json +// @Param body body categorieRequest true "Categorie a creer" +// @Success 201 {object} ent.Categorie +// @Failure 400 {object} map[string]string +// @Failure 500 {object} map[string]string +// @Router /categories [post] +func (h *Handler) CreateCategorie(c *gin.Context) { + var req categorieRequest + if err := c.ShouldBindJSON(&req); err != nil { + c.JSON(http.StatusBadRequest, gin.H{"erreur": "donnees invalides"}) + return + } + if req.Nom == nil || *req.Nom == "" { + c.JSON(http.StatusBadRequest, gin.H{"erreur": "le champ nom est obligatoire"}) + return + } + + create := h.client.Categorie.Create().SetNom(*req.Nom) + if req.ParentID != nil && *req.ParentID != "" { + if parsed, err := uuid.Parse(*req.ParentID); err == nil { + create.SetParentID(parsed) + } + } + if req.Slug != nil { + create.SetNillableSlug(req.Slug) + } + if req.Icone != nil { + create.SetNillableIcone(req.Icone) + } + + created, err := create.Save(c.Request.Context()) + if err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"erreur": "impossible de creer la categorie"}) + return + } + c.JSON(http.StatusCreated, created) +} + +// @Summary Recuperer une categorie +// @Tags Categories +// @Produce json +// @Param id path string true "ID categorie" +// @Success 200 {object} ent.Categorie +// @Failure 400 {object} map[string]string +// @Failure 404 {object} map[string]string +// @Failure 500 {object} map[string]string +// @Router /categories/{id} [get] +func (h *Handler) GetCategorie(c *gin.Context) { + id, err := uuid.Parse(c.Param("id")) + if err != nil { + c.JSON(http.StatusBadRequest, gin.H{"erreur": "identifiant invalide"}) + return + } + + item, err := h.client.Categorie.Get(c.Request.Context(), id) + if err != nil { + if ent.IsNotFound(err) { + c.JSON(http.StatusNotFound, gin.H{"erreur": "categorie introuvable"}) + return + } + c.JSON(http.StatusInternalServerError, gin.H{"erreur": "impossible de charger la categorie"}) + return + } + c.JSON(http.StatusOK, item) +} + +// @Summary Mettre a jour une categorie +// @Tags Categories +// @Accept json +// @Produce json +// @Param id path string true "ID categorie" +// @Param body body categorieRequest true "Categorie a mettre a jour" +// @Success 200 {object} ent.Categorie +// @Failure 400 {object} map[string]string +// @Failure 404 {object} map[string]string +// @Failure 500 {object} map[string]string +// @Router /categories/{id} [put] +func (h *Handler) UpdateCategorie(c *gin.Context) { + id, err := uuid.Parse(c.Param("id")) + if err != nil { + c.JSON(http.StatusBadRequest, gin.H{"erreur": "identifiant invalide"}) + return + } + + var req categorieRequest + if err := c.ShouldBindJSON(&req); err != nil { + c.JSON(http.StatusBadRequest, gin.H{"erreur": "donnees invalides"}) + return + } + + update := h.client.Categorie.UpdateOneID(id) + if req.Nom != nil { + update.SetNom(*req.Nom) + } + if req.ParentID != nil { + if *req.ParentID == "" { + update.ClearParentID() + } else if parsed, err := uuid.Parse(*req.ParentID); err == nil { + update.SetParentID(parsed) + } + } + if req.Slug != nil { + update.SetNillableSlug(req.Slug) + } + if req.Icone != nil { + update.SetNillableIcone(req.Icone) + } + + updated, err := update.Save(c.Request.Context()) + if err != nil { + if ent.IsNotFound(err) { + c.JSON(http.StatusNotFound, gin.H{"erreur": "categorie introuvable"}) + return + } + c.JSON(http.StatusInternalServerError, gin.H{"erreur": "impossible de mettre a jour la categorie"}) + return + } + c.JSON(http.StatusOK, updated) +} + +// @Summary Supprimer une categorie +// @Tags Categories +// @Param id path string true "ID categorie" +// @Success 204 {string} string "No Content" +// @Failure 400 {object} map[string]string +// @Failure 500 {object} map[string]string +// @Router /categories/{id} [delete] +func (h *Handler) DeleteCategorie(c *gin.Context) { + id, err := uuid.Parse(c.Param("id")) + if err != nil { + c.JSON(http.StatusBadRequest, gin.H{"erreur": "identifiant invalide"}) + return + } + + if err := h.client.Categorie.DeleteOneID(id).Exec(c.Request.Context()); err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"erreur": "impossible de supprimer la categorie"}) + return + } + c.Status(http.StatusNoContent) +} + +// helper for compile reference +var _ = ent.IsNotFound diff --git a/backend/internal/handlers/champs_personnalises.go b/backend/internal/handlers/champs_personnalises.go new file mode 100644 index 0000000..eda1160 --- /dev/null +++ b/backend/internal/handlers/champs_personnalises.go @@ -0,0 +1,207 @@ +package handlers + +import ( + "net/http" + + "github.com/gin-gonic/gin" + "github.com/google/uuid" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/champpersonnalise" +) + +type champPersonnaliseRequest struct { + NomChamp *string `json:"nom_champ"` + TypeChamp *string `json:"type_champ"` + Valeur *string `json:"valeur"` + Unite *string `json:"unite"` +} + +// @Summary Lister les champs personnalises +// @Tags ChampsPersonnalises +// @Produce json +// @Param id path string true "ID objet" +// @Param page query int false "Page" +// @Param limit query int false "Limite" +// @Success 200 {object} map[string]any +// @Failure 400 {object} map[string]string +// @Failure 500 {object} map[string]string +// @Router /objets/{id}/champs_personnalises [get] +func (h *Handler) ListChampsPersonnalises(c *gin.Context) { + objetID, err := uuid.Parse(c.Param("id")) + if err != nil { + c.JSON(http.StatusBadRequest, gin.H{"erreur": "identifiant invalide"}) + return + } + + limit, offset, page := parsePagination(c.Query("page"), c.Query("limit")) + query := h.client.ChampPersonnalise.Query(). + Where(champpersonnalise.ObjetID(objetID)) + total, err := query.Count(c.Request.Context()) + if err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"erreur": "impossible de compter les champs"}) + return + } + + items, err := query. + Order(ent.Desc(champpersonnalise.FieldCreatedAt)). + Limit(limit). + Offset(offset). + All(c.Request.Context()) + if err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"erreur": "impossible de lister les champs"}) + return + } + respondPaginated(c, items, total, page, limit) +} + +// @Summary Creer un champ personnalise +// @Tags ChampsPersonnalises +// @Accept json +// @Produce json +// @Param id path string true "ID objet" +// @Param body body champPersonnaliseRequest true "Champ personnalise" +// @Success 201 {object} ent.ChampPersonnalise +// @Failure 400 {object} map[string]string +// @Failure 500 {object} map[string]string +// @Router /objets/{id}/champs_personnalises [post] +func (h *Handler) CreateChampPersonnalise(c *gin.Context) { + objetID, err := uuid.Parse(c.Param("id")) + if err != nil { + c.JSON(http.StatusBadRequest, gin.H{"erreur": "identifiant invalide"}) + return + } + + var req champPersonnaliseRequest + if err := c.ShouldBindJSON(&req); err != nil { + c.JSON(http.StatusBadRequest, gin.H{"erreur": "donnees invalides"}) + return + } + if req.NomChamp == nil || *req.NomChamp == "" { + c.JSON(http.StatusBadRequest, gin.H{"erreur": "le champ nom_champ est obligatoire"}) + return + } + + create := h.client.ChampPersonnalise.Create(). + SetObjetID(objetID). + SetNomChamp(*req.NomChamp) + + if req.TypeChamp != nil && *req.TypeChamp != "" { + parsed, ok := parseTypeChamp(*req.TypeChamp) + if !ok { + c.JSON(http.StatusBadRequest, gin.H{"erreur": "type_champ invalide"}) + return + } + create.SetTypeChamp(parsed) + } + if req.Valeur != nil { + create.SetNillableValeur(req.Valeur) + } + if req.Unite != nil { + create.SetNillableUnite(req.Unite) + } + + created, err := create.Save(c.Request.Context()) + if err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"erreur": "impossible de creer le champ"}) + return + } + c.JSON(http.StatusCreated, created) +} + +// @Summary Mettre a jour un champ personnalise +// @Tags ChampsPersonnalises +// @Accept json +// @Produce json +// @Param id path string true "ID champ" +// @Param body body champPersonnaliseRequest true "Champ personnalise" +// @Success 200 {object} ent.ChampPersonnalise +// @Failure 400 {object} map[string]string +// @Failure 404 {object} map[string]string +// @Failure 500 {object} map[string]string +// @Router /champs_personnalises/{id} [put] +func (h *Handler) UpdateChampPersonnalise(c *gin.Context) { + champID, err := uuid.Parse(c.Param("id")) + if err != nil { + c.JSON(http.StatusBadRequest, gin.H{"erreur": "identifiant invalide"}) + return + } + + var req champPersonnaliseRequest + if err := c.ShouldBindJSON(&req); err != nil { + c.JSON(http.StatusBadRequest, gin.H{"erreur": "donnees invalides"}) + return + } + + update := h.client.ChampPersonnalise.UpdateOneID(champID) + if req.NomChamp != nil { + update.SetNomChamp(*req.NomChamp) + } + if req.TypeChamp != nil { + if *req.TypeChamp != "" { + parsed, ok := parseTypeChamp(*req.TypeChamp) + if !ok { + c.JSON(http.StatusBadRequest, gin.H{"erreur": "type_champ invalide"}) + return + } + update.SetTypeChamp(parsed) + } + } + if req.Valeur != nil { + update.SetNillableValeur(req.Valeur) + } + if req.Unite != nil { + update.SetNillableUnite(req.Unite) + } + + updated, err := update.Save(c.Request.Context()) + if err != nil { + if ent.IsNotFound(err) { + c.JSON(http.StatusNotFound, gin.H{"erreur": "champ introuvable"}) + return + } + c.JSON(http.StatusInternalServerError, gin.H{"erreur": "impossible de mettre a jour le champ"}) + return + } + c.JSON(http.StatusOK, updated) +} + +// @Summary Supprimer un champ personnalise +// @Tags ChampsPersonnalises +// @Param id path string true "ID champ" +// @Success 204 {string} string "No Content" +// @Failure 400 {object} map[string]string +// @Failure 404 {object} map[string]string +// @Failure 500 {object} map[string]string +// @Router /champs_personnalises/{id} [delete] +func (h *Handler) DeleteChampPersonnalise(c *gin.Context) { + champID, err := uuid.Parse(c.Param("id")) + if err != nil { + c.JSON(http.StatusBadRequest, gin.H{"erreur": "identifiant invalide"}) + return + } + + if err := h.client.ChampPersonnalise.DeleteOneID(champID).Exec(c.Request.Context()); err != nil { + if ent.IsNotFound(err) { + c.JSON(http.StatusNotFound, gin.H{"erreur": "champ introuvable"}) + return + } + c.JSON(http.StatusInternalServerError, gin.H{"erreur": "impossible de supprimer le champ"}) + return + } + c.Status(http.StatusNoContent) +} + +func parseTypeChamp(value string) (champpersonnalise.TypeChamp, bool) { + switch value { + case "string": + return champpersonnalise.TypeChampString, true + case "int": + return champpersonnalise.TypeChampInt, true + case "bool": + return champpersonnalise.TypeChampBool, true + case "date": + return champpersonnalise.TypeChampDate, true + default: + return "", false + } +} diff --git a/backend/internal/handlers/emplacements.go b/backend/internal/handlers/emplacements.go new file mode 100644 index 0000000..b9c18aa --- /dev/null +++ b/backend/internal/handlers/emplacements.go @@ -0,0 +1,214 @@ +package handlers + +import ( + "net/http" + + "github.com/gin-gonic/gin" + "github.com/google/uuid" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/emplacement" +) + +type emplacementRequest struct { + Nom *string `json:"nom"` + ParentID *string `json:"parent_id"` + Slug *string `json:"slug"` + Piece *string `json:"piece"` + Meuble *string `json:"meuble"` + NumeroBoite *string `json:"numero_boite"` + Icone *string `json:"icone"` +} + +// @Summary Lister les emplacements +// @Tags Emplacements +// @Produce json +// @Param page query int false "Page" +// @Param limit query int false "Limite" +// @Success 200 {object} map[string]any +// @Failure 500 {object} map[string]string +// @Router /emplacements [get] +func (h *Handler) ListEmplacements(c *gin.Context) { + limit, offset, page := parsePagination(c.Query("page"), c.Query("limit")) + query := h.client.Emplacement.Query() + total, err := query.Count(c.Request.Context()) + if err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"erreur": "impossible de compter les emplacements"}) + return + } + + items, err := query. + Order(ent.Desc(emplacement.FieldCreatedAt)). + Limit(limit). + Offset(offset). + All(c.Request.Context()) + if err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"erreur": "impossible de lister les emplacements"}) + return + } + respondPaginated(c, items, total, page, limit) +} + +// @Summary Creer un emplacement +// @Tags Emplacements +// @Accept json +// @Produce json +// @Param body body emplacementRequest true "Emplacement a creer" +// @Success 201 {object} ent.Emplacement +// @Failure 400 {object} map[string]string +// @Failure 500 {object} map[string]string +// @Router /emplacements [post] +func (h *Handler) CreateEmplacement(c *gin.Context) { + var req emplacementRequest + if err := c.ShouldBindJSON(&req); err != nil { + c.JSON(http.StatusBadRequest, gin.H{"erreur": "donnees invalides"}) + return + } + if req.Nom == nil || *req.Nom == "" { + c.JSON(http.StatusBadRequest, gin.H{"erreur": "le champ nom est obligatoire"}) + return + } + + create := h.client.Emplacement.Create().SetNom(*req.Nom) + if req.ParentID != nil && *req.ParentID != "" { + if parsed, err := uuid.Parse(*req.ParentID); err == nil { + create.SetParentID(parsed) + } + } + if req.Slug != nil { + create.SetNillableSlug(req.Slug) + } + if req.Piece != nil { + create.SetNillablePiece(req.Piece) + } + if req.Meuble != nil { + create.SetNillableMeuble(req.Meuble) + } + if req.NumeroBoite != nil { + create.SetNillableNumeroBoite(req.NumeroBoite) + } + if req.Icone != nil { + create.SetNillableIcone(req.Icone) + } + + created, err := create.Save(c.Request.Context()) + if err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"erreur": "impossible de creer l'emplacement"}) + return + } + c.JSON(http.StatusCreated, created) +} + +// @Summary Recuperer un emplacement +// @Tags Emplacements +// @Produce json +// @Param id path string true "ID emplacement" +// @Success 200 {object} ent.Emplacement +// @Failure 400 {object} map[string]string +// @Failure 404 {object} map[string]string +// @Failure 500 {object} map[string]string +// @Router /emplacements/{id} [get] +func (h *Handler) GetEmplacement(c *gin.Context) { + id, err := uuid.Parse(c.Param("id")) + if err != nil { + c.JSON(http.StatusBadRequest, gin.H{"erreur": "identifiant invalide"}) + return + } + + item, err := h.client.Emplacement.Get(c.Request.Context(), id) + if err != nil { + if ent.IsNotFound(err) { + c.JSON(http.StatusNotFound, gin.H{"erreur": "emplacement introuvable"}) + return + } + c.JSON(http.StatusInternalServerError, gin.H{"erreur": "impossible de charger l'emplacement"}) + return + } + c.JSON(http.StatusOK, item) +} + +// @Summary Mettre a jour un emplacement +// @Tags Emplacements +// @Accept json +// @Produce json +// @Param id path string true "ID emplacement" +// @Param body body emplacementRequest true "Emplacement a mettre a jour" +// @Success 200 {object} ent.Emplacement +// @Failure 400 {object} map[string]string +// @Failure 404 {object} map[string]string +// @Failure 500 {object} map[string]string +// @Router /emplacements/{id} [put] +func (h *Handler) UpdateEmplacement(c *gin.Context) { + id, err := uuid.Parse(c.Param("id")) + if err != nil { + c.JSON(http.StatusBadRequest, gin.H{"erreur": "identifiant invalide"}) + return + } + + var req emplacementRequest + if err := c.ShouldBindJSON(&req); err != nil { + c.JSON(http.StatusBadRequest, gin.H{"erreur": "donnees invalides"}) + return + } + + update := h.client.Emplacement.UpdateOneID(id) + if req.Nom != nil { + update.SetNom(*req.Nom) + } + if req.ParentID != nil { + if *req.ParentID == "" { + update.ClearParentID() + } else if parsed, err := uuid.Parse(*req.ParentID); err == nil { + update.SetParentID(parsed) + } + } + if req.Slug != nil { + update.SetNillableSlug(req.Slug) + } + if req.Piece != nil { + update.SetNillablePiece(req.Piece) + } + if req.Meuble != nil { + update.SetNillableMeuble(req.Meuble) + } + if req.NumeroBoite != nil { + update.SetNillableNumeroBoite(req.NumeroBoite) + } + if req.Icone != nil { + update.SetNillableIcone(req.Icone) + } + + updated, err := update.Save(c.Request.Context()) + if err != nil { + if ent.IsNotFound(err) { + c.JSON(http.StatusNotFound, gin.H{"erreur": "emplacement introuvable"}) + return + } + c.JSON(http.StatusInternalServerError, gin.H{"erreur": "impossible de mettre a jour l'emplacement"}) + return + } + c.JSON(http.StatusOK, updated) +} + +// @Summary Supprimer un emplacement +// @Tags Emplacements +// @Param id path string true "ID emplacement" +// @Success 204 {string} string "No Content" +// @Failure 400 {object} map[string]string +// @Failure 500 {object} map[string]string +// @Router /emplacements/{id} [delete] +func (h *Handler) DeleteEmplacement(c *gin.Context) { + id, err := uuid.Parse(c.Param("id")) + if err != nil { + c.JSON(http.StatusBadRequest, gin.H{"erreur": "identifiant invalide"}) + return + } + + if err := h.client.Emplacement.DeleteOneID(id).Exec(c.Request.Context()); err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"erreur": "impossible de supprimer l'emplacement"}) + return + } + c.Status(http.StatusNoContent) +} + +// helper for compile reference +var _ = ent.IsNotFound diff --git a/backend/internal/handlers/handler.go b/backend/internal/handlers/handler.go new file mode 100644 index 0000000..c7bd0ef --- /dev/null +++ b/backend/internal/handlers/handler.go @@ -0,0 +1,8 @@ +package handlers + +import "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent" + +// Handler regroupe les dependances pour les handlers. +type Handler struct { + client *ent.Client +} diff --git a/backend/internal/handlers/helpers.go b/backend/internal/handlers/helpers.go new file mode 100644 index 0000000..8f9b3d3 --- /dev/null +++ b/backend/internal/handlers/helpers.go @@ -0,0 +1,108 @@ +package handlers + +import ( + "os" + "strconv" + "strings" + "time" + + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/objet" +) + +// parseDateTime parse une date ISO-8601. +func parseDateTime(value string) (time.Time, error) { + return time.Parse(time.RFC3339, value) +} + +// resolveCategorie determine la categorie d'une piece jointe. +func resolveCategorie(ext string, mime string) string { + ext = strings.ToLower(ext) + mime = strings.ToLower(mime) + if ext == ".md" || mime == "text/markdown" { + return "markdown_tuto" + } + if mime == "application/pdf" || ext == ".pdf" { + return "pdf_notice" + } + if strings.HasPrefix(mime, "image/") { + return "image" + } + return "image" +} + +// maxUploadBytes retourne la taille max d'un fichier en octets. +func maxUploadBytes() int64 { + const defaultMB = 50 + value := os.Getenv("MAX_UPLOAD_MB") + if value == "" { + return defaultMB * 1024 * 1024 + } + parsed, err := strconv.Atoi(value) + if err != nil || parsed <= 0 { + return defaultMB * 1024 * 1024 + } + return int64(parsed) * 1024 * 1024 +} + +// parsePagination calcule la limite et l'offset a partir des params page/limit. +func parsePagination(pageValue string, limitValue string) (int, int, int) { + const ( + defaultLimit = 50 + maxLimit = 200 + ) + + page := 1 + if pageValue != "" { + if parsed, err := strconv.Atoi(pageValue); err == nil && parsed > 0 { + page = parsed + } + } + + limit := defaultLimit + if limitValue != "" { + if parsed, err := strconv.Atoi(limitValue); err == nil && parsed > 0 { + limit = parsed + } + } + if limit > maxLimit { + limit = maxLimit + } + + offset := (page - 1) * limit + return limit, offset, page +} + +// isAllowedUpload valide le type de fichier (images, PDF, Markdown). +func isAllowedUpload(mime string, ext string) bool { + mime = strings.ToLower(mime) + ext = strings.ToLower(ext) + if strings.HasPrefix(mime, "image/") { + return true + } + if mime == "application/pdf" || ext == ".pdf" { + return true + } + if mime == "text/markdown" || ext == ".md" || ext == ".markdown" { + return true + } + if mime == "text/plain" && (ext == ".md" || ext == ".markdown") { + return true + } + return false +} + +// parseStatut convertit un statut texte vers l'enum Ent. +func parseStatut(value string) (objet.Statut, bool) { + switch value { + case "en_stock": + return objet.StatutEnStock, true + case "pret": + return objet.StatutPret, true + case "hors_service": + return objet.StatutHorsService, true + case "archive": + return objet.StatutArchive, true + default: + return "", false + } +} diff --git a/backend/internal/handlers/helpers_test.go b/backend/internal/handlers/helpers_test.go new file mode 100644 index 0000000..5aec868 --- /dev/null +++ b/backend/internal/handlers/helpers_test.go @@ -0,0 +1,74 @@ +package handlers + +import "testing" + +func TestIsAllowedUpload(t *testing.T) { + cases := []struct { + name string + mime string + ext string + want bool + }{ + {"image", "image/png", ".png", true}, + {"pdf", "application/pdf", ".pdf", true}, + {"md", "text/markdown", ".md", true}, + {"md_plain", "text/plain", ".md", true}, + {"other", "application/zip", ".zip", false}, + } + + for _, c := range cases { + t.Run(c.name, func(t *testing.T) { + if got := isAllowedUpload(c.mime, c.ext); got != c.want { + t.Fatalf("attendu %v, obtenu %v", c.want, got) + } + }) + } +} + +func TestMaxUploadBytes(t *testing.T) { + t.Setenv("MAX_UPLOAD_MB", "1") + if got := maxUploadBytes(); got != 1*1024*1024 { + t.Fatalf("taille inattendue: %d", got) + } + + t.Setenv("MAX_UPLOAD_MB", "0") + if got := maxUploadBytes(); got != 50*1024*1024 { + t.Fatalf("taille par defaut inattendue: %d", got) + } +} + +func TestParseTypeChamp(t *testing.T) { + valid := []string{"string", "int", "bool", "date"} + for _, v := range valid { + if _, ok := parseTypeChamp(v); !ok { + t.Fatalf("type_champ invalide: %s", v) + } + } + if _, ok := parseTypeChamp("x"); ok { + t.Fatal("type_champ devrait etre invalide") + } +} + +func TestParseLienType(t *testing.T) { + valid := []string{"stocke", "utilise_dans"} + for _, v := range valid { + if _, ok := parseLienType(v); !ok { + t.Fatalf("type lien invalide: %s", v) + } + } + if _, ok := parseLienType("x"); ok { + t.Fatal("type lien devrait etre invalide") + } +} + +func TestParseStatut(t *testing.T) { + valid := []string{"en_stock", "pret", "hors_service", "archive"} + for _, v := range valid { + if _, ok := parseStatut(v); !ok { + t.Fatalf("statut invalide: %s", v) + } + } + if _, ok := parseStatut("x"); ok { + t.Fatal("statut devrait etre invalide") + } +} diff --git a/backend/internal/handlers/liens_objet_emplacement.go b/backend/internal/handlers/liens_objet_emplacement.go new file mode 100644 index 0000000..531cc59 --- /dev/null +++ b/backend/internal/handlers/liens_objet_emplacement.go @@ -0,0 +1,269 @@ +package handlers + +import ( + "net/http" + + "github.com/gin-gonic/gin" + "github.com/google/uuid" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/lienobjetemplacement" +) + +type lienObjetEmplacementRequest struct { + EmplacementID *string `json:"emplacement_id"` + Type *string `json:"type"` +} + +type lienObjetEmplacementUpdateRequest struct { + EmplacementID *string `json:"emplacement_id"` + Type *string `json:"type"` +} + +// @Summary Lister les liens objet/emplacement +// @Tags LiensEmplacements +// @Produce json +// @Param id path string true "ID objet" +// @Param page query int false "Page" +// @Param limit query int false "Limite" +// @Success 200 {object} map[string]any +// @Failure 400 {object} map[string]string +// @Failure 500 {object} map[string]string +// @Router /objets/{id}/liens_emplacements [get] +func (h *Handler) ListLiensEmplacements(c *gin.Context) { + objetID, err := uuid.Parse(c.Param("id")) + if err != nil { + c.JSON(http.StatusBadRequest, gin.H{"erreur": "identifiant invalide"}) + return + } + + limit, offset, page := parsePagination(c.Query("page"), c.Query("limit")) + query := h.client.LienObjetEmplacement.Query(). + Where(lienobjetemplacement.ObjetID(objetID)) + total, err := query.Count(c.Request.Context()) + if err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"erreur": "impossible de compter les liens"}) + return + } + + items, err := query. + Order(ent.Desc(lienobjetemplacement.FieldCreatedAt)). + Limit(limit). + Offset(offset). + All(c.Request.Context()) + if err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"erreur": "impossible de lister les liens"}) + return + } + respondPaginated(c, items, total, page, limit) +} + +// @Summary Creer un lien objet/emplacement +// @Tags LiensEmplacements +// @Accept json +// @Produce json +// @Param id path string true "ID objet" +// @Param body body lienObjetEmplacementRequest true "Lien" +// @Success 201 {object} ent.LienObjetEmplacement +// @Failure 400 {object} map[string]string +// @Failure 404 {object} map[string]string +// @Failure 409 {object} map[string]string +// @Failure 500 {object} map[string]string +// @Router /objets/{id}/liens_emplacements [post] +func (h *Handler) CreateLienEmplacement(c *gin.Context) { + objetID, err := uuid.Parse(c.Param("id")) + if err != nil { + c.JSON(http.StatusBadRequest, gin.H{"erreur": "identifiant invalide"}) + return + } + + var req lienObjetEmplacementRequest + if err := c.ShouldBindJSON(&req); err != nil { + c.JSON(http.StatusBadRequest, gin.H{"erreur": "donnees invalides"}) + return + } + if req.EmplacementID == nil || *req.EmplacementID == "" { + c.JSON(http.StatusBadRequest, gin.H{"erreur": "emplacement_id obligatoire"}) + return + } + + emplacementID, err := uuid.Parse(*req.EmplacementID) + if err != nil { + c.JSON(http.StatusBadRequest, gin.H{"erreur": "emplacement_id invalide"}) + return + } + + if _, err := h.client.Emplacement.Get(c.Request.Context(), emplacementID); err != nil { + if ent.IsNotFound(err) { + c.JSON(http.StatusNotFound, gin.H{"erreur": "emplacement introuvable"}) + return + } + c.JSON(http.StatusInternalServerError, gin.H{"erreur": "impossible de charger l'emplacement"}) + return + } + + create := h.client.LienObjetEmplacement.Create(). + SetObjetID(objetID). + SetEmplacementID(emplacementID) + + typeValeur := lienobjetemplacement.TypeStocke + if req.Type != nil && *req.Type != "" { + parsed, ok := parseLienType(*req.Type) + if !ok { + c.JSON(http.StatusBadRequest, gin.H{"erreur": "type invalide"}) + return + } + typeValeur = parsed + } + create.SetType(typeValeur) + + exists, err := h.client.LienObjetEmplacement.Query(). + Where( + lienobjetemplacement.ObjetID(objetID), + lienobjetemplacement.EmplacementID(emplacementID), + lienobjetemplacement.TypeEQ(typeValeur), + ). + Exist(c.Request.Context()) + if err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"erreur": "impossible de verifier le lien"}) + return + } + if exists { + c.JSON(http.StatusConflict, gin.H{"erreur": "lien deja existant"}) + return + } + + created, err := create.Save(c.Request.Context()) + if err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"erreur": "impossible de creer le lien"}) + return + } + c.JSON(http.StatusCreated, created) +} + +// @Summary Supprimer un lien objet/emplacement +// @Tags LiensEmplacements +// @Param id path string true "ID lien" +// @Success 204 {string} string "No Content" +// @Failure 400 {object} map[string]string +// @Failure 404 {object} map[string]string +// @Failure 500 {object} map[string]string +// @Router /liens_emplacements/{id} [delete] +func (h *Handler) DeleteLienEmplacement(c *gin.Context) { + lienID, err := uuid.Parse(c.Param("id")) + if err != nil { + c.JSON(http.StatusBadRequest, gin.H{"erreur": "identifiant invalide"}) + return + } + + if err := h.client.LienObjetEmplacement.DeleteOneID(lienID).Exec(c.Request.Context()); err != nil { + if ent.IsNotFound(err) { + c.JSON(http.StatusNotFound, gin.H{"erreur": "lien introuvable"}) + return + } + c.JSON(http.StatusInternalServerError, gin.H{"erreur": "impossible de supprimer le lien"}) + return + } + c.Status(http.StatusNoContent) +} + +// @Summary Mettre a jour un lien objet/emplacement +// @Tags LiensEmplacements +// @Accept json +// @Produce json +// @Param id path string true "ID lien" +// @Param body body lienObjetEmplacementUpdateRequest true "Mise a jour" +// @Success 200 {object} ent.LienObjetEmplacement +// @Failure 400 {object} map[string]string +// @Failure 404 {object} map[string]string +// @Failure 409 {object} map[string]string +// @Failure 500 {object} map[string]string +// @Router /liens_emplacements/{id} [put] +func (h *Handler) UpdateLienEmplacement(c *gin.Context) { + lienID, err := uuid.Parse(c.Param("id")) + if err != nil { + c.JSON(http.StatusBadRequest, gin.H{"erreur": "identifiant invalide"}) + return + } + + var req lienObjetEmplacementUpdateRequest + if err := c.ShouldBindJSON(&req); err != nil { + c.JSON(http.StatusBadRequest, gin.H{"erreur": "donnees invalides"}) + return + } + + existant, err := h.client.LienObjetEmplacement.Get(c.Request.Context(), lienID) + if err != nil { + if ent.IsNotFound(err) { + c.JSON(http.StatusNotFound, gin.H{"erreur": "lien introuvable"}) + return + } + c.JSON(http.StatusInternalServerError, gin.H{"erreur": "impossible de charger le lien"}) + return + } + + nouveauEmplacementID := existant.EmplacementID + if req.EmplacementID != nil && *req.EmplacementID != "" { + parsed, err := uuid.Parse(*req.EmplacementID) + if err != nil { + c.JSON(http.StatusBadRequest, gin.H{"erreur": "emplacement_id invalide"}) + return + } + if _, err := h.client.Emplacement.Get(c.Request.Context(), parsed); err != nil { + if ent.IsNotFound(err) { + c.JSON(http.StatusNotFound, gin.H{"erreur": "emplacement introuvable"}) + return + } + c.JSON(http.StatusInternalServerError, gin.H{"erreur": "impossible de charger l'emplacement"}) + return + } + nouveauEmplacementID = parsed + } + + nouveauType := existant.Type + if req.Type != nil && *req.Type != "" { + parsed, ok := parseLienType(*req.Type) + if !ok { + c.JSON(http.StatusBadRequest, gin.H{"erreur": "type invalide"}) + return + } + nouveauType = parsed + } + + dupe, err := h.client.LienObjetEmplacement.Query(). + Where( + lienobjetemplacement.ObjetID(existant.ObjetID), + lienobjetemplacement.EmplacementID(nouveauEmplacementID), + lienobjetemplacement.TypeEQ(nouveauType), + lienobjetemplacement.IDNEQ(lienID), + ). + Exist(c.Request.Context()) + if err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"erreur": "impossible de verifier le lien"}) + return + } + if dupe { + c.JSON(http.StatusConflict, gin.H{"erreur": "lien deja existant"}) + return + } + + updated, err := h.client.LienObjetEmplacement.UpdateOneID(lienID). + SetEmplacementID(nouveauEmplacementID). + SetType(nouveauType). + Save(c.Request.Context()) + if err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"erreur": "impossible de mettre a jour le lien"}) + return + } + c.JSON(http.StatusOK, updated) +} + +func parseLienType(value string) (lienobjetemplacement.Type, bool) { + switch value { + case "stocke": + return lienobjetemplacement.TypeStocke, true + case "utilise_dans": + return lienobjetemplacement.TypeUtiliseDans, true + default: + return "", false + } +} diff --git a/backend/internal/handlers/objets.go b/backend/internal/handlers/objets.go new file mode 100644 index 0000000..c37dcf4 --- /dev/null +++ b/backend/internal/handlers/objets.go @@ -0,0 +1,267 @@ +package handlers + +import ( + "net/http" + + "github.com/gin-gonic/gin" + "github.com/google/uuid" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/objet" +) + +type objetRequest struct { + Nom *string `json:"nom"` + Description *string `json:"description"` + Quantite *int `json:"quantite"` + PrixAchat *float64 `json:"prix_achat"` + DateAchat *string `json:"date_achat"` + Boutique *string `json:"boutique"` + NumeroSerie *string `json:"numero_serie"` + NumeroModele *string `json:"numero_modele"` + Fabricant *string `json:"fabricant"` + Statut *string `json:"statut"` + Caracteristiques map[string]any `json:"caracteristiques"` +} + +// @Summary Lister les objets +// @Tags Objets +// @Produce json +// @Param page query int false "Page" +// @Param limit query int false "Limite" +// @Param statut query string false "Statut" +// @Param nom query string false "Recherche nom" +// @Success 200 {object} map[string]any +// @Failure 500 {object} map[string]string +// @Router /objets [get] +func (h *Handler) ListObjets(c *gin.Context) { + ctx := c.Request.Context() + limit, offset, page := parsePagination(c.Query("page"), c.Query("limit")) + query := h.client.Objet.Query() + + if statutValue := c.Query("statut"); statutValue != "" { + statut, ok := parseStatut(statutValue) + if !ok { + c.JSON(http.StatusBadRequest, gin.H{"erreur": "statut invalide"}) + return + } + query = query.Where(objet.StatutEQ(statut)) + } + if nomValue := c.Query("nom"); nomValue != "" { + query = query.Where(objet.NomContainsFold(nomValue)) + } + total, err := query.Count(ctx) + if err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"erreur": "impossible de compter les objets"}) + return + } + + objets, err := query. + Order(ent.Desc(objet.FieldCreatedAt)). + Limit(limit). + Offset(offset). + All(ctx) + if err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"erreur": "impossible de lister les objets"}) + return + } + respondPaginated(c, objets, total, page, limit) +} + +// @Summary Creer un objet +// @Tags Objets +// @Accept json +// @Produce json +// @Param body body objetRequest true "Objet a creer" +// @Success 201 {object} ent.Objet +// @Failure 400 {object} map[string]string +// @Failure 500 {object} map[string]string +// @Router /objets [post] +func (h *Handler) CreateObjet(c *gin.Context) { + var req objetRequest + if err := c.ShouldBindJSON(&req); err != nil { + c.JSON(http.StatusBadRequest, gin.H{"erreur": "donnees invalides"}) + return + } + if req.Nom == nil || *req.Nom == "" { + c.JSON(http.StatusBadRequest, gin.H{"erreur": "le champ nom est obligatoire"}) + return + } + + create := h.client.Objet.Create().SetNom(*req.Nom) + + if req.Description != nil { + create.SetNillableDescription(req.Description) + } + if req.Quantite != nil { + create.SetQuantite(*req.Quantite) + } + if req.PrixAchat != nil { + create.SetNillablePrixAchat(req.PrixAchat) + } + if req.DateAchat != nil { + if parsed, err := parseDateTime(*req.DateAchat); err == nil { + create.SetNillableDateAchat(&parsed) + } + } + if req.Boutique != nil { + create.SetNillableBoutique(req.Boutique) + } + if req.NumeroSerie != nil { + create.SetNillableNumeroSerie(req.NumeroSerie) + } + if req.NumeroModele != nil { + create.SetNillableNumeroModele(req.NumeroModele) + } + if req.Fabricant != nil { + create.SetNillableFabricant(req.Fabricant) + } + if req.Statut != nil { + parsed, ok := parseStatut(*req.Statut) + if !ok { + c.JSON(http.StatusBadRequest, gin.H{"erreur": "statut invalide"}) + return + } + create.SetStatut(parsed) + } + if req.Caracteristiques != nil { + create.SetCaracteristiques(req.Caracteristiques) + } + + created, err := create.Save(c.Request.Context()) + if err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"erreur": "impossible de creer l'objet"}) + return + } + c.JSON(http.StatusCreated, created) +} + +// @Summary Recuperer un objet +// @Tags Objets +// @Produce json +// @Param id path string true "ID objet" +// @Success 200 {object} ent.Objet +// @Failure 400 {object} map[string]string +// @Failure 404 {object} map[string]string +// @Failure 500 {object} map[string]string +// @Router /objets/{id} [get] +func (h *Handler) GetObjet(c *gin.Context) { + id, err := uuid.Parse(c.Param("id")) + if err != nil { + c.JSON(http.StatusBadRequest, gin.H{"erreur": "identifiant invalide"}) + return + } + + item, err := h.client.Objet.Get(c.Request.Context(), id) + if err != nil { + if ent.IsNotFound(err) { + c.JSON(http.StatusNotFound, gin.H{"erreur": "objet introuvable"}) + return + } + c.JSON(http.StatusInternalServerError, gin.H{"erreur": "impossible de charger l'objet"}) + return + } + c.JSON(http.StatusOK, item) +} + +// @Summary Mettre a jour un objet +// @Tags Objets +// @Accept json +// @Produce json +// @Param id path string true "ID objet" +// @Param body body objetRequest true "Objet a mettre a jour" +// @Success 200 {object} ent.Objet +// @Failure 400 {object} map[string]string +// @Failure 404 {object} map[string]string +// @Failure 500 {object} map[string]string +// @Router /objets/{id} [put] +func (h *Handler) UpdateObjet(c *gin.Context) { + id, err := uuid.Parse(c.Param("id")) + if err != nil { + c.JSON(http.StatusBadRequest, gin.H{"erreur": "identifiant invalide"}) + return + } + + var req objetRequest + if err := c.ShouldBindJSON(&req); err != nil { + c.JSON(http.StatusBadRequest, gin.H{"erreur": "donnees invalides"}) + return + } + + update := h.client.Objet.UpdateOneID(id) + + if req.Nom != nil { + update.SetNom(*req.Nom) + } + if req.Description != nil { + update.SetNillableDescription(req.Description) + } + if req.Quantite != nil { + update.SetQuantite(*req.Quantite) + } + if req.PrixAchat != nil { + update.SetNillablePrixAchat(req.PrixAchat) + } + if req.DateAchat != nil { + if parsed, err := parseDateTime(*req.DateAchat); err == nil { + update.SetNillableDateAchat(&parsed) + } + } + if req.Boutique != nil { + update.SetNillableBoutique(req.Boutique) + } + if req.NumeroSerie != nil { + update.SetNillableNumeroSerie(req.NumeroSerie) + } + if req.NumeroModele != nil { + update.SetNillableNumeroModele(req.NumeroModele) + } + if req.Fabricant != nil { + update.SetNillableFabricant(req.Fabricant) + } + if req.Statut != nil { + parsed, ok := parseStatut(*req.Statut) + if !ok { + c.JSON(http.StatusBadRequest, gin.H{"erreur": "statut invalide"}) + return + } + update.SetStatut(parsed) + } + if req.Caracteristiques != nil { + update.SetCaracteristiques(req.Caracteristiques) + } + + updated, err := update.Save(c.Request.Context()) + if err != nil { + if ent.IsNotFound(err) { + c.JSON(http.StatusNotFound, gin.H{"erreur": "objet introuvable"}) + return + } + c.JSON(http.StatusInternalServerError, gin.H{"erreur": "impossible de mettre a jour l'objet"}) + return + } + c.JSON(http.StatusOK, updated) +} + +// @Summary Supprimer un objet +// @Tags Objets +// @Param id path string true "ID objet" +// @Success 204 {string} string "No Content" +// @Failure 400 {object} map[string]string +// @Failure 500 {object} map[string]string +// @Router /objets/{id} [delete] +func (h *Handler) DeleteObjet(c *gin.Context) { + id, err := uuid.Parse(c.Param("id")) + if err != nil { + c.JSON(http.StatusBadRequest, gin.H{"erreur": "identifiant invalide"}) + return + } + + if err := h.client.Objet.DeleteOneID(id).Exec(c.Request.Context()); err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"erreur": "impossible de supprimer l'objet"}) + return + } + c.Status(http.StatusNoContent) +} + +// helper for compile reference +var _ = ent.IsNotFound diff --git a/backend/internal/handlers/pagination.go b/backend/internal/handlers/pagination.go new file mode 100644 index 0000000..22ef16e --- /dev/null +++ b/backend/internal/handlers/pagination.go @@ -0,0 +1,25 @@ +package handlers + +import ( + "net/http" + + "github.com/gin-gonic/gin" +) + +type paginatedResponse struct { + Items any `json:"items"` + Meta struct { + Total int `json:"total"` + Page int `json:"page"` + Limit int `json:"limit"` + } `json:"meta"` +} + +func respondPaginated(c *gin.Context, items any, total int, page int, limit int) { + var resp paginatedResponse + resp.Items = items + resp.Meta.Total = total + resp.Meta.Page = page + resp.Meta.Limit = limit + c.JSON(http.StatusOK, resp) +} diff --git a/backend/internal/handlers/pieces_jointes.go b/backend/internal/handlers/pieces_jointes.go new file mode 100644 index 0000000..7db16d8 --- /dev/null +++ b/backend/internal/handlers/pieces_jointes.go @@ -0,0 +1,275 @@ +package handlers + +import ( + "errors" + "net/http" + "os" + "path/filepath" + "strings" + + "github.com/gin-gonic/gin" + "github.com/google/uuid" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/piecejointe" +) + +// UploadPiecesJointes gere l'upload multiple des fichiers d'un objet. +// @Summary Uploader des pieces jointes +// @Tags PiecesJointes +// @Accept multipart/form-data +// @Produce json +// @Param id path string true "ID objet" +// @Param fichiers formData file true "Fichiers (multi)" +// @Success 201 {object} map[string]any +// @Failure 400 {object} map[string]string +// @Failure 404 {object} map[string]string +// @Failure 413 {object} map[string]string +// @Failure 500 {object} map[string]string +// @Router /objets/{id}/pieces_jointes [post] +func (h *Handler) UploadPiecesJointes(c *gin.Context) { + id, err := uuid.Parse(c.Param("id")) + if err != nil { + c.JSON(http.StatusBadRequest, gin.H{"erreur": "identifiant invalide"}) + return + } + + if _, err := h.client.Objet.Get(c.Request.Context(), id); err != nil { + if ent.IsNotFound(err) { + c.JSON(http.StatusNotFound, gin.H{"erreur": "objet introuvable"}) + return + } + c.JSON(http.StatusInternalServerError, gin.H{"erreur": "impossible de charger l'objet"}) + return + } + + form, err := c.MultipartForm() + if err != nil { + c.JSON(http.StatusBadRequest, gin.H{"erreur": "formulaire invalide"}) + return + } + + files := form.File["fichiers"] + if len(files) == 0 { + c.JSON(http.StatusBadRequest, gin.H{"erreur": "aucun fichier fourni"}) + return + } + + maxBytes := maxUploadBytes() + + hasPrincipale, err := h.client.PieceJointe.Query(). + Where( + piecejointe.ObjetID(id), + piecejointe.EstPrincipale(true), + ). + Exist(c.Request.Context()) + if err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"erreur": "impossible de verifier la piece jointe principale"}) + return + } + + baseDir := os.Getenv("ATTACHMENTS_DIR") + if baseDir == "" { + baseDir = "./data/pieces_jointes" + } + if err := os.MkdirAll(baseDir, 0o755); err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"erreur": "impossible de creer le dossier de stockage"}) + return + } + + var saved []map[string]any + for idx, file := range files { + ext := strings.ToLower(filepath.Ext(file.Filename)) + if file.Size > maxBytes { + c.JSON(http.StatusRequestEntityTooLarge, gin.H{"erreur": "fichier trop volumineux"}) + return + } + + mime := file.Header.Get("Content-Type") + if !isAllowedUpload(mime, ext) { + c.JSON(http.StatusBadRequest, gin.H{"erreur": "type de fichier non supporte"}) + return + } + + uuidName := uuid.New().String() + ext + path := filepath.Join(baseDir, uuidName) + + if err := c.SaveUploadedFile(file, path); err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"erreur": "echec enregistrement fichier"}) + return + } + + categorie := resolveCategorie(ext, mime) + estPrincipale := idx == 0 && !hasPrincipale + + pj, err := h.client.PieceJointe.Create(). + SetObjetID(id). + SetNomFichier(file.Filename). + SetChemin(path). + SetTypeMime(mime). + SetCategorie(piecejointe.Categorie(categorie)). + SetEstPrincipale(estPrincipale). + Save(c.Request.Context()) + if err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"erreur": "impossible d'enregistrer la piece jointe"}) + return + } + + saved = append(saved, map[string]any{ + "id": pj.ID, + "nom_fichier": pj.NomFichier, + "chemin": pj.Chemin, + "type_mime": pj.TypeMime, + "categorie": pj.Categorie, + "est_principale": pj.EstPrincipale, + }) + } + + c.JSON(http.StatusCreated, gin.H{"pieces_jointes": saved}) +} + +// ListPiecesJointes retourne la liste des pieces jointes d'un objet. +// @Summary Lister les pieces jointes +// @Tags PiecesJointes +// @Produce json +// @Param id path string true "ID objet" +// @Param page query int false "Page" +// @Param limit query int false "Limite" +// @Success 200 {object} map[string]any +// @Failure 400 {object} map[string]string +// @Failure 500 {object} map[string]string +// @Router /objets/{id}/pieces_jointes [get] +func (h *Handler) ListPiecesJointes(c *gin.Context) { + objetID, err := uuid.Parse(c.Param("id")) + if err != nil { + c.JSON(http.StatusBadRequest, gin.H{"erreur": "identifiant invalide"}) + return + } + + limit, offset, page := parsePagination(c.Query("page"), c.Query("limit")) + query := h.client.PieceJointe.Query(). + Where(piecejointe.ObjetID(objetID)) + total, err := query.Count(c.Request.Context()) + if err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"erreur": "impossible de compter les pieces jointes"}) + return + } + + items, err := query. + Order(ent.Desc(piecejointe.FieldCreatedAt)). + Limit(limit). + Offset(offset). + All(c.Request.Context()) + if err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"erreur": "impossible de lister les pieces jointes"}) + return + } + respondPaginated(c, items, total, page, limit) +} + +// DeletePieceJointe supprime une piece jointe et son fichier. +// @Summary Supprimer une piece jointe +// @Tags PiecesJointes +// @Param id path string true "ID piece jointe" +// @Success 204 {string} string "No Content" +// @Failure 400 {object} map[string]string +// @Failure 404 {object} map[string]string +// @Failure 500 {object} map[string]string +// @Router /pieces_jointes/{id} [delete] +func (h *Handler) DeletePieceJointe(c *gin.Context) { + pieceID, err := uuid.Parse(c.Param("id")) + if err != nil { + c.JSON(http.StatusBadRequest, gin.H{"erreur": "identifiant invalide"}) + return + } + + item, err := h.client.PieceJointe.Get(c.Request.Context(), pieceID) + if err != nil { + if ent.IsNotFound(err) { + c.JSON(http.StatusNotFound, gin.H{"erreur": "piece jointe introuvable"}) + return + } + c.JSON(http.StatusInternalServerError, gin.H{"erreur": "impossible de charger la piece jointe"}) + return + } + + if item.Chemin != "" { + if err := os.Remove(item.Chemin); err != nil && !errors.Is(err, os.ErrNotExist) { + c.JSON(http.StatusInternalServerError, gin.H{"erreur": "impossible de supprimer le fichier"}) + return + } + } + + if err := h.client.PieceJointe.DeleteOneID(pieceID).Exec(c.Request.Context()); err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"erreur": "impossible de supprimer la piece jointe"}) + return + } + c.Status(http.StatusNoContent) +} + +// SetPieceJointePrincipale marque une piece jointe comme principale. +// @Summary Definir la piece jointe principale +// @Tags PiecesJointes +// @Produce json +// @Param id path string true "ID piece jointe" +// @Success 200 {object} ent.PieceJointe +// @Failure 400 {object} map[string]string +// @Failure 404 {object} map[string]string +// @Failure 500 {object} map[string]string +// @Router /pieces_jointes/{id}/principale [put] +func (h *Handler) SetPieceJointePrincipale(c *gin.Context) { + pieceID, err := uuid.Parse(c.Param("id")) + if err != nil { + c.JSON(http.StatusBadRequest, gin.H{"erreur": "identifiant invalide"}) + return + } + + item, err := h.client.PieceJointe.Get(c.Request.Context(), pieceID) + if err != nil { + if ent.IsNotFound(err) { + c.JSON(http.StatusNotFound, gin.H{"erreur": "piece jointe introuvable"}) + return + } + c.JSON(http.StatusInternalServerError, gin.H{"erreur": "impossible de charger la piece jointe"}) + return + } + + tx, err := h.client.Tx(c.Request.Context()) + if err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"erreur": "impossible d'ouvrir la transaction"}) + return + } + defer func() { + if err != nil { + _ = tx.Rollback() + } + }() + + if _, err = tx.PieceJointe.Update(). + Where(piecejointe.ObjetID(item.ObjetID)). + SetEstPrincipale(false). + Save(c.Request.Context()); err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"erreur": "impossible de reinitialiser la principale"}) + _ = tx.Rollback() + return + } + + if _, err = tx.PieceJointe.UpdateOneID(pieceID). + SetEstPrincipale(true). + Save(c.Request.Context()); err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"erreur": "impossible de definir la principale"}) + _ = tx.Rollback() + return + } + + if err = tx.Commit(); err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"erreur": "impossible de finaliser la transaction"}) + return + } + + updated, err := h.client.PieceJointe.Get(c.Request.Context(), pieceID) + if err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"erreur": "impossible de charger la piece jointe"}) + return + } + c.JSON(http.StatusOK, updated) +} diff --git a/backend/internal/handlers/router.go b/backend/internal/handlers/router.go new file mode 100644 index 0000000..3439545 --- /dev/null +++ b/backend/internal/handlers/router.go @@ -0,0 +1,44 @@ +package handlers + +import ( + "github.com/gin-gonic/gin" + "gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent" +) + +// RegisterRoutes enregistre les routes v1. +func RegisterRoutes(r *gin.Engine, client *ent.Client) { + h := &Handler{client: client} + + v1 := r.Group("/v1") + { + v1.GET("/objets", h.ListObjets) + v1.POST("/objets", h.CreateObjet) + v1.GET("/objets/:id", h.GetObjet) + v1.PUT("/objets/:id", h.UpdateObjet) + v1.DELETE("/objets/:id", h.DeleteObjet) + v1.POST("/objets/:id/pieces_jointes", h.UploadPiecesJointes) + v1.GET("/objets/:id/pieces_jointes", h.ListPiecesJointes) + v1.DELETE("/pieces_jointes/:id", h.DeletePieceJointe) + v1.PUT("/pieces_jointes/:id/principale", h.SetPieceJointePrincipale) + v1.GET("/objets/:id/champs_personnalises", h.ListChampsPersonnalises) + v1.POST("/objets/:id/champs_personnalises", h.CreateChampPersonnalise) + v1.PUT("/champs_personnalises/:id", h.UpdateChampPersonnalise) + v1.DELETE("/champs_personnalises/:id", h.DeleteChampPersonnalise) + v1.GET("/objets/:id/liens_emplacements", h.ListLiensEmplacements) + v1.POST("/objets/:id/liens_emplacements", h.CreateLienEmplacement) + v1.PUT("/liens_emplacements/:id", h.UpdateLienEmplacement) + v1.DELETE("/liens_emplacements/:id", h.DeleteLienEmplacement) + + v1.GET("/categories", h.ListCategories) + v1.POST("/categories", h.CreateCategorie) + v1.GET("/categories/:id", h.GetCategorie) + v1.PUT("/categories/:id", h.UpdateCategorie) + v1.DELETE("/categories/:id", h.DeleteCategorie) + + v1.GET("/emplacements", h.ListEmplacements) + v1.POST("/emplacements", h.CreateEmplacement) + v1.GET("/emplacements/:id", h.GetEmplacement) + v1.PUT("/emplacements/:id", h.UpdateEmplacement) + v1.DELETE("/emplacements/:id", h.DeleteEmplacement) + } +} diff --git a/backend/scripts/gen_swagger.sh b/backend/scripts/gen_swagger.sh new file mode 100644 index 0000000..e43c46e --- /dev/null +++ b/backend/scripts/gen_swagger.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +ROOT_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)" + +SWAG_BIN="${SWAG_BIN:-/tmp/go/bin/swag}" +if [ ! -x "${SWAG_BIN}" ]; then + echo "swag introuvable: ${SWAG_BIN}" >&2 + exit 1 +fi + +cd "${ROOT_DIR}" +"${SWAG_BIN}" init -g cmd/app/main.go -o docs diff --git a/doc_dev/08_etape3_migrations.md b/doc_dev/08_etape3_migrations.md new file mode 100644 index 0000000..17f3e7c --- /dev/null +++ b/doc_dev/08_etape3_migrations.md @@ -0,0 +1,12 @@ +# Etape 3 - Migrations initiales + +## Objectif +Ajouter une migration SQL initiale pour SQLite selon les schemas Ent. + +## Fichiers ajoutes +- `migrations/0001_init.sql` + +## Notes +- Ent generate non execute (commande `go` indisponible dans l'environnement). +- A relancer une fois Go installe : + `go run -mod=mod entgo.io/ent/cmd/ent generate ./internal/data/ent/schema --target ./internal/data/ent` diff --git a/doc_dev/09_etape4_handlers.md b/doc_dev/09_etape4_handlers.md new file mode 100644 index 0000000..cd76c52 --- /dev/null +++ b/doc_dev/09_etape4_handlers.md @@ -0,0 +1,17 @@ +# Etape 4 - Handlers CRUD (base) + +## Objectif +Ajouter les handlers CRUD pour Objets, Categories, Emplacements. + +## Fichiers ajoutes +- `backend/internal/handlers/handler.go` +- `backend/internal/handlers/router.go` +- `backend/internal/handlers/helpers.go` +- `backend/internal/handlers/objets.go` +- `backend/internal/handlers/categories.go` +- `backend/internal/handlers/emplacements.go` + +## Notes +- Routes REST sous `/v1`. +- Validation minimale (nom obligatoire, UUID). +- Parsing des dates au format RFC3339. diff --git a/doc_dev/10_etape5_upload.md b/doc_dev/10_etape5_upload.md new file mode 100644 index 0000000..d0c1880 --- /dev/null +++ b/doc_dev/10_etape5_upload.md @@ -0,0 +1,18 @@ +# Etape 5 - Upload pieces jointes + +## Objectif +Ajouter l'endpoint d'upload multiple pour les pieces jointes des objets. + +## Endpoint +- `POST /v1/objets/:id/pieces_jointes` +- Champ multipart : `fichiers` + +## Comportement +- Verifie l'existence de l'objet. +- Enregistre les fichiers dans `ATTACHMENTS_DIR` (defaut `./data/pieces_jointes`). +- Cree les entrees `PieceJointe` associees. +- Retourne la liste des pieces jointes creees. + +## Notes +- Categorie deduite par extension/MIME. +- Premiere piece jointe marquee comme principale. diff --git a/doc_dev/11_etape3_ent_gen.md b/doc_dev/11_etape3_ent_gen.md new file mode 100644 index 0000000..b00358e --- /dev/null +++ b/doc_dev/11_etape3_ent_gen.md @@ -0,0 +1,14 @@ +# Etape 3 - Generation Ent + +## Objectif +Generer le code Ent a partir des schemas. + +## Commande utilisee +``` +env GOPATH=/tmp/go GOMODCACHE=/tmp/go/pkg/mod GOCACHE=/tmp/go/cache go run -mod=mod entgo.io/ent/cmd/ent generate ./internal/data/ent/schema --target ./internal/data/ent +``` + +## Notes +- Mise a jour de Ent vers v0.14.5 pour compatibilite. +- Ajout d'un `doc.go` pour initialiser le package cible. +- Generation reussie apres correction des edges obligatoires. diff --git a/doc_dev/12_etape5_pieces_jointes_crud.md b/doc_dev/12_etape5_pieces_jointes_crud.md new file mode 100644 index 0000000..2886ff6 --- /dev/null +++ b/doc_dev/12_etape5_pieces_jointes_crud.md @@ -0,0 +1,12 @@ +# Etape 5 (suite) - Pieces jointes CRUD + +## Objectif +Ajouter des endpoints de lecture et suppression des pieces jointes. + +## Endpoints +- `GET /v1/objets/:id/pieces_jointes` : liste des pieces jointes d'un objet. +- `DELETE /v1/pieces_jointes/:id` : suppression d'une piece jointe + fichier. + +## Comportement +- Retourne 404 si la piece jointe n'existe pas. +- Le fichier est supprime du disque si present. diff --git a/doc_dev/13_etape6_upload_validations.md b/doc_dev/13_etape6_upload_validations.md new file mode 100644 index 0000000..62a5bfa --- /dev/null +++ b/doc_dev/13_etape6_upload_validations.md @@ -0,0 +1,14 @@ +# Etape 6 - Validations upload + +## Objectif +Renforcer la validation des pieces jointes. + +## Ajouts +- Taille max par fichier via `MAX_UPLOAD_MB` (defaut 50). +- Types acceptes : images, PDF, Markdown. +- Refus avec code 413 si taille depassee. +- Refus avec code 400 si type non supporte. + +## Comportement principale +- Une seule piece jointe principale par objet. +- La premiere piece upload est principale uniquement si aucune n'existe deja. diff --git a/doc_dev/14_etape7_champs_liens.md b/doc_dev/14_etape7_champs_liens.md new file mode 100644 index 0000000..2f8aa83 --- /dev/null +++ b/doc_dev/14_etape7_champs_liens.md @@ -0,0 +1,15 @@ +# Etape 7 - Champs personnalises et liens emplacements + +## Objectif +Ajouter les endpoints CRUD pour les champs personnalises et les liens objet/emplacement. + +## Champs personnalises +- `GET /v1/objets/:id/champs_personnalises` +- `POST /v1/objets/:id/champs_personnalises` +- `PUT /v1/champs_personnalises/:id` +- `DELETE /v1/champs_personnalises/:id` + +## Liens objet/emplacement +- `GET /v1/objets/:id/liens_emplacements` +- `POST /v1/objets/:id/liens_emplacements` +- `DELETE /v1/liens_emplacements/:id` diff --git a/doc_dev/15_etape8_principale_dedup_tests.md b/doc_dev/15_etape8_principale_dedup_tests.md new file mode 100644 index 0000000..82d4065 --- /dev/null +++ b/doc_dev/15_etape8_principale_dedup_tests.md @@ -0,0 +1,15 @@ +# Etape 8 - Principale, dedup, tests + +## Piece jointe principale +- `PUT /v1/pieces_jointes/:id/principale` +- Assure qu'une seule piece jointe est principale par objet (transaction). + +## Dedup liens objet/emplacement +- Refus si lien identique (objet, emplacement, type) existe deja. +- Retour 409 avec message explicite. + +## Tests +- Ajout de tests unitaires simples pour : + - types d'upload autorises + - taille max par fichier + - parsing type_champ et type lien diff --git a/doc_dev/16_etape9_pagination_liens.md b/doc_dev/16_etape9_pagination_liens.md new file mode 100644 index 0000000..16527bf --- /dev/null +++ b/doc_dev/16_etape9_pagination_liens.md @@ -0,0 +1,11 @@ +# Etape 9 - Pagination et liens + +## Pagination +- Ajout de `page` et `limit` sur les listes : objets, categories, emplacements, + pieces jointes, champs personnalises, liens. +- Defaut : 50 elements, max 200. + +## Liens objet/emplacement +- Verification d'existence de l'emplacement avant creation. +- Endpoint `PUT /v1/liens_emplacements/:id` pour modifier le type. +- Deduplication maintenue sur (objet, emplacement, type). diff --git a/doc_dev/17_etape10_liens_pagination_meta.md b/doc_dev/17_etape10_liens_pagination_meta.md new file mode 100644 index 0000000..f1b1105 --- /dev/null +++ b/doc_dev/17_etape10_liens_pagination_meta.md @@ -0,0 +1,11 @@ +# Etape 10 - Liens + pagination avec meta + +## Liens objet/emplacement +- `PUT /v1/liens_emplacements/:id` accepte `emplacement_id` et `type`. +- Verification de l'existence de l'emplacement avant mise a jour. +- Deduplication maintenue (objet, emplacement, type). + +## Pagination avec meta +- Les listes renvoient maintenant : + - `items` + - `meta.total`, `meta.page`, `meta.limit` diff --git a/doc_dev/18_etape11_swagger.md b/doc_dev/18_etape11_swagger.md new file mode 100644 index 0000000..1864ac1 --- /dev/null +++ b/doc_dev/18_etape11_swagger.md @@ -0,0 +1,14 @@ +# Etape 11 - Swagger + +## Objectif +Ajouter la documentation Swagger via Swaggo. + +## Ajouts +- Route Swagger : `GET /swagger/*any`. +- Commentaires Swaggo dans `cmd/app/main.go`. +- Generation des fichiers : `backend/docs/swagger.json` et `backend/docs/swagger.yaml`. + +## Commande de generation +``` +/tmp/go/bin/swag init -g cmd/app/main.go -o docs +``` diff --git a/doc_dev/19_etape12_swagger_auto.md b/doc_dev/19_etape12_swagger_auto.md new file mode 100644 index 0000000..79d334e --- /dev/null +++ b/doc_dev/19_etape12_swagger_auto.md @@ -0,0 +1,14 @@ +# Etape 12 - Swagger auto + +## Objectif +Documenter les endpoints avec Swaggo et fournir une commande d'auto-generation. + +## Annotations +- Ajout des annotations Swagger sur les handlers principaux. + +## Script +- `backend/scripts/gen_swagger.sh` +- Usage : + ``` + bash backend/scripts/gen_swagger.sh + ``` diff --git a/doc_dev/20_etape13_tooling_env.md b/doc_dev/20_etape13_tooling_env.md new file mode 100644 index 0000000..7251ee1 --- /dev/null +++ b/doc_dev/20_etape13_tooling_env.md @@ -0,0 +1,6 @@ +# Etape 13 - Tooling et env + +## Ajouts +- `Taskfile.yml` + `backend/Taskfile.yml` pour run/test/ent/swagger. +- `.env.example` pour variables backend. +- `docker-compose.yml` (backend + postgres optionnel). diff --git a/doc_dev/21_etape14_frontend.md b/doc_dev/21_etape14_frontend.md new file mode 100644 index 0000000..d2ed0c6 --- /dev/null +++ b/doc_dev/21_etape14_frontend.md @@ -0,0 +1,15 @@ +# Etape 14 - Frontend (squelette) + +## Structure +- Nuxt 3 minimal avec pages : + - `/` (accueil) + - `/objets` + - `/objets/[id]` + - `/emplacements` + +## Fichiers +- `frontend/package.json` +- `frontend/nuxt.config.ts` +- `frontend/app.vue` +- `frontend/pages/*` +- `frontend/assets/css/main.css` diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..501dae2 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,34 @@ +version: '3.9' + +services: + backend: + image: golang:1.24 + working_dir: /app/backend + command: bash -lc "go run ./cmd/app" + environment: + PORT: 8080 + DATABASE_DRIVER: sqlite3 + DATABASE_URL: file:./data/matosbox.db?_fk=1 + ATTACHMENTS_DIR: ./data/pieces_jointes + BACKUP_DIR: ./data/backups + MAX_UPLOAD_MB: 50 + volumes: + - ./:/app + - ./data:/app/data + ports: + - "8080:8080" + + postgres: + profiles: ["postgres"] + image: postgres:16 + environment: + POSTGRES_DB: matosbox + POSTGRES_USER: matosbox + POSTGRES_PASSWORD: matosbox + ports: + - "5432:5432" + volumes: + - postgres_data:/var/lib/postgresql/data + +volumes: + postgres_data: diff --git a/frontend/app.vue b/frontend/app.vue new file mode 100644 index 0000000..8f62b8b --- /dev/null +++ b/frontend/app.vue @@ -0,0 +1,3 @@ + diff --git a/frontend/assets/css/main.css b/frontend/assets/css/main.css new file mode 100644 index 0000000..01ba84a --- /dev/null +++ b/frontend/assets/css/main.css @@ -0,0 +1,45 @@ +:root { + --bg: #f5f1e8; + --text: #1f1b16; + --accent: #c46b2d; +} + +* { + box-sizing: border-box; +} + +body { + margin: 0; + font-family: "Space Grotesk", system-ui, sans-serif; + background: var(--bg); + color: var(--text); +} + +a { + color: var(--accent); + text-decoration: none; +} + +.container { + max-width: 1100px; + margin: 0 auto; + padding: 24px; +} + +.hero { + display: grid; + gap: 12px; +} + +.grid { + display: grid; + gap: 16px; + grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); +} + +.card { + border: 1px solid #e3d8c5; + border-radius: 16px; + padding: 16px; + background: #fffaf2; +} diff --git a/frontend/nuxt.config.ts b/frontend/nuxt.config.ts new file mode 100644 index 0000000..9466304 --- /dev/null +++ b/frontend/nuxt.config.ts @@ -0,0 +1,12 @@ +export default defineNuxtConfig({ + devtools: { enabled: true }, + app: { + head: { + title: 'MatosBox', + meta: [ + { name: 'viewport', content: 'width=device-width, initial-scale=1' } + ] + } + }, + css: ['~/assets/css/main.css'] +}) diff --git a/frontend/package.json b/frontend/package.json new file mode 100644 index 0000000..d9a83a6 --- /dev/null +++ b/frontend/package.json @@ -0,0 +1,13 @@ +{ + "name": "matosbox-frontend", + "private": true, + "type": "module", + "scripts": { + "dev": "nuxt dev", + "build": "nuxt build", + "preview": "nuxt preview" + }, + "dependencies": { + "nuxt": "3.12.3" + } +} diff --git a/frontend/pages/emplacements/index.vue b/frontend/pages/emplacements/index.vue new file mode 100644 index 0000000..7e14538 --- /dev/null +++ b/frontend/pages/emplacements/index.vue @@ -0,0 +1,6 @@ + diff --git a/frontend/pages/index.vue b/frontend/pages/index.vue new file mode 100644 index 0000000..3e95def --- /dev/null +++ b/frontend/pages/index.vue @@ -0,0 +1,12 @@ + diff --git a/frontend/pages/objets/[id].vue b/frontend/pages/objets/[id].vue new file mode 100644 index 0000000..dedf8f4 --- /dev/null +++ b/frontend/pages/objets/[id].vue @@ -0,0 +1,6 @@ + diff --git a/frontend/pages/objets/index.vue b/frontend/pages/objets/index.vue new file mode 100644 index 0000000..f7001da --- /dev/null +++ b/frontend/pages/objets/index.vue @@ -0,0 +1,6 @@ + diff --git a/migrations/0001_init.sql b/migrations/0001_init.sql new file mode 100644 index 0000000..a73e847 --- /dev/null +++ b/migrations/0001_init.sql @@ -0,0 +1,86 @@ +-- Migration initiale MatosBox (SQLite) + +CREATE TABLE IF NOT EXISTS objet ( + id TEXT PRIMARY KEY, + nom TEXT NOT NULL, + description TEXT, + quantite INTEGER NOT NULL DEFAULT 0, + prix_achat REAL, + date_achat DATETIME, + boutique TEXT, + numero_serie TEXT, + numero_modele TEXT, + fabricant TEXT, + statut TEXT NOT NULL DEFAULT 'en_stock' CHECK (statut IN ('en_stock','pret','hors_service','archive')), + caracteristiques TEXT, + created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP +); + +CREATE TABLE IF NOT EXISTS categorie ( + id TEXT PRIMARY KEY, + nom TEXT NOT NULL, + parent_id TEXT, + slug TEXT, + icone TEXT, + created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + FOREIGN KEY (parent_id) REFERENCES categorie(id) ON DELETE SET NULL +); + +CREATE TABLE IF NOT EXISTS emplacement ( + id TEXT PRIMARY KEY, + nom TEXT NOT NULL, + parent_id TEXT, + slug TEXT, + piece TEXT, + meuble TEXT, + numero_boite TEXT, + icone TEXT, + created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + FOREIGN KEY (parent_id) REFERENCES emplacement(id) ON DELETE SET NULL +); + +CREATE TABLE IF NOT EXISTS lien_objet_emplacement ( + id TEXT PRIMARY KEY, + objet_id TEXT NOT NULL, + emplacement_id TEXT NOT NULL, + type TEXT NOT NULL DEFAULT 'stocke' CHECK (type IN ('stocke','utilise_dans')), + created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + FOREIGN KEY (objet_id) REFERENCES objet(id) ON DELETE CASCADE, + FOREIGN KEY (emplacement_id) REFERENCES emplacement(id) ON DELETE CASCADE +); + +CREATE TABLE IF NOT EXISTS champ_personnalise ( + id TEXT PRIMARY KEY, + objet_id TEXT NOT NULL, + nom_champ TEXT NOT NULL, + type_champ TEXT NOT NULL DEFAULT 'string' CHECK (type_champ IN ('string','int','bool','date')), + valeur TEXT, + unite TEXT, + created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + FOREIGN KEY (objet_id) REFERENCES objet(id) ON DELETE CASCADE +); + +CREATE TABLE IF NOT EXISTS piece_jointe ( + id TEXT PRIMARY KEY, + objet_id TEXT NOT NULL, + nom_fichier TEXT NOT NULL, + chemin TEXT NOT NULL, + type_mime TEXT NOT NULL, + est_principale INTEGER NOT NULL DEFAULT 0, + categorie TEXT NOT NULL DEFAULT 'image' CHECK (categorie IN ('image','pdf_notice','markdown_tuto')), + created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + FOREIGN KEY (objet_id) REFERENCES objet(id) ON DELETE CASCADE +); + +CREATE INDEX IF NOT EXISTS idx_categorie_parent_id ON categorie(parent_id); +CREATE INDEX IF NOT EXISTS idx_emplacement_parent_id ON emplacement(parent_id); +CREATE INDEX IF NOT EXISTS idx_lien_objet_emplacement_objet_id ON lien_objet_emplacement(objet_id); +CREATE INDEX IF NOT EXISTS idx_lien_objet_emplacement_emplacement_id ON lien_objet_emplacement(emplacement_id); +CREATE INDEX IF NOT EXISTS idx_champ_personnalise_objet_id ON champ_personnalise(objet_id); +CREATE INDEX IF NOT EXISTS idx_piece_jointe_objet_id ON piece_jointe(objet_id);