github.com/thetreep/go-swagger@v0.0.0-20240223100711-35af64f14f01/examples/task-tracker/restapi/operations/tasks/add_comment_to_task.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 generate command
     7  
     8  import (
     9  	"context"
    10  	"net/http"
    11  
    12  	"github.com/go-openapi/errors"
    13  	"github.com/go-openapi/runtime/middleware"
    14  	"github.com/go-openapi/strfmt"
    15  	"github.com/go-openapi/swag"
    16  	"github.com/go-openapi/validate"
    17  )
    18  
    19  // AddCommentToTaskHandlerFunc turns a function with the right signature into a add comment to task handler
    20  type AddCommentToTaskHandlerFunc func(AddCommentToTaskParams, interface{}) middleware.Responder
    21  
    22  // Handle executing the request and returning a response
    23  func (fn AddCommentToTaskHandlerFunc) Handle(params AddCommentToTaskParams, principal interface{}) middleware.Responder {
    24  	return fn(params, principal)
    25  }
    26  
    27  // AddCommentToTaskHandler interface for that can handle valid add comment to task params
    28  type AddCommentToTaskHandler interface {
    29  	Handle(AddCommentToTaskParams, interface{}) middleware.Responder
    30  }
    31  
    32  // NewAddCommentToTask creates a new http.Handler for the add comment to task operation
    33  func NewAddCommentToTask(ctx *middleware.Context, handler AddCommentToTaskHandler) *AddCommentToTask {
    34  	return &AddCommentToTask{Context: ctx, Handler: handler}
    35  }
    36  
    37  /*
    38  	AddCommentToTask swagger:route POST /tasks/{id}/comments tasks addCommentToTask
    39  
    40  # Adds a comment to a task
    41  
    42  The comment can contain ___github markdown___ syntax.
    43  Fenced codeblocks etc are supported through pygments.
    44  */
    45  type AddCommentToTask struct {
    46  	Context *middleware.Context
    47  	Handler AddCommentToTaskHandler
    48  }
    49  
    50  func (o *AddCommentToTask) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
    51  	route, rCtx, _ := o.Context.RouteInfo(r)
    52  	if rCtx != nil {
    53  		*r = *rCtx
    54  	}
    55  	var Params = NewAddCommentToTaskParams()
    56  	uprinc, aCtx, err := o.Context.Authorize(r, route)
    57  	if err != nil {
    58  		o.Context.Respond(rw, r, route.Produces, route, err)
    59  		return
    60  	}
    61  	if aCtx != nil {
    62  		*r = *aCtx
    63  	}
    64  	var principal interface{}
    65  	if uprinc != nil {
    66  		principal = uprinc.(interface{}) // this is really a interface{}, I promise
    67  	}
    68  
    69  	if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params
    70  		o.Context.Respond(rw, r, route.Produces, route, err)
    71  		return
    72  	}
    73  
    74  	res := o.Handler.Handle(Params, principal) // actually handle the request
    75  	o.Context.Respond(rw, r, route.Produces, route, res)
    76  
    77  }
    78  
    79  // AddCommentToTaskBody A comment to create
    80  //
    81  // These values can have github flavored markdown.
    82  //
    83  // swagger:model AddCommentToTaskBody
    84  type AddCommentToTaskBody struct {
    85  
    86  	// content
    87  	// Required: true
    88  	Content *string `json:"content"`
    89  
    90  	// user Id
    91  	// Required: true
    92  	UserID *int64 `json:"userId"`
    93  }
    94  
    95  // Validate validates this add comment to task body
    96  func (o *AddCommentToTaskBody) Validate(formats strfmt.Registry) error {
    97  	var res []error
    98  
    99  	if err := o.validateContent(formats); err != nil {
   100  		res = append(res, err)
   101  	}
   102  
   103  	if err := o.validateUserID(formats); err != nil {
   104  		res = append(res, err)
   105  	}
   106  
   107  	if len(res) > 0 {
   108  		return errors.CompositeValidationError(res...)
   109  	}
   110  	return nil
   111  }
   112  
   113  func (o *AddCommentToTaskBody) validateContent(formats strfmt.Registry) error {
   114  
   115  	if err := validate.Required("body"+"."+"content", "body", o.Content); err != nil {
   116  		return err
   117  	}
   118  
   119  	return nil
   120  }
   121  
   122  func (o *AddCommentToTaskBody) validateUserID(formats strfmt.Registry) error {
   123  
   124  	if err := validate.Required("body"+"."+"userId", "body", o.UserID); err != nil {
   125  		return err
   126  	}
   127  
   128  	return nil
   129  }
   130  
   131  // ContextValidate validates this add comment to task body based on context it is used
   132  func (o *AddCommentToTaskBody) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   133  	return nil
   134  }
   135  
   136  // MarshalBinary interface implementation
   137  func (o *AddCommentToTaskBody) MarshalBinary() ([]byte, error) {
   138  	if o == nil {
   139  		return nil, nil
   140  	}
   141  	return swag.WriteJSON(o)
   142  }
   143  
   144  // UnmarshalBinary interface implementation
   145  func (o *AddCommentToTaskBody) UnmarshalBinary(b []byte) error {
   146  	var res AddCommentToTaskBody
   147  	if err := swag.ReadJSON(b, &res); err != nil {
   148  		return err
   149  	}
   150  	*o = res
   151  	return nil
   152  }