refactor(ui): retire article feed and legacy jobs surfaces
Remove obsolete article and scrape-job screens and APIs, preserve reports, and clear legacy API caches from the service worker. Refs #8 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@ -254,34 +254,6 @@ func (h *Handler) UpdateSource(c *gin.Context) {
|
||||
httputil.OK(c, gin.H{"ok": true})
|
||||
}
|
||||
|
||||
// ── Scrape Jobs ────────────────────────────────────────────────────────────
|
||||
|
||||
func (h *Handler) ListScrapeJobs(c *gin.Context) {
|
||||
jobs, err := h.repo.ListScrapeJobs(100)
|
||||
if err != nil {
|
||||
httputil.InternalError(c, err)
|
||||
return
|
||||
}
|
||||
httputil.OK(c, jobs)
|
||||
}
|
||||
|
||||
func (h *Handler) TriggerScrapeJob(c *gin.Context) {
|
||||
type triggerRequest struct {
|
||||
SourceID string `json:"source_id" binding:"required"`
|
||||
}
|
||||
var req triggerRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
httputil.BadRequest(c, err)
|
||||
return
|
||||
}
|
||||
go func() {
|
||||
if err := h.registry.Run(req.SourceID); err != nil {
|
||||
fmt.Printf("scrape job error: %v\n", err)
|
||||
}
|
||||
}()
|
||||
c.JSON(http.StatusAccepted, gin.H{"ok": true, "message": "job started"})
|
||||
}
|
||||
|
||||
// ── Settings ───────────────────────────────────────────────────────────────
|
||||
|
||||
func (h *Handler) ListSettings(c *gin.Context) {
|
||||
|
||||
@ -1,36 +0,0 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/tradarr/backend/internal/httputil"
|
||||
)
|
||||
|
||||
func (h *Handler) ListArticles(c *gin.Context) {
|
||||
symbol := c.Query("symbol")
|
||||
limit, _ := strconv.Atoi(c.DefaultQuery("limit", "50"))
|
||||
offset, _ := strconv.Atoi(c.DefaultQuery("offset", "0"))
|
||||
if limit > 100 {
|
||||
limit = 100
|
||||
}
|
||||
articles, err := h.repo.ListArticles(symbol, limit, offset)
|
||||
if err != nil {
|
||||
httputil.InternalError(c, err)
|
||||
return
|
||||
}
|
||||
httputil.OK(c, articles)
|
||||
}
|
||||
|
||||
func (h *Handler) GetArticle(c *gin.Context) {
|
||||
article, err := h.repo.GetArticleByID(c.Param("id"))
|
||||
if err != nil {
|
||||
httputil.InternalError(c, err)
|
||||
return
|
||||
}
|
||||
if article == nil {
|
||||
httputil.NotFound(c)
|
||||
return
|
||||
}
|
||||
httputil.OK(c, article)
|
||||
}
|
||||
123
backend/internal/api/retired_surfaces_ticket8_test.go
Normal file
123
backend/internal/api/retired_surfaces_ticket8_test.go
Normal file
@ -0,0 +1,123 @@
|
||||
package api_test
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/tradarr/backend/internal/api"
|
||||
"github.com/tradarr/backend/internal/api/handlers"
|
||||
"github.com/tradarr/backend/internal/auth"
|
||||
"github.com/tradarr/backend/internal/config"
|
||||
"github.com/tradarr/backend/internal/models"
|
||||
)
|
||||
|
||||
func TestRetiredArticleAndScrapeJobEndpointsReturnNotFound(t *testing.T) {
|
||||
db, _ := ticket7DB(t)
|
||||
for _, statement := range []string{
|
||||
`CREATE TABLE sources (id UUID PRIMARY KEY, name TEXT NOT NULL)`,
|
||||
`CREATE TABLE articles (id UUID PRIMARY KEY, source_id UUID NOT NULL, title TEXT NOT NULL, content TEXT NOT NULL, url TEXT NOT NULL, published_at TIMESTAMPTZ, created_at TIMESTAMPTZ NOT NULL)`,
|
||||
`CREATE TABLE scrape_jobs (id UUID PRIMARY KEY, source_id UUID NOT NULL, status TEXT NOT NULL, started_at TIMESTAMPTZ, finished_at TIMESTAMPTZ, articles_found INT NOT NULL, error_msg TEXT NOT NULL, created_at TIMESTAMPTZ NOT NULL)`,
|
||||
`INSERT INTO sources (id,name) VALUES ('00000000-0000-0000-0000-000000000010','Fixture source')`,
|
||||
`INSERT INTO articles (id,source_id,title,content,url,created_at) VALUES ('00000000-0000-0000-0000-000000000001','00000000-0000-0000-0000-000000000010','private-title','private-body','https://private.test/article',NOW())`,
|
||||
`INSERT INTO scrape_jobs (id,source_id,status,articles_found,error_msg,created_at) VALUES ('00000000-0000-0000-0000-000000000020','00000000-0000-0000-0000-000000000010','done',1,'',NOW())`,
|
||||
} {
|
||||
if _, err := db.Exec(statement); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
// Snapshot every stored field, so an UPDATE cannot pass a row-count check.
|
||||
const snapshotSQL = `SELECT jsonb_build_object('articles',(SELECT jsonb_agg(to_jsonb(a) ORDER BY id) FROM articles a),'jobs',(SELECT jsonb_agg(to_jsonb(j) ORDER BY id) FROM scrape_jobs j))::text`
|
||||
var before, after string
|
||||
if err := db.QueryRow(snapshotSQL).Scan(&before); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, statement := range []string{
|
||||
`CREATE FUNCTION forbid_legacy_write() RETURNS trigger LANGUAGE plpgsql AS $$ BEGIN RAISE EXCEPTION 'legacy write prohibited'; END $$`,
|
||||
`CREATE TRIGGER article_write_guard BEFORE INSERT OR UPDATE OR DELETE ON articles FOR EACH STATEMENT EXECUTE FUNCTION forbid_legacy_write()`,
|
||||
`CREATE TRIGGER job_write_guard BEFORE INSERT OR UPDATE OR DELETE ON scrape_jobs FOR EACH STATEMENT EXECUTE FUNCTION forbid_legacy_write()`,
|
||||
} {
|
||||
if _, err := db.Exec(statement); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
var articlesBefore, jobsBefore int
|
||||
if err := db.QueryRow(`SELECT COUNT(*) FROM articles`).Scan(&articlesBefore); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := db.QueryRow(`SELECT COUNT(*) FROM scrape_jobs`).Scan(&jobsBefore); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
router := api.SetupRouter(handlers.New(models.NewRepository(db), &config.Config{JWTSecret: ticket7JWTSecret}, nil, nil, nil, nil), ticket7JWTSecret)
|
||||
userToken, err := auth.GenerateToken("00000000-0000-0000-0000-000000000001", "reader@example.test", "user", ticket7JWTSecret)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
adminToken, err := auth.GenerateToken("00000000-0000-0000-0000-000000000002", "admin@example.test", "admin", ticket7JWTSecret)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
path string
|
||||
role string
|
||||
method string
|
||||
}{
|
||||
{name: "article collection", path: "/api/articles", role: userToken, method: http.MethodGet},
|
||||
{name: "article detail", path: "/api/articles/00000000-0000-0000-0000-000000000001", role: userToken, method: http.MethodGet},
|
||||
{name: "admin scrape jobs", path: "/api/admin/scrape-jobs", role: adminToken, method: http.MethodGet},
|
||||
{name: "scrape trigger", path: "/api/admin/scrape-jobs/trigger", role: adminToken, method: http.MethodPost},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
request := httptest.NewRequest(tc.method, tc.path, nil)
|
||||
request.Header.Set("Authorization", "Bearer "+tc.role)
|
||||
response := httptest.NewRecorder()
|
||||
router.ServeHTTP(response, request)
|
||||
if response.Code != http.StatusNotFound {
|
||||
t.Fatalf("%s %s: got %d, want 404; body=%s", tc.method, tc.path, response.Code, response.Body.String())
|
||||
}
|
||||
})
|
||||
}
|
||||
for _, route := range router.Routes() {
|
||||
if route.Path == "/api/articles" || route.Path == "/api/articles/:id" || route.Path == "/api/admin/scrape-jobs" || route.Path == "/api/admin/scrape-jobs/trigger" {
|
||||
t.Errorf("retired route remains callable: %s %s", route.Method, route.Path)
|
||||
}
|
||||
}
|
||||
var articlesAfter, jobsAfter int
|
||||
if err := db.QueryRow(`SELECT COUNT(*) FROM articles`).Scan(&articlesAfter); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := db.QueryRow(`SELECT COUNT(*) FROM scrape_jobs`).Scan(&jobsAfter); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if articlesAfter != articlesBefore || jobsAfter != jobsBefore {
|
||||
t.Fatalf("retired requests changed persisted data: articles %d→%d, scrape jobs %d→%d", articlesBefore, articlesAfter, jobsBefore, jobsAfter)
|
||||
}
|
||||
if err := db.QueryRow(snapshotSQL).Scan(&after); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if before != after {
|
||||
t.Fatalf("historical records changed: before=%s after=%s", before, after)
|
||||
}
|
||||
t.Logf("no writes from retired requests: articles=%d, scrape_jobs=%d before and after", articlesAfter, jobsAfter)
|
||||
}
|
||||
|
||||
// Route retirement must also hold without a database or retrieval adapters.
|
||||
func TestRetiredSurfacesAreAbsentWithoutDatabase(t *testing.T) {
|
||||
router := api.SetupRouter(handlers.New(nil, &config.Config{}, nil, nil, nil, nil), ticket7JWTSecret)
|
||||
token, err := auth.GenerateToken("admin", "admin@example.test", "admin", ticket7JWTSecret)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, path := range []string{"/api/articles", "/api/articles/legacy-id", "/api/admin/scrape-jobs", "/api/admin/scrape-jobs/trigger"} {
|
||||
for _, method := range []string{http.MethodGet, http.MethodPost} {
|
||||
request := httptest.NewRequest(method, path, nil)
|
||||
request.Header.Set("Authorization", "Bearer "+token)
|
||||
response := httptest.NewRecorder()
|
||||
router.ServeHTTP(response, request)
|
||||
if response.Code != http.StatusNotFound {
|
||||
t.Fatalf("%s %s: status=%d", method, path, response.Code)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user