58 lines
1.6 KiB
Go
58 lines
1.6 KiB
Go
package api
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"gitea.starryskymeow.cn/xkm/educode-controller/internal/k8s"
|
|
"gitea.starryskymeow.cn/xkm/educode-controller/internal/types"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func (h *Handler) createWorkspace(c *gin.Context) {
|
|
var req types.Workspace
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
c.JSON(http.StatusBadRequest, gin.H{"success": false, "message": err.Error()})
|
|
return
|
|
}
|
|
if !isValidDNS1035Label(req.ID) {
|
|
c.JSON(http.StatusBadRequest, gin.H{"success": false, "message": "a DNS-1035 label must consist of lower case alphanumeric characters or '-', start with an alphabetic character, and end with an alphanumeric character (e.g. 'my-name', or 'abc-123')"})
|
|
return
|
|
}
|
|
|
|
err := k8s.CreateWorkspace(&req, h.clientset)
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"success": false, "message": err.Error()})
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusAccepted, gin.H{"success": true})
|
|
}
|
|
|
|
func (h *Handler) deleteWorkspace(c *gin.Context) {
|
|
ID := c.Param("ID")
|
|
|
|
err := k8s.DeleteWorkspace(ID, h.clientset)
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"success": false, "message": err.Error()})
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusAccepted, gin.H{"success": true})
|
|
}
|
|
|
|
func (h *Handler) getWorkspaceByID(c *gin.Context) {
|
|
// workspaceID := c.Param("workspaceID")
|
|
|
|
// TODO: Call k8s manager to get resource status
|
|
}
|
|
|
|
func (h *Handler) getWorkspace(c *gin.Context) {
|
|
// TODO: Call k8s manager to get resource status
|
|
}
|
|
|
|
func (h *Handler) extendWorkspace(c *gin.Context) {
|
|
// workspaceID := c.Param("workspaceID")
|
|
|
|
// TODO: Call k8s manager to patch resource annotation
|
|
}
|