Skip to content

Commit

Permalink
Make sure that no notes retrieved returns an HTTP status code of 204,…
Browse files Browse the repository at this point in the history
… no content
  • Loading branch information
jhodapp committed Jul 29, 2024
1 parent 7de786f commit c3d16a6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
22 changes: 21 additions & 1 deletion entity_api/src/note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,27 @@ pub async fn find_by(
}
}

Ok(query.all(db).await?)
match query.all(db).await {
Ok(notes) => {
debug!("Note found: {:?}", notes);

if !notes.is_empty() {
Ok(notes)
} else {
Err(Error {
inner: None,
error_code: EntityApiErrorCode::RecordNotFound,
})
}
}
Err(err) => {
error!("Error encountered retrieving all notes {}", err);
Err(Error {
inner: None,
error_code: EntityApiErrorCode::SystemError,
})
}
}
}

#[cfg(test)]
Expand Down
9 changes: 3 additions & 6 deletions web/src/controller/note_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,11 @@ pub async fn index(
debug!("GET all Notes");
debug!("Filter Params: {:?}", params);

let coaching_sessions = NoteApi::find_by(app_state.db_conn_ref(), params).await?;
let notes = NoteApi::find_by(app_state.db_conn_ref(), params).await?;

debug!("Found Notes: {:?}", coaching_sessions);
debug!("Found Notes: {:?}", notes);

Ok(Json(ApiResponse::new(
StatusCode::OK.into(),
coaching_sessions,
)))
Ok(Json(ApiResponse::new(StatusCode::OK.into(), notes)))
}

/// GET a particular Note specified by its id.
Expand Down

0 comments on commit c3d16a6

Please sign in to comment.