Initial creation of endpoint to send messages to public reporters

This commit is contained in:
Eli Ribble 2026-03-15 22:38:36 +00:00
parent 9707e8793b
commit cc95c38ab5
No known key found for this signature in database
12 changed files with 240 additions and 20 deletions

View file

@ -3,6 +3,7 @@ package api
import (
"context"
"net/http"
"strconv"
"github.com/Gleipnir-Technology/nidus-sync/config"
nhttp "github.com/Gleipnir-Technology/nidus-sync/http"
@ -39,3 +40,21 @@ func postPublicreportInvalid(ctx context.Context, r *http.Request, user platform
URI: config.MakeURLNidus("/publicreport/%s", req.ReportID),
}, nil
}
type formPublicreportMessage struct {
Message string `json:"message"`
ReportID string `json:"reportID"`
}
type createdMessage struct {
URI string `json:"uri"`
}
func postPublicreportMessage(ctx context.Context, r *http.Request, user platform.User, req formPublicreportMessage) (*createdMessage, *nhttp.ErrorWithStatus) {
msg_id, err := platform.PublicReportMessageCreate(ctx, user, req.ReportID, req.Message)
if err != nil {
return nil, nhttp.NewError("failed to create message: %s", err)
}
return &createdMessage{
URI: config.MakeURLNidus("/message/%s", strconv.Itoa(int(*msg_id))),
}, nil
}

View file

@ -23,6 +23,7 @@ func AddRoutes(r chi.Router) {
r.Method("GET", "/mosquito-source", auth.NewEnsureAuth(apiMosquitoSource))
r.Method("POST", "/publicreport/invalid", authenticatedHandlerJSONPost(postPublicreportInvalid))
r.Method("POST", "/publicreport/lead", authenticatedHandlerJSONPost(postPublicreportLead))
r.Method("POST", "/publicreport/message", authenticatedHandlerJSONPost(postPublicreportMessage))
r.Method("POST", "/review/pool", authenticatedHandlerJSONPost(postReviewPool))
r.Method("GET", "/review-task/pool", authenticatedHandlerJSON(listReviewTaskPool))
r.Method("GET", "/service-request", auth.NewEnsureAuth(apiServiceRequest))