gitlab.com/evatix-go/core@v1.3.55/coredata/corepayload/User.go (about)

     1  package corepayload
     2  
     3  import (
     4  	"gitlab.com/evatix-go/core/constants"
     5  	"gitlab.com/evatix-go/core/converters"
     6  	"gitlab.com/evatix-go/core/coredata/corejson"
     7  )
     8  
     9  type User struct {
    10  	Identifier   string `json:"Identifier,omitempty"`
    11  	Name         string `json:"Name,omitempty"`
    12  	Type         string `json:"Type,omitempty"`
    13  	AuthToken    string `json:"AuthToken,omitempty"`
    14  	PasswordHash string `json:"PasswordHash,omitempty"`
    15  	IsSystemUser bool   `json:"IsSystemUser"`
    16  }
    17  
    18  // IdentifierInteger
    19  //
    20  // Invalid value returns constants.InvalidValue
    21  func (it *User) IdentifierInteger() int {
    22  	if it.Identifier == "" {
    23  		return constants.InvalidValue
    24  	}
    25  
    26  	idInt, _ := converters.StringToIntegerWithDefault(
    27  		it.Identifier,
    28  		constants.InvalidValue)
    29  
    30  	return idInt
    31  }
    32  
    33  // IdentifierUnsignedInteger
    34  //
    35  // Invalid value returns constants.Zero
    36  func (it *User) IdentifierUnsignedInteger() uint {
    37  	idInt := it.IdentifierInteger()
    38  
    39  	if idInt < 0 {
    40  		return constants.Zero
    41  	}
    42  
    43  	return uint(idInt)
    44  }
    45  
    46  func (it *User) HasAuthToken() bool {
    47  	return it != nil && it.AuthToken != ""
    48  }
    49  
    50  func (it *User) HasPasswordHash() bool {
    51  	return it != nil && it.PasswordHash != ""
    52  }
    53  
    54  func (it *User) IsPasswordHashEmpty() bool {
    55  	return it == nil || it.PasswordHash == ""
    56  }
    57  
    58  func (it *User) IsAuthTokenEmpty() bool {
    59  	return it == nil || it.AuthToken == ""
    60  }
    61  
    62  func (it *User) IsEmpty() bool {
    63  	return it == nil || it.Name == ""
    64  }
    65  
    66  func (it *User) IsValidUser() bool {
    67  	return !it.IsEmpty()
    68  }
    69  
    70  func (it *User) IsNameEmpty() bool {
    71  	return it == nil || it.Name == ""
    72  }
    73  
    74  func (it *User) IsNameEqual(name string) bool {
    75  	return it != nil && it.Name == name
    76  }
    77  
    78  func (it *User) IsNotSystemUser() bool {
    79  	return it != nil && !it.IsSystemUser
    80  }
    81  
    82  func (it *User) IsVirtualUser() bool {
    83  	return it != nil && !it.IsSystemUser
    84  }
    85  
    86  func (it *User) HasType() bool {
    87  	return it != nil && it.Type != ""
    88  }
    89  
    90  func (it *User) IsTypeEmpty() bool {
    91  	return it == nil || it.Type == ""
    92  }
    93  
    94  func (it User) String() string {
    95  	return it.JsonPtr().JsonString()
    96  }
    97  
    98  func (it *User) PrettyJsonString() string {
    99  	return it.JsonPtr().PrettyJsonString()
   100  }
   101  
   102  func (it *User) Json() corejson.Result {
   103  	return corejson.New(it)
   104  }
   105  
   106  func (it *User) JsonPtr() *corejson.Result {
   107  	return corejson.NewPtr(it)
   108  }
   109  
   110  func (it *User) Serialize() ([]byte, error) {
   111  	return corejson.Serialize.Raw(it)
   112  }
   113  
   114  func (it *User) Deserialize(rawJsonBytes []byte) error {
   115  	return corejson.
   116  		Deserialize.
   117  		UsingBytes(rawJsonBytes, it)
   118  }
   119  
   120  func (it User) Clone() User {
   121  	return User{
   122  		Name:         it.Name,
   123  		Type:         it.Type,
   124  		AuthToken:    it.AuthToken,
   125  		PasswordHash: it.PasswordHash,
   126  		IsSystemUser: it.IsSystemUser,
   127  	}
   128  }
   129  
   130  func (it *User) ClonePtr() *User {
   131  	if it == nil {
   132  		return nil
   133  	}
   134  
   135  	return it.Clone().Ptr()
   136  }
   137  
   138  func (it User) Ptr() *User {
   139  	return &it
   140  }