diff --git a/internal/download/handler.go b/internal/download/handler.go index 0ebb15a..f6bc46d 100644 --- a/internal/download/handler.go +++ b/internal/download/handler.go @@ -24,11 +24,12 @@ func (h *Handler) Upsert(c *fiber.Ctx) error { Version string `json:"version"` FileName string `json:"fileName"` FileSize string `json:"fileSize"` + FileHash string `json:"fileHash"` } - if err := c.BodyParser(&body); err != nil || body.URL == "" || body.Version == "" { - return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "url과 version은 필수입니다"}) + if err := c.BodyParser(&body); err != nil || body.URL == "" || body.Version == "" || body.FileHash == "" { + return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "url, version, fileHash는 필수입니다"}) } - info, err := h.svc.Upsert(body.URL, body.Version, body.FileName, body.FileSize) + info, err := h.svc.Upsert(body.URL, body.Version, body.FileName, body.FileSize, body.FileHash) if err != nil { return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{"error": "업데이트에 실패했습니다"}) } diff --git a/internal/download/model.go b/internal/download/model.go index 5a78800..8a26cd6 100644 --- a/internal/download/model.go +++ b/internal/download/model.go @@ -15,4 +15,5 @@ type Info struct { Version string `json:"version" gorm:"not null"` FileName string `json:"fileName" gorm:"not null"` FileSize string `json:"fileSize" gorm:"not null"` + FileHash string `json:"fileHash" gorm:"not null;default:''"` } diff --git a/internal/download/service.go b/internal/download/service.go index 413f682..42ef60d 100644 --- a/internal/download/service.go +++ b/internal/download/service.go @@ -12,7 +12,7 @@ func (s *Service) GetInfo() (*Info, error) { return s.repo.GetLatest() } -func (s *Service) Upsert(url, version, fileName, fileSize string) (*Info, error) { +func (s *Service) Upsert(url, version, fileName, fileSize, fileHash string) (*Info, error) { info, err := s.repo.GetLatest() if err != nil { info = &Info{} @@ -21,5 +21,6 @@ func (s *Service) Upsert(url, version, fileName, fileSize string) (*Info, error) info.Version = version info.FileName = fileName info.FileSize = fileSize + info.FileHash = fileHash return info, s.repo.Save(info) }