Big Backend Refatoring: Renamed Account -> Org

This commit is contained in:
Torkel Ödegaard
2015-02-23 20:07:49 +01:00
parent e9e2fa2927
commit 26e4809e2e
43 changed files with 774 additions and 773 deletions
-70
View File
@@ -1,70 +0,0 @@
package models
import (
"errors"
"time"
)
// Typed errors
var (
ErrAccountNotFound = errors.New("Account not found")
)
type Account struct {
Id int64
Version int
Name string
Created time.Time
Updated time.Time
}
// ---------------------
// COMMANDS
type CreateAccountCommand struct {
Name string `json:"name" binding:"Required"`
// initial admin user for account
UserId int64 `json:"-"`
Result Account `json:"-"`
}
type DeleteAccountCommand struct {
Id int64
}
type UpdateAccountCommand struct {
Name string `json:"name" binding:"Required"`
AccountId int64 `json:"-"`
}
type GetUserAccountsQuery struct {
UserId int64
Result []*UserAccountDTO
}
type GetAccountByIdQuery struct {
Id int64
Result *Account
}
type GetAccountByNameQuery struct {
Name string
Result *Account
}
type GetAccountsQuery struct {
Result []*Account
}
type AccountDTO struct {
Id int64 `json:"id"`
Name string `json:"name"`
}
type UserAccountDTO struct {
AccountId int64 `json:"accountId"`
Name string `json:"name"`
Role RoleType `json:"role"`
IsUsing bool `json:"isUsing"`
}
-67
View File
@@ -1,67 +0,0 @@
package models
import (
"errors"
"time"
)
// Typed errors
var (
ErrInvalidRoleType = errors.New("Invalid role type")
ErrLastAccountAdmin = errors.New("Cannot remove last account admin")
)
type RoleType string
const (
ROLE_VIEWER RoleType = "Viewer"
ROLE_EDITOR RoleType = "Editor"
ROLE_ADMIN RoleType = "Admin"
)
func (r RoleType) IsValid() bool {
return r == ROLE_VIEWER || r == ROLE_ADMIN || r == ROLE_EDITOR
}
type AccountUser struct {
AccountId int64
UserId int64
Role RoleType
Created time.Time
Updated time.Time
}
// ---------------------
// COMMANDS
type RemoveAccountUserCommand struct {
UserId int64
AccountId int64
}
type AddAccountUserCommand struct {
LoginOrEmail string `json:"loginOrEmail" binding:"Required"`
Role RoleType `json:"role" binding:"Required"`
AccountId int64 `json:"-"`
UserId int64 `json:"-"`
}
// ----------------------
// QUERIES
type GetAccountUsersQuery struct {
AccountId int64
Result []*AccountUserDTO
}
// ----------------------
// Projections and DTOs
type AccountUserDTO struct {
AccountId int64 `json:"accountId"`
UserId int64 `json:"userId"`
Email string `json:"email"`
Login string `json:"login"`
Role string `json:"role"`
}
+16 -16
View File
@@ -8,22 +8,22 @@ import (
var ErrInvalidApiKey = errors.New("Invalid API Key")
type ApiKey struct {
Id int64
AccountId int64
Name string
Key string
Role RoleType
Created time.Time
Updated time.Time
Id int64
OrgId int64
Name string
Key string
Role RoleType
Created time.Time
Updated time.Time
}
// ---------------------
// COMMANDS
type AddApiKeyCommand struct {
Name string `json:"name" binding:"Required"`
Role RoleType `json:"role" binding:"Required"`
AccountId int64 `json:"-"`
Key string `json:"-"`
Name string `json:"name" binding:"Required"`
Role RoleType `json:"role" binding:"Required"`
OrgId int64 `json:"-"`
Key string `json:"-"`
Result *ApiKey `json:"-"`
}
@@ -33,20 +33,20 @@ type UpdateApiKeyCommand struct {
Name string `json:"name"`
Role RoleType `json:"role"`
AccountId int64 `json:"-"`
OrgId int64 `json:"-"`
}
type DeleteApiKeyCommand struct {
Id int64 `json:"id"`
AccountId int64 `json:"-"`
Id int64 `json:"id"`
OrgId int64 `json:"-"`
}
// ----------------------
// QUERIES
type GetApiKeysQuery struct {
AccountId int64
Result []*ApiKey
OrgId int64
Result []*ApiKey
}
type GetApiKeyByKeyQuery struct {
+10 -10
View File
@@ -14,10 +14,10 @@ var (
)
type Dashboard struct {
Id int64
Slug string
AccountId int64
Version int
Id int64
Slug string
OrgId int64
Version int
Created time.Time
Updated time.Time
@@ -53,7 +53,7 @@ func (cmd *SaveDashboardCommand) GetDashboardModel() *Dashboard {
dash := &Dashboard{}
dash.Data = cmd.Dashboard
dash.Title = dash.Data["title"].(string)
dash.AccountId = cmd.AccountId
dash.OrgId = cmd.OrgId
dash.UpdateSlug()
if dash.Data["id"] != nil {
@@ -80,14 +80,14 @@ func (dash *Dashboard) UpdateSlug() {
type SaveDashboardCommand struct {
Dashboard map[string]interface{} `json:"dashboard"`
AccountId int64 `json:"-"`
OrgId int64 `json:"-"`
Result *Dashboard
}
type DeleteDashboardCommand struct {
Slug string
AccountId int64
Slug string
OrgId int64
}
//
@@ -95,8 +95,8 @@ type DeleteDashboardCommand struct {
//
type GetDashboardQuery struct {
Slug string
AccountId int64
Slug string
OrgId int64
Result *Dashboard
}
+15 -15
View File
@@ -23,9 +23,9 @@ type DsType string
type DsAccess string
type DataSource struct {
Id int64
AccountId int64
Version int
Id int64
OrgId int64
Version int
Name string
Type DsType
@@ -48,7 +48,7 @@ type DataSource struct {
// Also acts as api DTO
type AddDataSourceCommand struct {
AccountId int64 `json:"-"`
OrgId int64 `json:"-"`
Name string
Type DsType
Access DsAccess
@@ -64,7 +64,7 @@ type AddDataSourceCommand struct {
// Also acts as api DTO
type UpdateDataSourceCommand struct {
Id int64
AccountId int64
OrgId int64
Name string
Type DsType
Access DsAccess
@@ -76,28 +76,28 @@ type UpdateDataSourceCommand struct {
}
type DeleteDataSourceCommand struct {
Id int64
AccountId int64
Id int64
OrgId int64
}
// ---------------------
// QUERIES
type GetDataSourcesQuery struct {
AccountId int64
Result []*DataSource
OrgId int64
Result []*DataSource
}
type GetDataSourceByIdQuery struct {
Id int64
AccountId int64
Result DataSource
Id int64
OrgId int64
Result DataSource
}
type GetDataSourceByNameQuery struct {
Name string
AccountId int64
Result DataSource
Name string
OrgId int64
Result DataSource
}
// ---------------------
+65
View File
@@ -0,0 +1,65 @@
package models
import (
"errors"
"time"
)
// Typed errors
var (
ErrOrgNotFound = errors.New("Organization not found")
)
type Org struct {
Id int64
Version int
Name string
Created time.Time
Updated time.Time
}
// ---------------------
// COMMANDS
type CreateOrgCommand struct {
Name string `json:"name" binding:"Required"`
// initial admin user for account
UserId int64 `json:"-"`
Result Org `json:"-"`
}
type DeleteOrgCommand struct {
Id int64
}
type UpdateOrgCommand struct {
Name string `json:"name" binding:"Required"`
OrgId int64 `json:"-"`
}
type GetOrgByIdQuery struct {
Id int64
Result *Org
}
type GetOrgByNameQuery struct {
Name string
Result *Org
}
type GetOrgListQuery struct {
Result []*Org
}
type OrgDTO struct {
Id int64 `json:"id"`
Name string `json:"name"`
}
type UserOrgDTO struct {
OrgId int64 `json:"orgId"`
Name string `json:"name"`
Role RoleType `json:"role"`
IsUsing bool `json:"isUsing"`
}
+67
View File
@@ -0,0 +1,67 @@
package models
import (
"errors"
"time"
)
// Typed errors
var (
ErrInvalidRoleType = errors.New("Invalid role type")
ErrLastOrgAdmin = errors.New("Cannot remove last organization admin")
)
type RoleType string
const (
ROLE_VIEWER RoleType = "Viewer"
ROLE_EDITOR RoleType = "Editor"
ROLE_ADMIN RoleType = "Admin"
)
func (r RoleType) IsValid() bool {
return r == ROLE_VIEWER || r == ROLE_ADMIN || r == ROLE_EDITOR
}
type OrgUser struct {
OrgId int64
UserId int64
Role RoleType
Created time.Time
Updated time.Time
}
// ---------------------
// COMMANDS
type RemoveOrgUserCommand struct {
UserId int64
OrgId int64
}
type AddOrgUserCommand struct {
LoginOrEmail string `json:"loginOrEmail" binding:"Required"`
Role RoleType `json:"role" binding:"Required"`
OrgId int64 `json:"-"`
UserId int64 `json:"-"`
}
// ----------------------
// QUERIES
type GetOrgUsersQuery struct {
OrgId int64
Result []*OrgUserDTO
}
// ----------------------
// Projections and DTOs
type OrgUserDTO struct {
OrgId int64 `json:"orgId"`
UserId int64 `json:"userId"`
Email string `json:"email"`
Login string `json:"login"`
Role string `json:"role"`
}
+3 -3
View File
@@ -22,7 +22,7 @@ type DashboardTagCloudItem struct {
type SearchDashboardsQuery struct {
Title string
Tag string
AccountId int64
OrgId int64
UserId int64
Limit int
IsStarred bool
@@ -31,6 +31,6 @@ type SearchDashboardsQuery struct {
}
type GetDashboardTagsQuery struct {
AccountId int64
Result []*DashboardTagCloudItem
OrgId int64
Result []*DashboardTagCloudItem
}
+13 -8
View File
@@ -23,8 +23,8 @@ type User struct {
EmailVerified bool
Theme string
IsAdmin bool
AccountId int64
IsAdmin bool
OrgId int64
Created time.Time
Updated time.Time
@@ -63,9 +63,9 @@ type DeleteUserCommand struct {
UserId int64
}
type SetUsingAccountCommand struct {
UserId int64
AccountId int64
type SetUsingOrgCommand struct {
UserId int64
OrgId int64
}
// ----------------------
@@ -99,14 +99,19 @@ type SearchUsersQuery struct {
Result []*UserSearchHitDTO
}
type GetUserOrgListQuery struct {
UserId int64
Result []*UserOrgDTO
}
// ------------------------
// DTO & Projections
type SignedInUser struct {
UserId int64
AccountId int64
AccountName string
AccountRole RoleType
OrgId int64
OrgName string
OrgRole RoleType
Login string
Name string
Email string