swagger done
This commit is contained in:
@@ -6,9 +6,21 @@ import (
|
||||
"reCoreD-UI/models"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
_ "reCoreD-UI/docs"
|
||||
)
|
||||
|
||||
// GetDomains
|
||||
// GetDomains godoc
|
||||
//
|
||||
// @Router /domains/ [get]
|
||||
// @Summary List all domains
|
||||
// @Description List all domains
|
||||
// @Tags domains
|
||||
// @Accept json
|
||||
// @Product json
|
||||
// @Success 200 {object} Response{data=[]models.Domain}
|
||||
// @Failure 401 {object} Response{data=nil}
|
||||
// @Failure 500 {object} Response{data=nil}
|
||||
func getDomains(c *gin.Context) {
|
||||
domains, err := controllers.GetDomains("")
|
||||
if err != nil {
|
||||
@@ -22,6 +34,18 @@ func getDomains(c *gin.Context) {
|
||||
})
|
||||
}
|
||||
|
||||
// CreateDomain godoc
|
||||
//
|
||||
// @Router /domains/ [post]
|
||||
// @Summary Create a domain
|
||||
// @Description Create a domain
|
||||
// @Tags domains
|
||||
// @Product json
|
||||
// @Param object body models.Domain true "content"
|
||||
// @Success 201 {object} Response{data=models.Domain}
|
||||
// @Failure 400 {object} Response{data=nil}
|
||||
// @Failure 401 {object} Response{data=nil}
|
||||
// @Failure 500 {object} Response{data=nil}
|
||||
func createDomain(c *gin.Context) {
|
||||
domain := &models.Domain{}
|
||||
|
||||
@@ -45,6 +69,20 @@ func createDomain(c *gin.Context) {
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateDomain godoc
|
||||
//
|
||||
// @Router /domains/ [put]
|
||||
// @Summary Update a domain
|
||||
// @Description Update a domain
|
||||
// @Tags domains
|
||||
// @Accept json
|
||||
// @Product json
|
||||
// @Param object body models.Domain true "content"
|
||||
// @Success 200 {object} Response{data=models.Domain}
|
||||
// @Failure 400 {object} Response{data=nil}
|
||||
// @Failure 401 {object} Response{data=nil}
|
||||
// @Failure 404 {object} Response{data=nil}
|
||||
// @Failure 500 {object} Response{data=nil}
|
||||
func updateDomain(c *gin.Context) {
|
||||
domain := &models.Domain{}
|
||||
|
||||
@@ -66,6 +104,18 @@ func updateDomain(c *gin.Context) {
|
||||
})
|
||||
}
|
||||
|
||||
// DeleteDomain godoc
|
||||
//
|
||||
// @Router /domains/{id} [delete]
|
||||
// @Summary Delete a domain
|
||||
// @Description Delete a domain
|
||||
// @Tags domains
|
||||
// @Product json
|
||||
// @Param id path int true "Domain ID"
|
||||
// @Success 204 {object} Response{data=nil}
|
||||
// @Failure 401 {object} Response{data=nil}
|
||||
// @Failure 404 {object} Response{data=nil}
|
||||
// @Failure 500 {object} Response{data=nil}
|
||||
func deleteDomain(c *gin.Context) {
|
||||
id := c.Param("id")
|
||||
if err := controllers.DeleteDomain(id); err != nil {
|
||||
|
@@ -10,7 +10,6 @@ import (
|
||||
)
|
||||
|
||||
func validateRecord(r models.IRecord) error {
|
||||
|
||||
switch r.GetType() {
|
||||
case models.RecordTypeA:
|
||||
record := &models.Record[models.ARecord]{}
|
||||
@@ -71,6 +70,18 @@ func validateRecord(r models.IRecord) error {
|
||||
}
|
||||
}
|
||||
|
||||
// GetRecords godoc
|
||||
//
|
||||
// @Router /records/{domain} [get]
|
||||
// @Summary List all records of a domain
|
||||
// @Description List all records of a domain
|
||||
// @Tags records
|
||||
// @Product json
|
||||
// @Param domain path string true "domain"
|
||||
// @Success 200 {object} Response{data=[]models.Record[models.RecordContentDefault]}
|
||||
// @Failure 401 {object} Response{data=nil}
|
||||
// @Failure 404 {object} Response{data=nil}
|
||||
// @Failure 500 {object} Response{data=nil}
|
||||
func getRecords(c *gin.Context) {
|
||||
query := &models.Record[models.RecordContentDefault]{Content: make(models.RecordContentDefault)}
|
||||
if err := c.BindQuery(query); err != nil {
|
||||
@@ -95,6 +106,21 @@ func getRecords(c *gin.Context) {
|
||||
})
|
||||
}
|
||||
|
||||
// CreateRecord godoc
|
||||
//
|
||||
// @Router /records/{domain} [post]
|
||||
// @Summary Create a record of a domain
|
||||
// @Description Create a record of a domain
|
||||
// @Tags records
|
||||
// @Accept json
|
||||
// @Product json
|
||||
// @Param domain path string true "domain"
|
||||
// @Param object body models.Record[models.RecordContentDefault] true "content"
|
||||
// @Success 201 {object} Response{data=models.Record[models.RecordContentDefault]}
|
||||
// @Failure 400 {object} Response{data=nil}
|
||||
// @Failure 401 {object} Response{data=nil}
|
||||
// @Failure 404 {object} Response{data=nil}
|
||||
// @Failure 500 {object} Response{data=nil}
|
||||
func createRecord(c *gin.Context) {
|
||||
record := &models.Record[models.RecordContentDefault]{Content: make(models.RecordContentDefault)}
|
||||
if err := c.BindJSON(record); err != nil {
|
||||
@@ -134,6 +160,21 @@ func createRecord(c *gin.Context) {
|
||||
})
|
||||
}
|
||||
|
||||
// CreateRecords godoc
|
||||
//
|
||||
// @Router /records/{domain}/bulk [post]
|
||||
// @Summary Create some records of a domain
|
||||
// @Description Create some records of a domain
|
||||
// @Tags records
|
||||
// @Accept json
|
||||
// @Product json
|
||||
// @Param domain path string true "domain"
|
||||
// @Param object body []models.Record[models.RecordContentDefault] true "content"
|
||||
// @Success 201 {object} Response{data=models.Record[models.RecordContentDefault]}
|
||||
// @Failure 400 {object} Response{data=nil}
|
||||
// @Failure 401 {object} Response{data=nil}
|
||||
// @Failure 404 {object} Response{data=nil}
|
||||
// @Failure 500 {object} Response{data=nil}
|
||||
func createRecords(c *gin.Context) {
|
||||
var records []models.Record[models.RecordContentDefault]
|
||||
if err := c.BindJSON(&records); err != nil {
|
||||
@@ -159,6 +200,21 @@ func createRecords(c *gin.Context) {
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateRecord godoc
|
||||
//
|
||||
// @Router /records/{domain} [put]
|
||||
// @Summary Update a record of a domain
|
||||
// @Description Update a record of a domain
|
||||
// @Tags records
|
||||
// @Accept json
|
||||
// @Product json
|
||||
// @Param domain path string true "domain"
|
||||
// @Param object body models.Record[models.RecordContentDefault] true "content"
|
||||
// @Success 200 {object} Response{data=models.Record[models.RecordContentDefault]}
|
||||
// @Failure 400 {object} Response{data=nil}
|
||||
// @Failure 401 {object} Response{data=nil}
|
||||
// @Failure 404 {object} Response{data=nil}
|
||||
// @Failure 500 {object} Response{data=nil}
|
||||
func updateRecord(c *gin.Context) {
|
||||
record := &models.Record[models.RecordContentDefault]{Content: make(models.RecordContentDefault)}
|
||||
if err := c.BindJSON(record); err != nil {
|
||||
@@ -196,6 +252,20 @@ func updateRecord(c *gin.Context) {
|
||||
})
|
||||
}
|
||||
|
||||
// DeleteRecord godoc
|
||||
//
|
||||
// @Router /records/{domain}/{id} [delete]
|
||||
// @Summary Delete a record of a domain
|
||||
// @Description Delete a record of a domain, except SOA record.
|
||||
// @Tags records
|
||||
// @Product json
|
||||
// @Param domain path string true "domain"
|
||||
// @Param id path int true "Record ID"
|
||||
// @Success 204 {object} Response{data=nil}
|
||||
// @Failure 400 {object} Response{data=nil}
|
||||
// @Failure 401 {object} Response{data=nil}
|
||||
// @Failure 404 {object} Response{data=nil}
|
||||
// @Failure 500 {object} Response{data=nil}
|
||||
func deleteRecord(c *gin.Context) {
|
||||
domain := c.Param("domain")
|
||||
id := c.Param("id")
|
||||
|
@@ -10,10 +10,16 @@ import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// Response common http response
|
||||
type Response struct {
|
||||
Succeed bool `json:"succeed"`
|
||||
Message string `json:"message"`
|
||||
Data interface{} `json:"data"`
|
||||
// `true` for 2xx, else `false`
|
||||
Succeed bool `json:"succeed"`
|
||||
|
||||
// error message
|
||||
Message string `json:"message"`
|
||||
|
||||
// payload here
|
||||
Data interface{} `json:"data"`
|
||||
}
|
||||
|
||||
func errorHandler(c *gin.Context, err error) {
|
||||
|
@@ -18,6 +18,7 @@ const (
|
||||
swaggerPrefix = "/swagger"
|
||||
)
|
||||
|
||||
|
||||
func (s *Server) setupRoute() {
|
||||
username, password, err := controllers.GetAdmin()
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user