Skip to content

Commit

Permalink
Fixed a bug with user reviews (#2677)
Browse files Browse the repository at this point in the history
  • Loading branch information
majora2007 authored Feb 1, 2024
1 parent 828d62d commit a9ab848
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 10 deletions.
10 changes: 8 additions & 2 deletions API/Controllers/MetadataController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public async Task<ActionResult<SeriesDetailPlusDto>> GetKavitaPlusSeriesDetailDa
if (user == null) return Unauthorized();

var userReviews = (await unitOfWork.UserRepository.GetUserRatingDtosForSeriesAsync(seriesId, user.Id))
.Where(r => !string.IsNullOrEmpty(r.Body))
.Where(r => !string.IsNullOrEmpty(r.BodyJustText))
.OrderByDescending(review => review.Username.Equals(user.UserName) ? 1 : 0)
.ToList();

Expand All @@ -221,7 +221,13 @@ public async Task<ActionResult<SeriesDetailPlusDto>> GetKavitaPlusSeriesDetailDa
}

var ret = await metadataService.GetSeriesDetail(user.Id, seriesId);
if (ret == null) return Ok(null);
if (ret == null) return Ok(new SeriesDetailPlusDto()
{
Reviews = userReviews,
Recommendations = null,
Ratings = null
});

await _cacheProvider.SetAsync(cacheKey, ret, TimeSpan.FromHours(48));

// For some reason if we don't use a different instance, the cache keeps changes made below
Expand Down
4 changes: 2 additions & 2 deletions API/DTOs/SeriesDetail/SeriesDetailPlusDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace API.DTOs.SeriesDetail;
/// <remarks>This is what the UI sees, not what the API sends back</remarks>
public class SeriesDetailPlusDto
{
public RecommendationDto Recommendations { get; set; }
public RecommendationDto? Recommendations { get; set; }
public IEnumerable<UserReviewDto> Reviews { get; set; }
public IEnumerable<RatingDto> Ratings { get; set; }
public IEnumerable<RatingDto>? Ratings { get; set; }
}
4 changes: 2 additions & 2 deletions UI/Web/src/app/_models/series-detail/series-detail-plus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {UserReview} from "../../_single-module/review-card/user-review";
import {Rating} from "../rating";

export interface SeriesDetailPlus {
recommendations: Recommendation;
recommendations?: Recommendation;
reviews: Array<UserReview>;
ratings: Array<Rating>;
ratings?: Array<Rating>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ export class SeriesDetailComponent implements OnInit, AfterContentChecked {
});
this.setContinuePoint();

if (KavitaPlusSupportedLibraryTypes.includes(this.libraryType) && loadExternal) {
if (loadExternal) {
this.loadPlusMetadata(this.seriesId);
}

Expand Down Expand Up @@ -701,10 +701,16 @@ export class SeriesDetailComponent implements OnInit, AfterContentChecked {

// Reviews
this.reviews = [...data.reviews];
this.ratings = [...data.ratings];
if (data.ratings) {
this.ratings = [...data.ratings];
}


// Recommendations
this.combinedRecs = [...data.recommendations.ownedSeries, ...data.recommendations.externalSeries];
if (data.recommendations) {
this.combinedRecs = [...data.recommendations.ownedSeries, ...data.recommendations.externalSeries];
}

this.hasRecommendations = this.combinedRecs.length > 0;

this.cdRef.markForCheck();
Expand Down
2 changes: 1 addition & 1 deletion openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"name": "GPL-3.0",
"url": "https://github.com/Kareadita/Kavita/blob/develop/LICENSE"
},
"version": "0.7.13.12"
"version": "0.7.13.13"
},
"servers": [
{
Expand Down

0 comments on commit a9ab848

Please sign in to comment.