summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <matthias.beyer@atos.net>2021-04-22 08:27:49 +0200
committerMatthias Beyer <matthias.beyer@atos.net>2021-04-22 08:38:39 +0200
commitc52c4595f6aaab514e3ceaa72b8bf27456f4947f (patch)
tree4fcd8c586a653bc96cab7d62e8f7f2caa710e9ea
parent5390536f0a4d5e724134cb3b950390bc82025fb7 (diff)
Add helper functions to load Endpoint from DB
Signed-off-by: Matthias Beyer <matthias.beyer@atos.net>
-rw-r--r--src/db/models/endpoint.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/db/models/endpoint.rs b/src/db/models/endpoint.rs
index d7a7986..3909b2b 100644
--- a/src/db/models/endpoint.rs
+++ b/src/db/models/endpoint.rs
@@ -43,4 +43,16 @@ impl Endpoint {
.first::<Endpoint>(database_connection)
.map_err(Error::from)
}
+
+ pub fn fetch_for_job(database_connection: &PgConnection, j: &crate::db::models::Job) -> Result<Option<Endpoint>> {
+ Self::fetch_by_id(database_connection, j.endpoint_id)
+ }
+
+ pub fn fetch_by_id(database_connection: &PgConnection, eid: i32) -> Result<Option<Endpoint>> {
+ match dsl::endpoints.filter(id.eq(eid)).first::<Endpoint>(database_connection) {
+ Err(diesel::result::Error::NotFound) => Ok(None),
+ Err(e) => Err(Error::from(e)),
+ Ok(e) => Ok(Some(e)),
+ }
+ }
}