models

package
v0.0.0-...-c9838ac Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 6, 2016 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init()

Init initializes application models.

Types

type Model

type Model struct {
	ID        int64 `gorm:"primary_key"`
	CreatedAt time.Time
	UpdatedAt time.Time
}

Model represents base model.

type Repo

type Repo struct {
	Model

	ServiceID int64 `sql:"not null;unique_index:idx_serviceid_name"`

	Name        string `sql:"not null;unique_index:idx_serviceid_name"`
	Description string
	Private     bool
	Fork        bool
	RepoURL     string
	Homepage    string
}

func GetUserReposByService

func GetUserReposByService(id int64, serviceName string) ([]*Repo, error)

GetUserReposByService returns list of user repos by given user id and service if exists.

type Service

type Service struct {
	Model

	UserID int64 `sql:"not null;unique_index:idx_userid_userserviceid"`

	Name string `sql:"not null;index"`

	AccessToken string `sql:"not null"`

	UserServiceID    int64 `sql:"not null;unique_index:idx_userid_userserviceid"`
	UserServiceName  string
	UserServiceEmail string

	Repos []Repo
}

Service represents the object of external service.

func GetUserService

func GetUserService(id int64, serviceName string) (*Service, error)

GetUserService returns the user service object by given user id and service if exists.

type Token

type Token struct {
	Model

	UserID int64 `sql:"not null;unique_index:idx_userid_value"`

	Audience string `sql:"not null"`
	Value    string `sql:"not null;unique_index:idx_userid_value"`
}

func CreateUserToken

func CreateUserToken(id int64, audience string) (*Token, error)

CreateUserToken creates record of a new authentication token for user with specified `audience`.

type User

type User struct {
	Model

	Tokens   []Token
	Services []Service
}

User represents the object of individual user.

func CreateUserByService

func CreateUserByService(serviceName, serviceAccessToken string, userServiceID int64,
	userServiceName, userServiceEmail string) (*User, error)

CreateUserByService creates record of a new user using given service.

func GetUserByID

func GetUserByID(id int64) (*User, error)

GetUserByID returns the user object by given id if exists.

func GetUserByService

func GetUserByService(serviceName string, userServiceID int64) (*User, error)

GetUserByService returns the user object by given service if exists.

func GetUserByToken

func GetUserByToken(value string) (*User, error)

GetUserByToken returns the user object by given token value if exists.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL