-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_story.go
36 lines (30 loc) · 924 Bytes
/
get_story.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
package handler
import (
"github.com/nsnikhil/stories/pkg/http/internal/contract"
"github.com/nsnikhil/stories/pkg/http/internal/util"
"github.com/nsnikhil/stories/pkg/liberr"
"github.com/nsnikhil/stories/pkg/story/service"
"net/http"
)
type GetStoryHandler struct {
svc service.StoryService
}
func (gs *GetStoryHandler) GetStory(resp http.ResponseWriter, req *http.Request) error {
var data contract.GetStoryRequest
err := util.ParseRequest(req, &data)
if err != nil {
return liberr.WithArgs(liberr.Operation("GetStoryHandler.GetStory"), err)
}
st, err := gs.svc.GetStory(data.StoryID)
if err != nil {
return liberr.WithArgs(liberr.Operation("GetStoryHandler.GetStory"), err)
}
//TODO: ADD SUCCESS LOG
util.WriteSuccessResponse(http.StatusOK, util.ConvertToDTO(st), resp)
return nil
}
func NewGetStoryHandler(svc service.StoryService) *GetStoryHandler {
return &GetStoryHandler{
svc: svc,
}
}