add latest blog post to admin dashboard view
This commit is contained in:
parent
21912d4ec2
commit
fec3325503
5 changed files with 93 additions and 7 deletions
|
|
@ -62,39 +62,69 @@ func adminIndexHandler(app *model.AppState) http.Handler {
|
|||
|
||||
releases, err := controller.GetAllReleases(app.DB, false, 3, true)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "WARN: Failed to pull releases: %s\n", err)
|
||||
fmt.Fprintf(os.Stderr, "WARN: Failed to pull releases: %v\n", err)
|
||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
releaseCount, err := controller.GetReleaseCount(app.DB, false)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "WARN: Failed to pull releases count: %s\n", err)
|
||||
fmt.Fprintf(os.Stderr, "WARN: Failed to pull releases count: %v\n", err)
|
||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
artists, err := controller.GetAllArtists(app.DB)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "WARN: Failed to pull artists: %s\n", err)
|
||||
fmt.Fprintf(os.Stderr, "WARN: Failed to pull artists: %v\n", err)
|
||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
artistCount, err := controller.GetArtistCount(app.DB)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "WARN: Failed to pull artist count: %s\n", err)
|
||||
fmt.Fprintf(os.Stderr, "WARN: Failed to pull artist count: %v\n", err)
|
||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
tracks, err := controller.GetOrphanTracks(app.DB)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "WARN: Failed to pull orphan tracks: %s\n", err)
|
||||
fmt.Fprintf(os.Stderr, "WARN: Failed to pull orphan tracks: %v\n", err)
|
||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
trackCount, err := controller.GetTrackCount(app.DB)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "WARN: Failed to pull track count: %s\n", err)
|
||||
fmt.Fprintf(os.Stderr, "WARN: Failed to pull track count: %v\n", err)
|
||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
type BlogPost struct {
|
||||
*model.BlogPost
|
||||
Author *model.Account
|
||||
}
|
||||
blogPosts, err := controller.GetBlogPosts(app.DB, false, 1, 0)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "WARN: Failed to pull blog posts: %v\n", err)
|
||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
var latestBlogPost *BlogPost = nil
|
||||
if len(blogPosts) > 0 {
|
||||
author, err := controller.GetAccountByID(app.DB, blogPosts[0].AuthorID)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "WARN: Failed to pull latest blog post author %s: %v\n", blogPosts[0].AuthorID, err)
|
||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
latestBlogPost = &BlogPost{
|
||||
BlogPost: blogPosts[0],
|
||||
Author: author,
|
||||
}
|
||||
}
|
||||
blogCount, err := controller.GetBlogPostCount(app.DB, false)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "WARN: Failed to pull blog post count: %v\n", err)
|
||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
|
@ -107,6 +137,8 @@ func adminIndexHandler(app *model.AppState) http.Handler {
|
|||
ArtistCount int
|
||||
Tracks []*model.Track
|
||||
TrackCount int
|
||||
BlogPost *BlogPost
|
||||
BlogCount int
|
||||
}
|
||||
|
||||
err = templates.IndexTemplate.Execute(w, IndexData{
|
||||
|
|
@ -117,9 +149,11 @@ func adminIndexHandler(app *model.AppState) http.Handler {
|
|||
ArtistCount: artistCount,
|
||||
Tracks: tracks,
|
||||
TrackCount: trackCount,
|
||||
BlogPost: latestBlogPost,
|
||||
BlogCount: blogCount,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "WARN: Failed to render admin index: %s\n", err)
|
||||
fmt.Fprintf(os.Stderr, "WARN: Failed to render admin index: %v\n", err)
|
||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue