grafana/pkg/models/account.go

126 lines
2.4 KiB
Go
Raw Normal View History

2014-09-19 23:37:18 +08:00
package models
import (
"errors"
"time"
)
2014-10-06 03:13:01 +08:00
// Typed errors
var (
ErrAccountNotFound = errors.New("Account not found")
)
// Directly mapped to db schema, Do not change field names lighly
2014-09-20 18:13:46 +08:00
type Account struct {
Id int64
Login string `xorm:"UNIQUE NOT NULL"`
Email string `xorm:"UNIQUE NOT NULL"`
Name string
Password string
IsAdmin bool
Salt string `xorm:"VARCHAR(10)"`
Company string
UsingAccountId int64
Created time.Time
Updated time.Time
2014-09-21 21:01:59 +08:00
}
// ---------------------
// COMMANDS
type CreateAccountCommand struct {
Email string `json:"email" binding:"required"`
Login string `json:"login"`
Password string `json:"password" binding:"required"`
Name string `json:"name"`
Company string `json:"company"`
Salt string `json:"-"`
IsAdmin bool `json:"-"`
Result Account `json:"-"`
}
type UpdateAccountCommand struct {
2015-01-17 15:20:25 +08:00
Email string `json:"email" binding:"Required"`
Login string `json:"login"`
Name string `json:"name"`
AccountId int64 `json:"-"`
}
2014-12-19 20:12:47 +08:00
type SetUsingAccountCommand struct {
AccountId int64
UsingAccountId int64
}
// ----------------------
// QUERIES
type GetAccountInfoQuery struct {
Id int64
Result AccountDTO
}
type GetOtherAccountsQuery struct {
AccountId int64
Result []*OtherAccountDTO
}
type GetAccountByIdQuery struct {
Id int64
Result *Account
}
type GetAccountByLoginQuery struct {
LoginOrEmail string
Result *Account
}
type SearchAccountsQuery struct {
Query string
Page int
Limit int
Result []*AccountSearchHitDTO
}
type GetSignedInUserQuery struct {
AccountId int64
Result *SignedInUser
}
// ------------------------
// DTO & Projections
type SignedInUser struct {
AccountId int64
UsingAccountId int64
UsingAccountName string
UserRole RoleType
UserLogin string
UserName string
UserEmail string
2015-01-17 15:20:25 +08:00
ApiKeyId int64
IsGrafanaAdmin bool
}
type OtherAccountDTO struct {
AccountId int64 `json:"accountId"`
Email string `json:"email"`
Role RoleType `json:"role"`
IsUsing bool `json:"isUsing"`
2015-01-14 23:12:37 +08:00
}
type AccountSearchHitDTO struct {
2015-01-15 22:54:22 +08:00
Id int64 `json:"id"`
Name string `json:"name"`
Login string `json:"login"`
Email string `json:"email"`
IsAdmin bool `json:"isAdmin"`
}
type AccountDTO struct {
Email string `json:"email"`
Name string `json:"name"`
Login string `json:"login"`
}