Fixed "answered" API error

This commit is contained in:
Daniel J. Summers 2018-05-27 18:00:37 -05:00
parent 79ced40470
commit 9de713fc6a
3 changed files with 15 additions and 10 deletions

View File

@ -156,9 +156,6 @@ func Answered(userID string) []JournalRequest {
AND "lastStatus" = 'Answered'
ORDER BY "asOf" DESC`,
userID)
if err == sql.ErrNoRows {
return make([]JournalRequest, 0)
}
if err != nil {
log.Print(err)
return nil
@ -177,6 +174,9 @@ func ByID(userID, reqID string) (*JournalRequest, bool) {
&req.RequestID, &req.Text, &req.AsOf, &req.LastStatus,
)
if err != nil {
if err == sql.ErrNoRows {
return nil, true
}
log.Print(err)
return nil, false
}

View File

@ -83,6 +83,10 @@ func requestGet(c *routing.Context) error {
if !ok {
return sendError(c, errors.New("error retrieving request"))
}
if request == nil {
c.Response.WriteHeader(404)
return nil
}
return sendJSON(c, request)
}

View File

@ -35,6 +35,14 @@ var routes = Routes{
requestAdd,
false,
},
// Must be above GetRequestByID
Route{
"GetAnsweredRequests",
http.MethodGet,
"/api/request/answered",
requestsAnswered,
false,
},
Route{
"GetRequestByID",
http.MethodGet,
@ -77,13 +85,6 @@ var routes = Routes{
requestGetNotes,
false,
},
Route{
"GetAnsweredRequests",
http.MethodGet,
"/api/request/answered",
requestsAnswered,
false,
},
// keep this route last
Route{
"StaticFiles",