Skip to content
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.

Commit

Permalink
Cleanup backend after merge confusions.
Browse files Browse the repository at this point in the history
  • Loading branch information
horenso committed Mar 4, 2024
1 parent 013be58 commit bdcfc34
Show file tree
Hide file tree
Showing 16 changed files with 71 additions and 461 deletions.
4 changes: 2 additions & 2 deletions backend/src/config/api_doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::{
model::{
dto::{
core::{
ActionDtoWrapperDeletePlantings, ActionDtoWrapperPlantings,
ActionDtoWrapperDeletePlantings, ActionDtoWrapperNewPlantings,
ActionDtoWrapperUpdatePlantings, TimelinePagePlantingsDto,
},
plantings::{
Expand Down Expand Up @@ -179,7 +179,7 @@ struct BaseLayerImagesApiDoc;
UpdateAddDatePlantingDto,
UpdateRemoveDatePlantingDto,
UpdatePlantingNoteDto,
ActionDtoWrapperPlantings,
ActionDtoWrapperNewPlantings,
ActionDtoWrapperUpdatePlantings,
ActionDtoWrapperDeletePlantings,
)
Expand Down
15 changes: 4 additions & 11 deletions backend/src/controller/plantings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@ use crate::{
DeletePlantingDto, NewPlantingDto, PlantingSearchParameters, UpdatePlantingDto,
},
},
use crate::{
config::auth::user_info::UserInfo,
model::dto::{actions::Action, plantings::MapPlantingDto},
};
use crate::{config::data::AppDataInner, model::dto::core::ActionDtoWrapper};
use crate::{
model::dto::plantings::{DeletePlantingDto, PlantingSearchParameters, UpdatePlantingDto},
service::plantings,
};

Expand Down Expand Up @@ -63,9 +56,9 @@ pub async fn find(
params(
("map_id" = i32, Path, description = "The id of the map the layer is on"),
),
request_body = ActionDtoWrapperPlantings,
request_body = ActionDtoWrapperNewPlantings,
responses(
(status = 201, description = "Create plantings", body = Vec<MapPlantingDto>)
(status = 201, description = "Create plantings", body = Vec<NewPlantingDto>)
),
security(
("oauth2" = [])
Expand All @@ -74,7 +67,7 @@ pub async fn find(
#[post("")]
pub async fn create(
path: Path<i32>,
new_plantings: Json<ActionDtoWrapper<Vec<MapPlantingDto>>>,
new_plantings: Json<ActionDtoWrapper<Vec<NewPlantingDto>>>,
app_data: Data<AppDataInner>,
user_info: UserInfo,
) -> Result<HttpResponse> {
Expand Down Expand Up @@ -106,7 +99,7 @@ pub async fn create(
),
request_body = ActionDtoWrapperUpdatePlantings,
responses(
(status = 200, description = "Update plantings", body = Vec<MapPlantingDto>)
(status = 200, description = "Update plantings", body = Vec<PlantingDto>)
),
security(
("oauth2" = [])
Expand Down
2 changes: 1 addition & 1 deletion backend/src/model/dto/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use super::plantings::{DeletePlantingDto, PlantingDto, UpdatePlantingDto};
#[typeshare]
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
#[aliases(
ActionDtoWrapperPlantings = ActionDtoWrapper<Vec<PlantingDto>>,
ActionDtoWrapperNewPlantings = ActionDtoWrapper<Vec<PlantingDto>>,
ActionDtoWrapperUpdatePlantings = ActionDtoWrapper<UpdatePlantingDto>,
ActionDtoWrapperDeletePlantings = ActionDtoWrapper<Vec<DeletePlantingDto>>,
)]
Expand Down
7 changes: 3 additions & 4 deletions backend/src/model/dto/plantings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,9 @@ pub struct NewPlantingDto {
pub size_y: i32,
/// The rotation of the plant on the map.
pub rotation: f32,
/// The x scale of the plant on the map.
pub scale_x: f32,
/// The y scale of the plant on the map.
pub scale_y: f32,
/// The date the planting was added to the map.
/// If None, the planting always existed.
pub add_date: Option<NaiveDate>,
/// Plantings may be linked with a seed.
pub seed_id: Option<i32>,
/// Is the planting an area of plants.
Expand Down
9 changes: 4 additions & 5 deletions backend/src/model/dto/plantings_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use uuid::Uuid;
use crate::model::entity::plantings::{NewPlanting, Planting, UpdatePlanting};

use super::plantings::{
MovePlantingDto, PlantingDto, TransformPlantingDto, UpdateAddDatePlantingDto,
MovePlantingDto, NewPlantingDto, PlantingDto, TransformPlantingDto, UpdateAddDatePlantingDto,
UpdatePlantingDto, UpdatePlantingNoteDto, UpdateRemoveDatePlantingDto,
};

Expand Down Expand Up @@ -44,8 +44,8 @@ impl From<Planting> for PlantingDto {
}
}

impl From<(PlantingDto, Uuid)> for NewPlanting {
fn from((dto, user_id): (PlantingDto, Uuid)) -> Self {
impl From<(NewPlantingDto, Uuid)> for NewPlanting {
fn from((dto, user_id): (NewPlantingDto, Uuid)) -> Self {
Self {
id: dto.id,
plant_id: dto.plant_id,
Expand All @@ -57,10 +57,9 @@ impl From<(PlantingDto, Uuid)> for NewPlanting {
size_x: dto.size_x,
size_y: dto.size_y,
rotation: dto.rotation,
scale_x: dto.scale_x,
scale_y: dto.scale_y,
seed_id: dto.seed_id,
is_area: dto.is_area,
add_date: dto.add_date,
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion backend/src/model/entity/map_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ impl Map {
query.get_result::<Self>(conn).await.map(Into::into)
}

/// Update modified metadate (modified_at, modified_by) of the map.
/// Update modified metadate (`modified_at`, `modified_by`) of the map.
///
/// # Errors
/// * Unknown, diesel doesn't say why it might error.
Expand Down
22 changes: 7 additions & 15 deletions backend/src/model/entity/plantings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,16 @@ pub struct Planting {
pub layer_id: i32,
/// The plant that is planted.
pub plant_id: i32,

/// The x coordinate of the position on the map.
pub x: i32,
/// The y coordinate of the position on the map.
pub y: i32,
/// The width of the plant on the map.
pub width: i32,
/// The height of the plant on the map.
pub height: i32,
/// The size of the planting on the map in x direction.
pub size_x: i32,
/// The size of the planting on the map in y direction.
pub size_y: i32,
/// The rotation in degrees (0-360) of the plant on the map.
pub rotation: f32,
/// The x scale of the plant on the map.
pub scale_x: f32,
/// The y scale of the plant on the map.
pub scale_y: f32,

/// The date the planting was added to the map.
/// If None, the planting always existed.
pub add_date: Option<NaiveDate>,
Expand Down Expand Up @@ -84,11 +78,9 @@ pub struct NewPlanting {
pub size_y: i32,
/// The rotation in degrees (0-360) of the plant on the map.
pub rotation: f32,
/// The x scale of the plant on the map.
pub scale_x: f32,
/// The y scale of the plant on the map.
pub scale_y: f32,

/// The date the planting was added to the map.
/// If None, the planting always existed.
pub add_date: Option<NaiveDate>,
/// Plantings may be linked with a seed.
pub seed_id: Option<i32>,
/// Is the planting an area of plants.
Expand Down
16 changes: 9 additions & 7 deletions backend/src/model/entity/plantings_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ use uuid::Uuid;

use super::plantings::UpdatePlanting;
use super::Map;
use crate::model::dto::plantings::{DeletePlantingDto, MapPlantingDto, UpdatePlantingDto};
use crate::model::dto::plantings::{
DeletePlantingDto, NewPlantingDto, PlantingDto, UpdatePlantingDto,
};
use crate::model::entity::plantings::{NewPlanting, Planting};
use crate::schema::plantings::{self, layer_id, plant_id};
use crate::schema::seeds;
Expand All @@ -38,7 +40,7 @@ impl Planting {
pub async fn find(
search_parameters: FindPlantingsParameters,
conn: &mut AsyncPgConnection,
) -> QueryResult<Vec<MapPlantingDto>> {
) -> QueryResult<Vec<PlantingDto>> {
let mut query = plantings::table
.left_join(seeds::table)
.select((plantings::all_columns, seeds::name.nullable()))
Expand Down Expand Up @@ -79,7 +81,7 @@ impl Planting {
pub async fn find_by_seed_id(
seed_id: i32,
conn: &mut AsyncPgConnection,
) -> QueryResult<Vec<MapPlantingDto>> {
) -> QueryResult<Vec<PlantingDto>> {
let query = plantings::table
.select(plantings::all_columns)
.filter(plantings::seed_id.eq(seed_id));
Expand All @@ -98,11 +100,11 @@ impl Planting {
/// * If the `layer_id` references a layer that is not of type `plant`.
/// * Unknown, diesel doesn't say why it might error.
pub async fn create(
dto_vec: Vec<MapPlantingDto>,
dto_vec: Vec<NewPlantingDto>,
map_id: i32,
user_id: Uuid,
conn: &mut AsyncPgConnection,
) -> QueryResult<Vec<MapPlantingDto>> {
) -> QueryResult<Vec<PlantingDto>> {
let planting_creations: Vec<NewPlanting> = dto_vec
.into_iter()
.map(|dto| NewPlanting::from((dto, user_id)))
Expand Down Expand Up @@ -134,7 +136,7 @@ impl Planting {

let result_vec = query_result
.into_iter()
.map(MapPlantingDto::from)
.map(PlantingDto::from)
.map(|mut dto| {
if let Some(seed_id) = dto.seed_id {
dto.additional_name = seed_ids_to_names.get(&seed_id).cloned();
Expand All @@ -159,7 +161,7 @@ impl Planting {
map_id: i32,
user_id: Uuid,
conn: &mut AsyncPgConnection,
) -> QueryResult<Vec<MapPlantingDto>> {
) -> QueryResult<Vec<PlantingDto>> {
let planting_updates = Vec::from(dto);

let result = conn
Expand Down
Loading

0 comments on commit bdcfc34

Please sign in to comment.