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

Use DTOs to parse tracking API responses #1103

Merged
merged 9 commits into from
Sep 2, 2024

Conversation

MajorTanya
Copy link
Contributor

Changes the handling of tracker API responses to be parsed to DTOs instead of doing so "manually" by use of jsonPrimitives and/or Json.decodeFromString invocations.

This greatly simplifies the API response handling.

Renamed constants to SCREAMING_SNAKE_CASE.

Largely tried to name the DTOs in a uniform pattern, with the tracker's (short) name at the beginning of file and data class names (ALOAuth instead of OAuth, etc).

With these changes, no area of the code base should be using jsonPrimitive and/or Json.decodeFromString anymore.

@MajorTanya MajorTanya marked this pull request as draft August 10, 2024 23:40
@MajorTanya
Copy link
Contributor Author

MajorTanya commented Aug 11, 2024

Checked MAL, AL, Kitsu, MU, and Shikimori, they all seem to work just fine.

I don't have a Bangumi account nor do I have Komga/Kavita/Suwayomi set up (although I didn't touch those last three, they should be the same as before).

Bangumi needs checking whether it works correctly (searching, adding/deleting, updating progress, status, scores, dates). Should also check if Mihon can correctly fetch data from Bangumi when the user opens the tracking sheet by manually changing data on the website first and seeing if Mihon correctly updates when the tracking sheet is opened.

Once Bangumi is checked, this can be ready for review.

@MajorTanya

This comment was marked as resolved.

Copy link
Member

@AntsyLich AntsyLich left a comment

Choose a reason for hiding this comment

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

Bangumi can be shortened to BGM

@MajorTanya MajorTanya force-pushed the migrate-trackers-to-dtos branch 2 times, most recently from d318dc0 to 8e45d07 Compare August 11, 2024 17:09
@MajorTanya MajorTanya force-pushed the migrate-trackers-to-dtos branch 2 times, most recently from d11c4ec to d8b9e82 Compare August 15, 2024 19:45
@MajorTanya

This comment was marked as outdated.

@MajorTanya MajorTanya force-pushed the migrate-trackers-to-dtos branch 2 times, most recently from e3b014a to 4d24dee Compare August 19, 2024 22:11
@NeKoOuO

This comment has been minimized.

@MajorTanya
Copy link
Contributor Author

MajorTanya commented Aug 28, 2024

Shikimori still crashes the app if a user tries to delete an entry from it when the remote entry doesn't exist anymore (user deleted it through other means like the website) due to an uncaught HttpException (404). This is unchanged to previous behaviour but should be addressed somehow.

Edit: It also appears like none of the trackers remove a track in Mihon if the remote track has been externally removed like described. Behaviour is different between trackers though:
MAL re-adds the entry (!)
AL, Kitsu, (and after this current PR) Shikimori, Bangumi show an error Toast like "[Tracker] error: Could not find manga"
MU shows an error Toast without a message but with the 404 status code in it

@MajorTanya
Copy link
Contributor Author

Aside from the above mentioned and (somewhat) unrelated issues, I have checked all trackers and they appear to be behaving as expected.

Checklist:

  • Linking to Mihon: MAL, AL, Kitsu, Shikimori, Bangumi, MU
  • Adding titles: MAL, AL, Kitsu, Shikimori, Bangumi, MU
  • Updating/Resetting
    • status: MAL, AL, Kitsu, Shikimori, Bangumi, MU
    • dates (MAL, AL, Kitsu only)
      • start: MAL, AL, Kitsu
      • end: MAL, AL, Kitsu
    • progress: MAL, AL, Kitsu, Shikimori, Bangumi, MU
    • score: MAL, AL, Kitsu, Shikimori, Bangumi, MU
  • Removing titles
    • only in Mihon: MAL, AL, Kitsu, Shikimori, MU
    • Mihon & on site (Bangumi doesn't offer this): MAL, AL, Kitsu, Shikimori, MU

Changes the handling of tracker API responses to be parsed to DTOs
instead of doing so "manually" by use of `jsonPrimitive`s and/or
`Json.decodeFromString` invocations.

This greatly simplifies the API response handling.

Renamed constants to SCREAMING_SNAKE_CASE.

Largely tried to name the DTOs in a uniform pattern, with the
tracker's (short) name at the beginning of file and data class names
(ALOAuth instead of OAuth, etc).

With these changes, no area of the code base should be using
`jsonPrimitive` and/or `Json.decodeFromString` anymore.
This API returns start and end dates as Long and the score as Double.

Kitsu's docs claim they're strings (and they are, when requesting
manga details from Kitsu directly) but the Algolia search results
return Longs and Double, respectively.
- Renamed `BangumiX` classes to `BGMX` classes.
- Renamed `toXStatus` and `toXScore` to `toApiStatus` and `toApiScore`
Removed Suppressions added for detekt.

Specifically removed:
- `SwallowedException` where an exception ends as a default value
- `MagicNumber`
- `CyclomaticComplexMethod`
- `TooGenericExceptionThrown`

Also ran spotlessApply which changed SMAddMangaResponse
The `included` attribute seems to only appear when the user already
has the entry in their Kitsu list.

Since both `data` and `included` are required for `firstToTrack`, a
guard clause has been added before all its calls.
Previously, the non-null assertion (!!) would cause a
NullPointerException and a Toast with
"Bangumi error: " (no message) when the user had removed their list
entry from Bangumi through other means like the website.

Now it will show "Bangumi error: Could not find manga".

This is analogous to the error shown by Kitsu under these
circumstances.
The user would see no indication that Shikimori could not properly
refresh the track from the remote. This change causes the error Toast
notification to pop up with the following message
"Shikimori error: Could not find manga".

This is analogous to Kitsu and Bangumi.
These particular occurrences weren't needed because properties are
directly accessible to further act upon. This neatly simplifies these
clauses.
@AntsyLich AntsyLich changed the title Migrate tracking APIs to DTOs Use DTOs to parse tracking API responses Sep 2, 2024
@AntsyLich AntsyLich merged commit 9f99f03 into mihonapp:main Sep 2, 2024
1 check passed
@MajorTanya MajorTanya deleted the migrate-trackers-to-dtos branch September 2, 2024 19:51
cuong-tran pushed a commit to komikku-app/komikku that referenced this pull request Sep 4, 2024
* Migrate tracking APIs to DTOs

Changes the handling of tracker API responses to be parsed to DTOs
instead of doing so "manually" by use of `jsonPrimitive`s and/or
`Json.decodeFromString` invocations.

This greatly simplifies the API response handling.

Renamed constants to SCREAMING_SNAKE_CASE.

Largely tried to name the DTOs in a uniform pattern, with the
tracker's (short) name at the beginning of file and data class names
(ALOAuth instead of OAuth, etc).

With these changes, no area of the code base should be using
`jsonPrimitive` and/or `Json.decodeFromString` anymore.

* Fix wrong types in KitsuAlgoliaSearchItem

This API returns start and end dates as Long and the score as Double.

Kitsu's docs claim they're strings (and they are, when requesting
manga details from Kitsu directly) but the Algolia search results
return Longs and Double, respectively.

* Apply review changes

- Renamed `BangumiX` classes to `BGMX` classes.
- Renamed `toXStatus` and `toXScore` to `toApiStatus` and `toApiScore`

* Handle migration from detekt to spotless

Removed Suppressions added for detekt.

Specifically removed:
- `SwallowedException` where an exception ends as a default value
- `MagicNumber`
- `CyclomaticComplexMethod`
- `TooGenericExceptionThrown`

Also ran spotlessApply which changed SMAddMangaResponse

* Fix Kitsu failing to add series

The `included` attribute seems to only appear when the user already
has the entry in their Kitsu list.

Since both `data` and `included` are required for `firstToTrack`, a
guard clause has been added before all its calls.

* Fix empty Bangumi error when entry doesn't exist

Previously, the non-null assertion (!!) would cause a
NullPointerException and a Toast with
"Bangumi error: " (no message) when the user had removed their list
entry from Bangumi through other means like the website.

Now it will show "Bangumi error: Could not find manga".

This is analogous to the error shown by Kitsu under these
circumstances.

* Fix Shikimori ignoring missing remote entry

The user would see no indication that Shikimori could not properly
refresh the track from the remote. This change causes the error Toast
notification to pop up with the following message
"Shikimori error: Could not find manga".

This is analogous to Kitsu and Bangumi.

* Remove usage of let where not needed

These particular occurrences weren't needed because properties are
directly accessible to further act upon. This neatly simplifies these
clauses.

* Remove missed let

(cherry picked from commit 9f99f03)
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants