Add authentication to more handlers

This commit is contained in:
2020-08-01 02:18:31 -04:00
parent eb7706974e
commit d1c933e1ea
13 changed files with 99 additions and 60 deletions

View File

@@ -32,7 +32,7 @@ pub struct InteriorRef {
pub struct InteriorRefList {
pub id: Option<i32>,
pub shop_id: i32,
pub owner_id: i32,
pub owner_id: Option<i32>,
pub ref_list: Json<Vec<InteriorRef>>,
pub created_at: Option<NaiveDateTime>,
pub updated_at: Option<NaiveDateTime>,

View File

@@ -14,7 +14,7 @@ where
fn pk(&self) -> Option<i32>;
fn url(&self, api_url: &Url) -> Result<Url> {
if let Some(pk) = self.pk() {
Ok(api_url.join(&format!("/{}s/{}", Self::resource_name(), pk))?)
Ok(api_url.join(&format!("{}s/{}", Self::resource_name(), pk))?)
} else {
Err(anyhow!(
"Cannot get URL for {} with no primary key",

View File

@@ -15,7 +15,9 @@ use crate::problem::forbidden_permission;
pub struct Owner {
pub id: Option<i32>,
pub name: String,
pub api_key: Uuid,
#[serde(skip_serializing)]
pub api_key: Option<Uuid>,
#[serde(skip_serializing)]
pub ip_address: Option<IpNetwork>,
pub mod_version: String,
pub created_at: Option<NaiveDateTime>,
@@ -40,7 +42,7 @@ impl Model for Owner {
.map_err(Error::new)
}
#[instrument(level = "debug", skip(db))]
#[instrument(level = "debug", skip(self, db))]
async fn save(self, db: &PgPool) -> Result<Self> {
Ok(sqlx::query_as!(
Self,

View File

@@ -13,7 +13,7 @@ use crate::problem::forbidden_permission;
pub struct Shop {
pub id: Option<i32>,
pub name: String,
pub owner_id: i32,
pub owner_id: Option<i32>,
pub description: String,
pub is_not_sell_buy: bool,
pub sell_buy_list_id: i32,
@@ -41,7 +41,7 @@ impl Model for Shop {
.map_err(Error::new)
}
#[instrument(level = "debug", skip(db))]
#[instrument(level = "debug", skip(self, db))]
async fn save(self, db: &PgPool) -> Result<Self> {
Ok(sqlx::query_as!(
Self,