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

Refactor LoanInfo and HoldInfo to be dataclasses (PP-1728) #2113

Merged
merged 5 commits into from
Oct 16, 2024

Conversation

jonathangreen
Copy link
Member

@jonathangreen jonathangreen commented Oct 15, 2024

Description

Refactor LoanInfo and HoldInfo to be simple dataclasses, and move the logic for creating and updating loans and holds from a LoanInfo or HoldInfo into a method called create_or_update.

In the process, I removed the Hold.external_identifier column, which appears to be unused.

Motivation and Context

Needed to modify how LoanInfo and HoldInfo are used as part of PP-1728, this refactor makes that work easier, but I thought it would be easier to understand as a separate PR.

How Has This Been Tested?

  • Running tests

Checklist

  • I have updated the documentation accordingly.
  • All new and existing tests passed.

@jonathangreen jonathangreen requested a review from a team October 15, 2024 19:45
@jonathangreen jonathangreen changed the title Refactor LoanInfo and HoldInfo to be dataclasses Refactor LoanInfo and HoldInfo to be dataclasses (PP-1728) Oct 15, 2024
Copy link

codecov bot commented Oct 15, 2024

Codecov Report

Attention: Patch coverage is 90.17857% with 11 lines in your changes missing coverage. Please review.

Project coverage is 90.72%. Comparing base (5155b4d) to head (211b76d).
Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
src/palace/manager/api/axis.py 68.75% 4 Missing and 1 partial ⚠️
src/palace/manager/api/circulation.py 95.94% 2 Missing and 1 partial ⚠️
src/palace/manager/api/enki.py 33.33% 1 Missing and 1 partial ⚠️
src/palace/manager/api/bibliotheca.py 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2113      +/-   ##
==========================================
+ Coverage   90.69%   90.72%   +0.02%     
==========================================
  Files         351      351              
  Lines       40878    40878              
  Branches     8858     8853       -5     
==========================================
+ Hits        37073    37085      +12     
+ Misses       2493     2486       -7     
+ Partials     1312     1307       -5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jonathangreen
Copy link
Member Author

This one has some missing coverage, but all the lines that are not covered, we not previously covered, so I think it should be fine to merge as is.

@jonathangreen jonathangreen force-pushed the chore/refactor-loan-hold-info branch from d490e4b to 4e69c0c Compare October 16, 2024 12:38
@jonathangreen jonathangreen added the DB migration This PR contains a DB migration label Oct 16, 2024
Copy link
Contributor

@dbernstein dbernstein left a comment

Choose a reason for hiding this comment

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

Nice work. I made a few minor suggestions. Feel free to correct as you see fit before merging.

def process_one(self, e: _Element, namespaces: dict[str, str] | None) -> LoanInfo:
def process_one(
self, e: _Element, namespaces: dict[str, str] | None
) -> datetime.datetime | None:
"""Either turn the given document into a LoanInfo
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like the doc needs to be updated

holdinfo = HoldInfo.from_license_pool(
licensepool,
start_date=utc_now(),
end_date=None,
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this line be removed since None is the default for end date?

Comment on lines 1088 to 1090
start_date=None,
end_date=None,
hold_position=None,
Copy link
Contributor

Choose a reason for hiding this comment

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

Can these lines be removed since None is the default for start_date, end_date and hold_position?

None,
hold_info = HoldInfo.from_license_pool(
licensepool,
start_date=None,
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above

licensepool.identifier.type,
licensepool.identifier.identifier,
return HoldInfo.from_license_pool(
licensepool,
start_date=start_date,
end_date=None,
Copy link
Contributor

Choose a reason for hiding this comment

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

Can be removed.

Comment on lines 314 to 315
start_date=None,
end_date=None,
Copy link
Contributor

Choose a reason for hiding this comment

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

can be removed

Comment on lines 358 to 359
start_date=None,
end_date=None,
Copy link
Contributor

Choose a reason for hiding this comment

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

can be removed

LoanInfo.from_license_pool(
pool,
start_date=utc_now(),
end_date=None,
Copy link
Contributor

Choose a reason for hiding this comment

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

can be removed

Comment on lines 182 to 183
start_date=None,
end_date=None,
Copy link
Contributor

Choose a reason for hiding this comment

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

can be removed

Comment on lines 190 to 191
start_date=None,
end_date=None,
Copy link
Contributor

Choose a reason for hiding this comment

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

can be removed

@jonathangreen jonathangreen merged commit 7d44fa4 into main Oct 16, 2024
19 of 20 checks passed
@jonathangreen jonathangreen deleted the chore/refactor-loan-hold-info branch October 16, 2024 20:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DB migration This PR contains a DB migration
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants