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

View File

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

View File

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