github.com/circl-dev/go-swagger@v0.31.0/examples/task-tracker/restapi/operations/tasks/list_tasks_parameters.go (about)

     1  // Code generated by go-swagger; DO NOT EDIT.
     2  
     3  package tasks
     4  
     5  // This file was generated by the swagger tool.
     6  // Editing this file might prove futile when you re-run the swagger generate command
     7  
     8  import (
     9  	"fmt"
    10  	"net/http"
    11  
    12  	"github.com/go-openapi/errors"
    13  	"github.com/go-openapi/strfmt"
    14  	"github.com/go-openapi/swag"
    15  	"github.com/circl-dev/runtime"
    16  	"github.com/circl-dev/runtime/middleware"
    17  	"github.com/circl-dev/validate"
    18  )
    19  
    20  // NewListTasksParams creates a new ListTasksParams object
    21  // with the default values initialized.
    22  func NewListTasksParams() ListTasksParams {
    23  
    24  	var (
    25  		// initialize parameters with default values
    26  
    27  		pageSizeDefault = int32(20)
    28  	)
    29  
    30  	return ListTasksParams{
    31  		PageSize: &pageSizeDefault,
    32  	}
    33  }
    34  
    35  // ListTasksParams contains all the bound params for the list tasks operation
    36  // typically these are obtained from a http.Request
    37  //
    38  // swagger:parameters listTasks
    39  type ListTasksParams struct {
    40  
    41  	// HTTP Request Object
    42  	HTTPRequest *http.Request `json:"-"`
    43  
    44  	/*Amount of items to return in a single page
    45  	  In: query
    46  	  Default: 20
    47  	*/
    48  	PageSize *int32
    49  	/*The last id that was seen.
    50  	  In: query
    51  	*/
    52  	SinceID *int64
    53  	/*the status to filter by
    54  	  Unique: true
    55  	  In: query
    56  	  Collection Format: pipes
    57  	*/
    58  	Status []string
    59  	/*the tags to filter by
    60  	  Unique: true
    61  	  In: query
    62  	*/
    63  	Tags []string
    64  }
    65  
    66  // BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface
    67  // for simple values it will use straight method calls.
    68  //
    69  // To ensure default values, the struct must have been initialized with NewListTasksParams() beforehand.
    70  func (o *ListTasksParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {
    71  	var res []error
    72  
    73  	o.HTTPRequest = r
    74  
    75  	qs := runtime.Values(r.URL.Query())
    76  
    77  	qPageSize, qhkPageSize, _ := qs.GetOK("pageSize")
    78  	if err := o.bindPageSize(qPageSize, qhkPageSize, route.Formats); err != nil {
    79  		res = append(res, err)
    80  	}
    81  
    82  	qSinceID, qhkSinceID, _ := qs.GetOK("sinceId")
    83  	if err := o.bindSinceID(qSinceID, qhkSinceID, route.Formats); err != nil {
    84  		res = append(res, err)
    85  	}
    86  
    87  	qStatus, qhkStatus, _ := qs.GetOK("status")
    88  	if err := o.bindStatus(qStatus, qhkStatus, route.Formats); err != nil {
    89  		res = append(res, err)
    90  	}
    91  
    92  	qTags, qhkTags, _ := qs.GetOK("tags")
    93  	if err := o.bindTags(qTags, qhkTags, route.Formats); err != nil {
    94  		res = append(res, err)
    95  	}
    96  	if len(res) > 0 {
    97  		return errors.CompositeValidationError(res...)
    98  	}
    99  	return nil
   100  }
   101  
   102  // bindPageSize binds and validates parameter PageSize from query.
   103  func (o *ListTasksParams) bindPageSize(rawData []string, hasKey bool, formats strfmt.Registry) error {
   104  	var raw string
   105  	if len(rawData) > 0 {
   106  		raw = rawData[len(rawData)-1]
   107  	}
   108  
   109  	// Required: false
   110  	// AllowEmptyValue: false
   111  
   112  	if raw == "" { // empty values pass all other validations
   113  		// Default values have been previously initialized by NewListTasksParams()
   114  		return nil
   115  	}
   116  
   117  	value, err := swag.ConvertInt32(raw)
   118  	if err != nil {
   119  		return errors.InvalidType("pageSize", "query", "int32", raw)
   120  	}
   121  	o.PageSize = &value
   122  
   123  	return nil
   124  }
   125  
   126  // bindSinceID binds and validates parameter SinceID from query.
   127  func (o *ListTasksParams) bindSinceID(rawData []string, hasKey bool, formats strfmt.Registry) error {
   128  	var raw string
   129  	if len(rawData) > 0 {
   130  		raw = rawData[len(rawData)-1]
   131  	}
   132  
   133  	// Required: false
   134  	// AllowEmptyValue: false
   135  
   136  	if raw == "" { // empty values pass all other validations
   137  		return nil
   138  	}
   139  
   140  	value, err := swag.ConvertInt64(raw)
   141  	if err != nil {
   142  		return errors.InvalidType("sinceId", "query", "int64", raw)
   143  	}
   144  	o.SinceID = &value
   145  
   146  	return nil
   147  }
   148  
   149  // bindStatus binds and validates array parameter Status from query.
   150  //
   151  // Arrays are parsed according to CollectionFormat: "pipes" (defaults to "csv" when empty).
   152  func (o *ListTasksParams) bindStatus(rawData []string, hasKey bool, formats strfmt.Registry) error {
   153  	var qvStatus string
   154  	if len(rawData) > 0 {
   155  		qvStatus = rawData[len(rawData)-1]
   156  	}
   157  
   158  	// CollectionFormat: pipes
   159  	statusIC := swag.SplitByFormat(qvStatus, "pipes")
   160  	if len(statusIC) == 0 {
   161  		return nil
   162  	}
   163  
   164  	var statusIR []string
   165  	for i, statusIV := range statusIC {
   166  		statusI := statusIV
   167  
   168  		if err := validate.EnumCase(fmt.Sprintf("%s.%v", "status", i), "query", statusI, []interface{}{"open", "closed", "ignored", "rejected"}, true); err != nil {
   169  			return err
   170  		}
   171  
   172  		statusIR = append(statusIR, statusI)
   173  	}
   174  
   175  	o.Status = statusIR
   176  	if err := o.validateStatus(formats); err != nil {
   177  		return err
   178  	}
   179  
   180  	return nil
   181  }
   182  
   183  // validateStatus carries on validations for parameter Status
   184  func (o *ListTasksParams) validateStatus(formats strfmt.Registry) error {
   185  
   186  	// uniqueItems: true
   187  	if err := validate.UniqueItems("status", "query", o.Status); err != nil {
   188  		return err
   189  	}
   190  	return nil
   191  }
   192  
   193  // bindTags binds and validates array parameter Tags from query.
   194  //
   195  // Arrays are parsed according to CollectionFormat: "" (defaults to "csv" when empty).
   196  func (o *ListTasksParams) bindTags(rawData []string, hasKey bool, formats strfmt.Registry) error {
   197  	var qvTags string
   198  	if len(rawData) > 0 {
   199  		qvTags = rawData[len(rawData)-1]
   200  	}
   201  
   202  	// CollectionFormat:
   203  	tagsIC := swag.SplitByFormat(qvTags, "")
   204  	if len(tagsIC) == 0 {
   205  		return nil
   206  	}
   207  
   208  	var tagsIR []string
   209  	for _, tagsIV := range tagsIC {
   210  		tagsI := tagsIV
   211  
   212  		tagsIR = append(tagsIR, tagsI)
   213  	}
   214  
   215  	o.Tags = tagsIR
   216  	if err := o.validateTags(formats); err != nil {
   217  		return err
   218  	}
   219  
   220  	return nil
   221  }
   222  
   223  // validateTags carries on validations for parameter Tags
   224  func (o *ListTasksParams) validateTags(formats strfmt.Registry) error {
   225  
   226  	// uniqueItems: true
   227  	if err := validate.UniqueItems("tags", "query", o.Tags); err != nil {
   228  		return err
   229  	}
   230  	return nil
   231  }