2
0
mirror of https://github.com/acepanel/panel.git synced 2026-02-05 00:39:32 +08:00
Files
panel/internal/service/container_image.go
2024-10-27 22:52:42 +08:00

76 lines
1.6 KiB
Go

package service
import (
"net/http"
"github.com/go-rat/chix"
"github.com/TheTNB/panel/internal/biz"
"github.com/TheTNB/panel/internal/data"
"github.com/TheTNB/panel/internal/http/request"
)
type ContainerImageService struct {
containerImageRepo biz.ContainerImageRepo
}
func NewContainerImageService() *ContainerImageService {
return &ContainerImageService{
containerImageRepo: data.NewContainerImageRepo(),
}
}
func (s *ContainerImageService) List(w http.ResponseWriter, r *http.Request) {
images, err := s.containerImageRepo.List()
if err != nil {
Error(w, http.StatusInternalServerError, "%v", err)
return
}
paged, total := Paginate(r, images)
Success(w, chix.M{
"total": total,
"items": paged,
})
}
func (s *ContainerImageService) Pull(w http.ResponseWriter, r *http.Request) {
req, err := Bind[request.ContainerImagePull](r)
if err != nil {
Error(w, http.StatusUnprocessableEntity, "%v", err)
return
}
if err = s.containerImageRepo.Pull(req); err != nil {
Error(w, http.StatusInternalServerError, "%v", err)
return
}
Success(w, nil)
}
func (s *ContainerImageService) Remove(w http.ResponseWriter, r *http.Request) {
req, err := Bind[request.ContainerImageID](r)
if err != nil {
Error(w, http.StatusUnprocessableEntity, "%v", err)
return
}
if err = s.containerImageRepo.Remove(req.ID); err != nil {
Error(w, http.StatusInternalServerError, "%v", err)
return
}
Success(w, nil)
}
func (s *ContainerImageService) Prune(w http.ResponseWriter, r *http.Request) {
if err := s.containerImageRepo.Prune(); err != nil {
Error(w, http.StatusInternalServerError, "%v", err)
return
}
Success(w, nil)
}