From ffca8f0c0f930f714ff80e3aaf97ad8fbd97ec66 Mon Sep 17 00:00:00 2001 From: bnkai <48220860+bnkai@users.noreply.github.com> Date: Wed, 16 Nov 2022 23:22:11 +0200 Subject: [PATCH] Fix rating in SceneCreateInput graphql schema (#3137) * Fix rating in SceneCreateInput graphql schema * Fix rating not set at creation Co-authored-by: WithoutPants <53250216+WithoutPants@users.noreply.github.com> --- graphql/schema/types/scene.graphql | 5 ++++- internal/api/changeset_translator.go | 20 ++++++++++++++++++++ internal/api/resolver_mutation_scene.go | 2 +- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/graphql/schema/types/scene.graphql b/graphql/schema/types/scene.graphql index cfad136ee..7295a9530 100644 --- a/graphql/schema/types/scene.graphql +++ b/graphql/schema/types/scene.graphql @@ -85,7 +85,10 @@ input SceneCreateInput { director: String url: String date: String - rating: Int + # rating expressed as 1-5 + rating: Int @deprecated(reason: "Use 1-100 range with rating100") + # rating expressed as 1-100 + rating100: Int organized: Boolean studio_id: ID gallery_ids: [ID!] diff --git a/internal/api/changeset_translator.go b/internal/api/changeset_translator.go index 3f88a6483..eee74bd56 100644 --- a/internal/api/changeset_translator.go +++ b/internal/api/changeset_translator.go @@ -205,6 +205,26 @@ func (t changesetTranslator) ratingConversion(legacyValue *int, rating100Value * return t.nullInt64(rating100Value, rating100Field) } +func (t changesetTranslator) ratingConversionInt(legacyValue *int, rating100Value *int) *int { + const ( + legacyField = "rating" + rating100Field = "rating100" + ) + + legacyRating := t.optionalInt(legacyValue, legacyField) + if legacyRating.Set && !(legacyRating.Null) { + ret := int(models.Rating5To100(int(legacyRating.Value))) + return &ret + } + + o := t.optionalInt(rating100Value, rating100Field) + if o.Set && !(o.Null) { + return &o.Value + } + + return nil +} + func (t changesetTranslator) ratingConversionOptional(legacyValue *int, rating100Value *int) models.OptionalInt { const ( legacyField = "rating" diff --git a/internal/api/resolver_mutation_scene.go b/internal/api/resolver_mutation_scene.go index 2d3bf2725..c7ba87db3 100644 --- a/internal/api/resolver_mutation_scene.go +++ b/internal/api/resolver_mutation_scene.go @@ -71,7 +71,7 @@ func (r *mutationResolver) SceneCreate(ctx context.Context, input SceneCreateInp Director: translator.string(input.Director, "director"), URL: translator.string(input.URL, "url"), Date: translator.datePtr(input.Date, "date"), - Rating: input.Rating, + Rating: translator.ratingConversionInt(input.Rating, input.Rating100), Organized: translator.bool(input.Organized, "organized"), PerformerIDs: models.NewRelatedIDs(performerIDs), TagIDs: models.NewRelatedIDs(tagIDs),