add category api docs
This commit is contained in:
160
controllers/categoryController.go
Normal file
160
controllers/categoryController.go
Normal file
@@ -0,0 +1,160 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
_ "github.com/swaggo/swag/example/celler/httputil"
|
||||
|
||||
_ "git.dynamicdiscord.de/harakat/backend/models"
|
||||
)
|
||||
|
||||
/*
|
||||
models:
|
||||
- language
|
||||
- ressource
|
||||
- category
|
||||
- tag
|
||||
- region
|
||||
*/
|
||||
|
||||
type DummyController struct{}
|
||||
|
||||
// Register godoc
|
||||
// @Summary List all categories
|
||||
// @Tags category
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {array} models.Category
|
||||
// @Failure 400 {object} httputil.HTTPError
|
||||
// @Router /category/ [get]
|
||||
func (dc *DummyController) ListCategories(c *gin.Context) {}
|
||||
|
||||
// Register godoc
|
||||
// @Summary Create a category
|
||||
// @Tags category
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param category body models.CategoryRequest true "category"
|
||||
// @Success 200 {object} models.Category
|
||||
// @Failure 400 {object} httputil.HTTPError
|
||||
// @Router /category/ [post]
|
||||
func (dc *DummyController) CreateCategory(c *gin.Context) {}
|
||||
|
||||
// Register godoc
|
||||
// @Summary Retreive a category
|
||||
// @Tags category
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path int true "A unique integer value identifying this category."
|
||||
// @Success 200 {object} models.Category
|
||||
// @Failure 400 {object} httputil.HTTPError
|
||||
// @Router /category/{id} [get]
|
||||
func (dc *DummyController) RetreiveCategory(c *gin.Context) {}
|
||||
|
||||
// Register godoc
|
||||
// @Summary Update an existing category
|
||||
// @Tags category
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path int true "A unique integer value identifying this category."
|
||||
// @Param category body models.CategoryRequest true "updated category"
|
||||
// @Success 200 {object} models.Category
|
||||
// @Failure 400 {object} httputil.HTTPError
|
||||
// @Router /category/{id} [put]
|
||||
func (dc *DummyController) UpdateCategory(c *gin.Context) {}
|
||||
|
||||
// Register godoc
|
||||
// @Summary Partially update an existing category
|
||||
// @Tags category
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path int true "A unique integer value identifying this category."
|
||||
// @Param category body models.CategoryRequest true "partially updated category"
|
||||
// @Success 200 {object} models.Category
|
||||
// @Failure 400 {object} httputil.HTTPError
|
||||
// @Router /category/{id} [patch]
|
||||
func (dc *DummyController) PatchCategory(c *gin.Context) {}
|
||||
|
||||
// Register godoc
|
||||
// @Summary Delete an existing category
|
||||
// @Tags category
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path int true "A unique integer value identifying this category."
|
||||
// @Success 200 {object} EmptyResponse
|
||||
// @Failure 400 {object} httputil.HTTPError
|
||||
// @Router /category/{id} [delete]
|
||||
func (dc *DummyController) DeleteCategory(c *gin.Context) {}
|
||||
|
||||
// CATEGORY TRANSLATIONS
|
||||
|
||||
// Register godoc
|
||||
// @Summary List all category translations
|
||||
// @Tags category
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path int true "A unique integer value identifying the category."
|
||||
// @Success 200 {array} models.CategoryTranslation
|
||||
// @Failure 400 {object} httputil.HTTPError
|
||||
// @Router /category/{id}/translation [get]
|
||||
func (dc *DummyController) ListCategorieTranslation(c *gin.Context) {}
|
||||
|
||||
// Register godoc
|
||||
// @Summary Create a category translation
|
||||
// @Tags category
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param category body models.CategoryTranslationRequest true "category translation"
|
||||
// @Success 200 {object} models.CategoryTranslation
|
||||
// @Failure 400 {object} httputil.HTTPError
|
||||
// @Router /category/{id}/translation [post]
|
||||
func (dc *DummyController) CreateCategoryTranslation(c *gin.Context) {}
|
||||
|
||||
// Register godoc
|
||||
// @Summary Retreive a category translation
|
||||
// @Tags category
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path int true "A unique integer value identifying the category."
|
||||
// @Param id path int true "A unique integer value identifying the category translation."
|
||||
// @Success 200 {object} models.CategoryTranslation
|
||||
// @Failure 400 {object} httputil.HTTPError
|
||||
// @Router /category/{id}/translation/{id} [get]
|
||||
func (dc *DummyController) RetreiveCategoryTranslation(c *gin.Context) {}
|
||||
|
||||
// Register godoc
|
||||
// @Summary Update an existing category translation
|
||||
// @Tags category
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path int true "A unique integer value identifying this category."
|
||||
// @Param id path int true "A unique integer value identifying the category translation."
|
||||
// @Param category body models.CategoryTranslationRequest true "updated category translation"
|
||||
// @Success 200 {object} models.CategoryTranslation
|
||||
// @Failure 400 {object} httputil.HTTPError
|
||||
// @Router /category/{id}/translation/{id} [put]
|
||||
func (dc *DummyController) UpdateCategoryTranslation(c *gin.Context) {}
|
||||
|
||||
// Register godoc
|
||||
// @Summary Partially update an existing category translation
|
||||
// @Tags category
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path int true "A unique integer value identifying this category."
|
||||
// @Param id path int true "A unique integer value identifying the category translation."
|
||||
// @Param category body models.CategoryTranslationRequest true "partially updated category translation"
|
||||
// @Success 200 {object} models.CategoryTranslation
|
||||
// @Failure 400 {object} httputil.HTTPError
|
||||
// @Router /category/{id}/translation/{id} [patch]
|
||||
func (dc *DummyController) PatchCategoryTranslation(c *gin.Context) {}
|
||||
|
||||
// Register godoc
|
||||
// @Summary Delete an existing category translation
|
||||
// @Tags category
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path int true "A unique integer value identifying this category."
|
||||
// @Param id path int true "A unique integer value identifying the category translation."
|
||||
// @Success 200 {object} EmptyResponse
|
||||
// @Failure 400 {object} httputil.HTTPError
|
||||
// @Router /category/{id}/translation/{id} [delete]
|
||||
func (dc *DummyController) DeleteCategoryTranslation(c *gin.Context) {}
|
||||
26
models/category.go
Normal file
26
models/category.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type Category struct {
|
||||
gorm.Model
|
||||
Translations []CategoryTranslation `gorm:"foreignKey:CategoryID"`
|
||||
}
|
||||
|
||||
type CategoryTranslation struct {
|
||||
gorm.Model
|
||||
CategoryID uint `gorm:"uniqueIndex:idx_post_language"`
|
||||
LanguageID uint `gorm:"uniqueIndex:idx_post_language"`
|
||||
Name string
|
||||
}
|
||||
|
||||
type CategoryRequest struct {
|
||||
Translations []CategoryTranslationRequest `json:"translations" binding:"required"`
|
||||
}
|
||||
|
||||
type CategoryTranslationRequest struct {
|
||||
LanguageID uint `json:"languageId" binding:"required"`
|
||||
Name string `json:"name" binding:"required"`
|
||||
}
|
||||
Reference in New Issue
Block a user