Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: item query support and item types #19

Merged
merged 7 commits into from
Oct 21, 2024
Merged

Conversation

Mettwasser
Copy link
Collaborator

@Mettwasser Mettwasser commented Oct 19, 2024

What did you fix?

Adds support for the /items/{query} endpoint, with their respective types.

Reproduction steps

None


Evidence/screenshot/link to line

Considerations

  • Does this contain a new dependency? [Yes]
  • Does this introduce opinionated data formatting or manual data entry? [Yes]
  • Does this pr include updated data files in a separate commit that can be reverted for a clean code-only pr? [Yes]
  • Have I run the linter? [Yes]
  • Is is a bug fix, feature request, or enhancement? [Feature]

Summary by CodeRabbit

  • New Features

    • Introduced new dependencies for enhanced functionality.
    • Added caching capabilities to the market client for improved data retrieval.
    • New methods for querying items by name and language in the worldstate client.
    • Added new data models for various items, including Arcane, Archwing, Fish, Gear, and more.
    • Introduced new models for SyndicateJob and VoidTraderInventoryItem.
  • Bug Fixes

    • Improved error handling for API requests in the worldstate client.
  • Documentation

    • Enhanced code comments and documentation for better readability and understanding.
  • Style

    • Reformatted import statements and code comments across multiple files for improved clarity and consistency.

@Mettwasser Mettwasser requested a review from TobiTenno October 19, 2024 18:41
@Mettwasser Mettwasser requested review from CraigEge and removed request for TobiTenno October 19, 2024 18:47
src/worldstate/models/items/mod.rs Outdated Show resolved Hide resolved
Copy link

coderabbitai bot commented Oct 21, 2024

Walkthrough

The pull request introduces several updates across multiple files in the codebase. Key changes include the addition of new dependencies in the Cargo.toml file, the introduction of new configuration settings for Rust formatting in rustfmt.toml, and significant modifications to various models and client structures in the src directory. Notably, new structs and methods are added to enhance functionality, particularly for item querying and caching mechanisms. Additionally, many files undergo formatting improvements to enhance readability without altering existing logic.

Changes

File Path Change Summary
Cargo.toml Added dependencies: strum = { version = "0.26.3", features = ["derive"] }, urlencoding = "2.1.3".
rustfmt.toml Introduced configuration options for Rust code formatting, including comment_width, format_code_in_doc_comments, imports_granularity, imports_layout, wrap_comments, group_imports, use_field_init_shorthand.
src/lib.rs Removed #[forbid(missing_docs)] from worldstate module; restructured imports from ws module for clarity.
src/market/client.rs Enhanced Client struct with new caching methods and modified return types for several methods to use Arc<T> instead of T. Added new_with_cache method.
src/market/models/item.rs Reformatted serde imports for improved readability.
src/market/models/item_info.rs Reformatted serde imports for improved readability.
src/market/models/orders.rs Reformatted import statements; added comments for clarity.
src/market/models/statistic_item.rs Reformatted import statements for clarity.
src/worldstate/client.rs Added new methods for querying items by name and language, including query_item and query_item_using_lang. Introduced internal method query_by_url.
src/worldstate/language.rs Introduced Language enum with variants for supported languages and implementations for From and Display traits.
src/worldstate/listener.rs Reformatted documentation comments for better readability.
src/worldstate/mod.rs Restructured pub mod prelude section to consolidate pub use statements for clarity.
src/worldstate/models/alert.rs Reformatted import statements for improved readability.
src/worldstate/models/arbitration.rs Added new field activation to Arbitration struct; updated expiry field with a custom deserializer.
src/worldstate/models/archon_hunt.rs Reformatted import statements for improved readability.
src/worldstate/models/base.rs Reorganized import statements for readability; minor formatting changes in comments.
src/worldstate/models/cambion_drift.rs Reformatted import statements for clarity.
src/worldstate/models/cetus.rs Reformatted import statements and comments for clarity.
src/worldstate/models/construction_progress.rs Reformatted import statements for clarity; no functional changes.
src/worldstate/models/daily_deal.rs Reformatted import statements in the test module for clarity.
src/worldstate/models/event.rs Reformatted import statements for improved readability.
src/worldstate/models/fissure.rs Reformatted import statements for clarity; no functional changes.
src/worldstate/models/flash_sale.rs Added new field is_featured to FlashSale model.
src/worldstate/models/invasion.rs Reformatted import statements for clarity; no functional changes.
src/worldstate/models/items/arcane.rs Introduced Arcane struct with various fields and an asynchronous test function test_arcane_query.
src/worldstate/models/items/archwing.rs Introduced Archwing struct with various fields and an asynchronous test function test_archwing_query.
src/worldstate/models/items/fish.rs Introduced Fish struct with various fields and an asynchronous test function test_fish_query.
src/worldstate/models/items/gear.rs Introduced Gear struct with various fields and an asynchronous test function test_gear_query.
src/worldstate/models/items/glyph.rs Introduced Glyph struct with various fields and an asynchronous test function test_glyph_query.
src/worldstate/models/items/misc.rs Introduced Misc struct with various fields and an asynchronous test function test_misc_query.
src/worldstate/models/items/mod.rs Introduced comprehensive module for managing various item types, including enums and structs.
src/worldstate/models/items/modification.rs Introduced Mod struct and ModType enum, along with an asynchronous test function test_mod_query.
src/worldstate/models/items/node.rs Introduced Node struct and an asynchronous test function test_node_query.
src/worldstate/models/items/pet.rs Introduced Pet struct and an asynchronous test function test_pet_query.
src/worldstate/models/items/quest.rs Introduced Quest struct and an asynchronous test function test_quest_query.
src/worldstate/models/items/relic.rs Introduced Relic, MarketInfo, and Reward structs, along with an asynchronous test function test_relic_query.
src/worldstate/models/items/resource.rs Introduced Resource struct and an asynchronous test function test_resource_query.
src/worldstate/models/items/sentinel.rs Introduced Sentinel struct and an asynchronous test function test_sentinel_query.
src/worldstate/models/items/sigil.rs Introduced Sigil struct and an asynchronous test function test_sigil_query.
src/worldstate/models/items/skin.rs Introduced Skin struct and an asynchronous test function test_skin_query.
src/worldstate/models/items/warframe.rs Introduced Warframe and Ability structs, and Sex enum, along with an asynchronous test function test_warframe_query.
src/worldstate/models/items/weapon.rs Introduced Weapon, Attack, and Falloff structs, along with Trigger and ShotType enums, and an asynchronous test function test_weapon_query.
src/worldstate/models/macros.rs Updated impl_queryable macro to simplify handling of language parameter.
src/worldstate/models/mission.rs Reformatted import statements for improved readability.
src/worldstate/models/mod.rs Introduced new module pub mod items; reorganized pub use statements for clarity.
src/worldstate/models/news.rs Reformatted import statements for improved readability; no functional changes.
src/worldstate/models/nightwave.rs Reformatted import statements for improved readability; no functional changes.
src/worldstate/models/orb_vallis.rs Reformatted import statements for improved readability; no functional changes.
src/worldstate/models/sortie.rs Reformatted import statements for improved readability; no functional changes.
src/worldstate/models/syndicate_mission.rs Introduced SyndicateJob model and updated SyndicateMission model to include a vector of SyndicateJob.
src/worldstate/models/void_trader.rs Introduced VoidTraderInventoryItem model and updated VoidTrader model to include a vector of VoidTraderInventoryItem.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant API
    participant Cache

    Client->>Cache: Check for cached item
    alt Item found
        Cache-->>Client: Return cached item
    else Item not found
        Client->>API: Fetch item from API
        API-->>Client: Return item data
        Client->>Cache: Store item in cache
    end
Loading

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 9c49e92 and f5d3c16.

📒 Files selected for processing (1)
  • src/worldstate/models/items/node.rs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/worldstate/models/items/node.rs

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 37

🧹 Outside diff range and nitpick comments (27)
src/worldstate/models/items/sigil.rs (1)

1-24: LGTM! Consider adding documentation.

The Sigil struct is well-defined with appropriate derive macros and serde attributes. The renaming of the type field to sigil_type is a good practice to avoid conflicts with the Rust keyword.

Consider adding documentation comments to explain the purpose of the Sigil struct and its fields. This will improve code readability and maintainability. For example:

/// Represents a Sigil item in the game.
#[derive(Clone, Debug, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct Sigil {
    /// The category of the sigil.
    pub category: Category,
    /// A description of the sigil.
    pub description: String,
    // ... (add comments for other fields)
}
src/worldstate/models/items/skin.rs (2)

5-24: LGTM: Skin struct is well-defined, consider field visibility.

The Skin struct is well-structured with appropriate derive macros and serde attributes. The field renaming for skin_type is a good practice.

Consider reviewing the visibility of the struct fields. While making all fields public might be intentional, it's worth evaluating if some fields could benefit from being private for better encapsulation.


26-33: LGTM: Test function is well-structured, consider adding assertions.

The test function effectively verifies API integration and struct deserialization. The use of tokio for async testing and the error handling approach are appropriate.

Consider enhancing the test by adding assertions to verify the deserialized data. For example:

let skin = reqwest::get("https://api.warframestat.us/items/Academe%20Ink/")
    .await?
    .json::<Skin>()
    .await?;

assert_eq!(skin.name, "Academe Ink");
assert_eq!(skin.category, Category::Skins);
// Add more assertions as needed

This would provide stronger guarantees about the correctness of the deserialization process and the API response structure.

src/worldstate/models/items/quest.rs (1)

5-24: LGTM! Consider reviewing field visibility.

The Quest struct is well-defined and follows Rust conventions. The use of derive macros and Serde attributes is appropriate.

Consider reviewing the visibility of the struct fields. While making all fields public (pub) is valid, it might be more robust to limit access to some fields if they're not intended to be directly modified outside the module.

src/worldstate/models/items/misc.rs (1)

5-24: LGTM: Well-structured Misc struct with appropriate derive macros.

The struct definition is well-organized and uses appropriate derive macros. The camelCase renaming and the handling of the type field are good practices.

Consider reviewing the visibility of the struct fields. While making all fields public might be intentional, it's worth ensuring that this level of access is necessary for all fields to maintain encapsulation.

src/worldstate/models/items/resource.rs (2)

1-6: LGTM! Consider adding an explicit import for tokio.

The imports look good and are appropriate for the struct definition. However, for better readability and to make dependencies clear, consider adding an explicit import for tokio at the top of the file, as it's used in the test function.

Add the following import at the top of the file:

use tokio;

8-33: LGTM! Consider using String consistently for string fields.

The Resource struct is well-defined with appropriate derive macros and serde attributes. The field types are suitable for their intended purposes, and the renaming of the "type" field to resource_type is a good practice.

For consistency, consider using String instead of Vec<String> for the parents field if it's expected to be a single string. If it's meant to be a list of strings, the current implementation is correct.

If parents is meant to be a single string, update the field as follows:

parents: String,
src/worldstate/models/items/arcane.rs (1)

12-33: LGTM! Consider adding field-level documentation.

The Arcane struct is well-defined and follows Rust conventions. The use of derive macros and serde attributes is appropriate.

Consider adding documentation comments for each field to improve clarity and maintainability. For example:

/// The category of the Arcane
pub category: Category,

/// List of locations or methods to obtain this Arcane
pub drops: Vec<Drop>,

// ... (continue for other fields)
src/worldstate/models/items/gear.rs (1)

8-34: Consider adding documentation comments to the Gear struct and its fields.

The Gear struct is well-defined with appropriate derive macros and field types. To enhance code readability and maintainability, consider adding documentation comments (///) to the struct and its fields. This will provide clarity on the purpose of each field and any constraints or special considerations.

Here's an example of how you could start documenting the struct:

/// Represents a gear item in the game.
#[derive(Clone, Debug, Deserialize, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct Gear {
    /// The price to build this gear item.
    pub build_price: i64,

    /// The quantity that can be built at once.
    pub build_quantity: i64,

    // ... (continue for other fields)
}
src/worldstate/models/items/pet.rs (1)

5-36: LGTM: Well-structured Pet struct with appropriate derive macros.

The Pet struct is well-defined with appropriate field types and serde configurations. The use of #[serde(rename = "type")] for pet_type is a good practice to avoid conflicts with Rust keywords.

Consider adding documentation comments (///) for the struct and its fields to improve code readability and maintainability.

src/worldstate/mod.rs (1)

34-41: Improved import organization in the prelude.

The changes to the prelude section enhance code organization and readability. The consolidated import block for Client, ApiError, and ApiErrorResponse improves maintainability while preserving the existing functionality.

Consider adding a brief comment above the pub use crate::worldstate::models::*; line to explain the rationale behind the wildcard import, as it's generally discouraged in Rust for clarity reasons. For example:

// Import all models for convenience in the prelude
pub use crate::worldstate::models::*;
src/worldstate/models/flash_sale.rs (1)

Line range hint 36-61: Consider updating tests for the new is_featured field

While the existing tests check the overall functionality, they don't explicitly verify the new is_featured field. Consider adding a test case that checks this new field to ensure it's correctly populated and handled.

Here's a suggested addition to the test_flashsale function:

#[cfg(not(feature = "multilangual"))]
#[tokio::test]
async fn test_flashsale() -> Result<(), ApiError> {
    let client = Client::new();

    match client.fetch::<FlashSale>().await {
        Ok(flashsales) => {
            // Check if at least one FlashSale has the is_featured field set
            assert!(flashsales.iter().any(|fs| fs.is_featured.is_some()), "No FlashSale found with is_featured set");
            Ok(())
        },
        Err(why) => Err(why),
    }
}

Similarly, you could update the test_flashsale_ml function for multilingual support.

src/worldstate/models/void_trader.rs (2)

Line range hint 32-67: Tests look good, with room for enhancement

The test cases cover both non-multilingual and multilingual scenarios, which is great. The formatting changes in the import statements improve readability.

Consider the following suggestions to enhance the tests:

  1. Add more specific assertions to verify the structure and content of the returned VoidTrader object.
  2. Include error case scenarios to ensure proper error handling.
  3. Add a test case for an empty inventory scenario if applicable.

Would you like assistance in implementing these test enhancements?


Line range hint 1-67: Consider minor improvements for documentation and error handling

The overall implementation is solid, but consider the following minor improvements:

  1. Add more detailed documentation comments for the VoidTrader model, explaining the significance of each field and any constraints on their values.
  2. Consider adding custom error types or error handling mechanisms specific to Void Trader operations, if applicable.
  3. If there are any invariants or constraints on the inventory field (e.g., non-empty list), consider adding validation logic or documenting these constraints.

Let me know if you'd like assistance in implementing any of these suggestions.

src/worldstate/language.rs (3)

Line range hint 7-28: LGTM! Consider adding serde support.

The Language enum is well-defined with appropriate derived traits and clear documentation. It covers a good range of languages using standard ISO 639-1 codes.

Consider deriving serde::Serialize and serde::Deserialize traits if this enum needs to be serialized or deserialized in the future. This can be done by adding the following derive attributes:

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]

Don't forget to add the serde dependency to your Cargo.toml if it's not already present.


Line range hint 30-49: Minor optimization: Remove unnecessary .into()

The implementation is correct, but there's a small optimization opportunity.

You can simplify the implementation by removing the .into() call:

 impl From<Language> for String {
     fn from(value: Language) -> Self {
         use Language::*;
-        match value {
-            DE => "de",
-            ES => "es",
-            FR => "fr",
-            IT => "it",
-            KO => "ko",
-            PL => "pl",
-            PT => "pt",
-            RU => "ru",
-            ZH => "zh",
-            EN => "en",
-            UK => "uk",
-        }
-        .into()
+        String::from(match value {
+            DE => "de",
+            ES => "es",
+            FR => "fr",
+            IT => "it",
+            KO => "ko",
+            PL => "pl",
+            PT => "pt",
+            RU => "ru",
+            ZH => "zh",
+            EN => "en",
+            UK => "uk",
+        })
     }
 }

This change removes the unnecessary .into() call and directly constructs a String from the &str returned by the match expression.


Line range hint 51-70: Consider refactoring to reduce code duplication

The implementation is correct, but it's very similar to the From<Language> for String implementation.

To reduce code duplication, you could consider using a private method or const array to store the language codes. Here's an example using a const array:

impl Language {
    const CODES: [&'static str; 11] = ["de", "es", "fr", "it", "ko", "pl", "pt", "ru", "zh", "en", "uk"];

    fn code(&self) -> &'static str {
        Self::CODES[*self as usize]
    }
}

impl From<Language> for &'static str {
    fn from(value: Language) -> Self {
        value.code()
    }
}

impl From<Language> for String {
    fn from(value: Language) -> Self {
        value.code().to_string()
    }
}

This approach centralizes the language codes, making it easier to maintain and reducing the risk of inconsistencies between the two implementations.

src/worldstate/models/macros.rs (1)

242-242: Approve the change with a minor suggestion.

The modification to use language directly instead of String::from(language) is a good improvement. It simplifies the code and potentially offers a slight performance benefit by avoiding an unnecessary allocation.

To further enhance clarity, consider adding a type annotation to the language parameter in the function signature. This would make the expected type explicit and serve as documentation.

Consider updating the function signature as follows:

fn endpoint(language: Language) -> String {
    // ... (rest of the implementation)
}

This change assumes that Language is the correct type and is in scope. If it's not, you may need to add the appropriate import or use a fully qualified path.

src/worldstate/models/items/node.rs (4)

37-38: Rename type_ field to enhance clarity

The field type_ represents the JSON key nodeType. Using type_ with an underscore may be confusing. Consider renaming it to a more descriptive name like node_type_id or node_type_index to improve code clarity.

Apply this diff to rename the field:

 #[serde(rename = "nodeType")]
-pub type_: i64,
+pub node_type_id: i64,

54-54: Use variable node instead of _node

In the test function, the variable _node is being used. In Rust, a leading underscore indicates an intentionally unused variable. Since the variable is utilized, rename it to node for clarity.

Apply this diff:

-    let _node = reqwest::get("https://api.warframestat.us/items/oro/")
+    let node = reqwest::get("https://api.warframestat.us/items/oro/")

52-59: Add assertions to test function to validate deserialization

The test function currently deserializes the JSON response but doesn't verify the correctness of the data. Adding assertions will ensure that the deserialized Node object contains expected values.

Consider adding assertions like:

     let node = reqwest::get("https://api.warframestat.us/items/oro/")
         .await?
         .json::<Node>()
         .await?;
+    assert_eq!(node.name, "Oro");
+    // Add additional assertions as needed

18-50: Add documentation comments to the Node struct and its fields

Including documentation comments will improve code maintainability and provide clarity to other developers using this struct.

Example:

+/// Represents a node in the Warframe world state.
 #[derive(Clone, Debug, Deserialize, PartialEq, Eq)]
 #[serde(rename_all = "camelCase")]
 pub struct Node {
+    /// The category of the node.
     pub category: Category,
     // ... additional fields with comments
 }
src/worldstate/models/items/relic.rs (1)

59-66: Consider enhancing the test with assertions

The asynchronous test test_relic_query successfully checks deserialization from the API. To make the test more robust, consider adding assertions to validate critical fields of the Relic instance. This can help catch discrepancies between the expected and actual data structures.

src/worldstate/models/items/warframe.rs (1)

15-88: Add documentation comments for public fields

Adding documentation comments to the public fields of the Warframe struct will improve code readability and maintainability, providing clarity on what each field represents.

For example:

 pub struct Warframe {
+    /// The abilities of the Warframe
     pub abilities: Vec<Ability>,
+
+    /// The armor value of the Warframe
     pub armor: i64,
     // ...
 }
src/worldstate/models/items/weapon.rs (1)

32-68: Standardize field names for critical chance and critical multiplier

In the Weapon struct, the fields are named critical_chance and critical_multiplier, whereas in the Attack struct, they are crit_chance and crit_mult. To enhance code readability and maintainability, consider using consistent naming conventions across both structs.

Apply these diffs to standardize the field names:

For the Attack struct:

-pub crit_chance: f64,
+pub critical_chance: f64,

-pub crit_mult: f64,
+pub critical_multiplier: f64,

Or, alternatively, rename the fields in the Weapon struct to match those in the Attack struct.

src/worldstate/models/items/mod.rs (1)

246-270: Expand unit tests to cover more item categories and scenarios

The current unit tests verify the querying functionality for a sigil and a miscellaneous item in German. To ensure comprehensive coverage, consider adding tests for additional item categories such as weapons, warframes, mods, arcanes, and resources. Including tests for error cases, like querying non-existent items or handling malformed data, would strengthen the reliability of the querying functionality.

src/market/client.rs (1)

133-142: Optimize imports and module usage

Consider reorganizing your imports for clarity and efficiency. Importing the entire module with use super::*; can bring unnecessary items into scope.

Replace:

-    use super::*;
+    use super::{ApiError, Client, FetchResult, CacheValue};

This makes it clear which items are being used from the parent module.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 5fa1493 and 9c49e92.

📒 Files selected for processing (51)
  • Cargo.toml (1 hunks)
  • rustfmt.toml (1 hunks)
  • src/lib.rs (1 hunks)
  • src/market/client.rs (6 hunks)
  • src/market/models/item.rs (2 hunks)
  • src/market/models/item_info.rs (2 hunks)
  • src/market/models/orders.rs (2 hunks)
  • src/market/models/statistic_item.rs (2 hunks)
  • src/worldstate/client.rs (8 hunks)
  • src/worldstate/language.rs (2 hunks)
  • src/worldstate/listener.rs (5 hunks)
  • src/worldstate/mod.rs (1 hunks)
  • src/worldstate/models/alert.rs (2 hunks)
  • src/worldstate/models/arbitration.rs (2 hunks)
  • src/worldstate/models/archon_hunt.rs (2 hunks)
  • src/worldstate/models/base.rs (4 hunks)
  • src/worldstate/models/cambion_drift.rs (2 hunks)
  • src/worldstate/models/cetus.rs (2 hunks)
  • src/worldstate/models/construction_progress.rs (2 hunks)
  • src/worldstate/models/daily_deal.rs (1 hunks)
  • src/worldstate/models/event.rs (2 hunks)
  • src/worldstate/models/fissure.rs (2 hunks)
  • src/worldstate/models/flash_sale.rs (1 hunks)
  • src/worldstate/models/invasion.rs (2 hunks)
  • src/worldstate/models/items/arcane.rs (1 hunks)
  • src/worldstate/models/items/archwing.rs (1 hunks)
  • src/worldstate/models/items/fish.rs (1 hunks)
  • src/worldstate/models/items/gear.rs (1 hunks)
  • src/worldstate/models/items/glyph.rs (1 hunks)
  • src/worldstate/models/items/misc.rs (1 hunks)
  • src/worldstate/models/items/mod.rs (1 hunks)
  • src/worldstate/models/items/modification.rs (1 hunks)
  • src/worldstate/models/items/node.rs (1 hunks)
  • src/worldstate/models/items/pet.rs (1 hunks)
  • src/worldstate/models/items/quest.rs (1 hunks)
  • src/worldstate/models/items/relic.rs (1 hunks)
  • src/worldstate/models/items/resource.rs (1 hunks)
  • src/worldstate/models/items/sentinel.rs (1 hunks)
  • src/worldstate/models/items/sigil.rs (1 hunks)
  • src/worldstate/models/items/skin.rs (1 hunks)
  • src/worldstate/models/items/warframe.rs (1 hunks)
  • src/worldstate/models/items/weapon.rs (1 hunks)
  • src/worldstate/models/macros.rs (1 hunks)
  • src/worldstate/models/mission.rs (1 hunks)
  • src/worldstate/models/mod.rs (3 hunks)
  • src/worldstate/models/news.rs (2 hunks)
  • src/worldstate/models/nightwave.rs (2 hunks)
  • src/worldstate/models/orb_vallis.rs (2 hunks)
  • src/worldstate/models/sortie.rs (2 hunks)
  • src/worldstate/models/syndicate_mission.rs (1 hunks)
  • src/worldstate/models/void_trader.rs (1 hunks)
✅ Files skipped from review due to trivial changes (21)
  • rustfmt.toml
  • src/market/models/item.rs
  • src/market/models/item_info.rs
  • src/market/models/orders.rs
  • src/market/models/statistic_item.rs
  • src/worldstate/listener.rs
  • src/worldstate/models/alert.rs
  • src/worldstate/models/archon_hunt.rs
  • src/worldstate/models/base.rs
  • src/worldstate/models/cambion_drift.rs
  • src/worldstate/models/cetus.rs
  • src/worldstate/models/construction_progress.rs
  • src/worldstate/models/daily_deal.rs
  • src/worldstate/models/event.rs
  • src/worldstate/models/fissure.rs
  • src/worldstate/models/invasion.rs
  • src/worldstate/models/mission.rs
  • src/worldstate/models/news.rs
  • src/worldstate/models/nightwave.rs
  • src/worldstate/models/orb_vallis.rs
  • src/worldstate/models/sortie.rs
🧰 Additional context used
🔇 Additional comments (46)
src/lib.rs (2)

12-18: Improved import organization

The restructuring of import statements enhances code readability and organization. By grouping related imports from crate::worldstate::models, the code now follows a more idiomatic Rust style for larger modules.


Line range hint 1-18: Verify the status of documentation enforcement

The AI summary mentioned the removal of the #[forbid(missing_docs)] attribute from the worldstate module, but this change is not visible in the provided code. Could you please confirm if this attribute was indeed removed? If so, consider the potential impact on documentation quality and whether this was an intentional change.

To check the current status of the #[forbid(missing_docs)] attribute, please run the following command:

If the attribute is indeed missing, consider adding it back or documenting the reason for its removal.

src/worldstate/models/items/glyph.rs (1)

5-21: LGTM: Well-structured Glyph struct definition

The Glyph struct is well-defined with appropriate derive macros and field types. The use of #[serde(rename_all = "camelCase")] ensures compatibility with typical JSON API responses.

src/worldstate/models/items/fish.rs (2)

1-6: LGTM: Imports are appropriate for the struct definition.

The imports are concise and relevant to the Fish struct implementation. The use of super for importing Category and Drop suggests good module organization.


8-24: LGTM: Well-structured Fish struct with a minor consideration.

The Fish struct is well-defined with appropriate derive macros and serde attributes. The fields cover essential properties of a fish item.

Consider if all fields need to be public. If some fields are only used internally, making them private could improve encapsulation. Please verify the usage of these fields across the codebase:

✅ Verification successful

LGTM: Fish struct usage is confined to internal modules.

The Fish struct is well-defined, and all usages are internal to the items module. Consider making fields private to improve encapsulation if they aren't accessed externally.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check usage of Fish struct fields across the codebase

# Test: Search for usage of Fish struct fields
echo "Usage of Fish struct fields:"
rg -n 'fish\.(category|description|drops|image_name|name|tradable|unique_name)' --type rust

Length of output: 160


Script:

#!/bin/bash
# Description: Comprehensive search for Fish struct usage across the codebase

# Search for instantiations and usages of the Fish struct
rg -n 'Fish\s*::\s*\w+' --type rust

# Search for any occurrences of the Fish struct being used as a type
rg -n '\bFish\b' --type rust

Length of output: 499

src/worldstate/models/items/sigil.rs (1)

1-33: Overall, good addition with room for minor improvements.

The introduction of the Sigil struct and its corresponding test function is a valuable addition to the codebase. The struct is well-defined, and the test provides a basic verification of the HTTP request and deserialization process.

To further enhance this file:

  1. Add documentation comments to the Sigil struct and its fields.
  2. Improve the test function with assertions and better error handling.
  3. Consider parameterizing the test URL for better testing flexibility.

These improvements will increase the maintainability and robustness of the code.

src/worldstate/models/items/skin.rs (2)

1-3: LGTM: Imports are appropriate and concise.

The imports are correctly specified and all are used in the file.


1-33: Overall: Well-implemented Skin model with room for minor enhancements.

The Skin struct and its accompanying test function are well-implemented, contributing effectively to the PR's objective of adding item query support. The code follows Rust best practices and is structured appropriately.

Consider the following minor enhancements:

  1. Review field visibility in the Skin struct for better encapsulation.
  2. Strengthen the test function by adding specific assertions on the deserialized data.

These changes would further improve the robustness and maintainability of the code.

src/worldstate/models/items/misc.rs (1)

1-3: LGTM: Imports are appropriate and concise.

The imports are well-organized and relevant to the struct definition that follows.

src/worldstate/models/items/pet.rs (2)

1-3: LGTM: Imports are appropriate and concise.

The import statements are correctly bringing in the necessary dependencies for the Pet struct.


1-45: Overall, well-structured implementation with room for minor enhancements.

The Pet struct and its associated test function provide a solid foundation for handling pet data in the Warframe context. The code is well-organized and uses appropriate Rust and serde features.

To further improve the code:

  1. Add documentation comments for the Pet struct and its fields.
  2. Enhance the test function with assertions and better error handling.
  3. Consider adding more comprehensive tests to cover different scenarios.

These enhancements will improve code maintainability and robustness.

src/worldstate/mod.rs (1)

Line range hint 1-41: Add missing items module declaration.

The PR objective mentions introducing support for item queries, but the items module is not declared in this file. Consider adding the following line to include the new module:

pub mod items;

This ensures that the new functionality is properly integrated into the crate's module structure.

To verify the existence and location of the items module, run the following script:

Cargo.toml (1)

37-38: LGTM! Consider checking for the latest versions.

The addition of strum and urlencoding dependencies aligns well with the PR objectives of supporting item types and query functionality.

To ensure we're using the most up-to-date and compatible versions, please run the following script:

src/worldstate/models/flash_sale.rs (2)

31-34: Improved import formatting

The import statements have been reformatted for better readability, likely due to the new rustfmt.toml file. This change is consistent with good coding practices.


Line range hint 1-30: LGTM: New is_featured field added correctly

The new is_featured: Option<bool> field has been added to the FlashSale model with an appropriate comment. It's consistent with the existing is_popular field in type and naming convention.

To ensure this change is reflected in all relevant parts of the codebase, please run the following script:

src/worldstate/models/void_trader.rs (2)

Line range hint 1-15: LGTM: VoidTraderInventoryItem model looks good

The VoidTraderInventoryItem model is well-structured and accurately represents an item in Baro's inventory. The fields (item, ducats, and credits) are appropriate for this context, and the use of i32 for currency values is suitable.


Line range hint 17-30: LGTM: VoidTrader model is well-defined

The VoidTrader model is correctly structured to represent Void Trader information. The fields (id, location, and inventory) are appropriate, and the use of Vec<VoidTraderInventoryItem> for the inventory is a good design choice. The model is correctly associated with the "/voidTrader" endpoint and marked as timed, which is appropriate for time-sensitive data.

src/worldstate/language.rs (2)

72-76: LGTM! Well-implemented Display trait.

The Display implementation for Language is concise and correctly leverages the existing From<Language> for &'static str trait. This approach ensures consistency between the string representations used in different contexts.


Line range hint 1-76: Overall, well-implemented language support

The Language enum and its implementations provide a solid foundation for supporting multiple languages in the API, aligning well with the PR objectives. The code is well-structured and documented, with appropriate trait derivations and implementations.

While there are minor opportunities for optimization and refactoring (as noted in previous comments), the overall quality of the implementation is high. This addition will effectively support the /items/{query} endpoint with language-specific queries.

src/worldstate/models/syndicate_mission.rs (1)

58-61: Improved import organization

The restructuring of import statements enhances code readability by grouping related imports from the crate::worldstate module. This change aligns with Rust's recommended style and improves overall code organization.

src/worldstate/models/mod.rs (7)

5-7: LGTM: Improved comment formatting

The comment has been split into multiple lines, enhancing readability without changing functionality. This change adheres to Rust documentation best practices.


14-17: LGTM: Improved import statement organization

The import statement has been split into multiple lines and made more specific. This change enhances code readability and organization, potentially reducing naming conflicts.


60-63: LGTM: Improved archon_hunt re-export

The archon_hunt re-export has been split into multiple lines and now explicitly lists the structs being re-exported. This change enhances code readability and consistency with other re-exports in the file.


76-119: LGTM: Consistent improvement in re-export formatting

The re-exports for various modules have been consistently reformatted into a multi-line style. This change significantly improves code readability and organization, making it easier to identify which structs or enums are being re-exported from each module.


123-126: LGTM: Consistent improvement in test import formatting

The import statement in the test function has been updated to match the style used earlier in the file. This change enhances readability and maintains consistency throughout the module.


64-72: Improved re-exports, but use caution with wildcard import

The multi-line re-exports for cambion_drift and cetus enhance readability and are consistent with the new style. However, the wildcard re-export for base (pub use base::*;) might introduce naming conflicts if not carefully managed.

Consider explicitly listing the items re-exported from base to avoid potential naming conflicts. You can run the following script to inspect the contents of the base module:

✅ Verification successful

Re-exports verified and no conflicts found with base wildcard

The multi-line re-exports for cambion_drift and cetus enhance readability and are well-implemented. Additionally, the wildcard re-export for base (pub use base::*;) has been verified to be safe, as it only includes traits and functions that do not pose naming conflict risks.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Inspect the contents of the base module

# Test: Check the contents of the base module
cat src/worldstate/models/base.rs

# Test: Look for any potential naming conflicts
rg -n "^(pub )?(struct|enum|type|const|static|fn|trait) " src/worldstate/models/*.rs

Length of output: 7666


41-41: LGTM: New items module added

The addition of the items module aligns with the PR objective of introducing item query support. This is a good structural change.

Please ensure that the items module is implemented correctly. You can verify this by running the following script:

✅ Verification successful

Verified: items module implemented correctly

The items module is properly structured as a directory module with mod.rs and correctly references within the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of the items module

# Test: Check if the items module file exists
fd -t f "items.rs" src/worldstate/models

# Test: Inspect the contents of the items module
cat src/worldstate/models/items.rs

# Test: Check for any references to the items module in other files
rg "use (crate::worldstate::models::)?items::" src

Length of output: 249


Script:

#!/bin/bash
# Description: Find all module declarations of `items`

# Search for `mod items` declarations
rg 'mod\s+items\b' src

# Inspect the contents of items/mod.rs for potential issues
cat src/worldstate/models/items/mod.rs

Length of output: 6340

src/worldstate/models/macros.rs (1)

Line range hint 1-268: Overall assessment of changes in this file.

The modification in the impl_queryable macro is the only change in this file and aligns well with the PR objectives. It simplifies the code and potentially improves performance slightly. The change is consistent with the introduction of the Language enum mentioned in the AI-generated summary for other files.

The rest of the macros in this file remain unchanged, maintaining the existing functionality for model building, trait implementation, and enum creation.

src/worldstate/models/items/sentinel.rs (2)

11-53: LGTM: Sentinel struct is well-defined

The Sentinel struct is correctly defined with appropriate field names and types. The use of Serde's rename_all = "camelCase" attribute ensures proper serialization and deserialization.


49-50: Proper handling of reserved keyword with Serde

Good use of #[serde(rename = "type")] to handle the serialization of the sentinel_type field, avoiding conflicts with the Rust reserved keyword type.

src/worldstate/models/items/relic.rs (5)

1-2: Import statements are appropriate

The necessary imports for serde::Deserialize are correctly included, ensuring proper deserialization of the data structures.


3-4: Verify the definition of Category in the parent module

Ensure that the Category type imported from the parent module is correctly defined and matches the expected usage in this context.


16-18: Ensure consistency of MarketInfo with API data

Confirm that the MarketInfo struct fields align with the data provided by the API for market_info. This ensures that deserialization works correctly and that all necessary information is captured.


42-47: Check the accuracy of Reward and its nested structures

Ensure that the Reward struct and its nested RewardItem correctly represent the API's response structure. Verifying that all fields are correctly named and typed will prevent deserialization errors and runtime issues.


56-57: Review the nesting of MarketInfo within RewardItem

The RewardItem struct contains a warframe_market field of type MarketInfo. Confirm that this nesting accurately reflects the API's data. If MarketInfo is not provided within each RewardItem, consider adjusting the structure accordingly.

src/worldstate/models/items/warframe.rs (1)

80-81: Correct field name for type

The field is correctly renamed to avoid the Rust keyword type. No action needed.

src/worldstate/models/items/modification.rs (2)

14-55: Well-defined Mod struct with appropriate serialization

The Mod struct is properly defined with clear field types and Serde attributes for serialization. The use of #[serde(rename_all = "camelCase")] ensures JSON compatibility.


57-99: Correct implementation of ModType enum with Serde renaming

The ModType enum is correctly implemented, utilizing #[serde(rename)] for accurate serialization of variant names. This approach maintains consistency with the expected JSON values.

src/worldstate/models/items/weapon.rs (5)

1-98: Overall well-structured definition of Weapon struct

The Weapon struct is comprehensively defined with appropriate fields and data types. The use of serde attributes for serialization and deserialization is correctly implemented, ensuring compatibility with the external data formats.


101-122: Proper implementation of Attack struct with optional fields

The Attack struct is well-defined, and optional fields like shot_speed and flight are appropriately handled using Option<T>. This allows for flexibility when certain data may not be present.


124-131: Accurate representation of Falloff struct

The Falloff struct correctly models the damage falloff mechanics with clear field names and appropriate data types.


133-145: Correct use of serde attributes in Trigger enum

The Trigger enum accurately represents different firing mechanisms, and the use of #[serde(rename = "...")] appropriately handles variants with spaces or special characters, ensuring correct serialization and deserialization.


147-154: Well-defined ShotType enum with serialization considerations

The ShotType enum is properly defined, and the serde attributes correctly account for external representation differences, such as renaming "Hit-Scan" to HitScan.

src/worldstate/models/arbitration.rs (3)

1-4: Imports from 'chrono' are appropriately structured

The import statements from chrono are correctly organized, importing the necessary items DateTime and Utc for date and time handling.


5-8: Imports from 'serde' are appropriate

The import statements from serde correctly include Deserialize and Deserializer, which are utilized for custom deserialization logic in the code.


10-13: Imports from the parent module are properly defined

The super module imports base::TimedEvent, Faction, and MissionType, which are necessary for the Arbitration struct and its trait implementations.

src/worldstate/models/items/glyph.rs Show resolved Hide resolved
src/worldstate/models/items/glyph.rs Show resolved Hide resolved
src/worldstate/models/items/fish.rs Show resolved Hide resolved
src/worldstate/models/items/sigil.rs Show resolved Hide resolved
src/worldstate/models/items/quest.rs Show resolved Hide resolved
src/worldstate/models/items/mod.rs Show resolved Hide resolved
src/market/client.rs Show resolved Hide resolved
src/market/client.rs Show resolved Hide resolved
src/worldstate/client.rs Show resolved Hide resolved
src/worldstate/client.rs Show resolved Hide resolved
Copy link
Collaborator

@CraigEge CraigEge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (unless you want to action on any of the coderabbit stuff)

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@CraigEge CraigEge self-requested a review October 21, 2024 15:40
@Mettwasser Mettwasser requested a review from TobiTenno October 21, 2024 15:53
@Mettwasser Mettwasser merged commit f79f2d8 into master Oct 21, 2024
4 checks passed
@Mettwasser Mettwasser deleted the worldstate-items branch October 21, 2024 15:56
wfcd-bot-boi pushed a commit that referenced this pull request Oct 21, 2024
# [6.1.0](v6.0.1...v6.1.0) (2024-10-21)

### Features

* item query support and item types ([#19](#19)) ([f79f2d8](f79f2d8))
@wfcd-bot-boi
Copy link
Collaborator

🎉 This PR is included in version 6.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants