Skip to content

Commit

Permalink
feat(graphql): add children query
Browse files Browse the repository at this point in the history
  • Loading branch information
heyhippari committed Feb 20, 2022
1 parent 960a2b4 commit b8967a6
Show file tree
Hide file tree
Showing 6 changed files with 438 additions and 15 deletions.
28 changes: 28 additions & 0 deletions database/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,34 @@ func GetItemsCountFromLibrary(libraryID string) (*int64, error) {
return &count, nil
}

// Returns all the children of a given item.
func GetChildrenFromItem(id string, limit, offset *int64) ([]*ItemMetadata, error) {
var children []*ItemMetadata

result := db.
Limit(int(*limit)).
Offset(int(*offset)).
Where("parent_id = ?", id).
Find(&children)
if result.Error != nil {
return nil, result.Error
}

return children, nil
}

// Returns the number of children for a given item.
func GetChildrenCountFromItem(id string) (*int64, error) {
var count int64

result := db.Model(&ItemMetadata{}).Where("parent_id = ?", id).Count(&count)
if result.Error != nil {
return nil, result.Error
}

return &count, nil
}

func GetLatestItemsFromLibrary(libraryID uint64, limit int) ([]*ItemMetadata, error) {
var items []*ItemMetadata

Expand Down
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/middelink/go-parse-torrent-name v0.0.0-20190301154245-3ff4efacd4c4
github.com/panjf2000/ants/v2 v2.4.7
github.com/ryanbradynd05/go-tmdb v0.0.0-20201006144520-c0566c3d1506
github.com/spf13/viper v1.10.1
github.com/vektah/gqlparser/v2 v2.3.1
gopkg.in/vansante/go-ffprobe.v2 v2.0.3
gorm.io/datatypes v1.0.5
Expand All @@ -17,18 +18,15 @@ require (

require (
github.com/fsnotify/fsnotify v1.5.1 // indirect
github.com/google/go-cmp v0.5.6 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/magiconair/properties v1.8.5 // indirect
github.com/pelletier/go-toml v1.9.4 // indirect
github.com/spf13/afero v1.6.0 // indirect
github.com/spf13/cast v1.4.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.10.1 // indirect
github.com/subosito/gotenv v1.2.0 // indirect
gopkg.in/ini.v1 v1.66.2 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
)

require (
Expand Down
Loading

0 comments on commit b8967a6

Please sign in to comment.