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
5ba24236
Commit
5ba24236
authored
Jan 26, 2015
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Worked on account update view
parent
9a641ee7
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
58 additions
and
3 deletions
+58
-3
grafana
+1
-1
pkg/api/account.go
+33
-1
pkg/api/api.go
+2
-0
pkg/models/account.go
+6
-1
pkg/services/sqlstore/account.go
+16
-0
No files found.
grafana
@
a6b08560
Subproject commit a
b7e2f89fb596d6adc9a28177feb97574e860ce
7
Subproject commit a
6b0856020847b6530b9d1505fe39f347988be5
7
pkg/api/account.go
View file @
5ba24236
...
...
@@ -6,13 +6,45 @@ import (
m
"github.com/torkelo/grafana-pro/pkg/models"
)
func
GetAccount
(
c
*
middleware
.
Context
)
{
query
:=
m
.
GetAccountByIdQuery
{
Id
:
c
.
AccountId
}
if
err
:=
bus
.
Dispatch
(
&
query
);
err
!=
nil
{
if
err
==
m
.
ErrAccountNotFound
{
c
.
JsonApiErr
(
404
,
"Account not found"
,
err
)
return
}
c
.
JsonApiErr
(
500
,
"Failed to get account"
,
err
)
return
}
account
:=
m
.
AccountDTO
{
Id
:
query
.
Result
.
Id
,
Name
:
query
.
Result
.
Name
,
}
c
.
JSON
(
200
,
&
account
)
}
func
CreateAccount
(
c
*
middleware
.
Context
,
cmd
m
.
CreateAccountCommand
)
{
cmd
.
UserId
=
c
.
UserId
if
err
:=
bus
.
Dispatch
(
&
cmd
);
err
!=
nil
{
c
.
JsonApiErr
(
500
,
"Failed to create account"
,
nil
)
c
.
JsonApiErr
(
500
,
"Failed to create account"
,
err
)
return
}
c
.
JsonOK
(
"Account created"
)
}
func
UpdateAccount
(
c
*
middleware
.
Context
,
cmd
m
.
UpdateAccountCommand
)
{
cmd
.
AccountId
=
c
.
AccountId
if
err
:=
bus
.
Dispatch
(
&
cmd
);
err
!=
nil
{
c
.
JsonApiErr
(
500
,
"Failed to update account"
,
err
)
return
}
c
.
JsonOK
(
"Account updated"
)
}
pkg/api/api.go
View file @
5ba24236
...
...
@@ -49,7 +49,9 @@ func Register(r *macaron.Macaron) {
// account
r
.
Group
(
"/account"
,
func
()
{
r
.
Get
(
"/"
,
GetAccount
)
r
.
Post
(
"/"
,
bind
(
m
.
CreateAccountCommand
{}),
CreateAccount
)
r
.
Put
(
"/"
,
bind
(
m
.
UpdateAccountCommand
{}),
UpdateAccount
)
r
.
Post
(
"/users"
,
bind
(
m
.
AddAccountUserCommand
{}),
AddAccountUser
)
r
.
Get
(
"/users"
,
GetAccountUsers
)
r
.
Delete
(
"/users/:id"
,
RemoveAccountUser
)
...
...
pkg/models/account.go
View file @
5ba24236
...
...
@@ -29,7 +29,7 @@ type CreateAccountCommand struct {
}
type
UpdateAccountCommand
struct
{
Name
string
`json:"name"`
Name
string
`json:"name"
binding:"Required"
`
AccountId
int64
`json:"-"`
}
...
...
@@ -43,6 +43,11 @@ type GetAccountByIdQuery 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"`
...
...
pkg/services/sqlstore/account.go
View file @
5ba24236
...
...
@@ -10,11 +10,27 @@ import (
)
func
init
()
{
bus
.
AddHandler
(
"sql"
,
GetAccount
)
bus
.
AddHandler
(
"sql"
,
CreateAccount
)
bus
.
AddHandler
(
"sql"
,
SetUsingAccount
)
bus
.
AddHandler
(
"sql"
,
UpdateAccount
)
}
func
GetAccount
(
query
*
m
.
GetAccountByIdQuery
)
error
{
var
account
m
.
Account
exists
,
err
:=
x
.
Id
(
query
.
Id
)
.
Get
(
&
account
)
if
err
!=
nil
{
return
err
}
if
!
exists
{
return
m
.
ErrAccountNotFound
}
query
.
Result
=
&
account
return
nil
}
func
CreateAccount
(
cmd
*
m
.
CreateAccountCommand
)
error
{
return
inTransaction
(
func
(
sess
*
xorm
.
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