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
8f42bec2
Commit
8f42bec2
authored
Mar 06, 2016
by
utkarshcmu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implemented GetUserPreferences API
parent
660d3fa1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
53 additions
and
1 deletions
+53
-1
pkg/api/api.go
+1
-1
pkg/api/preferences.go
+11
-0
pkg/models/preferences.go
+19
-0
pkg/services/sqlstore/preferences.go
+22
-0
No files found.
pkg/api/api.go
View file @
8f42bec2
...
...
@@ -96,7 +96,7 @@ func Register(r *macaron.Macaron) {
r
.
Delete
(
"/stars/dashboard/:id"
,
wrap
(
UnstarDashboard
))
r
.
Put
(
"/password"
,
bind
(
m
.
ChangeUserPasswordCommand
{}),
wrap
(
ChangeUserPassword
))
r
.
Get
(
"/quotas"
,
wrap
(
GetUserQuotas
))
r
.
Put
(
"/prefs"
,
bind
(
m
.
SavePreferencesCommand
{}),
wrap
(
SaveUserPreferences
))
r
.
Combo
(
"/prefs"
)
.
Get
(
GetUserPreferences
)
.
Put
(
bind
(
m
.
SavePreferencesCommand
{}),
wrap
(
SaveUserPreferences
))
})
// users (admin permission required)
...
...
pkg/api/preferences.go
View file @
8f42bec2
...
...
@@ -19,3 +19,14 @@ func SaveUserPreferences(c *middleware.Context, cmd m.SavePreferencesCommand) Re
return
ApiSuccess
(
"User preferences saved"
)
}
func
GetUserPreferences
(
c
*
middleware
.
Context
)
Response
{
query
:=
m
.
GetPreferencesQuery
{
PrefId
:
c
.
UserId
,
PrefType
:
`user`
}
if
err
:=
bus
.
Dispatch
(
&
query
);
err
!=
nil
{
return
ApiError
(
500
,
"Failed to get user"
,
err
)
}
return
Json
(
200
,
query
.
Result
)
}
pkg/models/preferences.go
View file @
8f42bec2
...
...
@@ -17,6 +17,16 @@ type Preferences struct {
}
// ---------------------
// QUERIES
type
GetPreferencesQuery
struct
{
PrefId
int64
PrefType
string
Result
PreferencesDTO
}
// ---------------------
// COMMANDS
type
SavePreferencesCommand
struct
{
...
...
@@ -24,3 +34,12 @@ type SavePreferencesCommand struct {
PrefId
int64
`json:"-"`
PrefType
string
`json:"-"`
}
// ----------------------
// DTO & Projections
type
PreferencesDTO
struct
{
PrefId
int64
`json:"prefId"`
PrefType
string
`json:"prefType"`
PrefData
map
[
string
]
interface
{}
`json:"prefData"`
}
pkg/services/sqlstore/preferences.go
View file @
8f42bec2
...
...
@@ -6,9 +6,31 @@ import (
)
func
init
()
{
bus
.
AddHandler
(
"sql"
,
GetPreferences
)
bus
.
AddHandler
(
"sql"
,
SavePreferences
)
}
func
GetPreferences
(
query
*
m
.
GetPreferencesQuery
)
error
{
sql
:=
`SELECT * FROM preferences WHERE pref_id = ? `
+
`AND pref_type = ?`
var
prefResults
=
make
([]
m
.
Preferences
,
0
)
resultsErr
:=
x
.
Sql
(
sql
,
query
.
PrefId
,
query
.
PrefType
)
.
Find
(
&
prefResults
)
if
resultsErr
!=
nil
{
return
resultsErr
}
query
.
Result
=
m
.
PreferencesDTO
{
PrefId
:
prefResults
[
0
]
.
PrefId
,
PrefType
:
prefResults
[
0
]
.
PrefType
,
PrefData
:
prefResults
[
0
]
.
PrefData
,
}
return
nil
}
func
SavePreferences
(
cmd
*
m
.
SavePreferencesCommand
)
error
{
return
inTransaction2
(
func
(
sess
*
session
)
error
{
...
...
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