Files

28 lines
684 B
Go

package api
import (
"github.com/gin-gonic/gin"
"household-book/service"
"net/http"
)
type BackupHandler struct{ svc *service.BackupService }
func NewBackupHandler(s *service.BackupService) *BackupHandler { return &BackupHandler{svc: s} }
func (h *BackupHandler) Status(c *gin.Context) {
v, e := h.svc.Status()
if e != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": "获取备份状态失败"})
return
}
c.JSON(http.StatusOK, v)
}
func (h *BackupHandler) Create(c *gin.Context) {
v, e := h.svc.Create(c.Request.Context())
if e != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": "创建备份失败"})
return
}
c.JSON(http.StatusOK, v)
}