Skip to content

[Schedules 2/8] CRUD API endpoints for Schedules #30

@sre-helmcode

Description

@sre-helmcode

Implementation Order: 2 of 8

Depends on: #29 (models)
Feature: Schedules — Recurring automated tasks for AI agent teams

Summary

Implement the REST API endpoints for managing schedules and viewing run history.

Endpoints

Schedules CRUD

Method Path Description
GET /api/schedules List all schedules (include team name via join/preload)
POST /api/schedules Create a new schedule
GET /api/schedules/:id Get schedule by ID
PUT /api/schedules/:id Update a schedule
DELETE /api/schedules/:id Delete a schedule (and its runs)
PATCH /api/schedules/:id/toggle Toggle enabled/disabled

Schedule Runs

Method Path Description
GET /api/schedules/:id/runs List runs for a schedule (paginated, newest first)
GET /api/schedules/:id/runs/:runId Get a specific run detail

DTOs

CreateScheduleRequest

type CreateScheduleRequest struct {
    Name           string `json:"name" validate:"required"`
    TeamID         string `json:"team_id" validate:"required"`
    Prompt         string `json:"prompt" validate:"required"`
    CronExpression string `json:"cron_expression" validate:"required"`
    Timezone       string `json:"timezone"` // default UTC
    Enabled        bool   `json:"enabled"`  // default true
}

UpdateScheduleRequest

type UpdateScheduleRequest struct {
    Name           *string `json:"name"`
    Prompt         *string `json:"prompt"`
    CronExpression *string `json:"cron_expression"`
    Timezone       *string `json:"timezone"`
    Enabled        *bool   `json:"enabled"`
}

Validation

  • cron_expression must be a valid cron expression (use a parser library to validate)
  • timezone must be a valid IANA timezone (validate with time.LoadLocation())
  • team_id must reference an existing team
  • name must not be empty
  • On create, calculate and set next_run_at based on cron + timezone

Acceptance Criteria

  • All endpoints implemented and registered in routes.go
  • DTOs with proper validation
  • Cron expression validated on create/update
  • Timezone validated on create/update
  • next_run_at calculated on create and on update (when cron/timezone changes)
  • List endpoints return enriched data (team name, run count)
  • Delete cascades to ScheduleRuns
  • Unit/integration tests for all endpoints

Metadata

Metadata

Assignees

Labels

featureNew feature or request

Type

No type

Projects

Status

Todo

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions