Newer
Older
"github.com/gorilla/mux"
)
type api struct {
func Init(dbPath string, signKey string, mail *Mail, r *mux.Router) error {
if err != nil {
return err
}
r.HandleFunc("/signin", a.SignIn).Methods("POST")
r.HandleFunc("/reset", a.SendPasswordReset).Methods("POST")
r.HandleFunc("/reset/{token}", a.ValidatePasswordReset).Methods("GET")
r.HandleFunc("/reset/{token}", a.PasswordReset).Methods("PUT")
r.HandleFunc("/member", a.authAdmin(a.ListMembers)).Methods("GET")
r.HandleFunc("/member", a.authAdmin(a.AddMember)).Methods("POST")
r.HandleFunc("/member/me", a.authNum(a.getMemberNum)).Methods("GET")
r.HandleFunc("/member/me", a.authNum(a.UpdateMemberMe)).Methods("PUT")
r.HandleFunc("/member/{num:[0-9]+}", a.authAdmin(a.GetMember)).Methods("GET")
r.HandleFunc("/member/{num:[0-9]+}", a.authAdmin(a.UpdateMember)).Methods("PUT")
r.HandleFunc("/member/{num:[0-9]+}", a.authAdmin(a.DeleteMember)).Methods("DELETE")
r.HandleFunc("/member/{num:[0-9]+}/transactions", a.authAdmin(a.GetMemberTransactions)).Methods("GET")
r.HandleFunc("/member/{num:[0-9]+}/purchase", a.authAdminNum(a.AddMemberPurchase)).Methods("POST")
r.HandleFunc("/product", a.authAdmin(a.AddProduct)).Methods("POST")
r.HandleFunc("/product/{code:[0-9]+}", a.auth(a.GetProduct)).Methods("GET")
r.HandleFunc("/product/{code:[0-9]+}", a.authAdmin(a.UpdateProduct)).Methods("PUT")
r.HandleFunc("/product/{code:[0-9]+}", a.authAdmin(a.DeleteProduct)).Methods("DELETE")
r.HandleFunc("/supplier", a.auth(a.ListSuppliers)).Methods("GET")
r.HandleFunc("/supplier", a.authAdmin(a.AddSupplier)).Methods("POST")
r.HandleFunc("/transaction", a.authAdmin(a.ListTransactions)).Methods("GET")
r.HandleFunc("/transaction/{id:[0-9]+}", a.authNumRole(a.GetTransaction)).Methods("GET")
r.HandleFunc("/transaction/mine", a.authNum(a.getTransactionsByMember)).Methods("GET")
r.HandleFunc("/purchase", a.authNum(a.AddPurchase)).Methods("POST")
r.HandleFunc("/topup", a.authAdminNum(a.AddTopup)).Methods("POST")
r.HandleFunc("/order", a.authOrderNum(a.AddOrder)).Methods("POST")
r.HandleFunc("/order/{id:[0-9]+}", a.authNum(a.GetOrder)).Methods("GET")
r.HandleFunc("/order/{id:[0-9]+}", a.authNumRole(a.UpdateOrder)).Methods("PUT")
r.HandleFunc("/order/{id:[0-9]+}", a.authNumRole(a.DeleteOrder)).Methods("DELETE")
r.HandleFunc("/order/active", a.auth(a.ListActiveOrders)).Methods("GET")
r.HandleFunc("/order/picks", a.authOrderNum(a.ListOrderPicks)).Methods("GET")
r.HandleFunc("/order/{id:[0-9]+}/purchase", a.authNum(a.AddOrderPurchase)).Methods("POST")