Skip to content

Commit 619f968

Browse files
committed
Trusted Publishing: Add NewUsedJti data access object
1 parent 46f612a commit 619f968

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
mod github_config;
22
mod token;
3+
mod used_jti;
34

45
pub use self::github_config::{GitHubConfig, NewGitHubConfig};
56
pub use self::token::NewToken;
7+
pub use self::used_jti::NewUsedJti;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
use crate::schema::trustpub_used_jtis;
2+
use chrono::{DateTime, Utc};
3+
use diesel::prelude::*;
4+
use diesel_async::{AsyncPgConnection, RunQueryDsl};
5+
6+
#[derive(Debug, Insertable)]
7+
#[diesel(table_name = trustpub_used_jtis, check_for_backend(diesel::pg::Pg))]
8+
pub struct NewUsedJti<'a> {
9+
pub jti: &'a str,
10+
pub expires_at: DateTime<Utc>,
11+
}
12+
13+
impl<'a> NewUsedJti<'a> {
14+
pub fn new(jti: &'a str, expires_at: DateTime<Utc>) -> Self {
15+
Self { jti, expires_at }
16+
}
17+
18+
pub async fn insert(&self, conn: &mut AsyncPgConnection) -> QueryResult<usize> {
19+
diesel::insert_into(trustpub_used_jtis::table)
20+
.values(self)
21+
.execute(conn)
22+
.await
23+
}
24+
}

0 commit comments

Comments
 (0)