package handlers import ( "net/http" "strconv" "github.com/labstack/echo/v4" "gorm.io/gorm" "ytdlp-site/database" "ytdlp-site/originals" ) func SetTimestamp(c echo.Context) error { // Parse the ID from the URL parameter id, err := strconv.ParseUint(c.Param("id"), 10, 64) if err != nil { return c.JSON(http.StatusBadRequest, map[string]string{"error": "Invalid ID format"}) } // Define a struct to receive the timestamp from JSON type TimestampRequest struct { Timestamp string `json:"timestamp"` } // Parse the request body var req TimestampRequest if err := c.Bind(&req); err != nil { return c.JSON(http.StatusBadRequest, map[string]string{"error": "Invalid request body"}) } // Validate that timestamp was provided if req.Timestamp == "" { return c.JSON(http.StatusBadRequest, map[string]string{"error": "Timestamp is required"}) } // Get database connection db := database.Get() // Update the timestamp field with the value from the request result := db.Model(&originals.Original{}). Where("id = ?", id). Update("timestamp", req.Timestamp) // Handle database errors if result.Error != nil { log.Errorln(result.Error) return c.JSON(http.StatusInternalServerError, map[string]string{"error": "Database error"}) } // Check if record was found if result.RowsAffected == 0 { log.Errorln(gorm.ErrRecordNotFound) return c.JSON(http.StatusNotFound, map[string]string{"error": "Record not found"}) } return c.NoContent(http.StatusOK) }