Skip to content

Commit

Permalink
Add Details, Studio Code, and Photographer to Images (#4217)
Browse files Browse the repository at this point in the history
* Add Details, Code, and Photographer to Images
* Add date and details to image card
---------
Co-authored-by: WithoutPants <53250216+WithoutPants@users.noreply.github.com>
  • Loading branch information
bob123491234 authored Nov 28, 2023
1 parent d1018b4 commit 4133117
Show file tree
Hide file tree
Showing 19 changed files with 244 additions and 81 deletions.
3 changes: 3 additions & 0 deletions graphql/documents/data/image-slim.graphql
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
fragment SlimImageData on Image {
id
title
code
date
urls
details
photographer
rating100
organized
o_counter
Expand Down
3 changes: 3 additions & 0 deletions graphql/documents/data/image.graphql
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
fragment ImageData on Image {
id
title
code
rating100
date
urls
details
photographer
organized
o_counter
created_at
Expand Down
5 changes: 5 additions & 0 deletions graphql/schema/types/filters.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ input ImageFilterType {
NOT: ImageFilterType

title: StringCriterionInput
details: StringCriterionInput

" Filter by image id"
id: IntCriterionInput
Expand Down Expand Up @@ -486,6 +487,10 @@ input ImageFilterType {
created_at: TimestampCriterionInput
"Filter by last update time"
updated_at: TimestampCriterionInput
"Filter by studio code"
code: StringCriterionInput
"Filter by photographer"
photographer: StringCriterionInput
}

enum CriterionModifier {
Expand Down
9 changes: 9 additions & 0 deletions graphql/schema/types/image.graphql
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
type Image {
id: ID!
title: String
code: String
# rating expressed as 1-100
rating100: Int
url: String @deprecated(reason: "Use urls")
urls: [String!]!
date: String
details: String
photographer: String
o_counter: Int
organized: Boolean!
created_at: Time!
Expand Down Expand Up @@ -37,12 +40,15 @@ input ImageUpdateInput {
clientMutationId: String
id: ID!
title: String
code: String
# rating expressed as 1-100
rating100: Int
organized: Boolean
url: String @deprecated(reason: "Use urls")
urls: [String!]
date: String
details: String
photographer: String

studio_id: ID
performer_ids: [ID!]
Expand All @@ -56,12 +62,15 @@ input BulkImageUpdateInput {
clientMutationId: String
ids: [ID!]
title: String
code: String
# rating expressed as 1-100
rating100: Int
organized: Boolean
url: String @deprecated(reason: "Use urls")
urls: BulkUpdateStrings
date: String
details: String
photographer: String

studio_id: ID
performer_ids: BulkUpdateIds
Expand Down
6 changes: 6 additions & 0 deletions internal/api/resolver_mutation_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ func (r *mutationResolver) imageUpdate(ctx context.Context, input ImageUpdateInp
updatedImage := models.NewImagePartial()

updatedImage.Title = translator.optionalString(input.Title, "title")
updatedImage.Code = translator.optionalString(input.Code, "code")
updatedImage.Details = translator.optionalString(input.Details, "details")
updatedImage.Photographer = translator.optionalString(input.Photographer, "photographer")
updatedImage.Rating = translator.optionalInt(input.Rating100, "rating100")
updatedImage.Organized = translator.optionalBool(input.Organized, "organized")

Expand Down Expand Up @@ -203,6 +206,9 @@ func (r *mutationResolver) BulkImageUpdate(ctx context.Context, input BulkImageU
updatedImage := models.NewImagePartial()

updatedImage.Title = translator.optionalString(input.Title, "title")
updatedImage.Code = translator.optionalString(input.Code, "code")
updatedImage.Details = translator.optionalString(input.Details, "details")
updatedImage.Photographer = translator.optionalString(input.Photographer, "photographer")
updatedImage.Rating = translator.optionalInt(input.Rating100, "rating100")
updatedImage.Organized = translator.optionalBool(input.Organized, "organized")

Expand Down
11 changes: 7 additions & 4 deletions pkg/image/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ import (
// of cover image.
func ToBasicJSON(image *models.Image) *jsonschema.Image {
newImageJSON := jsonschema.Image{
Title: image.Title,
URLs: image.URLs.List(),
CreatedAt: json.JSONTime{Time: image.CreatedAt},
UpdatedAt: json.JSONTime{Time: image.UpdatedAt},
Title: image.Title,
Code: image.Code,
URLs: image.URLs.List(),
Details: image.Details,
Photographer: image.Photographer,
CreatedAt: json.JSONTime{Time: image.CreatedAt},
UpdatedAt: json.JSONTime{Time: image.UpdatedAt},
}

if image.Rating != nil {
Expand Down
9 changes: 9 additions & 0 deletions pkg/image/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ func (i *Importer) imageJSONToImage(imageJSON jsonschema.Image) models.Image {
if imageJSON.Title != "" {
newImage.Title = imageJSON.Title
}
if imageJSON.Code != "" {
newImage.Code = imageJSON.Code
}
if imageJSON.Details != "" {
newImage.Details = imageJSON.Details
}
if imageJSON.Photographer != "" {
newImage.Photographer = imageJSON.Photographer
}
if imageJSON.Rating != 0 {
newImage.Rating = &imageJSON.Rating
}
Expand Down
13 changes: 8 additions & 5 deletions pkg/models/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ package models
import "context"

type ImageFilterType struct {
And *ImageFilterType `json:"AND"`
Or *ImageFilterType `json:"OR"`
Not *ImageFilterType `json:"NOT"`
ID *IntCriterionInput `json:"id"`
Title *StringCriterionInput `json:"title"`
And *ImageFilterType `json:"AND"`
Or *ImageFilterType `json:"OR"`
Not *ImageFilterType `json:"NOT"`
ID *IntCriterionInput `json:"id"`
Title *StringCriterionInput `json:"title"`
Code *StringCriterionInput `json:"code"`
Details *StringCriterionInput `json:"details"`
Photographer *StringCriterionInput `json:"photographer"`
// Filter by file checksum
Checksum *StringCriterionInput `json:"checksum"`
// Filter by path
Expand Down
23 changes: 13 additions & 10 deletions pkg/models/jsonschema/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,25 @@ import (

type Image struct {
Title string `json:"title,omitempty"`
Code string `json:"code,omitempty"`
Studio string `json:"studio,omitempty"`
Rating int `json:"rating,omitempty"`

// deprecated - for import only
URL string `json:"url,omitempty"`

URLs []string `json:"urls,omitempty"`
Date string `json:"date,omitempty"`
Organized bool `json:"organized,omitempty"`
OCounter int `json:"o_counter,omitempty"`
Galleries []GalleryRef `json:"galleries,omitempty"`
Performers []string `json:"performers,omitempty"`
Tags []string `json:"tags,omitempty"`
Files []string `json:"files,omitempty"`
CreatedAt json.JSONTime `json:"created_at,omitempty"`
UpdatedAt json.JSONTime `json:"updated_at,omitempty"`
URLs []string `json:"urls,omitempty"`
Date string `json:"date,omitempty"`
Details string `json:"details,omitempty"`
Photographer string `json:"photographer,omitempty"`
Organized bool `json:"organized,omitempty"`
OCounter int `json:"o_counter,omitempty"`
Galleries []GalleryRef `json:"galleries,omitempty"`
Performers []string `json:"performers,omitempty"`
Tags []string `json:"tags,omitempty"`
Files []string `json:"files,omitempty"`
CreatedAt json.JSONTime `json:"created_at,omitempty"`
UpdatedAt json.JSONTime `json:"updated_at,omitempty"`
}

func (s Image) Filename(basename string, hash string) string {
Expand Down
24 changes: 15 additions & 9 deletions pkg/models/model_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import (
type Image struct {
ID int `json:"id"`

Title string `json:"title"`
Title string `json:"title"`
Code string `json:"code"`
Details string `json:"details"`
Photographer string `json:"photographer"`
// Rating expressed in 1-100 scale
Rating *int `json:"rating"`
Organized bool `json:"organized"`
Expand Down Expand Up @@ -46,15 +49,18 @@ func NewImage() Image {

type ImagePartial struct {
Title OptionalString
Code OptionalString
// Rating expressed in 1-100 scale
Rating OptionalInt
URLs *UpdateStrings
Date OptionalDate
Organized OptionalBool
OCounter OptionalInt
StudioID OptionalInt
CreatedAt OptionalTime
UpdatedAt OptionalTime
Rating OptionalInt
URLs *UpdateStrings
Date OptionalDate
Details OptionalString
Photographer OptionalString
Organized OptionalBool
OCounter OptionalInt
StudioID OptionalInt
CreatedAt OptionalTime
UpdatedAt OptionalTime

GalleryIDs *UpdateIDs
TagIDs *UpdateIDs
Expand Down
2 changes: 1 addition & 1 deletion pkg/sqlite/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const (
dbConnTimeout = 30
)

var appSchemaVersion uint = 53
var appSchemaVersion uint = 54

//go:embed migrations/*.sql
var migrationsBox embed.FS
Expand Down
43 changes: 29 additions & 14 deletions pkg/sqlite/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,27 @@ const (
type imageRow struct {
ID int `db:"id" goqu:"skipinsert"`
Title zero.String `db:"title"`
Code zero.String `db:"code"`
// expressed as 1-100
Rating null.Int `db:"rating"`
Date NullDate `db:"date"`
Organized bool `db:"organized"`
OCounter int `db:"o_counter"`
StudioID null.Int `db:"studio_id,omitempty"`
CreatedAt Timestamp `db:"created_at"`
UpdatedAt Timestamp `db:"updated_at"`
Rating null.Int `db:"rating"`
Date NullDate `db:"date"`
Details zero.String `db:"details"`
Photographer zero.String `db:"photographer"`
Organized bool `db:"organized"`
OCounter int `db:"o_counter"`
StudioID null.Int `db:"studio_id,omitempty"`
CreatedAt Timestamp `db:"created_at"`
UpdatedAt Timestamp `db:"updated_at"`
}

func (r *imageRow) fromImage(i models.Image) {
r.ID = i.ID
r.Title = zero.StringFrom(i.Title)
r.Code = zero.StringFrom(i.Code)
r.Rating = intFromPtr(i.Rating)
r.Date = NullDateFromDatePtr(i.Date)
r.Details = zero.StringFrom(i.Details)
r.Photographer = zero.StringFrom(i.Photographer)
r.Organized = i.Organized
r.OCounter = i.OCounter
r.StudioID = intFromPtr(i.StudioID)
Expand All @@ -63,13 +69,16 @@ type imageQueryRow struct {

func (r *imageQueryRow) resolve() *models.Image {
ret := &models.Image{
ID: r.ID,
Title: r.Title.String,
Rating: nullIntPtr(r.Rating),
Date: r.Date.DatePtr(),
Organized: r.Organized,
OCounter: r.OCounter,
StudioID: nullIntPtr(r.StudioID),
ID: r.ID,
Title: r.Title.String,
Code: r.Code.String,
Rating: nullIntPtr(r.Rating),
Date: r.Date.DatePtr(),
Details: r.Details.String,
Photographer: r.Photographer.String,
Organized: r.Organized,
OCounter: r.OCounter,
StudioID: nullIntPtr(r.StudioID),

PrimaryFileID: nullIntFileIDPtr(r.PrimaryFileID),
Checksum: r.PrimaryFileChecksum.String,
Expand All @@ -91,8 +100,11 @@ type imageRowRecord struct {

func (r *imageRowRecord) fromPartial(i models.ImagePartial) {
r.setNullString("title", i.Title)
r.setNullString("code", i.Code)
r.setNullInt("rating", i.Rating)
r.setNullDate("date", i.Date)
r.setNullString("details", i.Details)
r.setNullString("photographer", i.Photographer)
r.setBool("organized", i.Organized)
r.setInt("o_counter", i.OCounter)
r.setNullInt("studio_id", i.StudioID)
Expand Down Expand Up @@ -672,6 +684,9 @@ func (qb *ImageStore) makeFilter(ctx context.Context, imageFilter *models.ImageF
stringCriterionHandler(imageFilter.Checksum, "fingerprints_md5.fingerprint")(ctx, f)
}))
query.handleCriterion(ctx, stringCriterionHandler(imageFilter.Title, "images.title"))
query.handleCriterion(ctx, stringCriterionHandler(imageFilter.Code, "images.code"))
query.handleCriterion(ctx, stringCriterionHandler(imageFilter.Details, "images.details"))
query.handleCriterion(ctx, stringCriterionHandler(imageFilter.Photographer, "images.photographer"))

query.handleCriterion(ctx, pathCriterionHandler(imageFilter.Path, "folders.path", "files.basename", qb.addFoldersTable))
query.handleCriterion(ctx, imageFileCountCriterionHandler(qb, imageFilter.FileCount))
Expand Down
Loading

0 comments on commit 4133117

Please sign in to comment.