-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from FuelLabs/sophie/poll-api
feat: Package updates API for explorer indexer
- Loading branch information
Showing
13 changed files
with
459 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use rocket::FromForm; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Deserialize, FromForm, Clone, Debug)] | ||
pub struct Pagination { | ||
pub page: Option<i64>, | ||
pub per_page: Option<i64>, | ||
} | ||
|
||
impl Pagination { | ||
pub fn page(&self) -> i64 { | ||
self.page.unwrap_or(1) | ||
} | ||
|
||
pub fn limit(&self) -> i64 { | ||
self.per_page.unwrap_or(10).max(1) // Default to 10 per page | ||
} | ||
|
||
pub fn offset(&self) -> i64 { | ||
(self.page() - 1) * self.limit() | ||
} | ||
} | ||
|
||
#[derive(Serialize)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct PaginatedResponse<T> { | ||
pub data: Vec<T>, | ||
pub total_count: i64, | ||
pub total_pages: i64, | ||
pub current_page: i64, | ||
pub per_page: i64, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,71 @@ | ||
use crate::models::PackagePreview; | ||
use crate::{ | ||
models::PackagePreview, | ||
pinata::{ipfs_hash_to_abi_url, ipfs_hash_to_tgz_url}, | ||
}; | ||
use serde::Serialize; | ||
use url::Url; | ||
|
||
#[derive(Serialize, Debug)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct RecentPackagesResponse { | ||
pub recently_created: Vec<PackagePreview>, | ||
pub recently_updated: Vec<PackagePreview>, | ||
} | ||
|
||
#[derive(Serialize, Debug)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct FullPackage { | ||
#[serde(flatten)] | ||
pub package_preview: PackagePreview, | ||
|
||
// Metadata from Uploads table | ||
pub bytecode_identifier: Option<String>, | ||
pub forc_version: String, | ||
|
||
// IPFS URLs | ||
pub source_code_ipfs_url: String, | ||
pub abi_ipfs_url: Option<String>, | ||
|
||
// Version Metadata | ||
pub repository: Option<Url>, | ||
pub documentation: Option<Url>, | ||
pub homepage: Option<Url>, | ||
pub urls: Vec<Url>, | ||
pub readme: Option<String>, | ||
pub license: Option<String>, | ||
} | ||
|
||
impl From<crate::models::FullPackage> for FullPackage { | ||
fn from(full_package: crate::models::FullPackage) -> Self { | ||
fn string_to_url(s: String) -> Option<Url> { | ||
Url::parse(&s).ok() | ||
} | ||
|
||
FullPackage { | ||
package_preview: PackagePreview { | ||
name: full_package.name, | ||
version: full_package.version, | ||
description: full_package.description, | ||
created_at: full_package.created_at, | ||
updated_at: full_package.updated_at, | ||
}, | ||
bytecode_identifier: full_package.bytecode_identifier, | ||
forc_version: full_package.forc_version, | ||
source_code_ipfs_url: ipfs_hash_to_tgz_url(&full_package.source_code_ipfs_hash), | ||
abi_ipfs_url: full_package | ||
.abi_ipfs_hash | ||
.map(|hash| ipfs_hash_to_abi_url(&hash)), | ||
repository: full_package.repository.and_then(string_to_url), | ||
documentation: full_package.documentation.and_then(string_to_url), | ||
homepage: full_package.homepage.and_then(string_to_url), | ||
urls: full_package | ||
.urls | ||
.into_iter() | ||
.flatten() | ||
.filter_map(string_to_url) | ||
.collect(), | ||
license: full_package.license, | ||
readme: full_package.readme, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.