comparison pkg/controllers/routes.go @ 442:fc37e7072022

Moved some models used in controllers to to model package because they may be needed elsewhere (e.g. GeoServer config).
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 21 Aug 2018 16:57:55 +0200
parents 76a76691a298
children 5e8ac1c67fe6
comparison
equal deleted inserted replaced
441:76a76691a298 442:fc37e7072022
6 6
7 "github.com/gorilla/mux" 7 "github.com/gorilla/mux"
8 8
9 "gemma.intevation.de/gemma/pkg/auth" 9 "gemma.intevation.de/gemma/pkg/auth"
10 "gemma.intevation.de/gemma/pkg/middleware" 10 "gemma.intevation.de/gemma/pkg/middleware"
11 "gemma.intevation.de/gemma/pkg/models"
11 ) 12 )
12 13
13 func BindRoutes(m *mux.Router) { 14 func BindRoutes(m *mux.Router) {
14 15
15 api := m.PathPrefix("/api").Subrouter() 16 api := m.PathPrefix("/api").Subrouter()
23 api.Handle("/users", all(&JSONHandler{ 24 api.Handle("/users", all(&JSONHandler{
24 Handle: listUsers, 25 Handle: listUsers,
25 })).Methods(http.MethodGet) 26 })).Methods(http.MethodGet)
26 27
27 api.Handle("/users", sysAdmin(&JSONHandler{ 28 api.Handle("/users", sysAdmin(&JSONHandler{
28 Input: func() interface{} { return new(User) }, 29 Input: func() interface{} { return new(models.User) },
29 Handle: createUser, 30 Handle: createUser,
30 })).Methods(http.MethodPost) 31 })).Methods(http.MethodPost)
31 32
32 api.Handle("/users/{user}", all(&JSONHandler{ 33 api.Handle("/users/{user}", all(&JSONHandler{
33 Handle: listUser, 34 Handle: listUser,
34 })).Methods(http.MethodGet) 35 })).Methods(http.MethodGet)
35 36
36 api.Handle("/users/{user}", all(&JSONHandler{ 37 api.Handle("/users/{user}", all(&JSONHandler{
37 Input: func() interface{} { return new(User) }, 38 Input: func() interface{} { return new(models.User) },
38 Handle: updateUser, 39 Handle: updateUser,
39 })).Methods(http.MethodPut) 40 })).Methods(http.MethodPut)
40 41
41 api.Handle("/users/{user}", sysAdmin(&JSONHandler{ 42 api.Handle("/users/{user}", sysAdmin(&JSONHandler{
42 Handle: deleteUser, 43 Handle: deleteUser,
43 })).Methods(http.MethodDelete) 44 })).Methods(http.MethodDelete)
44 45
45 // Password resets. 46 // Password resets.
46 api.Handle("/users/passwordreset", &JSONHandler{ 47 api.Handle("/users/passwordreset", &JSONHandler{
47 Input: func() interface{} { return new(PWResetUser) }, 48 Input: func() interface{} { return new(models.PWResetUser) },
48 Handle: passwordResetRequest, 49 Handle: passwordResetRequest,
49 }).Methods(http.MethodPost) 50 }).Methods(http.MethodPost)
50 51
51 api.Handle("/users/passwordreset/{hash}", &JSONHandler{ 52 api.Handle("/users/passwordreset/{hash}", &JSONHandler{
52 Handle: passwordReset, 53 Handle: passwordReset,
53 }).Methods(http.MethodGet) 54 }).Methods(http.MethodGet)
54 55
55 // External proxies. 56 // External proxies.
56 proxy := &httputil.ReverseProxy{ 57 proxy := &httputil.ReverseProxy{
57 Director: proxyDirector(externalServices.find), 58 Director: proxyDirector(models.ExternalServices.Find),
58 ModifyResponse: proxyModifyResponse("/api/external/"), 59 ModifyResponse: proxyModifyResponse("/api/external/"),
59 } 60 }
60 61
61 api.Handle("/external/{hash}/{url}", proxy). 62 api.Handle("/external/{hash}/{url}", proxy).
62 Methods( 63 Methods(
68 http.MethodGet, http.MethodPost, 69 http.MethodGet, http.MethodPost,
69 http.MethodPut, http.MethodDelete) 70 http.MethodPut, http.MethodDelete)
70 71
71 // Internal proxies. 72 // Internal proxies.
72 internal := &httputil.ReverseProxy{ 73 internal := &httputil.ReverseProxy{
73 Director: proxyDirector(publishedServices.find), 74 Director: proxyDirector(models.PublishedServices.Find),
74 ModifyResponse: proxyModifyResponse("/api/internal/"), 75 ModifyResponse: proxyModifyResponse("/api/internal/"),
75 } 76 }
76 77
77 internalAuth := all( 78 internalAuth := all(
78 middleware.ModifyQuery(internal, middleware.InjectUser)) 79 middleware.ModifyQuery(internal, middleware.InjectUser))