This repository has been archived by the owner on Jul 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
route.go
66 lines (56 loc) · 2.41 KB
/
route.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package post
import (
"time"
"github.com/factly/dega-server/config"
"github.com/factly/dega-server/service/core/model"
factCheckModel "github.com/factly/dega-server/service/fact-check/model"
"github.com/factly/dega-server/util"
"github.com/go-chi/chi"
"github.com/jinzhu/gorm/dialects/postgres"
)
// post request body
type post struct {
Title string `json:"title" validate:"required,min=3,max=150"`
Subtitle string `json:"subtitle"`
Slug string `json:"slug"`
Excerpt string `json:"excerpt"`
Description postgres.Jsonb `json:"description" swaggertype:"primitive,string"`
Status string `json:"status"`
IsPage bool `json:"is_page"`
IsFeatured bool `json:"is_featured"`
IsSticky bool `json:"is_sticky"`
IsHighlighted bool `json:"is_highlighted"`
FeaturedMediumID uint `json:"featured_medium_id"`
PublishedDate *time.Time `json:"published_date"`
FormatID uint `json:"format_id" validate:"required"`
SpaceID uint `json:"space_id"`
Meta postgres.Jsonb `json:"meta" swaggertype:"primitive,string"`
HeaderCode string `json:"header_code"`
FooterCode string `json:"footer_code"`
MetaFields postgres.Jsonb `json:"meta_fields" swaggertype:"primitive,string"`
CategoryIDs []uint `json:"category_ids"`
TagIDs []uint `json:"tag_ids"`
ClaimIDs []uint `json:"claim_ids"`
AuthorIDs []uint `json:"author_ids"`
}
type postData struct {
model.Post
Authors []model.Author `json:"authors"`
Claims []factCheckModel.Claim `json:"claims"`
ClaimOrder []uint `json:"claim_order"`
}
var userContext config.ContextKey = "post_user"
// Router - Group of post router
func Router() chi.Router {
r := chi.NewRouter()
entity := "posts"
r.With(util.CheckKetoPolicy(entity, "get")).Get("/", list)
r.With(util.CheckKetoPolicy(entity, "create")).Post("/", create)
r.With(util.CheckKetoPolicy(entity, "update")).Post("/templates", createTemplate)
r.Route("/{post_id}", func(r chi.Router) {
r.With(util.CheckKetoPolicy(entity, "get")).Get("/", details)
r.With(util.CheckKetoPolicy(entity, "update")).Put("/", update)
r.With(util.CheckKetoPolicy(entity, "delete")).Delete("/", delete)
})
return r
}