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
54 lines (43 loc) · 1.71 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
package episode
import (
"time"
"github.com/factly/dega-server/config"
coreModel "github.com/factly/dega-server/service/core/model"
"github.com/factly/dega-server/service/podcast/model"
"github.com/factly/dega-server/util"
"github.com/go-chi/chi"
"github.com/jinzhu/gorm/dialects/postgres"
)
// episode model
type episode struct {
Title string `json:"title" validate:"required,min=3,max=50"`
Slug string `json:"slug"`
Season int `json:"season" validate:"required"`
Episode int `json:"episode" validate:"required"`
AudioURL string `json:"audio_url" validate:"required"`
PodcastID uint `json:"podcast_id"`
Description postgres.Jsonb `json:"description" swaggertype:"primitive,string"`
PublishedDate *time.Time `json:"published_date" sql:"DEFAULT:NULL"`
MediumID uint `json:"medium_id"`
SpaceID uint `json:"space_id"`
AuthorIDs []uint `json:"author_ids"`
MetaFields postgres.Jsonb `json:"meta_fields" swaggertype:"primitive,string"`
}
type episodeData struct {
model.Episode
Authors []coreModel.Author `json:"authors"`
}
var episodeUser config.ContextKey = "episode_user"
// Router - Group of episode router
func Router() chi.Router {
r := chi.NewRouter()
entity := "episodes"
r.With(util.CheckKetoPolicy(entity, "get")).Get("/", list)
r.With(util.CheckKetoPolicy(entity, "create")).Post("/", create)
r.Route("/{episode_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
}