nidus-sync/api/publicreport.go

51 lines
1.5 KiB
Go
Raw Normal View History

package api
import (
"context"
2026-03-27 06:08:55 -07:00
"fmt"
"net/http"
nhttp "github.com/Gleipnir-Technology/nidus-sync/http"
"github.com/Gleipnir-Technology/nidus-sync/platform"
)
type formPublicreportSignal struct {
ReportID string `json:"reportID"`
}
2026-03-27 06:08:55 -07:00
func postPublicreportSignal(ctx context.Context, r *http.Request, user platform.User, req formPublicreportSignal) (string, *nhttp.ErrorWithStatus) {
signal_id, err := platform.SignalCreateFromPublicreport(ctx, user, req.ReportID)
if err != nil {
2026-03-27 06:08:55 -07:00
return "", nhttp.NewError("create signal: %w", err)
}
2026-03-27 06:08:55 -07:00
return fmt.Sprintf("/signal/%d", *signal_id), nil
}
type formPublicreportInvalid struct {
ReportID string `json:"reportID"`
}
2026-03-27 06:08:55 -07:00
func postPublicreportInvalid(ctx context.Context, r *http.Request, user platform.User, req formPublicreportSignal) (string, *nhttp.ErrorWithStatus) {
err := platform.PublicreportInvalid(ctx, user, req.ReportID)
if err != nil {
2026-03-27 06:08:55 -07:00
return "", nhttp.NewError("create signal: %w", err)
}
2026-03-27 06:08:55 -07:00
return fmt.Sprintf("/publicreport/%s", req.ReportID), nil
}
type formPublicreportMessage struct {
Message string `json:"message"`
ReportID string `json:"reportID"`
}
2026-03-27 06:08:55 -07:00
func postPublicreportMessage(ctx context.Context, r *http.Request, user platform.User, req formPublicreportMessage) (string, *nhttp.ErrorWithStatus) {
msg_id, err := platform.PublicReportMessageCreate(ctx, user, req.ReportID, req.Message)
if err != nil {
2026-03-27 06:08:55 -07:00
return "", nhttp.NewError("failed to create message: %s", err)
}
if msg_id == nil {
2026-03-27 06:08:55 -07:00
return "", nhttp.NewError("nil message id")
}
2026-03-27 06:08:55 -07:00
return fmt.Sprintf("/message/%d", *msg_id), nil
}