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
|
||||
|
||||
Reference in New Issue
Block a user