backend/model/dto/
new_seed_impl.rs1use actix_http::StatusCode;
4use uuid::Uuid;
5
6use crate::{error::ServiceError, model::entity::NewSeed};
7
8use super::NewSeedDto;
9
10impl TryFrom<(NewSeedDto, Uuid)> for NewSeed {
11 type Error = ServiceError;
12
13 fn try_from((new_seed, user_id): (NewSeedDto, Uuid)) -> Result<Self, ServiceError> {
14 let plant_id =
15 i64::from(new_seed.plant_id.ok_or_else(|| {
16 ServiceError::new(StatusCode::BAD_REQUEST, "No Plant was specified")
17 })?);
18 Ok(Self {
19 name: new_seed.name,
20 plant_id,
21 harvest_year: new_seed.harvest_year,
22 quantity: new_seed.quantity,
23 use_by: new_seed.use_by,
24 origin: new_seed.origin,
25 taste: new_seed.taste,
26 yield_: new_seed.yield_,
27 generation: new_seed.generation,
28 quality: new_seed.quality,
29 price: new_seed.price,
30 notes: new_seed.notes,
31 created_by: user_id,
32 })
33 }
34}