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

Performer urls #4958

Merged
merged 15 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions graphql/schema/types/performer.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ type Performer {
id: ID!
name: String!
disambiguation: String
url: String
url: String @deprecated(reason: "Use urls")
urls: [String!]
gender: GenderEnum
twitter: String
instagram: String
twitter: String @deprecated(reason: "Use urls")
instagram: String @deprecated(reason: "Use urls")
birthdate: String
ethnicity: String
country: String
Expand Down Expand Up @@ -60,7 +61,8 @@ type Performer {
input PerformerCreateInput {
name: String!
disambiguation: String
url: String
url: String @deprecated(reason: "Use urls")
urls: [String!]
gender: GenderEnum
birthdate: String
ethnicity: String
Expand All @@ -75,8 +77,8 @@ input PerformerCreateInput {
tattoos: String
piercings: String
alias_list: [String!]
twitter: String
instagram: String
twitter: String @deprecated(reason: "Use urls")
instagram: String @deprecated(reason: "Use urls")
favorite: Boolean
tag_ids: [ID!]
"This should be a URL or a base64 encoded data URL"
Expand All @@ -95,7 +97,8 @@ input PerformerUpdateInput {
id: ID!
name: String
disambiguation: String
url: String
url: String @deprecated(reason: "Use urls")
urls: [String!]
gender: GenderEnum
birthdate: String
ethnicity: String
Expand All @@ -110,8 +113,8 @@ input PerformerUpdateInput {
tattoos: String
piercings: String
alias_list: [String!]
twitter: String
instagram: String
twitter: String @deprecated(reason: "Use urls")
instagram: String @deprecated(reason: "Use urls")
favorite: Boolean
tag_ids: [ID!]
"This should be a URL or a base64 encoded data URL"
Expand All @@ -135,7 +138,8 @@ input BulkPerformerUpdateInput {
clientMutationId: String
ids: [ID!]
disambiguation: String
url: String
url: String @deprecated(reason: "Use urls")
urls: BulkUpdateStrings
gender: GenderEnum
birthdate: String
ethnicity: String
Expand All @@ -150,8 +154,8 @@ input BulkPerformerUpdateInput {
tattoos: String
piercings: String
alias_list: BulkUpdateStrings
twitter: String
instagram: String
twitter: String @deprecated(reason: "Use urls")
instagram: String @deprecated(reason: "Use urls")
favorite: Boolean
tag_ids: BulkUpdateIds
# rating expressed as 1-100
Expand Down
14 changes: 8 additions & 6 deletions graphql/schema/types/scraped-performer.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ type ScrapedPerformer {
name: String
disambiguation: String
gender: String
url: String
twitter: String
instagram: String
url: String @deprecated(reason: "use urls")
urls: [String!]
twitter: String @deprecated(reason: "use urls")
instagram: String @deprecated(reason: "use urls")
birthdate: String
ethnicity: String
country: String
Expand Down Expand Up @@ -40,9 +41,10 @@ input ScrapedPerformerInput {
name: String
disambiguation: String
gender: String
url: String
twitter: String
instagram: String
url: String @deprecated(reason: "use urls")
urls: [String!]
twitter: String @deprecated(reason: "use urls")
instagram: String @deprecated(reason: "use urls")
birthdate: String
ethnicity: String
country: String
Expand Down
73 changes: 73 additions & 0 deletions internal/api/resolver_model_performer.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,79 @@ func (r *performerResolver) AliasList(ctx context.Context, obj *models.Performer
return obj.Aliases.List(), nil
}

func (r *performerResolver) URL(ctx context.Context, obj *models.Performer) (*string, error) {
if !obj.URLs.Loaded() {
if err := r.withReadTxn(ctx, func(ctx context.Context) error {
return obj.LoadURLs(ctx, r.repository.Performer)
}); err != nil {
return nil, err
}
}

urls := obj.URLs.List()
if len(urls) == 0 {
return nil, nil
}

return &urls[0], nil
}

func (r *performerResolver) Twitter(ctx context.Context, obj *models.Performer) (*string, error) {
if !obj.URLs.Loaded() {
if err := r.withReadTxn(ctx, func(ctx context.Context) error {
return obj.LoadURLs(ctx, r.repository.Performer)
}); err != nil {
return nil, err
}
}

urls := obj.URLs.List()

// find the first twitter url
for _, url := range urls {
if performer.IsTwitterURL(url) {
u := url
return &u, nil
}
}

return nil, nil
}

func (r *performerResolver) Instagram(ctx context.Context, obj *models.Performer) (*string, error) {
if !obj.URLs.Loaded() {
if err := r.withReadTxn(ctx, func(ctx context.Context) error {
return obj.LoadURLs(ctx, r.repository.Performer)
}); err != nil {
return nil, err
}
}

urls := obj.URLs.List()

// find the first instagram url
for _, url := range urls {
if performer.IsInstagramURL(url) {
u := url
return &u, nil
}
}

return nil, nil
}

func (r *performerResolver) Urls(ctx context.Context, obj *models.Performer) ([]string, error) {
if !obj.URLs.Loaded() {
if err := r.withReadTxn(ctx, func(ctx context.Context) error {
return obj.LoadURLs(ctx, r.repository.Performer)
}); err != nil {
return nil, err
}
}

return obj.URLs.List(), nil
}

func (r *performerResolver) Height(ctx context.Context, obj *models.Performer) (*string, error) {
if obj.Height != nil {
ret := strconv.Itoa(*obj.Height)
Expand Down
Loading
Loading