package web

import (
	"net/http"

	"github.com/Jaculabilis/intake/core"
	"github.com/Jaculabilis/intake/web/html"
)

func (env *Env) getSource(writer http.ResponseWriter, req *http.Request) {
	source := req.PathValue("source")
	if source == "" {
		http.NotFound(writer, req)
		return
	}

	// TODO this needs to properly error if the source doesn't exist instead of just returning []
	items, err := core.GetAllItemsForSource(env.db, source)
	if err != nil {
		http.NotFound(writer, req)
		return
	}
	data := html.FeedData{
		Items: items,
	}
	html.Feed(writer, data)
}