Misc final tweaks
- Handle notes being nil - Distinguish between request not found, error retrieving notes, and no notes for present request - Minor UI tweaks to use smart quotes
This commit is contained in:
parent
d57e2e863a
commit
91daa387cb
@ -232,7 +232,11 @@ func FullByID(userID, reqID string) (*JournalRequest, bool) {
|
|||||||
log.Print(hRows.Err())
|
log.Print(hRows.Err())
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
req.Notes = NotesByID(userID, reqID)
|
req.Notes, err = NotesByID(userID, reqID)
|
||||||
|
if err != nil {
|
||||||
|
log.Print(err)
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
return req, true
|
return req, true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -248,9 +252,9 @@ func Journal(userID string) []JournalRequest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NotesByID retrieves the notes for a given prayer request
|
// NotesByID retrieves the notes for a given prayer request
|
||||||
func NotesByID(userID, reqID string) []Note {
|
func NotesByID(userID, reqID string) ([]Note, error) {
|
||||||
if _, ok := retrieveRequest(reqID, userID); !ok {
|
if _, ok := retrieveRequest(reqID, userID); !ok {
|
||||||
return nil
|
return nil, sql.ErrNoRows
|
||||||
}
|
}
|
||||||
rows, err := db.Query(`
|
rows, err := db.Query(`
|
||||||
SELECT "asOf", "notes"
|
SELECT "asOf", "notes"
|
||||||
@ -260,7 +264,7 @@ func NotesByID(userID, reqID string) []Note {
|
|||||||
reqID)
|
reqID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Print(err)
|
log.Print(err)
|
||||||
return nil
|
return nil, err
|
||||||
}
|
}
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
var notes []Note
|
var notes []Note
|
||||||
@ -275,9 +279,9 @@ func NotesByID(userID, reqID string) []Note {
|
|||||||
}
|
}
|
||||||
if rows.Err() != nil {
|
if rows.Err() != nil {
|
||||||
log.Print(rows.Err())
|
log.Print(rows.Err())
|
||||||
return nil
|
return nil, err
|
||||||
}
|
}
|
||||||
return notes
|
return notes, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
/* DDL */
|
/* DDL */
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package routes
|
package routes
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"database/sql"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"log"
|
"log"
|
||||||
@ -36,6 +37,12 @@ func sendJSON(c *routing.Context, result interface{}) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Send an HTTP 404 response.
|
||||||
|
func notFound(c *routing.Context) error {
|
||||||
|
c.Response.WriteHeader(404)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// Parse the request body as JSON.
|
// Parse the request body as JSON.
|
||||||
func parseJSON(c *routing.Context) (map[string]interface{}, error) {
|
func parseJSON(c *routing.Context) (map[string]interface{}, error) {
|
||||||
payload := make(map[string]interface{})
|
payload := make(map[string]interface{})
|
||||||
@ -84,8 +91,7 @@ func requestGet(c *routing.Context) error {
|
|||||||
return sendError(c, errors.New("error retrieving request"))
|
return sendError(c, errors.New("error retrieving request"))
|
||||||
}
|
}
|
||||||
if request == nil {
|
if request == nil {
|
||||||
c.Response.WriteHeader(404)
|
return notFound(c)
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
return sendJSON(c, request)
|
return sendJSON(c, request)
|
||||||
}
|
}
|
||||||
@ -96,7 +102,11 @@ func requestGetComplete(c *routing.Context) error {
|
|||||||
if !ok {
|
if !ok {
|
||||||
return sendError(c, errors.New("error retrieving request"))
|
return sendError(c, errors.New("error retrieving request"))
|
||||||
}
|
}
|
||||||
request.Notes = data.NotesByID(userID(c), c.Param("id"))
|
var err error
|
||||||
|
request.Notes, err = data.NotesByID(userID(c), c.Param("id"))
|
||||||
|
if err != nil {
|
||||||
|
return sendError(c, err)
|
||||||
|
}
|
||||||
return sendJSON(c, request)
|
return sendJSON(c, request)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,10 +142,15 @@ func requestAddNote(c *routing.Context) error {
|
|||||||
|
|
||||||
// GET: /api/request/<id>/notes
|
// GET: /api/request/<id>/notes
|
||||||
func requestGetNotes(c *routing.Context) error {
|
func requestGetNotes(c *routing.Context) error {
|
||||||
notes := data.NotesByID(userID(c), c.Param("id"))
|
notes, err := data.NotesByID(userID(c), c.Param("id"))
|
||||||
|
if err != nil {
|
||||||
|
if err == sql.ErrNoRows {
|
||||||
|
return notFound(c)
|
||||||
|
}
|
||||||
|
return sendError(c, err)
|
||||||
|
}
|
||||||
if notes == nil {
|
if notes == nil {
|
||||||
c.Response.WriteHeader(http.StatusNotFound)
|
notes = []data.Note{}
|
||||||
return errors.New("Not Found")
|
|
||||||
}
|
}
|
||||||
return sendJSON(c, notes)
|
return sendJSON(c, notes)
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,8 @@ article
|
|||||||
page-title(title='Answered Requests')
|
page-title(title='Answered Requests')
|
||||||
p(v-if='!loaded') Loading answered requests...
|
p(v-if='!loaded') Loading answered requests...
|
||||||
div(v-if='loaded').mpj-answered-list
|
div(v-if='loaded').mpj-answered-list
|
||||||
|
p.text-center(v-if='requests.length === 0'): em.
|
||||||
|
No answered requests found; once you have marked one as “Answered”, it will appear here
|
||||||
p.mpj-request-text(v-for='req in requests' :key='req.requestId')
|
p.mpj-request-text(v-for='req in requests' :key='req.requestId')
|
||||||
| {{ req.text }}
|
| {{ req.text }}
|
||||||
br
|
br
|
||||||
|
@ -48,7 +48,7 @@ export default {
|
|||||||
.sort(asOfDesc)[0].text
|
.sort(asOfDesc)[0].text
|
||||||
},
|
},
|
||||||
log () {
|
log () {
|
||||||
return this.request.notes
|
return (this.request.notes || [])
|
||||||
.map(note => ({ asOf: note.asOf, text: note.notes, status: 'Notes' }))
|
.map(note => ({ asOf: note.asOf, text: note.notes, status: 'Notes' }))
|
||||||
.concat(this.request.history)
|
.concat(this.request.history)
|
||||||
.sort(asOfDesc)
|
.sort(asOfDesc)
|
||||||
|
@ -11,7 +11,8 @@ article
|
|||||||
:request='request'
|
:request='request'
|
||||||
:events='eventBus'
|
:events='eventBus'
|
||||||
:toast='toast')
|
:toast='toast')
|
||||||
p.text-center(v-if='journal.length === 0'): em No requests found; click the "Add a New Request" button to add one
|
p.text-center(v-if='journal.length === 0'): em.
|
||||||
|
No requests found; click the “Add a New Request” button to add one
|
||||||
edit-request(:events='eventBus'
|
edit-request(:events='eventBus'
|
||||||
:toast='toast')
|
:toast='toast')
|
||||||
notes-edit(:events='eventBus'
|
notes-edit(:events='eventBus'
|
||||||
@ -50,7 +51,7 @@ export default {
|
|||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
title () {
|
title () {
|
||||||
return `${this.user.given_name}'s Prayer Journal`
|
return `${this.user.given_name}’s Prayer Journal`
|
||||||
},
|
},
|
||||||
journalCardRows () {
|
journalCardRows () {
|
||||||
return chunk(this.journal, 3)
|
return chunk(this.journal, 3)
|
||||||
|
@ -18,11 +18,11 @@ export default {
|
|||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
title () {
|
title () {
|
||||||
document.title = `${this.title} « myPrayerJournal`
|
document.title = `${this.title.replace('’', "'")} « myPrayerJournal`
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created () {
|
created () {
|
||||||
document.title = `${this.title} « myPrayerJournal`
|
document.title = `${this.title.replace('’', "'")} « myPrayerJournal`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
Reference in New Issue
Block a user