github.com/circl-dev/go-swagger@v0.31.0/examples/task-tracker/models/user_card.go (about)

     1  // Code generated by go-swagger; DO NOT EDIT.
     2  
     3  package models
     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  	"context"
    10  
    11  	"github.com/go-openapi/errors"
    12  	"github.com/go-openapi/strfmt"
    13  	"github.com/go-openapi/swag"
    14  	"github.com/circl-dev/validate"
    15  )
    16  
    17  // UserCard A minimal representation of a user.
    18  //
    19  // This representation of a user is mainly meant for inclusion in other models, or for list views.
    20  //
    21  //
    22  // swagger:model UserCard
    23  type UserCard struct {
    24  
    25  	// When true this user is an admin.
    26  	//
    27  	// Only employees of the owning company can be admins.
    28  	// Admins are like project owners but have access to all the projects in the application.
    29  	// There aren't many admins, and it's only used for extremly critical issues with the application.
    30  	//
    31  	// Read Only: true
    32  	Admin *bool `json:"admin,omitempty"`
    33  
    34  	// The amount of karma this user has available.
    35  	//
    36  	// In this application users get a cerain amount of karma alotted.
    37  	// This karma can be donated to other users to show appreciation, or it can be used
    38  	// by a user to vote on issues.
    39  	// Once an issue is closed or rejected, the user gets his karma back.
    40  	//
    41  	// Read Only: true
    42  	// Maximum: < 1000
    43  	AvailableKarma float64 `json:"availableKarma,omitempty"`
    44  
    45  	// A unique identifier for a user.
    46  	//
    47  	// This id is automatically generated on the server when a user is created.
    48  	//
    49  	// Required: true
    50  	// Read Only: true
    51  	ID int64 `json:"id"`
    52  
    53  	// The screen name for the user.
    54  	//
    55  	// This is used for vanity type urls as well as login credentials.
    56  	//
    57  	// Required: true
    58  	// Max Length: 255
    59  	// Min Length: 3
    60  	// Pattern: \w[\w_-]+
    61  	ScreenName *string `json:"screenName"`
    62  }
    63  
    64  // Validate validates this user card
    65  func (m *UserCard) Validate(formats strfmt.Registry) error {
    66  	var res []error
    67  
    68  	if err := m.validateAvailableKarma(formats); err != nil {
    69  		res = append(res, err)
    70  	}
    71  
    72  	if err := m.validateID(formats); err != nil {
    73  		res = append(res, err)
    74  	}
    75  
    76  	if err := m.validateScreenName(formats); err != nil {
    77  		res = append(res, err)
    78  	}
    79  
    80  	if len(res) > 0 {
    81  		return errors.CompositeValidationError(res...)
    82  	}
    83  	return nil
    84  }
    85  
    86  func (m *UserCard) validateAvailableKarma(formats strfmt.Registry) error {
    87  	if swag.IsZero(m.AvailableKarma) { // not required
    88  		return nil
    89  	}
    90  
    91  	if err := validate.Maximum("availableKarma", "body", m.AvailableKarma, 1000, true); err != nil {
    92  		return err
    93  	}
    94  
    95  	return nil
    96  }
    97  
    98  func (m *UserCard) validateID(formats strfmt.Registry) error {
    99  
   100  	if err := validate.Required("id", "body", int64(m.ID)); err != nil {
   101  		return err
   102  	}
   103  
   104  	return nil
   105  }
   106  
   107  func (m *UserCard) validateScreenName(formats strfmt.Registry) error {
   108  
   109  	if err := validate.Required("screenName", "body", m.ScreenName); err != nil {
   110  		return err
   111  	}
   112  
   113  	if err := validate.MinLength("screenName", "body", *m.ScreenName, 3); err != nil {
   114  		return err
   115  	}
   116  
   117  	if err := validate.MaxLength("screenName", "body", *m.ScreenName, 255); err != nil {
   118  		return err
   119  	}
   120  
   121  	if err := validate.Pattern("screenName", "body", *m.ScreenName, `\w[\w_-]+`); err != nil {
   122  		return err
   123  	}
   124  
   125  	return nil
   126  }
   127  
   128  // ContextValidate validate this user card based on the context it is used
   129  func (m *UserCard) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   130  	var res []error
   131  
   132  	if err := m.contextValidateAdmin(ctx, formats); err != nil {
   133  		res = append(res, err)
   134  	}
   135  
   136  	if err := m.contextValidateAvailableKarma(ctx, formats); err != nil {
   137  		res = append(res, err)
   138  	}
   139  
   140  	if err := m.contextValidateID(ctx, formats); err != nil {
   141  		res = append(res, err)
   142  	}
   143  
   144  	if len(res) > 0 {
   145  		return errors.CompositeValidationError(res...)
   146  	}
   147  	return nil
   148  }
   149  
   150  func (m *UserCard) contextValidateAdmin(ctx context.Context, formats strfmt.Registry) error {
   151  
   152  	if err := validate.ReadOnly(ctx, "admin", "body", m.Admin); err != nil {
   153  		return err
   154  	}
   155  
   156  	return nil
   157  }
   158  
   159  func (m *UserCard) contextValidateAvailableKarma(ctx context.Context, formats strfmt.Registry) error {
   160  
   161  	if err := validate.ReadOnly(ctx, "availableKarma", "body", float64(m.AvailableKarma)); err != nil {
   162  		return err
   163  	}
   164  
   165  	return nil
   166  }
   167  
   168  func (m *UserCard) contextValidateID(ctx context.Context, formats strfmt.Registry) error {
   169  
   170  	if err := validate.ReadOnly(ctx, "id", "body", int64(m.ID)); err != nil {
   171  		return err
   172  	}
   173  
   174  	return nil
   175  }
   176  
   177  // MarshalBinary interface implementation
   178  func (m *UserCard) MarshalBinary() ([]byte, error) {
   179  	if m == nil {
   180  		return nil, nil
   181  	}
   182  	return swag.WriteJSON(m)
   183  }
   184  
   185  // UnmarshalBinary interface implementation
   186  func (m *UserCard) UnmarshalBinary(b []byte) error {
   187  	var res UserCard
   188  	if err := swag.ReadJSON(b, &res); err != nil {
   189  		return err
   190  	}
   191  	*m = res
   192  	return nil
   193  }