feat(gpodder): add signup link admin methods
This commit is contained in:
parent
c48d2a78ca
commit
5cd1f4f736
5 changed files with 102 additions and 2 deletions
|
|
@ -7,6 +7,7 @@ use crate::{
|
|||
DbError,
|
||||
models::{
|
||||
session::Session,
|
||||
signup_link::SignupLink,
|
||||
user::{NewUser, User},
|
||||
},
|
||||
schema::*,
|
||||
|
|
@ -23,6 +24,15 @@ impl From<User> for gpodder::User {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<SignupLink> for gpodder::SignupLink {
|
||||
fn from(value: SignupLink) -> Self {
|
||||
Self {
|
||||
id: value.id,
|
||||
time_created: DateTime::from_timestamp(value.created_at, 0).unwrap(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl gpodder::GpodderAuthStore for SqliteRepository {
|
||||
fn get_user(&self, username: &str) -> Result<Option<gpodder::models::User>, AuthErr> {
|
||||
Ok(users::table
|
||||
|
|
@ -170,4 +180,39 @@ impl gpodder::GpodderAuthStore for SqliteRepository {
|
|||
})()
|
||||
.map_err(AuthErr::from)
|
||||
}
|
||||
|
||||
fn get_signup_link(&self, id: i64) -> Result<Option<gpodder::SignupLink>, AuthErr> {
|
||||
match signup_links::table
|
||||
.find(id)
|
||||
.select(SignupLink::as_select())
|
||||
.first(&mut self.pool.get().map_err(DbError::from)?)
|
||||
.optional()
|
||||
{
|
||||
Ok(Some(link)) => Ok(Some(gpodder::SignupLink::from(link))),
|
||||
Ok(None) => Ok(None),
|
||||
Err(err) => Err(DbError::from(err).into()),
|
||||
}
|
||||
}
|
||||
|
||||
fn insert_signup_link(&self, link: &gpodder::SignupLink) -> Result<(), AuthErr> {
|
||||
diesel::insert_into(signup_links::table)
|
||||
.values(SignupLink {
|
||||
id: link.id,
|
||||
created_at: link.time_created.timestamp(),
|
||||
})
|
||||
.execute(&mut self.pool.get().map_err(DbError::from)?)
|
||||
.map_err(DbError::from)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn remove_signup_link(&self, id: i64) -> Result<bool, AuthErr> {
|
||||
match diesel::delete(signup_links::table.filter(signup_links::id.eq(id)))
|
||||
.execute(&mut self.pool.get().map_err(DbError::from)?)
|
||||
{
|
||||
Ok(0) => Ok(false),
|
||||
Ok(_) => Ok(true),
|
||||
Err(err) => Err(DbError::from(err).into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue