2022-12-15 15:13:01 +00:00
|
|
|
package handlers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2023-04-21 06:49:17 +00:00
|
|
|
. "github.com/reiver/greatape/components/api/protobuf"
|
|
|
|
. "github.com/reiver/greatape/components/contracts"
|
2022-12-15 15:13:01 +00:00
|
|
|
. "github.com/xeronith/diamante/contracts/network/http"
|
|
|
|
pipeline "github.com/xeronith/diamante/network/http"
|
|
|
|
)
|
|
|
|
|
|
|
|
type postToOutboxHandler struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func PostToOutboxHandler() IHttpHandler {
|
|
|
|
return &postToOutboxHandler{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (handler *postToOutboxHandler) Method() string {
|
|
|
|
return http.MethodPost
|
|
|
|
}
|
|
|
|
|
|
|
|
func (handler *postToOutboxHandler) Path() string {
|
2023-07-17 13:41:21 +00:00
|
|
|
return "/users/:username/outbox"
|
2022-12-15 15:13:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (handler *postToOutboxHandler) HandlerFunc() HttpHandlerFunc {
|
|
|
|
return func(x IServerDispatcher) error {
|
|
|
|
request := &PostToOutboxRequest{}
|
|
|
|
result := &PostToOutboxResult{}
|
|
|
|
|
|
|
|
onRequestUnmarshalled := func(request *PostToOutboxRequest) {
|
|
|
|
request.Username = x.Param("username")
|
|
|
|
}
|
|
|
|
|
2023-05-03 18:24:05 +00:00
|
|
|
onRequestProcessed := func(output *PostToOutboxResult) (string, []byte) {
|
|
|
|
return "application/activity+json; charset=utf-8", output.Body
|
|
|
|
}
|
|
|
|
|
2022-12-15 15:13:01 +00:00
|
|
|
return pipeline.Handle(x,
|
|
|
|
POST_TO_OUTBOX_REQUEST,
|
|
|
|
POST_TO_OUTBOX_RESULT,
|
|
|
|
request, result,
|
|
|
|
onRequestUnmarshalled,
|
2023-05-03 18:24:05 +00:00
|
|
|
onRequestProcessed,
|
2022-12-15 15:13:01 +00:00
|
|
|
false,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|