Initial creation of endpoint to send messages to public reporters
This commit is contained in:
parent
9707e8793b
commit
cc95c38ab5
12 changed files with 240 additions and 20 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue