BLOG-78 Backend image upload and download #84
@ -60,13 +60,14 @@ impl ImageController for ImageControllerImpl {
|
||||
return Err(ImageError::UnsupportedMimeType);
|
||||
}
|
||||
|
||||
let mime_type = image.mime_type.clone();
|
||||
let id = self
|
||||
.upload_image_use_case
|
||||
.execute(image.to_entity())
|
||||
.execute(image.into_entity())
|
||||
.await?;
|
||||
Ok(ImageInfoResponseDto {
|
||||
id: id,
|
||||
mime_type: image.mime_type,
|
||||
mime_type: mime_type,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -6,11 +6,11 @@ pub struct ImageRequestDto {
|
||||
}
|
||||
|
||||
impl ImageRequestDto {
|
||||
pub fn to_entity(&self) -> Image {
|
||||
pub fn into_entity(self) -> Image {
|
||||
Image {
|
||||
id: None,
|
||||
mime_type: self.mime_type.clone(),
|
||||
data: self.data.clone(),
|
||||
mime_type: self.mime_type,
|
||||
data: self.data,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,10 +6,10 @@ pub struct ImageDbMapper {
|
||||
}
|
||||
|
||||
impl ImageDbMapper {
|
||||
pub fn to_entity(&self) -> Image {
|
||||
pub fn into_entity(self) -> Image {
|
||||
Image {
|
||||
id: self.id,
|
||||
mime_type: self.mime_type.clone(),
|
||||
mime_type: self.mime_type,
|
||||
data: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ pub struct ColorMapper {
|
||||
}
|
||||
|
||||
impl ColorMapper {
|
||||
pub fn to_entity(&self) -> Color {
|
||||
pub fn into_entity(self) -> Color {
|
||||
Color {
|
||||
red: (self.value >> 24) as u8,
|
||||
green: ((self.value >> 16) & 0xFF) as u8,
|
||||
|
@ -7,11 +7,11 @@ pub struct LabelMapper {
|
||||
}
|
||||
|
||||
impl LabelMapper {
|
||||
pub fn to_entity(&self) -> Label {
|
||||
pub fn into_entity(self) -> Label {
|
||||
Label {
|
||||
id: self.id,
|
||||
name: self.name.clone(),
|
||||
color: self.color.to_entity(),
|
||||
name: self.name,
|
||||
color: self.color.into_entity(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,11 +7,11 @@ pub struct PostMapper {
|
||||
}
|
||||
|
||||
impl PostMapper {
|
||||
pub fn to_entity(&self) -> Post {
|
||||
pub fn into_entity(self) -> Post {
|
||||
Post {
|
||||
id: self.id,
|
||||
info: self.info.to_entity(),
|
||||
content: self.content.clone(),
|
||||
info: self.info.into_entity(),
|
||||
content: self.content,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ pub struct PostInfoMapper {
|
||||
}
|
||||
|
||||
impl PostInfoMapper {
|
||||
pub fn to_entity(&self) -> PostInfo {
|
||||
pub fn into_entity(self) -> PostInfo {
|
||||
PostInfo {
|
||||
id: self.id,
|
||||
title: self.title.clone(),
|
||||
@ -21,7 +21,7 @@ impl PostInfoMapper {
|
||||
published_time: self
|
||||
.published_time
|
||||
.map(|dt| DateTime::<Utc>::from_naive_utc_and_offset(dt, Utc)),
|
||||
labels: self.labels.iter().map(LabelMapper::to_entity).collect(),
|
||||
labels: self.labels.into_iter().map(LabelMapper::into_entity).collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ impl PostRepository for PostRepositoryImpl {
|
||||
.map(|mappers| {
|
||||
mappers
|
||||
.into_iter()
|
||||
.map(|mapper| mapper.to_entity())
|
||||
.map(|mapper| mapper.into_entity())
|
||||
.collect::<Vec<PostInfo>>()
|
||||
})
|
||||
}
|
||||
@ -37,6 +37,6 @@ impl PostRepository for PostRepositoryImpl {
|
||||
self.post_db_service
|
||||
.get_full_post(id)
|
||||
.await
|
||||
.map(|mapper| mapper.to_entity())
|
||||
.map(|mapper| mapper.into_entity())
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user