Progres on move to sql from rethinkdb

This commit is contained in:
Torkel Ödegaard
2014-11-20 12:11:07 +01:00
parent 9b68911d00
commit eb2c078898
13 changed files with 118 additions and 62 deletions
+16 -16
View File
@@ -9,8 +9,8 @@ var (
CreateAccount func(acccount *Account) error
UpdateAccount func(acccount *Account) error
GetAccountByLogin func(emailOrName string) (*Account, error)
GetAccount func(accountId int) (*Account, error)
GetOtherAccountsFor func(accountId int) ([]*OtherAccount, error)
GetAccount func(accountId int64) (*Account, error)
GetOtherAccountsFor func(accountId int64) ([]*OtherAccount, error)
)
// Typed errors
@@ -19,7 +19,7 @@ var (
)
type CollaboratorLink struct {
AccountId int
AccountId int64
Role string
Email string
ModifiedOn time.Time
@@ -33,20 +33,20 @@ type OtherAccount struct {
}
type Account struct {
Id int `gorethink:"id"`
Version int
Login string
Email string
AccountName string
Id int64
Login string `xorm:"UNIQUE NOT NULL"`
Email string `xorm:"UNIQUE NOT NULL"`
Name string `xorm:"UNIQUE NOT NULL"`
FullName string
Password string
Name string
IsAdmin bool
Salt string `xorm:"VARCHAR(10)"`
Company string
NextDashboardId int
UsingAccountId int
Collaborators []CollaboratorLink
CreatedOn time.Time
ModifiedOn time.Time
LastLoginOn time.Time
UsingAccountId int64
Collaborators []CollaboratorLink `xorm:"-"`
Created time.Time `xorm:"CREATED"`
Updated time.Time `xorm:"UPDATED"`
}
func (account *Account) AddCollaborator(newCollaborator *Account) error {
@@ -67,7 +67,7 @@ func (account *Account) AddCollaborator(newCollaborator *Account) error {
return nil
}
func (account *Account) RemoveCollaborator(accountId int) {
func (account *Account) RemoveCollaborator(accountId int64) {
list := account.Collaborators
for i, collaborator := range list {
if collaborator.AccountId == accountId {
@@ -77,7 +77,7 @@ func (account *Account) RemoveCollaborator(accountId int) {
}
}
func (account *Account) HasCollaborator(accountId int) bool {
func (account *Account) HasCollaborator(accountId int64) bool {
for _, collaborator := range account.Collaborators {
if collaborator.AccountId == accountId {
return true
+16 -13
View File
@@ -2,6 +2,7 @@ package models
import (
"encoding/json"
"errors"
"io"
"regexp"
"strings"
@@ -9,19 +10,24 @@ import (
)
var (
GetDashboard func(slug string, accountId int) (*Dashboard, error)
GetDashboard func(slug string, accountId int64) (*Dashboard, error)
SaveDashboard func(dash *Dashboard) error
DeleteDashboard func(slug string, accountId int) error
SearchQuery func(query string, acccountId int) ([]*SearchResult, error)
DeleteDashboard func(slug string, accountId int64) error
SearchQuery func(query string, acccountId int64) ([]*SearchResult, error)
)
// Typed errors
var (
ErrDashboardNotFound = errors.New("Account not found")
)
type Dashboard struct {
Id string `gorethink:"id,omitempty"`
Slug string
AccountId int
LastModifiedByUserId string
LastModifiedByDate time.Time
CreatedDate time.Time
Id int64
Slug string `xorm:"index(IX_AccountIdSlug)"`
AccountId int64 `xorm:"index(IX_AccountIdSlug)"`
Created time.Time `xorm:"CREATED"`
Updated time.Time `xorm:"UPDATED"`
Title string
Tags []string
@@ -36,10 +42,7 @@ type SearchResult struct {
func NewDashboard(title string) *Dashboard {
dash := &Dashboard{}
dash.Id = ""
dash.LastModifiedByDate = time.Now()
dash.CreatedDate = time.Now()
dash.LastModifiedByUserId = "123"
dash.Id = 0
dash.Data = make(map[string]interface{})
dash.Data["title"] = title
dash.Title = title