feat: add monitoring marked articles and retention updates
This commit is contained in:
@@ -25,6 +25,12 @@ type monitoringCollectNowRequest struct {
|
||||
TargetClientID *string `json:"target_client_id"`
|
||||
}
|
||||
|
||||
type monitoringMarkedArticleRequest struct {
|
||||
ArticleTitle string `json:"article_title"`
|
||||
OriginalURL string `json:"original_url"`
|
||||
BrandID *int64 `json:"brand_id"`
|
||||
}
|
||||
|
||||
func NewMonitoringHandler(a *bootstrap.App) *MonitoringHandler {
|
||||
return &MonitoringHandler{
|
||||
svc: a.MonitoringService,
|
||||
@@ -178,6 +184,86 @@ func (h *MonitoringHandler) CollectNow(c *gin.Context) {
|
||||
response.Success(c, data)
|
||||
}
|
||||
|
||||
func (h *MonitoringHandler) ListMarkedArticles(c *gin.Context) {
|
||||
page, err := parseOptionalInt(c.Query("page"))
|
||||
if err != nil {
|
||||
response.Error(c, response.ErrBadRequest(40031, "invalid_page", "page must be a number"))
|
||||
return
|
||||
}
|
||||
pageSize, err := parseOptionalInt(c.Query("page_size"))
|
||||
if err != nil {
|
||||
response.Error(c, response.ErrBadRequest(40031, "invalid_page_size", "page_size must be a number"))
|
||||
return
|
||||
}
|
||||
data, svcErr := h.svc.ListMarkedArticles(c.Request.Context(), app.MonitoringMarkedArticleListParams{
|
||||
Domain: c.Query("domain"),
|
||||
Title: c.Query("title"),
|
||||
CreatedFrom: c.Query("created_from"),
|
||||
CreatedTo: c.Query("created_to"),
|
||||
Page: page,
|
||||
PageSize: pageSize,
|
||||
})
|
||||
if svcErr != nil {
|
||||
response.Error(c, svcErr)
|
||||
return
|
||||
}
|
||||
response.Success(c, data)
|
||||
}
|
||||
|
||||
func (h *MonitoringHandler) CreateMarkedArticle(c *gin.Context) {
|
||||
var req monitoringMarkedArticleRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
response.Error(c, response.ErrBadRequest(40031, "invalid_marked_article_request", "marked article request is invalid"))
|
||||
return
|
||||
}
|
||||
data, svcErr := h.svc.CreateMarkedArticle(c.Request.Context(), app.MonitoringMarkedArticleRequest{
|
||||
ArticleTitle: req.ArticleTitle,
|
||||
OriginalURL: req.OriginalURL,
|
||||
BrandID: req.BrandID,
|
||||
})
|
||||
if svcErr != nil {
|
||||
response.Error(c, svcErr)
|
||||
return
|
||||
}
|
||||
response.Success(c, data)
|
||||
}
|
||||
|
||||
func (h *MonitoringHandler) UpdateMarkedArticle(c *gin.Context) {
|
||||
id, err := strconv.ParseInt(c.Param("id"), 10, 64)
|
||||
if err != nil {
|
||||
response.Error(c, response.ErrBadRequest(40031, "invalid_marked_article_id", "marked article id must be a number"))
|
||||
return
|
||||
}
|
||||
var req monitoringMarkedArticleRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
response.Error(c, response.ErrBadRequest(40031, "invalid_marked_article_request", "marked article request is invalid"))
|
||||
return
|
||||
}
|
||||
data, svcErr := h.svc.UpdateMarkedArticle(c.Request.Context(), id, app.MonitoringMarkedArticleRequest{
|
||||
ArticleTitle: req.ArticleTitle,
|
||||
OriginalURL: req.OriginalURL,
|
||||
BrandID: req.BrandID,
|
||||
})
|
||||
if svcErr != nil {
|
||||
response.Error(c, svcErr)
|
||||
return
|
||||
}
|
||||
response.Success(c, data)
|
||||
}
|
||||
|
||||
func (h *MonitoringHandler) DeleteMarkedArticle(c *gin.Context) {
|
||||
id, err := strconv.ParseInt(c.Param("id"), 10, 64)
|
||||
if err != nil {
|
||||
response.Error(c, response.ErrBadRequest(40031, "invalid_marked_article_id", "marked article id must be a number"))
|
||||
return
|
||||
}
|
||||
if svcErr := h.svc.DeleteMarkedArticle(c.Request.Context(), id); svcErr != nil {
|
||||
response.Error(c, svcErr)
|
||||
return
|
||||
}
|
||||
response.Success(c, gin.H{"ok": true})
|
||||
}
|
||||
|
||||
func parseOptionalInt64(raw string) (int64, error) {
|
||||
if raw == "" {
|
||||
return 0, nil
|
||||
|
||||
@@ -257,6 +257,10 @@ func RegisterRoutes(app *bootstrap.App) {
|
||||
monitoringHandler := NewMonitoringHandler(app)
|
||||
monitoring.GET("/dashboard/composite", monitoringHandler.DashboardComposite)
|
||||
monitoring.GET("/citation-summary", monitoringHandler.CitationSummary)
|
||||
monitoring.GET("/marked-articles", monitoringHandler.ListMarkedArticles)
|
||||
monitoring.POST("/marked-articles", monitoringHandler.CreateMarkedArticle)
|
||||
monitoring.PUT("/marked-articles/:id", monitoringHandler.UpdateMarkedArticle)
|
||||
monitoring.DELETE("/marked-articles/:id", monitoringHandler.DeleteMarkedArticle)
|
||||
monitoring.GET("/brands/:brand_id/questions/:question_id/detail", monitoringHandler.QuestionDetail)
|
||||
monitoring.POST("/brands/:brand_id/collect-now", monitoringHandler.CollectNow)
|
||||
|
||||
|
||||
@@ -42,6 +42,10 @@ func TestProtectedRoutes_RequireAuth(t *testing.T) {
|
||||
{http.MethodGet, "/api/tenant/brands"},
|
||||
{http.MethodGet, "/api/tenant/brands/library-summary"},
|
||||
{http.MethodGet, "/api/tenant/monitoring/brands/:brand_id/questions/:question_id/detail"},
|
||||
{http.MethodGet, "/api/tenant/monitoring/marked-articles"},
|
||||
{http.MethodPost, "/api/tenant/monitoring/marked-articles"},
|
||||
{http.MethodPut, "/api/tenant/monitoring/marked-articles/:id"},
|
||||
{http.MethodDelete, "/api/tenant/monitoring/marked-articles/:id"},
|
||||
{http.MethodPost, "/api/tenant/brands"},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user