示例#1
0
	}

	type DestroyerCase struct {
		rep             repository.Destroyer
		id              int
		expectedCode    int
		expectedBody    string
		expectedHeaders map[string]string
	}

	Describe("#Destroy", func() {
		destroy := func(s DestroyerCase) {
			w := httptest.NewRecorder()
			r, err := http.NewRequest("DELETE", "http://example.com", nil)
			Expect(err).ToNot(HaveOccurred())
			c := handler.Crud{}

			// When
			c.Destroy(s.rep)(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("Destroy",
			destroy,
			Entry("without error", DestroyerCase{
示例#2
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")
}
示例#3
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")
}