/
getDocumentHandler.go
47 lines (39 loc) · 1.17 KB
/
getDocumentHandler.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package documents
import (
"github.com/google/wire"
"github.com/luminosita/honeycomb/pkg/http/ctx"
"github.com/luminosita/honeycomb/pkg/http/handlers"
"github.com/luminosita/sample-bee/internal/interfaces/use-cases/documents"
)
var GetWireSet = wire.NewSet(NewGetDocumentHandler,
wire.Bind(new(handlers.Handler), new(*GetDocumentHandler)))
type GetDocumentHandler struct {
cd documents.GetDocumenter
}
func NewGetDocumentHandler(cd documents.GetDocumenter) *GetDocumentHandler {
return &GetDocumentHandler{
cd: cd,
}
}
// GetDocument godoc
// @Summary Show something
// @Description Get Document By ID
// @Tags documents
// @Accept json
// @Produce json
// @Param id path int true "Document ID"
// @Success 200 {object} string
// @Failure 400 {object} error
// @Failure 404 {object} error
// @Failure 500 {object} error
// @Router /documents/{id} [get]
func (h *GetDocumentHandler) Handle(ctx *ctx.Ctx) error {
documentId := ctx.Params["id"]
res, err := h.cd.Execute(&documents.GetDocumenterRequest{
DocumentId: documentId,
})
if err != nil {
return err
}
return ctx.SendResponse(res.Document)
}