Beispiel #1
0
func AddRoutes(r *mux.Router, db *sqlx.DB) {
	rh := handler.Crud{}
	rv := Validator{}
	rd := Decoder{Whitelist: []string{"Latitude", "Longitude"}}
	repo := Repository{Db: db}

	r.HandleFunc("/rocks", rh.Index(repo, []string{"id", "before", "after", "latitude", "longitude", "createdAt", "updatedAt"}, []string{"id", "latitude", "longitude", "createdAt", "updatedAt"}, rv)).Methods("GET")
	r.HandleFunc("/rocks/{id:[0-9]+}", rh.Show(repo)).Methods("GET")
	r.HandleFunc("/rocks", rh.Create(repo, rd, rv)).Methods("POST")
	r.HandleFunc("/rocks/{id:[0-9]+}", rh.Update(repo, rd, rv)).Methods("PATCH")
	r.HandleFunc("/rocks/{id:[0-9]+}", rh.Destroy(repo)).Methods("DELETE")
}
Beispiel #2
0
func AddRoutes(r *mux.Router, db *sqlx.DB) {
	ch := handler.Crud{}
	cv := Validator{}
	cd := Decoder{Whitelist: []string{"Name", "Rating", "Description"}}

	repo := Repository{Db: db}

	r.HandleFunc("/climbs", ch.Index(repo, []string{"bounds", "id", "rockId", "before", "after", "rating", "createdAt", "updatedAt"}, []string{"bounds", "id", "rating", "createdAt", "updatedAt"}, cv)).Methods("GET")
	r.HandleFunc("/climbs/{id:[0-9]+}", ch.Show(repo)).Methods("GET")
	r.HandleFunc("/climbs/{id:[0-9]+}", ch.Update(repo, cd, cv)).Methods("PATCH")
	r.HandleFunc("/climbs/{id:[0-9]+}", ch.Destroy(repo)).Methods("DELETE")
	r.HandleFunc("/rocks/{id:[0-9]+}/climbs", ch.Create(repo, cd, cv)).Methods("POST")
}
Beispiel #3
0
				rep:          DestroyerErrorStub{},
				expectedCode: 500,
				expectedBody: serverError,
			}),
		)
	})

	Describe("#Update", func() {
		update := func(s UpdaterCase) {
			w := httptest.NewRecorder()
			r, err := http.NewRequest("PATCH", "http://example.com", nil)
			Expect(err).ToNot(HaveOccurred())
			c := handler.Crud{}

			// When
			c.Update(s.rep, s.d, s.v)(w, r)

			// Expect
			Expect(w.Code).To(Equal(s.expectedCode))
			for key, value := range s.expectedHeaders {
				Expect(w.Header().Get(key)).To(Equal(value))
			}
			Expect(w.Body.String()).To(Equal(s.expectedBody))
		}

		DescribeTable("Update",
			update,
			Entry("without error", UpdaterCase{
				rep:             UpdaterStub{},
				d:               ModelDecoder{},
				v:               ModelValidationStub{},