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

Move find_all to entity_api #15

Closed
wants to merge 7 commits into from
Closed

Conversation

calebbourg
Copy link
Collaborator

Description

describe the intent of your changes here

GitHub Issue: [Closes|Fixes|Resolves] #your GitHub issue number here

Changes

  • ...
  • ...
  • ...

Testing Strategy

describe how you or someone else can test and verify the changes

Concerns

describe any concerns that might be worth mentioning or discussing

Also starts to consider error handling patterns. Not sure if this is ultimately where we will go as the usage does not feel quite right but will continue to play with it.
@jhodapp jhodapp changed the title move find_all to entity_api Move find_all to entity_api Nov 26, 2023
@jhodapp jhodapp added the enhancement Improves existing functionality or feature label Nov 26, 2023
use entity_api::error::EntityApiErrorType;
use entity_api::error::Error as EntityApiError;
use entity_api::error::EntityApiError;
use entity_api::error::Error as EntityApiErrorSuper;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Let's talk through this when we meet later today. I think you've definitely exposed a part of how this is set up that could use more thought. I'm not sure I love adding the Super since to me that implies inheritance or nesting. But I also don't have a better option in mind off-hand.

Copy link
Member

@jhodapp jhodapp Dec 1, 2023

Choose a reason for hiding this comment

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

Indeed, I borrowed the Super nomenclature from Rust modules which I think makes this fair. My approach also localizes the name distinction to this module only instead of EntityApiErrorType having "Type" always. From my understanding of Rust convention in the community, adding "Type" to the end of a type is not a common practice. It is in C/C++ land, but not Rust.

@@ -22,7 +22,9 @@ impl OrganizationController {
/// --request GET \
/// http://localhost:4000/organizations
pub async fn index(State(app_state): State<AppState>) -> impl IntoResponse {
let organizations = OrganizationApi::find_all(&app_state).await;
let organizations = OrganizationApi::find_all(&app_state)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think I prefer keeping the unwrap_or_default detail inside of the entity_api context since to me it's an implementation detail and will always be the behavior we're expecting with a find_all. Open to your thoughts on this.

Copy link
Member

Choose a reason for hiding this comment

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

That's ok, this was only recognizing that unwrap_or(vec![]) vs unwrap_or_default() should return the same thing. But if you think moving any unwrap into the EntityAPI for Organization is even stronger, I'm good with that. Let's take a look at this further together.

.one(db)
.await
.map_err(|err| err.into())
Ok(Entity::find_by_id(id).one(db).await?)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I like this a lot. I'm curious, though, if we're now only transforming the error up one level in the actual controller? I think we'd need to write a test to determine this.

Copy link
Member

@jhodapp jhodapp Dec 1, 2023

Choose a reason for hiding this comment

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

I think you figured this out better in your other branch. Wrapping in Ok() is a valid solution because the Result<> is unwrapped from await(), but we need it to be in a Result<> for both the Ok or Err cases.

But having a naked ? operator is always going to be my favorite solution syntactically, so I'm excited to see what you came up with.

@calebbourg calebbourg closed this Dec 5, 2023
@calebbourg calebbourg reopened this Dec 5, 2023
@calebbourg
Copy link
Collaborator Author

Closing in favor of #21

@calebbourg calebbourg closed this Dec 5, 2023
@calebbourg calebbourg deleted the refactor_organization branch January 9, 2024 14:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improves existing functionality or feature
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

2 participants