This repository has been archived by the owner on Jun 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
routes.go
52 lines (41 loc) · 1.66 KB
/
routes.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
package catalog
import (
"time"
"github.com/factly/mande-server/model"
"github.com/go-chi/chi"
)
// Catalog request body
type catalog struct {
Title string `json:"title" validate:"required"`
Slug string `json:"slug" validate:"required"`
Price int `json:"price" validate:"required"`
Description string `json:"description"`
CurrencyID uint `json:"currency_id"`
FeaturedMediumID uint `json:"featured_medium_id"`
PublishedDate *time.Time `json:"published_date"`
ProductIDs []uint `json:"product_ids"`
ProductTitles []string `json:"product_titles"`
}
var userContext model.ContextKey = "catalog_user"
// PublicRouter - Group of catalog user router
func PublicRouter() chi.Router {
r := chi.NewRouter()
r.Get("/", list) // GET /catalogs - return list of catalogs
r.Get("/my", my) // GET /catalogs/my - return list of catalogs owned by user
r.Route("/{catalog_id}", func(r chi.Router) {
r.Get("/", details) // GET /catalogs/{catalog_id} - read a single catalog by :catalog_id
})
return r
}
// AdminRouter - Group of catalog user router
func AdminRouter() chi.Router {
r := chi.NewRouter()
r.Get("/", list) // GET /catalogs - return list of catalogs
r.Post("/", create) // POST /catalogs - create a new catalog and persist it
r.Route("/{catalog_id}", func(r chi.Router) {
r.Get("/", details) // GET /catalogs/{catalog_id} - read a single catalog by :catalog_id
r.Put("/", update) // PUT /catalogs/{catalog_id} - update a single catalog by :catalog_id
r.Delete("/", delete) // DELETE /catalogs/{catalog_id} - delete a single catalog by :catalog_id
})
return r
}