forked from loafle/openapi-generator-original
[Go-Server] Add support for DateTime Query Parameters (#16749)
* Add support for DateTime objects in the Path, Query Params, and as a List * Fix indentation * Add an exaple that has dateTimes Move the date parsing into a common util in the routers.go file. * Fix compilation issue and regen * Use the `RequiredError` to handle this case * Only split on a "," and not an extra 'space' after the ",".
This commit is contained in:
@@ -223,7 +223,21 @@ func (c *PetAPIController) FindPetsByTags(w http.ResponseWriter, r *http.Request
|
||||
if query.Has("tags") {
|
||||
tagsParam = strings.Split(query.Get("tags"), ",")
|
||||
}
|
||||
result, err := c.service.FindPetsByTags(r.Context(), tagsParam)
|
||||
if !query.Has("bornAfter"){
|
||||
c.errorHandler(w, r, &RequiredError{"bornAfter"}, nil)
|
||||
return
|
||||
}
|
||||
bornAfterParam, err := parseTime(query.Get("bornAfter"))
|
||||
if err != nil {
|
||||
c.errorHandler(w, r, &ParsingError{Err: err}, nil)
|
||||
return
|
||||
}
|
||||
bornBeforeParam, err := parseTime(query.Get("bornBefore"))
|
||||
if err != nil {
|
||||
c.errorHandler(w, r, &ParsingError{Err: err}, nil)
|
||||
return
|
||||
}
|
||||
result, err := c.service.FindPetsByTags(r.Context(), tagsParam, bornAfterParam, bornBeforeParam)
|
||||
// If an error occurred, encode the error with the status code
|
||||
if err != nil {
|
||||
c.errorHandler(w, r, err, &result)
|
||||
|
||||
Reference in New Issue
Block a user