refactor: remove dataset cron records

This commit is contained in:
2026-07-23 23:08:25 +08:00
parent 3705d75e59
commit fbd142803a
14 changed files with 125 additions and 380 deletions

View File

@@ -54,14 +54,10 @@ type ItemPageDTO struct {
Offset int `json:"offset"`
}
type CronDTO struct {
ID string `json:"id"`
SourceID string `json:"sourceId"`
Status string `json:"status"`
LastRunAt *time.Time `json:"lastRunAt"`
LastResult string `json:"lastResult"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
type SyncResultDTO struct {
SourceID string `json:"sourceId"`
Status string `json:"status"`
Result string `json:"result"`
}
type DepositDTO struct {
@@ -91,8 +87,7 @@ func (h *Handler) Register(router gin.IRouter) {
router.POST("/dataset-items", h.createItem)
router.PATCH("/dataset-items/:id", h.updateItem)
router.POST("/dataset-items/:id/deposit", h.depositItem)
router.GET("/dataset-crons", h.listCrons)
router.POST("/dataset-crons/sync", h.queueSync)
router.POST("/dataset-sources/sync", h.syncSources)
}
func (h *Handler) listSources(c *gin.Context) {
@@ -309,38 +304,25 @@ func (h *Handler) depositItem(c *gin.Context) {
})
}
func (h *Handler) listCrons(c *gin.Context) {
func (h *Handler) syncSources(c *gin.Context) {
userID, ok := currentUser(c)
if !ok {
return
}
crons, err := h.service.ListCrons(userID)
results, err := h.service.SyncSources(c.Request.Context(), userID)
if err != nil {
writeError(c, err)
return
}
result := make([]CronDTO, 0, len(crons))
for _, cron := range crons {
result = append(result, cronDTO(cron))
response := make([]SyncResultDTO, 0, len(results))
for _, result := range results {
response = append(response, SyncResultDTO{
SourceID: result.SourceIdentity,
Status: result.Status,
Result: result.Result,
})
}
c.JSON(http.StatusOK, result)
}
func (h *Handler) queueSync(c *gin.Context) {
userID, ok := currentUser(c)
if !ok {
return
}
crons, err := h.service.QueueSources(userID)
if err != nil {
writeError(c, err)
return
}
result := make([]CronDTO, 0, len(crons))
for _, cron := range crons {
result = append(result, cronDTO(cron))
}
c.JSON(http.StatusAccepted, result)
c.JSON(http.StatusOK, response)
}
func currentUser(c *gin.Context) (uint, bool) {
@@ -390,14 +372,6 @@ func itemDTO(item models.SaDatasetItem) ItemDTO {
}
}
func cronDTO(cron models.SaDatasetCron) CronDTO {
return CronDTO{
ID: cron.Identity, SourceID: cron.SourceIdentity, Status: cron.Status,
LastRunAt: utcTime(cron.LastRunAt), LastResult: cron.LastResult,
CreatedAt: cron.CreatedAt.UTC(), UpdatedAt: cron.UpdatedAt.UTC(),
}
}
func optionalNonNegativeInt(value string) (int, error) {
if strings.TrimSpace(value) == "" {
return 0, nil