Skip to content
This repository has been archived by the owner on Jun 27, 2020. It is now read-only.

Commit

Permalink
Sort books on author page alphabetically
Browse files Browse the repository at this point in the history
  • Loading branch information
pgaskin committed Jun 26, 2017
1 parent 8fc9f88 commit 84748fb
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion server.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,20 @@ func AuthorsHandler(w http.ResponseWriter, r *http.Request) {
var booksHTML bytes.Buffer
booksHTML.WriteString(`<div class="books cards">`)
aname := ""
matched := []Book{}
for _, b := range books {
if b.AuthorID == aid {
aname = b.Author
booksHTML.WriteString(bookHTML(&b, true))
matched = append(matched, b)
found = true
}
}
sort.Slice(matched, func(i, j int) bool {
return matched[i].Title < matched[j].Title
})
for _, b := range matched {
booksHTML.WriteString(bookHTML(&b, true))
}
booksHTML.WriteString(`</div>`)
if found != true {
w.WriteHeader(http.StatusNotFound)
Expand Down

0 comments on commit 84748fb

Please sign in to comment.