reCoreD-UI/server/handlers_domains.go

78 lines
1.3 KiB
Go
Raw Normal View History

2024-04-03 09:05:12 +00:00
package server
import (
"net/http"
"reCoreD-UI/models"
"github.com/gin-gonic/gin"
)
func (s *Server) getDomains(c *gin.Context) {
domains, err := s.controller.GetDomains("")
if err != nil {
errorHandler(c, err)
return
}
c.JSON(http.StatusOK, Response{
Succeed: true,
Data: domains,
})
}
func (s *Server) createDomain(c *gin.Context) {
domain := &models.Domain{}
if err := c.BindJSON(domain); err != nil {
c.JSON(http.StatusBadRequest, Response{
Succeed: false,
Message: err.Error(),
})
return
}
2024-04-07 05:08:30 +00:00
domain, err := s.controller.CreateDomain(domain)
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
})
}
func (s *Server) updateDomain(c *gin.Context) {
domain := &models.Domain{}
if err := c.BindJSON(domain); err != nil {
c.JSON(http.StatusBadRequest, Response{
Succeed: false,
Message: err.Error(),
})
return
}
if err := s.controller.UpdateDomain(domain); err != nil {
errorHandler(c, err)
return
}
c.JSON(http.StatusOK, Response{
Succeed: true,
})
}
func (s *Server) deleteDomain(c *gin.Context) {
id := c.Param("id")
if err := s.controller.DeleteDomain(id); err != nil {
errorHandler(c, err)
return
}
c.JSON(http.StatusNoContent, Response{
Succeed: true,
})
}