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
b79f0449
Commit
b79f0449
authored
Jan 12, 2016
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
style(playlist): abstract DTO creation
parent
7e7d9457
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
42 deletions
+23
-42
pkg/api/playlist.go
+23
-42
No files found.
pkg/api/playlist.go
View file @
b79f0449
...
...
@@ -55,33 +55,40 @@ func GetPlaylist(c *middleware.Context) Response {
return
ApiError
(
500
,
"Playlist not found"
,
err
)
}
itemQuery
:=
m
.
GetPlaylistItemsByIdQuery
{
PlaylistId
:
id
}
if
err
:=
bus
.
Dispatch
(
&
itemQuery
);
err
!=
nil
{
log
.
Warn
(
"itemQuery failed: %v"
,
err
)
return
ApiError
(
500
,
"Playlist items not found"
,
err
)
playlistDTOs
,
_
:=
LoadPlaylistItemDTOs
(
id
)
dto
:=
&
m
.
PlaylistDTO
{
Id
:
cmd
.
Result
.
Id
,
Title
:
cmd
.
Result
.
Title
,
Timespan
:
cmd
.
Result
.
Timespan
,
OrgId
:
cmd
.
Result
.
OrgId
,
Items
:
playlistDTOs
,
}
return
Json
(
200
,
dto
)
}
func
LoadPlaylistItemDTOs
(
id
int64
)
([]
m
.
PlaylistItemDTO
,
error
)
{
playlistitems
,
err
:=
LoadPlaylistItems
(
id
)
if
err
!=
nil
{
return
nil
,
err
}
playlistDTOs
:=
make
([]
m
.
PlaylistItemDTO
,
0
)
for
_
,
item
:=
range
*
itemQuery
.
Result
{
for
_
,
item
:=
range
playlistitems
{
playlistDTOs
=
append
(
playlistDTOs
,
m
.
PlaylistItemDTO
{
Id
:
item
.
Id
,
PlaylistId
:
item
.
PlaylistId
,
Type
:
item
.
Type
,
Value
:
item
.
Value
,
Order
:
item
.
Order
,
Title
:
item
.
Title
,
})
}
dto
:=
&
m
.
PlaylistDTO
{
Id
:
cmd
.
Result
.
Id
,
Title
:
cmd
.
Result
.
Title
,
Timespan
:
cmd
.
Result
.
Timespan
,
OrgId
:
cmd
.
Result
.
OrgId
,
Items
:
playlistDTOs
,
}
return
Json
(
200
,
dto
)
return
playlistDTOs
,
nil
}
func
LoadPlaylistItems
(
id
int64
)
([]
m
.
PlaylistItem
,
error
)
{
...
...
@@ -130,25 +137,12 @@ func LoadPlaylistDashboards(id int64) ([]m.PlaylistDashboardDto, error) {
func
GetPlaylistItems
(
c
*
middleware
.
Context
)
Response
{
id
:=
c
.
ParamsInt64
(
":id"
)
items
,
err
:=
LoadPlaylistItem
s
(
id
)
playlistDTOs
,
err
:=
LoadPlaylistItemDTO
s
(
id
)
if
err
!=
nil
{
return
ApiError
(
500
,
"Could not load playlist items"
,
err
)
}
playlistDTOs
:=
make
([]
m
.
PlaylistItemDTO
,
0
)
for
_
,
item
:=
range
items
{
playlistDTOs
=
append
(
playlistDTOs
,
m
.
PlaylistItemDTO
{
Id
:
item
.
Id
,
PlaylistId
:
item
.
PlaylistId
,
Type
:
item
.
Type
,
Value
:
item
.
Value
,
Order
:
item
.
Order
,
Title
:
item
.
Title
,
})
}
return
Json
(
200
,
playlistDTOs
)
}
...
...
@@ -190,20 +184,7 @@ func UpdatePlaylist(c *middleware.Context, query m.UpdatePlaylistQuery) Response
return
ApiError
(
500
,
"Failed to save playlist"
,
err
)
}
items
,
err
:=
LoadPlaylistItems
(
query
.
Id
)
playlistDTOs
:=
make
([]
m
.
PlaylistItemDTO
,
0
)
for
_
,
item
:=
range
items
{
playlistDTOs
=
append
(
playlistDTOs
,
m
.
PlaylistItemDTO
{
Id
:
item
.
Id
,
PlaylistId
:
item
.
PlaylistId
,
Type
:
item
.
Type
,
Value
:
item
.
Value
,
Order
:
item
.
Order
,
})
}
playlistDTOs
,
err
:=
LoadPlaylistItemDTOs
(
query
.
Id
)
if
err
!=
nil
{
return
ApiError
(
500
,
"Failed to save playlist"
,
err
)
}
...
...
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