37 lines
1.0 KiB
Go
37 lines
1.0 KiB
Go
package download
|
|
|
|
import "github.com/gofiber/fiber/v2"
|
|
|
|
type Handler struct {
|
|
svc *Service
|
|
}
|
|
|
|
func NewHandler(svc *Service) *Handler {
|
|
return &Handler{svc: svc}
|
|
}
|
|
|
|
func (h *Handler) GetInfo(c *fiber.Ctx) error {
|
|
info, err := h.svc.GetInfo()
|
|
if err != nil {
|
|
return c.Status(fiber.StatusNotFound).JSON(fiber.Map{"error": "다운로드 정보가 없습니다"})
|
|
}
|
|
return c.JSON(info)
|
|
}
|
|
|
|
func (h *Handler) Upsert(c *fiber.Ctx) error {
|
|
var body struct {
|
|
URL string `json:"url"`
|
|
Version string `json:"version"`
|
|
FileName string `json:"fileName"`
|
|
FileSize string `json:"fileSize"`
|
|
}
|
|
if err := c.BodyParser(&body); err != nil || body.URL == "" || body.Version == "" {
|
|
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "url과 version은 필수입니다"})
|
|
}
|
|
info, err := h.svc.Upsert(body.URL, body.Version, body.FileName, body.FileSize)
|
|
if err != nil {
|
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{"error": "업데이트에 실패했습니다"})
|
|
}
|
|
return c.JSON(info)
|
|
}
|