From abe247e46f43b99614cedbe4bb2311535f583da4 Mon Sep 17 00:00:00 2001 From: kalipso Date: Tue, 7 Apr 2026 10:51:12 +0200 Subject: [PATCH] add ressource api docs --- controllers/ressourceController.go | 153 ++++++ docs/docs.go | 785 ++++++++++++++++++++++++++++- docs/swagger.json | 785 ++++++++++++++++++++++++++++- docs/swagger.yaml | 525 ++++++++++++++++++- models/ressource.go | 71 +++ 5 files changed, 2313 insertions(+), 6 deletions(-) create mode 100644 controllers/ressourceController.go create mode 100644 models/ressource.go diff --git a/controllers/ressourceController.go b/controllers/ressourceController.go new file mode 100644 index 0000000..287ef0c --- /dev/null +++ b/controllers/ressourceController.go @@ -0,0 +1,153 @@ +package controllers + +import ( + "github.com/gin-gonic/gin" + _ "github.com/swaggo/swag/example/celler/httputil" + + _ "git.dynamicdiscord.de/harakat/backend/models" +) + +// Register godoc +// @Summary List all ressources +// @Tags ressource +// @Accept json +// @Produce json +// @Param lang query string false "Language code of language that should be returned. Defaults to 'en'" +// @Param include query string false "Comma-separated related resources to include" +// @Success 200 {array} models.RessourceLocalizedResponse +// @Failure 400 {object} httputil.HTTPError +// @Router /ressource/ [get] +func (dc *DummyController) ListRessources(c *gin.Context) {} + +// Register godoc +// @Summary Create a ressource +// @Tags ressource +// @Accept json +// @Produce json +// @Param ressource body models.RessourceRequest true "ressource" +// @Success 200 {object} models.Ressource +// @Failure 400 {object} httputil.HTTPError +// @Router /ressource/ [post] +func (dc *DummyController) CreateRessource(c *gin.Context) {} + +// Register godoc +// @Summary Retreive a ressource +// @Tags ressource +// @Accept json +// @Produce json +// @Param lang query string false "Language code of language that should be returned. Defaults to 'en'" +// @Param include query string false "Comma-separated related resources to include" +// @Param id path int true "A unique integer value identifying this ressource." +// @Success 200 {object} models.RessourceLocalizedResponse +// @Failure 400 {object} httputil.HTTPError +// @Router /ressource/{id} [get] +func (dc *DummyController) RetreiveRessource(c *gin.Context) {} + +// Register godoc +// @Summary Update an existing ressource +// @Tags ressource +// @Accept json +// @Produce json +// @Param id path int true "A unique integer value identifying this ressource." +// @Param ressource body models.RessourceRequest true "updated ressource" +// @Success 200 {object} models.Ressource +// @Failure 400 {object} httputil.HTTPError +// @Router /ressource/{id} [put] +func (dc *DummyController) UpdateRessource(c *gin.Context) {} + +// Register godoc +// @Summary Partially update an existing ressource +// @Tags ressource +// @Accept json +// @Produce json +// @Param id path int true "A unique integer value identifying this ressource." +// @Param ressource body models.RessourceRequest true "partially updated ressource" +// @Success 200 {object} models.Ressource +// @Failure 400 {object} httputil.HTTPError +// @Router /ressource/{id} [patch] +func (dc *DummyController) PatchRessource(c *gin.Context) {} + +// Register godoc +// @Summary Delete an existing ressource +// @Tags ressource +// @Accept json +// @Produce json +// @Param id path int true "A unique integer value identifying this ressource." +// @Success 200 {object} EmptyResponse +// @Failure 400 {object} httputil.HTTPError +// @Router /ressource/{id} [delete] +func (dc *DummyController) DeleteRessource(c *gin.Context) {} + +// ressource TRANSLATIONS + +// Register godoc +// @Summary List all ressource translations +// @Tags ressource +// @Accept json +// @Produce json +// @Param id path int true "A unique integer value identifying the ressource." +// @Success 200 {array} models.RessourceTranslation +// @Failure 400 {object} httputil.HTTPError +// @Router /ressource/{id}/translation [get] +func (dc *DummyController) ListRessourceTranslation(c *gin.Context) {} + +// Register godoc +// @Summary Create a ressource translation +// @Tags ressource +// @Accept json +// @Produce json +// @Param ressource body models.RessourceTranslationRequest true "ressource translation" +// @Success 200 {object} models.RessourceTranslation +// @Failure 400 {object} httputil.HTTPError +// @Router /ressource/{id}/translation [post] +func (dc *DummyController) CreateRessourceTranslation(c *gin.Context) {} + +// Register godoc +// @Summary Retreive a ressource translation +// @Tags ressource +// @Accept json +// @Produce json +// @Param id path int true "A unique integer value identifying the ressource." +// @Param id path int true "A unique integer value identifying the ressource translation." +// @Success 200 {object} models.RessourceTranslation +// @Failure 400 {object} httputil.HTTPError +// @Router /ressource/{id}/translation/{id} [get] +func (dc *DummyController) RetreiveRessourceTranslation(c *gin.Context) {} + +// Register godoc +// @Summary Update an existing ressource translation +// @Tags ressource +// @Accept json +// @Produce json +// @Param id path int true "A unique integer value identifying this ressource." +// @Param id path int true "A unique integer value identifying the ressource translation." +// @Param ressource body models.RessourceTranslationRequest true "updated ressource translation" +// @Success 200 {object} models.RessourceTranslation +// @Failure 400 {object} httputil.HTTPError +// @Router /ressource/{id}/translation/{id} [put] +func (dc *DummyController) UpdateRessourceTranslation(c *gin.Context) {} + +// Register godoc +// @Summary Partially update an existing ressource translation +// @Tags ressource +// @Accept json +// @Produce json +// @Param id path int true "A unique integer value identifying this ressource." +// @Param id path int true "A unique integer value identifying the ressource translation." +// @Param ressource body models.RessourceTranslationRequest true "partially updated ressource translation" +// @Success 200 {object} models.RessourceTranslation +// @Failure 400 {object} httputil.HTTPError +// @Router /ressource/{id}/translation/{id} [patch] +func (dc *DummyController) PatchRessourceTranslation(c *gin.Context) {} + +// Register godoc +// @Summary Delete an existing ressource translation +// @Tags ressource +// @Accept json +// @Produce json +// @Param id path int true "A unique integer value identifying this ressource." +// @Param id path int true "A unique integer value identifying the ressource translation." +// @Success 200 {object} EmptyResponse +// @Failure 400 {object} httputil.HTTPError +// @Router /ressource/{id}/translation/{id} [delete] +func (dc *DummyController) DeleteRessourceTranslation(c *gin.Context) {} diff --git a/docs/docs.go b/docs/docs.go index ae56698..9423246 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -36,13 +36,27 @@ const docTemplate = `{ "category" ], "summary": "List all categories", + "parameters": [ + { + "type": "string", + "description": "Language code of language that should be returned. Defaults to 'en'", + "name": "lang", + "in": "query" + }, + { + "type": "string", + "description": "Comma-separated related resources to include", + "name": "include", + "in": "query" + } + ], "responses": { "200": { "description": "OK", "schema": { "type": "array", "items": { - "$ref": "#/definitions/models.Category" + "$ref": "#/definitions/models.CategoryLocalizedResponse" } } }, @@ -105,6 +119,18 @@ const docTemplate = `{ ], "summary": "Retreive a category", "parameters": [ + { + "type": "string", + "description": "Language code of language that should be returned. Defaults to 'en'", + "name": "lang", + "in": "query" + }, + { + "type": "string", + "description": "Comma-separated related resources to include", + "name": "include", + "in": "query" + }, { "type": "integer", "description": "A unique integer value identifying this category.", @@ -117,7 +143,7 @@ const docTemplate = `{ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/models.Category" + "$ref": "#/definitions/models.CategoryLocalizedResponse" } }, "400": { @@ -745,6 +771,525 @@ const docTemplate = `{ } } }, + "/ressource/": { + "get": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "ressource" + ], + "summary": "List all ressources", + "parameters": [ + { + "type": "string", + "description": "Language code of language that should be returned. Defaults to 'en'", + "name": "lang", + "in": "query" + }, + { + "type": "string", + "description": "Comma-separated related resources to include", + "name": "include", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/models.RessourceLocalizedResponse" + } + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/httputil.HTTPError" + } + } + } + }, + "post": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "ressource" + ], + "summary": "Create a ressource", + "parameters": [ + { + "description": "ressource", + "name": "ressource", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/models.RessourceRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/models.Ressource" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/httputil.HTTPError" + } + } + } + } + }, + "/ressource/{id}": { + "get": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "ressource" + ], + "summary": "Retreive a ressource", + "parameters": [ + { + "type": "string", + "description": "Language code of language that should be returned. Defaults to 'en'", + "name": "lang", + "in": "query" + }, + { + "type": "string", + "description": "Comma-separated related resources to include", + "name": "include", + "in": "query" + }, + { + "type": "integer", + "description": "A unique integer value identifying this ressource.", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/models.RessourceLocalizedResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/httputil.HTTPError" + } + } + } + }, + "put": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "ressource" + ], + "summary": "Update an existing ressource", + "parameters": [ + { + "type": "integer", + "description": "A unique integer value identifying this ressource.", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "updated ressource", + "name": "ressource", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/models.RessourceRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/models.Ressource" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/httputil.HTTPError" + } + } + } + }, + "delete": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "ressource" + ], + "summary": "Delete an existing ressource", + "parameters": [ + { + "type": "integer", + "description": "A unique integer value identifying this ressource.", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/controllers.EmptyResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/httputil.HTTPError" + } + } + } + }, + "patch": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "ressource" + ], + "summary": "Partially update an existing ressource", + "parameters": [ + { + "type": "integer", + "description": "A unique integer value identifying this ressource.", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "partially updated ressource", + "name": "ressource", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/models.RessourceRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/models.Ressource" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/httputil.HTTPError" + } + } + } + } + }, + "/ressource/{id}/translation": { + "get": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "ressource" + ], + "summary": "List all ressource translations", + "parameters": [ + { + "type": "integer", + "description": "A unique integer value identifying the ressource.", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/models.RessourceTranslation" + } + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/httputil.HTTPError" + } + } + } + }, + "post": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "ressource" + ], + "summary": "Create a ressource translation", + "parameters": [ + { + "description": "ressource translation", + "name": "ressource", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/models.RessourceTranslationRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/models.RessourceTranslation" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/httputil.HTTPError" + } + } + } + } + }, + "/ressource/{id}/translation/{id}": { + "get": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "ressource" + ], + "summary": "Retreive a ressource translation", + "parameters": [ + { + "type": "integer", + "description": "A unique integer value identifying the ressource.", + "name": "id", + "in": "path", + "required": true + }, + { + "type": "integer", + "description": "A unique integer value identifying the ressource translation.", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/models.RessourceTranslation" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/httputil.HTTPError" + } + } + } + }, + "put": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "ressource" + ], + "summary": "Update an existing ressource translation", + "parameters": [ + { + "type": "integer", + "description": "A unique integer value identifying this ressource.", + "name": "id", + "in": "path", + "required": true + }, + { + "type": "integer", + "description": "A unique integer value identifying the ressource translation.", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "updated ressource translation", + "name": "ressource", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/models.RessourceTranslationRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/models.RessourceTranslation" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/httputil.HTTPError" + } + } + } + }, + "delete": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "ressource" + ], + "summary": "Delete an existing ressource translation", + "parameters": [ + { + "type": "integer", + "description": "A unique integer value identifying this ressource.", + "name": "id", + "in": "path", + "required": true + }, + { + "type": "integer", + "description": "A unique integer value identifying the ressource translation.", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/controllers.EmptyResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/httputil.HTTPError" + } + } + } + }, + "patch": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "ressource" + ], + "summary": "Partially update an existing ressource translation", + "parameters": [ + { + "type": "integer", + "description": "A unique integer value identifying this ressource.", + "name": "id", + "in": "path", + "required": true + }, + { + "type": "integer", + "description": "A unique integer value identifying the ressource translation.", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "partially updated ressource translation", + "name": "ressource", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/models.RessourceTranslationRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/models.RessourceTranslation" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/httputil.HTTPError" + } + } + } + } + }, "/user/login": { "post": { "description": "Login user", @@ -977,6 +1522,31 @@ const docTemplate = `{ } } }, + "models.CategoryLocalizedResponse": { + "type": "object", + "required": [ + "id", + "language", + "name" + ], + "properties": { + "id": { + "type": "integer" + }, + "language": { + "type": "string" + }, + "name": { + "type": "string" + }, + "translation": { + "type": "array", + "items": { + "$ref": "#/definitions/models.CategoryTranslation" + } + } + } + }, "models.CategoryRequest": { "type": "object", "required": [ @@ -1073,6 +1643,217 @@ const docTemplate = `{ "type": "string" } } + }, + "models.Ressource": { + "type": "object", + "properties": { + "category": { + "$ref": "#/definitions/models.Category" + }, + "createdAt": { + "type": "string" + }, + "deletedAt": { + "$ref": "#/definitions/gorm.DeletedAt" + }, + "feedback": { + "type": "array", + "items": { + "$ref": "#/definitions/models.RessourceFeedback" + } + }, + "id": { + "type": "integer" + }, + "image": { + "type": "string" + }, + "region": { + "type": "string" + }, + "spokenLanguages": { + "type": "string" + }, + "tag": { + "type": "string" + }, + "translations": { + "type": "array", + "items": { + "$ref": "#/definitions/models.RessourceTranslation" + } + }, + "updatedAt": { + "type": "string" + } + } + }, + "models.RessourceFeedback": { + "type": "object", + "properties": { + "createdAt": { + "type": "string" + }, + "deletedAt": { + "$ref": "#/definitions/gorm.DeletedAt" + }, + "id": { + "type": "integer" + }, + "name": { + "type": "string" + }, + "ressourceID": { + "type": "integer" + }, + "text": { + "type": "string" + }, + "updatedAt": { + "type": "string" + } + } + }, + "models.RessourceLocalizedResponse": { + "type": "object", + "required": [ + "categoryName", + "id", + "language", + "name", + "region", + "text" + ], + "properties": { + "category": { + "$ref": "#/definitions/models.Category" + }, + "categoryName": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "image": { + "type": "string" + }, + "language": { + "type": "string" + }, + "metadata": { + "type": "string" + }, + "name": { + "type": "string" + }, + "region": { + "type": "string" + }, + "spokenLanguages": { + "type": "string" + }, + "tag": { + "type": "string" + }, + "text": { + "type": "string" + }, + "translations": { + "type": "array", + "items": { + "$ref": "#/definitions/models.RessourceTranslation" + } + } + } + }, + "models.RessourceRequest": { + "type": "object", + "required": [ + "categoryId", + "region", + "translations" + ], + "properties": { + "categoryId": { + "type": "integer" + }, + "image": { + "type": "string" + }, + "region": { + "type": "string" + }, + "spokenLanguages": { + "type": "string" + }, + "tag": { + "type": "string" + }, + "translations": { + "type": "array", + "items": { + "$ref": "#/definitions/models.RessourceTranslationRequest" + } + } + } + }, + "models.RessourceTranslation": { + "type": "object", + "properties": { + "createdAt": { + "type": "string" + }, + "deletedAt": { + "$ref": "#/definitions/gorm.DeletedAt" + }, + "id": { + "type": "integer" + }, + "languageID": { + "type": "integer" + }, + "metadata": { + "type": "string" + }, + "name": { + "type": "string" + }, + "ressourceID": { + "type": "integer" + }, + "text": { + "type": "string" + }, + "updatedAt": { + "type": "string" + } + } + }, + "models.RessourceTranslationRequest": { + "type": "object", + "required": [ + "languageId", + "name", + "ressourceId", + "text" + ], + "properties": { + "languageId": { + "type": "integer" + }, + "metadata": { + "type": "string" + }, + "name": { + "type": "string" + }, + "ressourceId": { + "type": "integer" + }, + "text": { + "type": "string" + } + } } }, "securityDefinitions": { diff --git a/docs/swagger.json b/docs/swagger.json index 912076b..9cb255a 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -30,13 +30,27 @@ "category" ], "summary": "List all categories", + "parameters": [ + { + "type": "string", + "description": "Language code of language that should be returned. Defaults to 'en'", + "name": "lang", + "in": "query" + }, + { + "type": "string", + "description": "Comma-separated related resources to include", + "name": "include", + "in": "query" + } + ], "responses": { "200": { "description": "OK", "schema": { "type": "array", "items": { - "$ref": "#/definitions/models.Category" + "$ref": "#/definitions/models.CategoryLocalizedResponse" } } }, @@ -99,6 +113,18 @@ ], "summary": "Retreive a category", "parameters": [ + { + "type": "string", + "description": "Language code of language that should be returned. Defaults to 'en'", + "name": "lang", + "in": "query" + }, + { + "type": "string", + "description": "Comma-separated related resources to include", + "name": "include", + "in": "query" + }, { "type": "integer", "description": "A unique integer value identifying this category.", @@ -111,7 +137,7 @@ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/models.Category" + "$ref": "#/definitions/models.CategoryLocalizedResponse" } }, "400": { @@ -739,6 +765,525 @@ } } }, + "/ressource/": { + "get": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "ressource" + ], + "summary": "List all ressources", + "parameters": [ + { + "type": "string", + "description": "Language code of language that should be returned. Defaults to 'en'", + "name": "lang", + "in": "query" + }, + { + "type": "string", + "description": "Comma-separated related resources to include", + "name": "include", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/models.RessourceLocalizedResponse" + } + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/httputil.HTTPError" + } + } + } + }, + "post": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "ressource" + ], + "summary": "Create a ressource", + "parameters": [ + { + "description": "ressource", + "name": "ressource", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/models.RessourceRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/models.Ressource" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/httputil.HTTPError" + } + } + } + } + }, + "/ressource/{id}": { + "get": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "ressource" + ], + "summary": "Retreive a ressource", + "parameters": [ + { + "type": "string", + "description": "Language code of language that should be returned. Defaults to 'en'", + "name": "lang", + "in": "query" + }, + { + "type": "string", + "description": "Comma-separated related resources to include", + "name": "include", + "in": "query" + }, + { + "type": "integer", + "description": "A unique integer value identifying this ressource.", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/models.RessourceLocalizedResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/httputil.HTTPError" + } + } + } + }, + "put": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "ressource" + ], + "summary": "Update an existing ressource", + "parameters": [ + { + "type": "integer", + "description": "A unique integer value identifying this ressource.", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "updated ressource", + "name": "ressource", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/models.RessourceRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/models.Ressource" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/httputil.HTTPError" + } + } + } + }, + "delete": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "ressource" + ], + "summary": "Delete an existing ressource", + "parameters": [ + { + "type": "integer", + "description": "A unique integer value identifying this ressource.", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/controllers.EmptyResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/httputil.HTTPError" + } + } + } + }, + "patch": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "ressource" + ], + "summary": "Partially update an existing ressource", + "parameters": [ + { + "type": "integer", + "description": "A unique integer value identifying this ressource.", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "partially updated ressource", + "name": "ressource", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/models.RessourceRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/models.Ressource" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/httputil.HTTPError" + } + } + } + } + }, + "/ressource/{id}/translation": { + "get": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "ressource" + ], + "summary": "List all ressource translations", + "parameters": [ + { + "type": "integer", + "description": "A unique integer value identifying the ressource.", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/models.RessourceTranslation" + } + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/httputil.HTTPError" + } + } + } + }, + "post": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "ressource" + ], + "summary": "Create a ressource translation", + "parameters": [ + { + "description": "ressource translation", + "name": "ressource", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/models.RessourceTranslationRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/models.RessourceTranslation" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/httputil.HTTPError" + } + } + } + } + }, + "/ressource/{id}/translation/{id}": { + "get": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "ressource" + ], + "summary": "Retreive a ressource translation", + "parameters": [ + { + "type": "integer", + "description": "A unique integer value identifying the ressource.", + "name": "id", + "in": "path", + "required": true + }, + { + "type": "integer", + "description": "A unique integer value identifying the ressource translation.", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/models.RessourceTranslation" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/httputil.HTTPError" + } + } + } + }, + "put": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "ressource" + ], + "summary": "Update an existing ressource translation", + "parameters": [ + { + "type": "integer", + "description": "A unique integer value identifying this ressource.", + "name": "id", + "in": "path", + "required": true + }, + { + "type": "integer", + "description": "A unique integer value identifying the ressource translation.", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "updated ressource translation", + "name": "ressource", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/models.RessourceTranslationRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/models.RessourceTranslation" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/httputil.HTTPError" + } + } + } + }, + "delete": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "ressource" + ], + "summary": "Delete an existing ressource translation", + "parameters": [ + { + "type": "integer", + "description": "A unique integer value identifying this ressource.", + "name": "id", + "in": "path", + "required": true + }, + { + "type": "integer", + "description": "A unique integer value identifying the ressource translation.", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/controllers.EmptyResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/httputil.HTTPError" + } + } + } + }, + "patch": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "ressource" + ], + "summary": "Partially update an existing ressource translation", + "parameters": [ + { + "type": "integer", + "description": "A unique integer value identifying this ressource.", + "name": "id", + "in": "path", + "required": true + }, + { + "type": "integer", + "description": "A unique integer value identifying the ressource translation.", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "partially updated ressource translation", + "name": "ressource", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/models.RessourceTranslationRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/models.RessourceTranslation" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/httputil.HTTPError" + } + } + } + } + }, "/user/login": { "post": { "description": "Login user", @@ -971,6 +1516,31 @@ } } }, + "models.CategoryLocalizedResponse": { + "type": "object", + "required": [ + "id", + "language", + "name" + ], + "properties": { + "id": { + "type": "integer" + }, + "language": { + "type": "string" + }, + "name": { + "type": "string" + }, + "translation": { + "type": "array", + "items": { + "$ref": "#/definitions/models.CategoryTranslation" + } + } + } + }, "models.CategoryRequest": { "type": "object", "required": [ @@ -1067,6 +1637,217 @@ "type": "string" } } + }, + "models.Ressource": { + "type": "object", + "properties": { + "category": { + "$ref": "#/definitions/models.Category" + }, + "createdAt": { + "type": "string" + }, + "deletedAt": { + "$ref": "#/definitions/gorm.DeletedAt" + }, + "feedback": { + "type": "array", + "items": { + "$ref": "#/definitions/models.RessourceFeedback" + } + }, + "id": { + "type": "integer" + }, + "image": { + "type": "string" + }, + "region": { + "type": "string" + }, + "spokenLanguages": { + "type": "string" + }, + "tag": { + "type": "string" + }, + "translations": { + "type": "array", + "items": { + "$ref": "#/definitions/models.RessourceTranslation" + } + }, + "updatedAt": { + "type": "string" + } + } + }, + "models.RessourceFeedback": { + "type": "object", + "properties": { + "createdAt": { + "type": "string" + }, + "deletedAt": { + "$ref": "#/definitions/gorm.DeletedAt" + }, + "id": { + "type": "integer" + }, + "name": { + "type": "string" + }, + "ressourceID": { + "type": "integer" + }, + "text": { + "type": "string" + }, + "updatedAt": { + "type": "string" + } + } + }, + "models.RessourceLocalizedResponse": { + "type": "object", + "required": [ + "categoryName", + "id", + "language", + "name", + "region", + "text" + ], + "properties": { + "category": { + "$ref": "#/definitions/models.Category" + }, + "categoryName": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "image": { + "type": "string" + }, + "language": { + "type": "string" + }, + "metadata": { + "type": "string" + }, + "name": { + "type": "string" + }, + "region": { + "type": "string" + }, + "spokenLanguages": { + "type": "string" + }, + "tag": { + "type": "string" + }, + "text": { + "type": "string" + }, + "translations": { + "type": "array", + "items": { + "$ref": "#/definitions/models.RessourceTranslation" + } + } + } + }, + "models.RessourceRequest": { + "type": "object", + "required": [ + "categoryId", + "region", + "translations" + ], + "properties": { + "categoryId": { + "type": "integer" + }, + "image": { + "type": "string" + }, + "region": { + "type": "string" + }, + "spokenLanguages": { + "type": "string" + }, + "tag": { + "type": "string" + }, + "translations": { + "type": "array", + "items": { + "$ref": "#/definitions/models.RessourceTranslationRequest" + } + } + } + }, + "models.RessourceTranslation": { + "type": "object", + "properties": { + "createdAt": { + "type": "string" + }, + "deletedAt": { + "$ref": "#/definitions/gorm.DeletedAt" + }, + "id": { + "type": "integer" + }, + "languageID": { + "type": "integer" + }, + "metadata": { + "type": "string" + }, + "name": { + "type": "string" + }, + "ressourceID": { + "type": "integer" + }, + "text": { + "type": "string" + }, + "updatedAt": { + "type": "string" + } + } + }, + "models.RessourceTranslationRequest": { + "type": "object", + "required": [ + "languageId", + "name", + "ressourceId", + "text" + ], + "properties": { + "languageId": { + "type": "integer" + }, + "metadata": { + "type": "string" + }, + "name": { + "type": "string" + }, + "ressourceId": { + "type": "integer" + }, + "text": { + "type": "string" + } + } } }, "securityDefinitions": { diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 59ea724..7e1a11f 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -57,6 +57,23 @@ definitions: updatedAt: type: string type: object + models.CategoryLocalizedResponse: + properties: + id: + type: integer + language: + type: string + name: + type: string + translation: + items: + $ref: '#/definitions/models.CategoryTranslation' + type: array + required: + - id + - language + - name + type: object models.CategoryRequest: properties: translations: @@ -121,6 +138,148 @@ definitions: - code - name type: object + models.Ressource: + properties: + category: + $ref: '#/definitions/models.Category' + createdAt: + type: string + deletedAt: + $ref: '#/definitions/gorm.DeletedAt' + feedback: + items: + $ref: '#/definitions/models.RessourceFeedback' + type: array + id: + type: integer + image: + type: string + region: + type: string + spokenLanguages: + type: string + tag: + type: string + translations: + items: + $ref: '#/definitions/models.RessourceTranslation' + type: array + updatedAt: + type: string + type: object + models.RessourceFeedback: + properties: + createdAt: + type: string + deletedAt: + $ref: '#/definitions/gorm.DeletedAt' + id: + type: integer + name: + type: string + ressourceID: + type: integer + text: + type: string + updatedAt: + type: string + type: object + models.RessourceLocalizedResponse: + properties: + category: + $ref: '#/definitions/models.Category' + categoryName: + type: string + id: + type: integer + image: + type: string + language: + type: string + metadata: + type: string + name: + type: string + region: + type: string + spokenLanguages: + type: string + tag: + type: string + text: + type: string + translations: + items: + $ref: '#/definitions/models.RessourceTranslation' + type: array + required: + - categoryName + - id + - language + - name + - region + - text + type: object + models.RessourceRequest: + properties: + categoryId: + type: integer + image: + type: string + region: + type: string + spokenLanguages: + type: string + tag: + type: string + translations: + items: + $ref: '#/definitions/models.RessourceTranslationRequest' + type: array + required: + - categoryId + - region + - translations + type: object + models.RessourceTranslation: + properties: + createdAt: + type: string + deletedAt: + $ref: '#/definitions/gorm.DeletedAt' + id: + type: integer + languageID: + type: integer + metadata: + type: string + name: + type: string + ressourceID: + type: integer + text: + type: string + updatedAt: + type: string + type: object + models.RessourceTranslationRequest: + properties: + languageId: + type: integer + metadata: + type: string + name: + type: string + ressourceId: + type: integer + text: + type: string + required: + - languageId + - name + - ressourceId + - text + type: object externalDocs: description: OpenAPI url: https://swagger.io/resources/open-api/ @@ -142,6 +301,16 @@ paths: get: consumes: - application/json + parameters: + - description: Language code of language that should be returned. Defaults to + 'en' + in: query + name: lang + type: string + - description: Comma-separated related resources to include + in: query + name: include + type: string produces: - application/json responses: @@ -149,7 +318,7 @@ paths: description: OK schema: items: - $ref: '#/definitions/models.Category' + $ref: '#/definitions/models.CategoryLocalizedResponse' type: array "400": description: Bad Request @@ -210,6 +379,15 @@ paths: consumes: - application/json parameters: + - description: Language code of language that should be returned. Defaults to + 'en' + in: query + name: lang + type: string + - description: Comma-separated related resources to include + in: query + name: include + type: string - description: A unique integer value identifying this category. in: path name: id @@ -221,7 +399,7 @@ paths: "200": description: OK schema: - $ref: '#/definitions/models.Category' + $ref: '#/definitions/models.CategoryLocalizedResponse' "400": description: Bad Request schema: @@ -611,6 +789,349 @@ paths: summary: Update an existing language tags: - lang + /ressource/: + get: + consumes: + - application/json + parameters: + - description: Language code of language that should be returned. Defaults to + 'en' + in: query + name: lang + type: string + - description: Comma-separated related resources to include + in: query + name: include + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + items: + $ref: '#/definitions/models.RessourceLocalizedResponse' + type: array + "400": + description: Bad Request + schema: + $ref: '#/definitions/httputil.HTTPError' + summary: List all ressources + tags: + - ressource + post: + consumes: + - application/json + parameters: + - description: ressource + in: body + name: ressource + required: true + schema: + $ref: '#/definitions/models.RessourceRequest' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/models.Ressource' + "400": + description: Bad Request + schema: + $ref: '#/definitions/httputil.HTTPError' + summary: Create a ressource + tags: + - ressource + /ressource/{id}: + delete: + consumes: + - application/json + parameters: + - description: A unique integer value identifying this ressource. + in: path + name: id + required: true + type: integer + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/controllers.EmptyResponse' + "400": + description: Bad Request + schema: + $ref: '#/definitions/httputil.HTTPError' + summary: Delete an existing ressource + tags: + - ressource + get: + consumes: + - application/json + parameters: + - description: Language code of language that should be returned. Defaults to + 'en' + in: query + name: lang + type: string + - description: Comma-separated related resources to include + in: query + name: include + type: string + - description: A unique integer value identifying this ressource. + in: path + name: id + required: true + type: integer + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/models.RessourceLocalizedResponse' + "400": + description: Bad Request + schema: + $ref: '#/definitions/httputil.HTTPError' + summary: Retreive a ressource + tags: + - ressource + patch: + consumes: + - application/json + parameters: + - description: A unique integer value identifying this ressource. + in: path + name: id + required: true + type: integer + - description: partially updated ressource + in: body + name: ressource + required: true + schema: + $ref: '#/definitions/models.RessourceRequest' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/models.Ressource' + "400": + description: Bad Request + schema: + $ref: '#/definitions/httputil.HTTPError' + summary: Partially update an existing ressource + tags: + - ressource + put: + consumes: + - application/json + parameters: + - description: A unique integer value identifying this ressource. + in: path + name: id + required: true + type: integer + - description: updated ressource + in: body + name: ressource + required: true + schema: + $ref: '#/definitions/models.RessourceRequest' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/models.Ressource' + "400": + description: Bad Request + schema: + $ref: '#/definitions/httputil.HTTPError' + summary: Update an existing ressource + tags: + - ressource + /ressource/{id}/translation: + get: + consumes: + - application/json + parameters: + - description: A unique integer value identifying the ressource. + in: path + name: id + required: true + type: integer + produces: + - application/json + responses: + "200": + description: OK + schema: + items: + $ref: '#/definitions/models.RessourceTranslation' + type: array + "400": + description: Bad Request + schema: + $ref: '#/definitions/httputil.HTTPError' + summary: List all ressource translations + tags: + - ressource + post: + consumes: + - application/json + parameters: + - description: ressource translation + in: body + name: ressource + required: true + schema: + $ref: '#/definitions/models.RessourceTranslationRequest' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/models.RessourceTranslation' + "400": + description: Bad Request + schema: + $ref: '#/definitions/httputil.HTTPError' + summary: Create a ressource translation + tags: + - ressource + /ressource/{id}/translation/{id}: + delete: + consumes: + - application/json + parameters: + - description: A unique integer value identifying this ressource. + in: path + name: id + required: true + type: integer + - description: A unique integer value identifying the ressource translation. + in: path + name: id + required: true + type: integer + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/controllers.EmptyResponse' + "400": + description: Bad Request + schema: + $ref: '#/definitions/httputil.HTTPError' + summary: Delete an existing ressource translation + tags: + - ressource + get: + consumes: + - application/json + parameters: + - description: A unique integer value identifying the ressource. + in: path + name: id + required: true + type: integer + - description: A unique integer value identifying the ressource translation. + in: path + name: id + required: true + type: integer + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/models.RessourceTranslation' + "400": + description: Bad Request + schema: + $ref: '#/definitions/httputil.HTTPError' + summary: Retreive a ressource translation + tags: + - ressource + patch: + consumes: + - application/json + parameters: + - description: A unique integer value identifying this ressource. + in: path + name: id + required: true + type: integer + - description: A unique integer value identifying the ressource translation. + in: path + name: id + required: true + type: integer + - description: partially updated ressource translation + in: body + name: ressource + required: true + schema: + $ref: '#/definitions/models.RessourceTranslationRequest' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/models.RessourceTranslation' + "400": + description: Bad Request + schema: + $ref: '#/definitions/httputil.HTTPError' + summary: Partially update an existing ressource translation + tags: + - ressource + put: + consumes: + - application/json + parameters: + - description: A unique integer value identifying this ressource. + in: path + name: id + required: true + type: integer + - description: A unique integer value identifying the ressource translation. + in: path + name: id + required: true + type: integer + - description: updated ressource translation + in: body + name: ressource + required: true + schema: + $ref: '#/definitions/models.RessourceTranslationRequest' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/models.RessourceTranslation' + "400": + description: Bad Request + schema: + $ref: '#/definitions/httputil.HTTPError' + summary: Update an existing ressource translation + tags: + - ressource /user/login: post: consumes: diff --git a/models/ressource.go b/models/ressource.go new file mode 100644 index 0000000..643376b --- /dev/null +++ b/models/ressource.go @@ -0,0 +1,71 @@ +package models + +import ( + "gorm.io/gorm" +) + +type Ressource struct { + gorm.Model + Category Category + Tag string + Region string + Image string + SpokenLanguages string + + Translations []RessourceTranslation `gorm:"foreignKey:RessourceID"` + Feedback []RessourceFeedback `gorm:"foreignKey:RessourceID"` +} + +type RessourceLocalizedResponse struct { + ID uint `json:"id" binding:"required"` + CategoryName string `json:"categoryName" binding:"required"` + Language string `json:"language" binding:"required"` + Tag string `json:"tag"` + Region string `json:"region" binding:"required"` + Image string `json:"image"` + SpokenLanguages string `json:"spokenLanguages"` + Name string `json:"name" binding:"required"` + Text string `json:"text" binding:"required"` + Metadata string `json:"metadata"` + Translations []RessourceTranslation `json:"translations"` + Category Category `json:"category"` +} + +type RessourceRequest struct { + CategoryID uint `json:"categoryId" binding:"required"` + Tag string `json:"tag"` + Region string `json:"region" binding:"required"` + Image string `json:"image"` + SpokenLanguages string `json:"spokenLanguages"` + Translations []RessourceTranslationRequest `json:"translations" binding:"required"` +} + +type RessourceTranslationRequest struct { + RessourceID uint `json:"ressourceId" binding:"required"` + LanguageID uint `json:"languageId" binding:"required"` + Name string `json:"name" binding:"required"` + Text string `json:"text" binding:"required"` + Metadata string `json:"metadata"` +} + +type RessourceTranslation struct { + gorm.Model + RessourceID uint `gorm:"uniqueIndex:idx_post_language"` + LanguageID uint `gorm:"uniqueIndex:idx_post_language"` + Name string + Text string + Metadata string +} + +type RessourceFeedbackRequest struct { + RessourceID uint `json:"ressourceId" binding:"required"` + Name string `json:"name" binding:"required"` + Text string `json:"text" binding:"required"` +} + +type RessourceFeedback struct { + gorm.Model + RessourceID uint `gorm:"uniqueIndex:idx_post_language"` + Name string + Text string +}