reCoreD-UI/server/handlers_domains.go

80 lines
1.3 KiB
Go
Raw Normal View History

2024-04-03 09:05:12 +00:00
package server
import (
"net/http"
2024-04-09 08:28:18 +00:00
"reCoreD-UI/controllers"
2024-04-03 09:05:12 +00:00
"reCoreD-UI/models"
"github.com/gin-gonic/gin"
)
2024-04-13 02:30:02 +00:00
// GetDomains
2024-04-09 13:16:19 +00:00
func getDomains(c *gin.Context) {
2024-04-09 08:28:18 +00:00
domains, err := controllers.GetDomains("")
2024-04-03 09:05:12 +00:00
if err != nil {
errorHandler(c, err)
return
}
c.JSON(http.StatusOK, Response{
Succeed: true,
Data: domains,
})
}
2024-04-09 13:16:19 +00:00
func createDomain(c *gin.Context) {
2024-04-03 09:05:12 +00:00
domain := &models.Domain{}
if err := c.BindJSON(domain); err != nil {
c.JSON(http.StatusBadRequest, Response{
Succeed: false,
Message: err.Error(),
})
return
}
2024-04-09 08:28:18 +00:00
domain, err := controllers.CreateDomain(domain)
2024-04-07 05:08:30 +00:00
if err != nil {
2024-04-03 09:05:12 +00:00
errorHandler(c, err)
return
}
c.JSON(http.StatusCreated, Response{
Succeed: true,
2024-04-07 05:08:30 +00:00
Data: domain,
2024-04-03 09:05:12 +00:00
})
}
2024-04-09 13:16:19 +00:00
func updateDomain(c *gin.Context) {
2024-04-03 09:05:12 +00:00
domain := &models.Domain{}
if err := c.BindJSON(domain); err != nil {
c.JSON(http.StatusBadRequest, Response{
Succeed: false,
Message: err.Error(),
})
return
}
2024-04-09 08:28:18 +00:00
if err := controllers.UpdateDomain(domain); err != nil {
2024-04-03 09:05:12 +00:00
errorHandler(c, err)
return
}
c.JSON(http.StatusOK, Response{
Succeed: true,
})
}
2024-04-09 13:16:19 +00:00
func deleteDomain(c *gin.Context) {
2024-04-03 09:05:12 +00:00
id := c.Param("id")
2024-04-09 08:28:18 +00:00
if err := controllers.DeleteDomain(id); err != nil {
2024-04-03 09:05:12 +00:00
errorHandler(c, err)
return
}
c.JSON(http.StatusNoContent, Response{
Succeed: true,
})
}