devrelcollective/xela

View on GitHub
models/user.go

Summary

Maintainability
A
0 mins
Test Coverage
package models

import (
    "encoding/json"
    "time"

    "github.com/gobuffalo/pop"
    "github.com/gobuffalo/pop/nulls"
    "github.com/gobuffalo/uuid"
    "github.com/gobuffalo/validate"
    "github.com/gobuffalo/validate/validators"
)

type User struct {
    ID         uuid.UUID    `json:"id" db:"id"`
    CreatedAt  time.Time    `json:"created_at" db:"created_at"`
    UpdatedAt  time.Time    `json:"updated_at" db:"updated_at"`
    Name       string       `json:"name" db:"name"`
    Email      nulls.String `json:"email" db:"email"`
    Provider   string       `json:"provider" db:"provider"`
    ProviderID string       `json:"provider_id" db:"provider_id"`
}

// String is not required by pop and may be deleted
func (u User) String() string {
    ju, _ := json.Marshal(u)
    return string(ju)
}

// Users is not required by pop and may be deleted
type Users []User

// String is not required by pop and may be deleted
func (u Users) String() string {
    ju, _ := json.Marshal(u)
    return string(ju)
}

// Validate gets run every time you call a "pop.Validate*" (pop.ValidateAndSave, pop.ValidateAndCreate, pop.ValidateAndUpdate) method.
// This method is not required and may be deleted.
func (u *User) Validate(tx *pop.Connection) (*validate.Errors, error) {
    return validate.Validate(
        &validators.StringIsPresent{Field: u.Name, Name: "Name"},
        &validators.StringIsPresent{Field: u.Provider, Name: "Provider"},
        &validators.StringIsPresent{Field: u.ProviderID, Name: "ProviderID"},
    ), nil
}

// ValidateCreate gets run every time you call "pop.ValidateAndCreate" method.
// This method is not required and may be deleted.
func (u *User) ValidateCreate(tx *pop.Connection) (*validate.Errors, error) {
    return validate.NewErrors(), nil
}

// ValidateUpdate gets run every time you call "pop.ValidateAndUpdate" method.
// This method is not required and may be deleted.
func (u *User) ValidateUpdate(tx *pop.Connection) (*validate.Errors, error) {
    return validate.NewErrors(), nil
}