Skip to content

Commit 4a3c305

Browse files
committed
feat(product): enhance product info endpoint
1 parent b0fed6e commit 4a3c305

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

route/api.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ pub fn api_router(cfg: &mut web::ServiceConfig) {
5858
)
5959
.service(
6060
scope("/product")
61-
.service(
61+
.route("/list", post().to(product_list))
62+
.route("/info/{uid}",get().to(product_info))
63+
.route("/down/{uid}",get().to(product_download)).service(
6264
scope("/{owner}/{repo}")
6365
.route("/post",post().to(product_post))
6466
)
65-
.route("/list", post().to(product_list))
66-
.route("/info/{uid}",get().to(product_info))
67-
.route("/down/{uid}",get().to(product_download))
67+
6868
)
6969

7070
;

services/product/download.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use crate::services::AppState;
66
impl AppState {
77
pub async fn product_data_download_zip(&self, product: Uuid) -> io::Result<actix_files::NamedFile> {
88
let product = self.product_info(product).await?;
9-
let repo = self.repo_get_by_uid(product.repository_uid).await?;
10-
let hash = product.hash;
9+
let repo = self.repo_get_by_uid(product.data.repository_uid).await?;
10+
let hash = product.data.hash;
1111
let path = format!("{}/{}/{}/", GIT_ROOT, repo.node_uid, repo.uid);
1212
let zip_path = format!("{}/product/{}.zip", path, hash);
1313
if std::fs::metadata(&zip_path).is_err() {

services/product/info.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,19 @@ use sea_orm::EntityTrait;
33
use uuid::Uuid;
44
use crate::model::product::data_product;
55
use crate::services::AppState;
6+
use crate::services::product::list::ProductList;
67

78
impl AppState {
8-
pub async fn product_info(&self, uid: Uuid) -> io::Result<data_product::Model> {
9-
data_product::Entity::find_by_id(uid)
9+
pub async fn product_info(&self, uid: Uuid) -> io::Result<ProductList> {
10+
let data = data_product::Entity::find_by_id(uid)
1011
.one(&self.read)
1112
.await
1213
.map_err(|e| io::Error::new(io::ErrorKind::Other, e.to_string()))?
13-
.ok_or_else(|| io::Error::new(io::ErrorKind::NotFound, "Product not found"))
14+
.ok_or_else(|| io::Error::new(io::ErrorKind::NotFound, "Product not found"))?;
15+
Ok(ProductList {
16+
data: data.clone(),
17+
owner: self.user_info_by_uid(data.owner).await?,
18+
repo: self.repo_get_by_uid(data.repository_uid).await?,
19+
})
1420
}
1521
}

0 commit comments

Comments
 (0)