2026-03-14 01:14:30 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
2026-03-27 06:08:55 -07:00
|
|
|
"fmt"
|
2026-03-14 01:14:30 +00:00
|
|
|
"net/http"
|
|
|
|
|
|
|
|
|
|
nhttp "github.com/Gleipnir-Technology/nidus-sync/http"
|
|
|
|
|
"github.com/Gleipnir-Technology/nidus-sync/platform"
|
|
|
|
|
)
|
|
|
|
|
|
2026-03-19 17:41:38 +00:00
|
|
|
type formPublicreportSignal struct {
|
2026-03-14 01:14:30 +00:00
|
|
|
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) {
|
2026-03-19 17:41:38 +00:00
|
|
|
signal_id, err := platform.SignalCreateFromPublicreport(ctx, user, req.ReportID)
|
2026-03-14 01:14:30 +00:00
|
|
|
if err != nil {
|
2026-03-27 06:08:55 -07:00
|
|
|
return "", nhttp.NewError("create signal: %w", err)
|
2026-03-14 01:14:30 +00:00
|
|
|
}
|
2026-03-27 06:08:55 -07:00
|
|
|
return fmt.Sprintf("/signal/%d", *signal_id), nil
|
2026-03-14 01:14:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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) {
|
2026-04-28 06:36:55 +00:00
|
|
|
err := platform.PublicReportInvalid(ctx, user, req.ReportID)
|
2026-03-14 01:14:30 +00:00
|
|
|
if err != nil {
|
2026-03-27 06:08:55 -07:00
|
|
|
return "", nhttp.NewError("create signal: %w", err)
|
2026-03-14 01:14:30 +00:00
|
|
|
}
|
2026-03-27 06:08:55 -07:00
|
|
|
return fmt.Sprintf("/publicreport/%s", req.ReportID), nil
|
2026-03-14 01:14:30 +00:00
|
|
|
}
|
2026-03-15 22:38:36 +00:00
|
|
|
|
|
|
|
|
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) {
|
2026-03-15 22:38:36 +00:00
|
|
|
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)
|
2026-03-15 22:38:36 +00:00
|
|
|
}
|
2026-03-18 15:36:20 +00:00
|
|
|
if msg_id == nil {
|
2026-03-27 06:08:55 -07:00
|
|
|
return "", nhttp.NewError("nil message id")
|
2026-03-18 15:36:20 +00:00
|
|
|
}
|
2026-03-27 06:08:55 -07:00
|
|
|
return fmt.Sprintf("/message/%d", *msg_id), nil
|
2026-03-15 22:38:36 +00:00
|
|
|
}
|