update readme

and something else on the little things
This commit is contained in:
GenZmeY 2021-03-20 23:01:36 +03:00
parent ac25d1bfc6
commit 8eccf45b0c
3 changed files with 22 additions and 4 deletions

View File

@ -1 +1,20 @@
# go-jsonapi-example
# go-jsonapi-example
`make && make run`
## Create a new car:
`curl -X POST http://localhost:8080/v1/cars -d '{"data" : {"type" : "cars" , "attributes": {"brand" : "bmw", "model": "x5", "price": 999, "status": "OnTheWay"}}}'`
## List cars:
`curl -X GET http://localhost:8080/v1/cars`
## List paginated cars:
`curl -X GET 'http://localhost:8080/v1/cars?page\[offset\]=0&page\[limit\]=2'`
## OR
`curl -X GET 'http://localhost:8080/v1/cars?page\[number\]=1&page\[size\]=2'`
## Update:
`curl -X PATCH http://localhost:8080/v1/cars/1 -d '{ "data" : {"type" : "cars", "id": "1", "attributes": {"model" : "x3"}}}'`
## Delete:
`curl -X DELETE http://localhost:8080/v1/cars/2`

View File

@ -42,7 +42,7 @@ func (c Car) Verify() (bool, api2go.HTTPError) {
newErr := newVerifyError(
"Invalid Attribute",
"attribute must be one of: OnTheWay, InStock, Sold, Discontinued",
"/data/attributes/brand")
"/data/attributes/status")
verifyErrors = append(verifyErrors, newErr)
}

View File

@ -19,8 +19,8 @@ type CarResource struct {
// FindAll to satisfy api2go data source interface
func (s CarResource) FindAll(r api2go.Request) (api2go.Responder, error) {
var result []model.Car
cars := s.CarStorage.GetAll()
result := make([]model.Car, 0, len(cars))
for _, car := range cars {
result = append(result, *car)
@ -106,7 +106,6 @@ func (s CarResource) PaginatedFindAll(r api2go.Request) (uint, api2go.Responder,
}
// FindOne to satisfy `api2go.DataSource` interface
// this method should return the car with the given ID, otherwise an error
func (s CarResource) FindOne(ID string, r api2go.Request) (api2go.Responder, error) {
car, err := s.CarStorage.GetOne(ID)
if err != nil {