feat: scaffold codespace backend
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"codespace/internal/model"
|
||||
"codespace/internal/service"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type processHandler struct {
|
||||
svc *service.ProcessService
|
||||
}
|
||||
|
||||
func (h *processHandler) start(c *gin.Context) {
|
||||
id := c.Param("id")
|
||||
if err := h.svc.Start(id); err != nil {
|
||||
writeError(c, err)
|
||||
return
|
||||
}
|
||||
c.Status(http.StatusNoContent)
|
||||
}
|
||||
|
||||
func (h *processHandler) stop(c *gin.Context) {
|
||||
id := c.Param("id")
|
||||
if err := h.svc.Stop(id); err != nil {
|
||||
writeError(c, err)
|
||||
return
|
||||
}
|
||||
c.Status(http.StatusNoContent)
|
||||
}
|
||||
|
||||
func (h *processHandler) restart(c *gin.Context) {
|
||||
id := c.Param("id")
|
||||
if err := h.svc.Restart(id); err != nil {
|
||||
writeError(c, err)
|
||||
return
|
||||
}
|
||||
c.Status(http.StatusNoContent)
|
||||
}
|
||||
|
||||
func (h *processHandler) status(c *gin.Context) {
|
||||
id := c.Param("id")
|
||||
status, err := h.svc.Status(id)
|
||||
if err != nil {
|
||||
writeError(c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, model.ProcessStatusResponse{
|
||||
WorkspaceID: status.WorkspaceID,
|
||||
Running: status.Running,
|
||||
PID: status.PID,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user