Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
43b47414
Commit
43b47414
authored
Mar 11, 2016
by
utkarshcmu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Preferences model updated
parent
02221c99
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
48 additions
and
37 deletions
+48
-37
pkg/api/api.go
+2
-1
pkg/api/preferences.go
+12
-11
pkg/models/preferences.go
+18
-12
pkg/services/sqlstore/migrations/preferences_mig.go
+6
-3
pkg/services/sqlstore/preferences.go
+10
-10
No files found.
pkg/api/api.go
View file @
43b47414
...
@@ -96,7 +96,6 @@ func Register(r *macaron.Macaron) {
...
@@ -96,7 +96,6 @@ func Register(r *macaron.Macaron) {
r
.
Delete
(
"/stars/dashboard/:id"
,
wrap
(
UnstarDashboard
))
r
.
Delete
(
"/stars/dashboard/:id"
,
wrap
(
UnstarDashboard
))
r
.
Put
(
"/password"
,
bind
(
m
.
ChangeUserPasswordCommand
{}),
wrap
(
ChangeUserPassword
))
r
.
Put
(
"/password"
,
bind
(
m
.
ChangeUserPasswordCommand
{}),
wrap
(
ChangeUserPassword
))
r
.
Get
(
"/quotas"
,
wrap
(
GetUserQuotas
))
r
.
Get
(
"/quotas"
,
wrap
(
GetUserQuotas
))
r
.
Combo
(
"/prefs"
)
.
Get
(
GetUserPreferences
)
.
Put
(
bind
(
m
.
SavePreferencesCommand
{}),
wrap
(
SaveUserPreferences
))
})
})
// users (admin permission required)
// users (admin permission required)
...
@@ -165,6 +164,8 @@ func Register(r *macaron.Macaron) {
...
@@ -165,6 +164,8 @@ func Register(r *macaron.Macaron) {
r
.
Delete
(
"/:id"
,
wrap
(
DeleteApiKey
))
r
.
Delete
(
"/:id"
,
wrap
(
DeleteApiKey
))
},
reqOrgAdmin
)
},
reqOrgAdmin
)
r
.
Combo
(
"/preferences"
)
.
Get
(
GetPreferences
)
.
Put
(
bind
(
m
.
SavePreferencesCommand
{}),
wrap
(
SavePreferences
))
// Data sources
// Data sources
r
.
Group
(
"/datasources"
,
func
()
{
r
.
Group
(
"/datasources"
,
func
()
{
r
.
Get
(
"/"
,
GetDataSources
)
r
.
Get
(
"/"
,
GetDataSources
)
...
...
pkg/api/preferences.go
View file @
43b47414
...
@@ -7,32 +7,33 @@ import (
...
@@ -7,32 +7,33 @@ import (
)
)
// PUT /api/user/prefs
// PUT /api/user/prefs
func
Save
User
Preferences
(
c
*
middleware
.
Context
,
cmd
m
.
SavePreferencesCommand
)
Response
{
func
SavePreferences
(
c
*
middleware
.
Context
,
cmd
m
.
SavePreferencesCommand
)
Response
{
cmd
.
Pref
Id
=
c
.
UserId
cmd
.
User
Id
=
c
.
UserId
cmd
.
PrefType
=
`user`
cmd
.
OrgId
=
c
.
OrgId
if
err
:=
bus
.
Dispatch
(
&
cmd
);
err
!=
nil
{
if
err
:=
bus
.
Dispatch
(
&
cmd
);
err
!=
nil
{
return
ApiError
(
500
,
"Failed to saved
user
preferences"
,
err
)
return
ApiError
(
500
,
"Failed to saved preferences"
,
err
)
}
}
return
ApiSuccess
(
"
User p
references saved"
)
return
ApiSuccess
(
"
P
references saved"
)
}
}
// GET /api/user/prefs
// GET /api/user/prefs
func
Get
User
Preferences
(
c
*
middleware
.
Context
)
{
func
GetPreferences
(
c
*
middleware
.
Context
)
{
query
:=
m
.
GetPreferencesQuery
{
PrefId
:
c
.
UserId
,
PrefType
:
`user`
}
query
:=
m
.
GetPreferencesQuery
{
UserId
:
c
.
UserId
,
OrgId
:
c
.
OrgId
}
if
err
:=
bus
.
Dispatch
(
&
query
);
err
!=
nil
{
if
err
:=
bus
.
Dispatch
(
&
query
);
err
!=
nil
{
c
.
JsonApiErr
(
500
,
"Failed to get preferences
for user
"
,
err
)
c
.
JsonApiErr
(
500
,
"Failed to get preferences"
,
err
)
}
}
dto
:=
m
.
PreferencesDTO
{
dto
:=
m
.
PreferencesDTO
{
PrefId
:
query
.
Result
.
PrefId
,
Id
:
query
.
Result
.
Id
,
PrefType
:
query
.
Result
.
PrefType
,
UserId
:
query
.
Result
.
UserId
,
PrefData
:
query
.
Result
.
PrefData
,
OrgId
:
query
.
Result
.
OrgId
,
Preference
:
query
.
Result
.
Preference
,
}
}
c
.
JSON
(
200
,
dto
)
c
.
JSON
(
200
,
dto
)
...
...
pkg/models/preferences.go
View file @
43b47414
...
@@ -2,6 +2,7 @@ package models
...
@@ -2,6 +2,7 @@ package models
import
(
import
(
"errors"
"errors"
"time"
)
)
// Typed errors
// Typed errors
...
@@ -10,18 +11,22 @@ var (
...
@@ -10,18 +11,22 @@ var (
)
)
type
Preferences
struct
{
type
Preferences
struct
{
Id
int64
Id
int64
PrefId
int64
OrgId
int64
PrefType
string
UserId
int64
PrefData
map
[
string
]
interface
{}
Version
int
Preference
map
[
string
]
interface
{}
Created
time
.
Time
Updated
time
.
Time
}
}
// ---------------------
// ---------------------
// QUERIES
// QUERIES
type
GetPreferencesQuery
struct
{
type
GetPreferencesQuery
struct
{
PrefId
int64
Id
int64
PrefType
string
OrgId
int64
UserId
int64
Result
*
Preferences
Result
*
Preferences
}
}
...
@@ -30,16 +35,17 @@ type GetPreferencesQuery struct {
...
@@ -30,16 +35,17 @@ type GetPreferencesQuery struct {
// COMMANDS
// COMMANDS
type
SavePreferencesCommand
struct
{
type
SavePreferencesCommand
struct
{
Pref
Data
map
[
string
]
interface
{}
`json:"prefData
" binding:"Required"`
Pref
erence
map
[
string
]
interface
{}
`json:"Preference
" binding:"Required"`
PrefId
int64
`json:"-"`
UserId
int64
`json:"-"`
PrefType
string
`json:"-"`
OrgId
int64
`json:"-"`
}
}
// ----------------------
// ----------------------
// DTO & Projections
// DTO & Projections
type
PreferencesDTO
struct
{
type
PreferencesDTO
struct
{
PrefId
int64
`json:"prefId"`
Id
int64
`json:"Id"`
PrefType
string
`json:"prefType"`
UserId
int64
`json:"UserId"`
PrefData
map
[
string
]
interface
{}
`json:"prefData"`
OrgId
int64
`json:"OrgId"`
Preference
map
[
string
]
interface
{}
`json:"Preference"`
}
}
pkg/services/sqlstore/migrations/preferences_mig.go
View file @
43b47414
...
@@ -8,9 +8,12 @@ func addPreferencesMigrations(mg *Migrator) {
...
@@ -8,9 +8,12 @@ func addPreferencesMigrations(mg *Migrator) {
Name
:
"preferences"
,
Name
:
"preferences"
,
Columns
:
[]
*
Column
{
Columns
:
[]
*
Column
{
{
Name
:
"id"
,
Type
:
DB_BigInt
,
IsPrimaryKey
:
true
,
IsAutoIncrement
:
true
},
{
Name
:
"id"
,
Type
:
DB_BigInt
,
IsPrimaryKey
:
true
,
IsAutoIncrement
:
true
},
{
Name
:
"pref_id"
,
Type
:
DB_Int
,
Nullable
:
false
},
{
Name
:
"org_id"
,
Type
:
DB_Int
,
Nullable
:
false
},
{
Name
:
"pref_type"
,
Type
:
DB_NVarchar
,
Length
:
255
,
Nullable
:
false
},
{
Name
:
"user_id"
,
Type
:
DB_NVarchar
,
Length
:
255
,
Nullable
:
false
},
{
Name
:
"pref_data"
,
Type
:
DB_Text
,
Nullable
:
false
},
{
Name
:
"version"
,
Type
:
DB_Int
,
Nullable
:
false
},
{
Name
:
"preference"
,
Type
:
DB_Text
,
Nullable
:
false
},
{
Name
:
"created"
,
Type
:
DB_DateTime
,
Nullable
:
false
},
{
Name
:
"updated"
,
Type
:
DB_DateTime
,
Nullable
:
false
},
},
},
}
}
...
...
pkg/services/sqlstore/preferences.go
View file @
43b47414
...
@@ -12,12 +12,12 @@ func init() {
...
@@ -12,12 +12,12 @@ func init() {
func
GetPreferences
(
query
*
m
.
GetPreferencesQuery
)
error
{
func
GetPreferences
(
query
*
m
.
GetPreferencesQuery
)
error
{
sql
:=
`SELECT * FROM preferences WHERE
pref
_id = ? `
+
sql
:=
`SELECT * FROM preferences WHERE
user
_id = ? `
+
`AND
pref_type
= ?`
`AND
org_id
= ?`
var
prefResults
=
make
([]
m
.
Preferences
,
0
)
var
prefResults
=
make
([]
m
.
Preferences
,
0
)
resultsErr
:=
x
.
Sql
(
sql
,
query
.
PrefId
,
query
.
PrefType
)
.
Find
(
&
prefResults
)
resultsErr
:=
x
.
Sql
(
sql
,
query
.
UserId
,
query
.
OrgId
)
.
Find
(
&
prefResults
)
if
resultsErr
!=
nil
{
if
resultsErr
!=
nil
{
return
resultsErr
return
resultsErr
...
@@ -35,12 +35,12 @@ func GetPreferences(query *m.GetPreferencesQuery) error {
...
@@ -35,12 +35,12 @@ func GetPreferences(query *m.GetPreferencesQuery) error {
func
SavePreferences
(
cmd
*
m
.
SavePreferencesCommand
)
error
{
func
SavePreferences
(
cmd
*
m
.
SavePreferencesCommand
)
error
{
return
inTransaction2
(
func
(
sess
*
session
)
error
{
return
inTransaction2
(
func
(
sess
*
session
)
error
{
sql
:=
`SELECT * FROM preferences WHERE
pref
_id = ? `
+
sql
:=
`SELECT * FROM preferences WHERE
user
_id = ? `
+
`AND
pref_type
= ?`
`AND
org_id
= ?`
var
prefResults
=
make
([]
m
.
Preferences
,
0
)
var
prefResults
=
make
([]
m
.
Preferences
,
0
)
resultsErr
:=
sess
.
Sql
(
sql
,
cmd
.
PrefId
,
cmd
.
PrefType
)
.
Find
(
&
prefResults
)
resultsErr
:=
sess
.
Sql
(
sql
,
cmd
.
UserId
,
cmd
.
OrgId
)
.
Find
(
&
prefResults
)
if
resultsErr
!=
nil
{
if
resultsErr
!=
nil
{
return
resultsErr
return
resultsErr
...
@@ -51,13 +51,13 @@ func SavePreferences(cmd *m.SavePreferencesCommand) error {
...
@@ -51,13 +51,13 @@ func SavePreferences(cmd *m.SavePreferencesCommand) error {
var
saveErr
error
var
saveErr
error
if
len
(
prefResults
)
==
0
{
if
len
(
prefResults
)
==
0
{
savePref
.
PrefId
=
cmd
.
Pref
Id
savePref
.
UserId
=
cmd
.
User
Id
savePref
.
PrefType
=
cmd
.
PrefType
savePref
.
OrgId
=
cmd
.
OrgId
savePref
.
Pref
Data
=
cmd
.
PrefData
savePref
.
Pref
erence
=
cmd
.
Preference
affectedRows
,
saveErr
=
sess
.
Insert
(
&
savePref
)
affectedRows
,
saveErr
=
sess
.
Insert
(
&
savePref
)
}
else
{
}
else
{
savePref
=
prefResults
[
0
]
savePref
=
prefResults
[
0
]
savePref
.
Pref
Data
=
cmd
.
PrefData
savePref
.
Pref
erence
=
cmd
.
Preference
affectedRows
,
saveErr
=
sess
.
Id
(
savePref
.
Id
)
.
Update
(
&
savePref
)
affectedRows
,
saveErr
=
sess
.
Id
(
savePref
.
Id
)
.
Update
(
&
savePref
)
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment