feat: complete qbittorrent support

This commit is contained in:
Simon Ding
2024-10-04 10:31:49 +08:00
parent 6a5c105f8c
commit c42cbb5e5d
20 changed files with 431 additions and 284 deletions

View File

@@ -21,7 +21,7 @@ type DownloadClients struct {
// Name holds the value of the "name" field.
Name string `json:"name,omitempty"`
// Implementation holds the value of the "implementation" field.
Implementation string `json:"implementation,omitempty"`
Implementation downloadclients.Implementation `json:"implementation,omitempty"`
// URL holds the value of the "url" field.
URL string `json:"url,omitempty"`
// User holds the value of the "user" field.
@@ -30,8 +30,8 @@ type DownloadClients struct {
Password string `json:"password,omitempty"`
// Settings holds the value of the "settings" field.
Settings string `json:"settings,omitempty"`
// Priority holds the value of the "priority" field.
Priority string `json:"priority,omitempty"`
// Ordering holds the value of the "ordering" field.
Ordering int `json:"ordering,omitempty"`
// RemoveCompletedDownloads holds the value of the "remove_completed_downloads" field.
RemoveCompletedDownloads bool `json:"remove_completed_downloads,omitempty"`
// RemoveFailedDownloads holds the value of the "remove_failed_downloads" field.
@@ -48,9 +48,9 @@ func (*DownloadClients) scanValues(columns []string) ([]any, error) {
switch columns[i] {
case downloadclients.FieldEnable, downloadclients.FieldRemoveCompletedDownloads, downloadclients.FieldRemoveFailedDownloads:
values[i] = new(sql.NullBool)
case downloadclients.FieldID:
case downloadclients.FieldID, downloadclients.FieldOrdering:
values[i] = new(sql.NullInt64)
case downloadclients.FieldName, downloadclients.FieldImplementation, downloadclients.FieldURL, downloadclients.FieldUser, downloadclients.FieldPassword, downloadclients.FieldSettings, downloadclients.FieldPriority, downloadclients.FieldTags:
case downloadclients.FieldName, downloadclients.FieldImplementation, downloadclients.FieldURL, downloadclients.FieldUser, downloadclients.FieldPassword, downloadclients.FieldSettings, downloadclients.FieldTags:
values[i] = new(sql.NullString)
default:
values[i] = new(sql.UnknownType)
@@ -89,7 +89,7 @@ func (dc *DownloadClients) assignValues(columns []string, values []any) error {
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field implementation", values[i])
} else if value.Valid {
dc.Implementation = value.String
dc.Implementation = downloadclients.Implementation(value.String)
}
case downloadclients.FieldURL:
if value, ok := values[i].(*sql.NullString); !ok {
@@ -115,11 +115,11 @@ func (dc *DownloadClients) assignValues(columns []string, values []any) error {
} else if value.Valid {
dc.Settings = value.String
}
case downloadclients.FieldPriority:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field priority", values[i])
case downloadclients.FieldOrdering:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field ordering", values[i])
} else if value.Valid {
dc.Priority = value.String
dc.Ordering = int(value.Int64)
}
case downloadclients.FieldRemoveCompletedDownloads:
if value, ok := values[i].(*sql.NullBool); !ok {
@@ -182,7 +182,7 @@ func (dc *DownloadClients) String() string {
builder.WriteString(dc.Name)
builder.WriteString(", ")
builder.WriteString("implementation=")
builder.WriteString(dc.Implementation)
builder.WriteString(fmt.Sprintf("%v", dc.Implementation))
builder.WriteString(", ")
builder.WriteString("url=")
builder.WriteString(dc.URL)
@@ -196,8 +196,8 @@ func (dc *DownloadClients) String() string {
builder.WriteString("settings=")
builder.WriteString(dc.Settings)
builder.WriteString(", ")
builder.WriteString("priority=")
builder.WriteString(dc.Priority)
builder.WriteString("ordering=")
builder.WriteString(fmt.Sprintf("%v", dc.Ordering))
builder.WriteString(", ")
builder.WriteString("remove_completed_downloads=")
builder.WriteString(fmt.Sprintf("%v", dc.RemoveCompletedDownloads))

View File

@@ -3,6 +3,8 @@
package downloadclients
import (
"fmt"
"entgo.io/ent/dialect/sql"
)
@@ -25,8 +27,8 @@ const (
FieldPassword = "password"
// FieldSettings holds the string denoting the settings field in the database.
FieldSettings = "settings"
// FieldPriority holds the string denoting the priority field in the database.
FieldPriority = "priority"
// FieldOrdering holds the string denoting the ordering field in the database.
FieldOrdering = "ordering"
// FieldRemoveCompletedDownloads holds the string denoting the remove_completed_downloads field in the database.
FieldRemoveCompletedDownloads = "remove_completed_downloads"
// FieldRemoveFailedDownloads holds the string denoting the remove_failed_downloads field in the database.
@@ -47,7 +49,7 @@ var Columns = []string{
FieldUser,
FieldPassword,
FieldSettings,
FieldPriority,
FieldOrdering,
FieldRemoveCompletedDownloads,
FieldRemoveFailedDownloads,
FieldTags,
@@ -70,8 +72,10 @@ var (
DefaultPassword string
// DefaultSettings holds the default value on creation for the "settings" field.
DefaultSettings string
// DefaultPriority holds the default value on creation for the "priority" field.
DefaultPriority string
// DefaultOrdering holds the default value on creation for the "ordering" field.
DefaultOrdering int
// OrderingValidator is a validator for the "ordering" field. It is called by the builders before save.
OrderingValidator func(int) error
// DefaultRemoveCompletedDownloads holds the default value on creation for the "remove_completed_downloads" field.
DefaultRemoveCompletedDownloads bool
// DefaultRemoveFailedDownloads holds the default value on creation for the "remove_failed_downloads" field.
@@ -80,6 +84,29 @@ var (
DefaultTags string
)
// Implementation defines the type for the "implementation" enum field.
type Implementation string
// Implementation values.
const (
ImplementationTransmission Implementation = "transmission"
ImplementationQbittorrent Implementation = "qbittorrent"
)
func (i Implementation) String() string {
return string(i)
}
// ImplementationValidator is a validator for the "implementation" field enum values. It is called by the builders before save.
func ImplementationValidator(i Implementation) error {
switch i {
case ImplementationTransmission, ImplementationQbittorrent:
return nil
default:
return fmt.Errorf("downloadclients: invalid enum value for implementation field: %q", i)
}
}
// OrderOption defines the ordering options for the DownloadClients queries.
type OrderOption func(*sql.Selector)
@@ -123,9 +150,9 @@ func BySettings(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldSettings, opts...).ToFunc()
}
// ByPriority orders the results by the priority field.
func ByPriority(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldPriority, opts...).ToFunc()
// ByOrdering orders the results by the ordering field.
func ByOrdering(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldOrdering, opts...).ToFunc()
}
// ByRemoveCompletedDownloads orders the results by the remove_completed_downloads field.

View File

@@ -63,11 +63,6 @@ func Name(v string) predicate.DownloadClients {
return predicate.DownloadClients(sql.FieldEQ(FieldName, v))
}
// Implementation applies equality check predicate on the "implementation" field. It's identical to ImplementationEQ.
func Implementation(v string) predicate.DownloadClients {
return predicate.DownloadClients(sql.FieldEQ(FieldImplementation, v))
}
// URL applies equality check predicate on the "url" field. It's identical to URLEQ.
func URL(v string) predicate.DownloadClients {
return predicate.DownloadClients(sql.FieldEQ(FieldURL, v))
@@ -88,9 +83,9 @@ func Settings(v string) predicate.DownloadClients {
return predicate.DownloadClients(sql.FieldEQ(FieldSettings, v))
}
// Priority applies equality check predicate on the "priority" field. It's identical to PriorityEQ.
func Priority(v string) predicate.DownloadClients {
return predicate.DownloadClients(sql.FieldEQ(FieldPriority, v))
// Ordering applies equality check predicate on the "ordering" field. It's identical to OrderingEQ.
func Ordering(v int) predicate.DownloadClients {
return predicate.DownloadClients(sql.FieldEQ(FieldOrdering, v))
}
// RemoveCompletedDownloads applies equality check predicate on the "remove_completed_downloads" field. It's identical to RemoveCompletedDownloadsEQ.
@@ -184,70 +179,25 @@ func NameContainsFold(v string) predicate.DownloadClients {
}
// ImplementationEQ applies the EQ predicate on the "implementation" field.
func ImplementationEQ(v string) predicate.DownloadClients {
func ImplementationEQ(v Implementation) predicate.DownloadClients {
return predicate.DownloadClients(sql.FieldEQ(FieldImplementation, v))
}
// ImplementationNEQ applies the NEQ predicate on the "implementation" field.
func ImplementationNEQ(v string) predicate.DownloadClients {
func ImplementationNEQ(v Implementation) predicate.DownloadClients {
return predicate.DownloadClients(sql.FieldNEQ(FieldImplementation, v))
}
// ImplementationIn applies the In predicate on the "implementation" field.
func ImplementationIn(vs ...string) predicate.DownloadClients {
func ImplementationIn(vs ...Implementation) predicate.DownloadClients {
return predicate.DownloadClients(sql.FieldIn(FieldImplementation, vs...))
}
// ImplementationNotIn applies the NotIn predicate on the "implementation" field.
func ImplementationNotIn(vs ...string) predicate.DownloadClients {
func ImplementationNotIn(vs ...Implementation) predicate.DownloadClients {
return predicate.DownloadClients(sql.FieldNotIn(FieldImplementation, vs...))
}
// ImplementationGT applies the GT predicate on the "implementation" field.
func ImplementationGT(v string) predicate.DownloadClients {
return predicate.DownloadClients(sql.FieldGT(FieldImplementation, v))
}
// ImplementationGTE applies the GTE predicate on the "implementation" field.
func ImplementationGTE(v string) predicate.DownloadClients {
return predicate.DownloadClients(sql.FieldGTE(FieldImplementation, v))
}
// ImplementationLT applies the LT predicate on the "implementation" field.
func ImplementationLT(v string) predicate.DownloadClients {
return predicate.DownloadClients(sql.FieldLT(FieldImplementation, v))
}
// ImplementationLTE applies the LTE predicate on the "implementation" field.
func ImplementationLTE(v string) predicate.DownloadClients {
return predicate.DownloadClients(sql.FieldLTE(FieldImplementation, v))
}
// ImplementationContains applies the Contains predicate on the "implementation" field.
func ImplementationContains(v string) predicate.DownloadClients {
return predicate.DownloadClients(sql.FieldContains(FieldImplementation, v))
}
// ImplementationHasPrefix applies the HasPrefix predicate on the "implementation" field.
func ImplementationHasPrefix(v string) predicate.DownloadClients {
return predicate.DownloadClients(sql.FieldHasPrefix(FieldImplementation, v))
}
// ImplementationHasSuffix applies the HasSuffix predicate on the "implementation" field.
func ImplementationHasSuffix(v string) predicate.DownloadClients {
return predicate.DownloadClients(sql.FieldHasSuffix(FieldImplementation, v))
}
// ImplementationEqualFold applies the EqualFold predicate on the "implementation" field.
func ImplementationEqualFold(v string) predicate.DownloadClients {
return predicate.DownloadClients(sql.FieldEqualFold(FieldImplementation, v))
}
// ImplementationContainsFold applies the ContainsFold predicate on the "implementation" field.
func ImplementationContainsFold(v string) predicate.DownloadClients {
return predicate.DownloadClients(sql.FieldContainsFold(FieldImplementation, v))
}
// URLEQ applies the EQ predicate on the "url" field.
func URLEQ(v string) predicate.DownloadClients {
return predicate.DownloadClients(sql.FieldEQ(FieldURL, v))
@@ -508,69 +458,44 @@ func SettingsContainsFold(v string) predicate.DownloadClients {
return predicate.DownloadClients(sql.FieldContainsFold(FieldSettings, v))
}
// PriorityEQ applies the EQ predicate on the "priority" field.
func PriorityEQ(v string) predicate.DownloadClients {
return predicate.DownloadClients(sql.FieldEQ(FieldPriority, v))
// OrderingEQ applies the EQ predicate on the "ordering" field.
func OrderingEQ(v int) predicate.DownloadClients {
return predicate.DownloadClients(sql.FieldEQ(FieldOrdering, v))
}
// PriorityNEQ applies the NEQ predicate on the "priority" field.
func PriorityNEQ(v string) predicate.DownloadClients {
return predicate.DownloadClients(sql.FieldNEQ(FieldPriority, v))
// OrderingNEQ applies the NEQ predicate on the "ordering" field.
func OrderingNEQ(v int) predicate.DownloadClients {
return predicate.DownloadClients(sql.FieldNEQ(FieldOrdering, v))
}
// PriorityIn applies the In predicate on the "priority" field.
func PriorityIn(vs ...string) predicate.DownloadClients {
return predicate.DownloadClients(sql.FieldIn(FieldPriority, vs...))
// OrderingIn applies the In predicate on the "ordering" field.
func OrderingIn(vs ...int) predicate.DownloadClients {
return predicate.DownloadClients(sql.FieldIn(FieldOrdering, vs...))
}
// PriorityNotIn applies the NotIn predicate on the "priority" field.
func PriorityNotIn(vs ...string) predicate.DownloadClients {
return predicate.DownloadClients(sql.FieldNotIn(FieldPriority, vs...))
// OrderingNotIn applies the NotIn predicate on the "ordering" field.
func OrderingNotIn(vs ...int) predicate.DownloadClients {
return predicate.DownloadClients(sql.FieldNotIn(FieldOrdering, vs...))
}
// PriorityGT applies the GT predicate on the "priority" field.
func PriorityGT(v string) predicate.DownloadClients {
return predicate.DownloadClients(sql.FieldGT(FieldPriority, v))
// OrderingGT applies the GT predicate on the "ordering" field.
func OrderingGT(v int) predicate.DownloadClients {
return predicate.DownloadClients(sql.FieldGT(FieldOrdering, v))
}
// PriorityGTE applies the GTE predicate on the "priority" field.
func PriorityGTE(v string) predicate.DownloadClients {
return predicate.DownloadClients(sql.FieldGTE(FieldPriority, v))
// OrderingGTE applies the GTE predicate on the "ordering" field.
func OrderingGTE(v int) predicate.DownloadClients {
return predicate.DownloadClients(sql.FieldGTE(FieldOrdering, v))
}
// PriorityLT applies the LT predicate on the "priority" field.
func PriorityLT(v string) predicate.DownloadClients {
return predicate.DownloadClients(sql.FieldLT(FieldPriority, v))
// OrderingLT applies the LT predicate on the "ordering" field.
func OrderingLT(v int) predicate.DownloadClients {
return predicate.DownloadClients(sql.FieldLT(FieldOrdering, v))
}
// PriorityLTE applies the LTE predicate on the "priority" field.
func PriorityLTE(v string) predicate.DownloadClients {
return predicate.DownloadClients(sql.FieldLTE(FieldPriority, v))
}
// PriorityContains applies the Contains predicate on the "priority" field.
func PriorityContains(v string) predicate.DownloadClients {
return predicate.DownloadClients(sql.FieldContains(FieldPriority, v))
}
// PriorityHasPrefix applies the HasPrefix predicate on the "priority" field.
func PriorityHasPrefix(v string) predicate.DownloadClients {
return predicate.DownloadClients(sql.FieldHasPrefix(FieldPriority, v))
}
// PriorityHasSuffix applies the HasSuffix predicate on the "priority" field.
func PriorityHasSuffix(v string) predicate.DownloadClients {
return predicate.DownloadClients(sql.FieldHasSuffix(FieldPriority, v))
}
// PriorityEqualFold applies the EqualFold predicate on the "priority" field.
func PriorityEqualFold(v string) predicate.DownloadClients {
return predicate.DownloadClients(sql.FieldEqualFold(FieldPriority, v))
}
// PriorityContainsFold applies the ContainsFold predicate on the "priority" field.
func PriorityContainsFold(v string) predicate.DownloadClients {
return predicate.DownloadClients(sql.FieldContainsFold(FieldPriority, v))
// OrderingLTE applies the LTE predicate on the "ordering" field.
func OrderingLTE(v int) predicate.DownloadClients {
return predicate.DownloadClients(sql.FieldLTE(FieldOrdering, v))
}
// RemoveCompletedDownloadsEQ applies the EQ predicate on the "remove_completed_downloads" field.

View File

@@ -32,8 +32,8 @@ func (dcc *DownloadClientsCreate) SetName(s string) *DownloadClientsCreate {
}
// SetImplementation sets the "implementation" field.
func (dcc *DownloadClientsCreate) SetImplementation(s string) *DownloadClientsCreate {
dcc.mutation.SetImplementation(s)
func (dcc *DownloadClientsCreate) SetImplementation(d downloadclients.Implementation) *DownloadClientsCreate {
dcc.mutation.SetImplementation(d)
return dcc
}
@@ -85,16 +85,16 @@ func (dcc *DownloadClientsCreate) SetNillableSettings(s *string) *DownloadClient
return dcc
}
// SetPriority sets the "priority" field.
func (dcc *DownloadClientsCreate) SetPriority(s string) *DownloadClientsCreate {
dcc.mutation.SetPriority(s)
// SetOrdering sets the "ordering" field.
func (dcc *DownloadClientsCreate) SetOrdering(i int) *DownloadClientsCreate {
dcc.mutation.SetOrdering(i)
return dcc
}
// SetNillablePriority sets the "priority" field if the given value is not nil.
func (dcc *DownloadClientsCreate) SetNillablePriority(s *string) *DownloadClientsCreate {
if s != nil {
dcc.SetPriority(*s)
// SetNillableOrdering sets the "ordering" field if the given value is not nil.
func (dcc *DownloadClientsCreate) SetNillableOrdering(i *int) *DownloadClientsCreate {
if i != nil {
dcc.SetOrdering(*i)
}
return dcc
}
@@ -188,9 +188,9 @@ func (dcc *DownloadClientsCreate) defaults() {
v := downloadclients.DefaultSettings
dcc.mutation.SetSettings(v)
}
if _, ok := dcc.mutation.Priority(); !ok {
v := downloadclients.DefaultPriority
dcc.mutation.SetPriority(v)
if _, ok := dcc.mutation.Ordering(); !ok {
v := downloadclients.DefaultOrdering
dcc.mutation.SetOrdering(v)
}
if _, ok := dcc.mutation.RemoveCompletedDownloads(); !ok {
v := downloadclients.DefaultRemoveCompletedDownloads
@@ -217,6 +217,11 @@ func (dcc *DownloadClientsCreate) check() error {
if _, ok := dcc.mutation.Implementation(); !ok {
return &ValidationError{Name: "implementation", err: errors.New(`ent: missing required field "DownloadClients.implementation"`)}
}
if v, ok := dcc.mutation.Implementation(); ok {
if err := downloadclients.ImplementationValidator(v); err != nil {
return &ValidationError{Name: "implementation", err: fmt.Errorf(`ent: validator failed for field "DownloadClients.implementation": %w`, err)}
}
}
if _, ok := dcc.mutation.URL(); !ok {
return &ValidationError{Name: "url", err: errors.New(`ent: missing required field "DownloadClients.url"`)}
}
@@ -229,8 +234,13 @@ func (dcc *DownloadClientsCreate) check() error {
if _, ok := dcc.mutation.Settings(); !ok {
return &ValidationError{Name: "settings", err: errors.New(`ent: missing required field "DownloadClients.settings"`)}
}
if _, ok := dcc.mutation.Priority(); !ok {
return &ValidationError{Name: "priority", err: errors.New(`ent: missing required field "DownloadClients.priority"`)}
if _, ok := dcc.mutation.Ordering(); !ok {
return &ValidationError{Name: "ordering", err: errors.New(`ent: missing required field "DownloadClients.ordering"`)}
}
if v, ok := dcc.mutation.Ordering(); ok {
if err := downloadclients.OrderingValidator(v); err != nil {
return &ValidationError{Name: "ordering", err: fmt.Errorf(`ent: validator failed for field "DownloadClients.ordering": %w`, err)}
}
}
if _, ok := dcc.mutation.RemoveCompletedDownloads(); !ok {
return &ValidationError{Name: "remove_completed_downloads", err: errors.New(`ent: missing required field "DownloadClients.remove_completed_downloads"`)}
@@ -276,7 +286,7 @@ func (dcc *DownloadClientsCreate) createSpec() (*DownloadClients, *sqlgraph.Crea
_node.Name = value
}
if value, ok := dcc.mutation.Implementation(); ok {
_spec.SetField(downloadclients.FieldImplementation, field.TypeString, value)
_spec.SetField(downloadclients.FieldImplementation, field.TypeEnum, value)
_node.Implementation = value
}
if value, ok := dcc.mutation.URL(); ok {
@@ -295,9 +305,9 @@ func (dcc *DownloadClientsCreate) createSpec() (*DownloadClients, *sqlgraph.Crea
_spec.SetField(downloadclients.FieldSettings, field.TypeString, value)
_node.Settings = value
}
if value, ok := dcc.mutation.Priority(); ok {
_spec.SetField(downloadclients.FieldPriority, field.TypeString, value)
_node.Priority = value
if value, ok := dcc.mutation.Ordering(); ok {
_spec.SetField(downloadclients.FieldOrdering, field.TypeInt, value)
_node.Ordering = value
}
if value, ok := dcc.mutation.RemoveCompletedDownloads(); ok {
_spec.SetField(downloadclients.FieldRemoveCompletedDownloads, field.TypeBool, value)

View File

@@ -56,15 +56,15 @@ func (dcu *DownloadClientsUpdate) SetNillableName(s *string) *DownloadClientsUpd
}
// SetImplementation sets the "implementation" field.
func (dcu *DownloadClientsUpdate) SetImplementation(s string) *DownloadClientsUpdate {
dcu.mutation.SetImplementation(s)
func (dcu *DownloadClientsUpdate) SetImplementation(d downloadclients.Implementation) *DownloadClientsUpdate {
dcu.mutation.SetImplementation(d)
return dcu
}
// SetNillableImplementation sets the "implementation" field if the given value is not nil.
func (dcu *DownloadClientsUpdate) SetNillableImplementation(s *string) *DownloadClientsUpdate {
if s != nil {
dcu.SetImplementation(*s)
func (dcu *DownloadClientsUpdate) SetNillableImplementation(d *downloadclients.Implementation) *DownloadClientsUpdate {
if d != nil {
dcu.SetImplementation(*d)
}
return dcu
}
@@ -125,20 +125,27 @@ func (dcu *DownloadClientsUpdate) SetNillableSettings(s *string) *DownloadClient
return dcu
}
// SetPriority sets the "priority" field.
func (dcu *DownloadClientsUpdate) SetPriority(s string) *DownloadClientsUpdate {
dcu.mutation.SetPriority(s)
// SetOrdering sets the "ordering" field.
func (dcu *DownloadClientsUpdate) SetOrdering(i int) *DownloadClientsUpdate {
dcu.mutation.ResetOrdering()
dcu.mutation.SetOrdering(i)
return dcu
}
// SetNillablePriority sets the "priority" field if the given value is not nil.
func (dcu *DownloadClientsUpdate) SetNillablePriority(s *string) *DownloadClientsUpdate {
if s != nil {
dcu.SetPriority(*s)
// SetNillableOrdering sets the "ordering" field if the given value is not nil.
func (dcu *DownloadClientsUpdate) SetNillableOrdering(i *int) *DownloadClientsUpdate {
if i != nil {
dcu.SetOrdering(*i)
}
return dcu
}
// AddOrdering adds i to the "ordering" field.
func (dcu *DownloadClientsUpdate) AddOrdering(i int) *DownloadClientsUpdate {
dcu.mutation.AddOrdering(i)
return dcu
}
// SetRemoveCompletedDownloads sets the "remove_completed_downloads" field.
func (dcu *DownloadClientsUpdate) SetRemoveCompletedDownloads(b bool) *DownloadClientsUpdate {
dcu.mutation.SetRemoveCompletedDownloads(b)
@@ -213,7 +220,25 @@ func (dcu *DownloadClientsUpdate) ExecX(ctx context.Context) {
}
}
// check runs all checks and user-defined validators on the builder.
func (dcu *DownloadClientsUpdate) check() error {
if v, ok := dcu.mutation.Implementation(); ok {
if err := downloadclients.ImplementationValidator(v); err != nil {
return &ValidationError{Name: "implementation", err: fmt.Errorf(`ent: validator failed for field "DownloadClients.implementation": %w`, err)}
}
}
if v, ok := dcu.mutation.Ordering(); ok {
if err := downloadclients.OrderingValidator(v); err != nil {
return &ValidationError{Name: "ordering", err: fmt.Errorf(`ent: validator failed for field "DownloadClients.ordering": %w`, err)}
}
}
return nil
}
func (dcu *DownloadClientsUpdate) sqlSave(ctx context.Context) (n int, err error) {
if err := dcu.check(); err != nil {
return n, err
}
_spec := sqlgraph.NewUpdateSpec(downloadclients.Table, downloadclients.Columns, sqlgraph.NewFieldSpec(downloadclients.FieldID, field.TypeInt))
if ps := dcu.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
@@ -229,7 +254,7 @@ func (dcu *DownloadClientsUpdate) sqlSave(ctx context.Context) (n int, err error
_spec.SetField(downloadclients.FieldName, field.TypeString, value)
}
if value, ok := dcu.mutation.Implementation(); ok {
_spec.SetField(downloadclients.FieldImplementation, field.TypeString, value)
_spec.SetField(downloadclients.FieldImplementation, field.TypeEnum, value)
}
if value, ok := dcu.mutation.URL(); ok {
_spec.SetField(downloadclients.FieldURL, field.TypeString, value)
@@ -243,8 +268,11 @@ func (dcu *DownloadClientsUpdate) sqlSave(ctx context.Context) (n int, err error
if value, ok := dcu.mutation.Settings(); ok {
_spec.SetField(downloadclients.FieldSettings, field.TypeString, value)
}
if value, ok := dcu.mutation.Priority(); ok {
_spec.SetField(downloadclients.FieldPriority, field.TypeString, value)
if value, ok := dcu.mutation.Ordering(); ok {
_spec.SetField(downloadclients.FieldOrdering, field.TypeInt, value)
}
if value, ok := dcu.mutation.AddedOrdering(); ok {
_spec.AddField(downloadclients.FieldOrdering, field.TypeInt, value)
}
if value, ok := dcu.mutation.RemoveCompletedDownloads(); ok {
_spec.SetField(downloadclients.FieldRemoveCompletedDownloads, field.TypeBool, value)
@@ -304,15 +332,15 @@ func (dcuo *DownloadClientsUpdateOne) SetNillableName(s *string) *DownloadClient
}
// SetImplementation sets the "implementation" field.
func (dcuo *DownloadClientsUpdateOne) SetImplementation(s string) *DownloadClientsUpdateOne {
dcuo.mutation.SetImplementation(s)
func (dcuo *DownloadClientsUpdateOne) SetImplementation(d downloadclients.Implementation) *DownloadClientsUpdateOne {
dcuo.mutation.SetImplementation(d)
return dcuo
}
// SetNillableImplementation sets the "implementation" field if the given value is not nil.
func (dcuo *DownloadClientsUpdateOne) SetNillableImplementation(s *string) *DownloadClientsUpdateOne {
if s != nil {
dcuo.SetImplementation(*s)
func (dcuo *DownloadClientsUpdateOne) SetNillableImplementation(d *downloadclients.Implementation) *DownloadClientsUpdateOne {
if d != nil {
dcuo.SetImplementation(*d)
}
return dcuo
}
@@ -373,20 +401,27 @@ func (dcuo *DownloadClientsUpdateOne) SetNillableSettings(s *string) *DownloadCl
return dcuo
}
// SetPriority sets the "priority" field.
func (dcuo *DownloadClientsUpdateOne) SetPriority(s string) *DownloadClientsUpdateOne {
dcuo.mutation.SetPriority(s)
// SetOrdering sets the "ordering" field.
func (dcuo *DownloadClientsUpdateOne) SetOrdering(i int) *DownloadClientsUpdateOne {
dcuo.mutation.ResetOrdering()
dcuo.mutation.SetOrdering(i)
return dcuo
}
// SetNillablePriority sets the "priority" field if the given value is not nil.
func (dcuo *DownloadClientsUpdateOne) SetNillablePriority(s *string) *DownloadClientsUpdateOne {
if s != nil {
dcuo.SetPriority(*s)
// SetNillableOrdering sets the "ordering" field if the given value is not nil.
func (dcuo *DownloadClientsUpdateOne) SetNillableOrdering(i *int) *DownloadClientsUpdateOne {
if i != nil {
dcuo.SetOrdering(*i)
}
return dcuo
}
// AddOrdering adds i to the "ordering" field.
func (dcuo *DownloadClientsUpdateOne) AddOrdering(i int) *DownloadClientsUpdateOne {
dcuo.mutation.AddOrdering(i)
return dcuo
}
// SetRemoveCompletedDownloads sets the "remove_completed_downloads" field.
func (dcuo *DownloadClientsUpdateOne) SetRemoveCompletedDownloads(b bool) *DownloadClientsUpdateOne {
dcuo.mutation.SetRemoveCompletedDownloads(b)
@@ -474,7 +509,25 @@ func (dcuo *DownloadClientsUpdateOne) ExecX(ctx context.Context) {
}
}
// check runs all checks and user-defined validators on the builder.
func (dcuo *DownloadClientsUpdateOne) check() error {
if v, ok := dcuo.mutation.Implementation(); ok {
if err := downloadclients.ImplementationValidator(v); err != nil {
return &ValidationError{Name: "implementation", err: fmt.Errorf(`ent: validator failed for field "DownloadClients.implementation": %w`, err)}
}
}
if v, ok := dcuo.mutation.Ordering(); ok {
if err := downloadclients.OrderingValidator(v); err != nil {
return &ValidationError{Name: "ordering", err: fmt.Errorf(`ent: validator failed for field "DownloadClients.ordering": %w`, err)}
}
}
return nil
}
func (dcuo *DownloadClientsUpdateOne) sqlSave(ctx context.Context) (_node *DownloadClients, err error) {
if err := dcuo.check(); err != nil {
return _node, err
}
_spec := sqlgraph.NewUpdateSpec(downloadclients.Table, downloadclients.Columns, sqlgraph.NewFieldSpec(downloadclients.FieldID, field.TypeInt))
id, ok := dcuo.mutation.ID()
if !ok {
@@ -507,7 +560,7 @@ func (dcuo *DownloadClientsUpdateOne) sqlSave(ctx context.Context) (_node *Downl
_spec.SetField(downloadclients.FieldName, field.TypeString, value)
}
if value, ok := dcuo.mutation.Implementation(); ok {
_spec.SetField(downloadclients.FieldImplementation, field.TypeString, value)
_spec.SetField(downloadclients.FieldImplementation, field.TypeEnum, value)
}
if value, ok := dcuo.mutation.URL(); ok {
_spec.SetField(downloadclients.FieldURL, field.TypeString, value)
@@ -521,8 +574,11 @@ func (dcuo *DownloadClientsUpdateOne) sqlSave(ctx context.Context) (_node *Downl
if value, ok := dcuo.mutation.Settings(); ok {
_spec.SetField(downloadclients.FieldSettings, field.TypeString, value)
}
if value, ok := dcuo.mutation.Priority(); ok {
_spec.SetField(downloadclients.FieldPriority, field.TypeString, value)
if value, ok := dcuo.mutation.Ordering(); ok {
_spec.SetField(downloadclients.FieldOrdering, field.TypeInt, value)
}
if value, ok := dcuo.mutation.AddedOrdering(); ok {
_spec.AddField(downloadclients.FieldOrdering, field.TypeInt, value)
}
if value, ok := dcuo.mutation.RemoveCompletedDownloads(); ok {
_spec.SetField(downloadclients.FieldRemoveCompletedDownloads, field.TypeBool, value)

View File

@@ -25,12 +25,12 @@ var (
{Name: "id", Type: field.TypeInt, Increment: true},
{Name: "enable", Type: field.TypeBool},
{Name: "name", Type: field.TypeString},
{Name: "implementation", Type: field.TypeString},
{Name: "implementation", Type: field.TypeEnum, Enums: []string{"transmission", "qbittorrent"}},
{Name: "url", Type: field.TypeString},
{Name: "user", Type: field.TypeString, Default: ""},
{Name: "password", Type: field.TypeString, Default: ""},
{Name: "settings", Type: field.TypeString, Default: ""},
{Name: "priority", Type: field.TypeString, Default: ""},
{Name: "ordering", Type: field.TypeInt, Default: 1},
{Name: "remove_completed_downloads", Type: field.TypeBool, Default: true},
{Name: "remove_failed_downloads", Type: field.TypeBool, Default: true},
{Name: "tags", Type: field.TypeString, Default: ""},

View File

@@ -434,12 +434,13 @@ type DownloadClientsMutation struct {
id *int
enable *bool
name *string
implementation *string
implementation *downloadclients.Implementation
url *string
user *string
password *string
settings *string
priority *string
ordering *int
addordering *int
remove_completed_downloads *bool
remove_failed_downloads *bool
tags *string
@@ -620,12 +621,12 @@ func (m *DownloadClientsMutation) ResetName() {
}
// SetImplementation sets the "implementation" field.
func (m *DownloadClientsMutation) SetImplementation(s string) {
m.implementation = &s
func (m *DownloadClientsMutation) SetImplementation(d downloadclients.Implementation) {
m.implementation = &d
}
// Implementation returns the value of the "implementation" field in the mutation.
func (m *DownloadClientsMutation) Implementation() (r string, exists bool) {
func (m *DownloadClientsMutation) Implementation() (r downloadclients.Implementation, exists bool) {
v := m.implementation
if v == nil {
return
@@ -636,7 +637,7 @@ func (m *DownloadClientsMutation) Implementation() (r string, exists bool) {
// OldImplementation returns the old "implementation" field's value of the DownloadClients entity.
// If the DownloadClients object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *DownloadClientsMutation) OldImplementation(ctx context.Context) (v string, err error) {
func (m *DownloadClientsMutation) OldImplementation(ctx context.Context) (v downloadclients.Implementation, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldImplementation is only allowed on UpdateOne operations")
}
@@ -799,40 +800,60 @@ func (m *DownloadClientsMutation) ResetSettings() {
m.settings = nil
}
// SetPriority sets the "priority" field.
func (m *DownloadClientsMutation) SetPriority(s string) {
m.priority = &s
// SetOrdering sets the "ordering" field.
func (m *DownloadClientsMutation) SetOrdering(i int) {
m.ordering = &i
m.addordering = nil
}
// Priority returns the value of the "priority" field in the mutation.
func (m *DownloadClientsMutation) Priority() (r string, exists bool) {
v := m.priority
// Ordering returns the value of the "ordering" field in the mutation.
func (m *DownloadClientsMutation) Ordering() (r int, exists bool) {
v := m.ordering
if v == nil {
return
}
return *v, true
}
// OldPriority returns the old "priority" field's value of the DownloadClients entity.
// OldOrdering returns the old "ordering" field's value of the DownloadClients entity.
// If the DownloadClients object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *DownloadClientsMutation) OldPriority(ctx context.Context) (v string, err error) {
func (m *DownloadClientsMutation) OldOrdering(ctx context.Context) (v int, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldPriority is only allowed on UpdateOne operations")
return v, errors.New("OldOrdering is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldPriority requires an ID field in the mutation")
return v, errors.New("OldOrdering requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldPriority: %w", err)
return v, fmt.Errorf("querying old value for OldOrdering: %w", err)
}
return oldValue.Priority, nil
return oldValue.Ordering, nil
}
// ResetPriority resets all changes to the "priority" field.
func (m *DownloadClientsMutation) ResetPriority() {
m.priority = nil
// AddOrdering adds i to the "ordering" field.
func (m *DownloadClientsMutation) AddOrdering(i int) {
if m.addordering != nil {
*m.addordering += i
} else {
m.addordering = &i
}
}
// AddedOrdering returns the value that was added to the "ordering" field in this mutation.
func (m *DownloadClientsMutation) AddedOrdering() (r int, exists bool) {
v := m.addordering
if v == nil {
return
}
return *v, true
}
// ResetOrdering resets all changes to the "ordering" field.
func (m *DownloadClientsMutation) ResetOrdering() {
m.ordering = nil
m.addordering = nil
}
// SetRemoveCompletedDownloads sets the "remove_completed_downloads" field.
@@ -999,8 +1020,8 @@ func (m *DownloadClientsMutation) Fields() []string {
if m.settings != nil {
fields = append(fields, downloadclients.FieldSettings)
}
if m.priority != nil {
fields = append(fields, downloadclients.FieldPriority)
if m.ordering != nil {
fields = append(fields, downloadclients.FieldOrdering)
}
if m.remove_completed_downloads != nil {
fields = append(fields, downloadclients.FieldRemoveCompletedDownloads)
@@ -1033,8 +1054,8 @@ func (m *DownloadClientsMutation) Field(name string) (ent.Value, bool) {
return m.Password()
case downloadclients.FieldSettings:
return m.Settings()
case downloadclients.FieldPriority:
return m.Priority()
case downloadclients.FieldOrdering:
return m.Ordering()
case downloadclients.FieldRemoveCompletedDownloads:
return m.RemoveCompletedDownloads()
case downloadclients.FieldRemoveFailedDownloads:
@@ -1064,8 +1085,8 @@ func (m *DownloadClientsMutation) OldField(ctx context.Context, name string) (en
return m.OldPassword(ctx)
case downloadclients.FieldSettings:
return m.OldSettings(ctx)
case downloadclients.FieldPriority:
return m.OldPriority(ctx)
case downloadclients.FieldOrdering:
return m.OldOrdering(ctx)
case downloadclients.FieldRemoveCompletedDownloads:
return m.OldRemoveCompletedDownloads(ctx)
case downloadclients.FieldRemoveFailedDownloads:
@@ -1096,7 +1117,7 @@ func (m *DownloadClientsMutation) SetField(name string, value ent.Value) error {
m.SetName(v)
return nil
case downloadclients.FieldImplementation:
v, ok := value.(string)
v, ok := value.(downloadclients.Implementation)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
@@ -1130,12 +1151,12 @@ func (m *DownloadClientsMutation) SetField(name string, value ent.Value) error {
}
m.SetSettings(v)
return nil
case downloadclients.FieldPriority:
v, ok := value.(string)
case downloadclients.FieldOrdering:
v, ok := value.(int)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetPriority(v)
m.SetOrdering(v)
return nil
case downloadclients.FieldRemoveCompletedDownloads:
v, ok := value.(bool)
@@ -1165,13 +1186,21 @@ func (m *DownloadClientsMutation) SetField(name string, value ent.Value) error {
// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *DownloadClientsMutation) AddedFields() []string {
return nil
var fields []string
if m.addordering != nil {
fields = append(fields, downloadclients.FieldOrdering)
}
return fields
}
// AddedField returns the numeric value that was incremented/decremented on a field
// with the given name. The second boolean return value indicates that this field
// was not set, or was not defined in the schema.
func (m *DownloadClientsMutation) AddedField(name string) (ent.Value, bool) {
switch name {
case downloadclients.FieldOrdering:
return m.AddedOrdering()
}
return nil, false
}
@@ -1180,6 +1209,13 @@ func (m *DownloadClientsMutation) AddedField(name string) (ent.Value, bool) {
// type.
func (m *DownloadClientsMutation) AddField(name string, value ent.Value) error {
switch name {
case downloadclients.FieldOrdering:
v, ok := value.(int)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddOrdering(v)
return nil
}
return fmt.Errorf("unknown DownloadClients numeric field %s", name)
}
@@ -1228,8 +1264,8 @@ func (m *DownloadClientsMutation) ResetField(name string) error {
case downloadclients.FieldSettings:
m.ResetSettings()
return nil
case downloadclients.FieldPriority:
m.ResetPriority()
case downloadclients.FieldOrdering:
m.ResetOrdering()
return nil
case downloadclients.FieldRemoveCompletedDownloads:
m.ResetRemoveCompletedDownloads()

View File

@@ -32,10 +32,12 @@ func init() {
downloadclientsDescSettings := downloadclientsFields[6].Descriptor()
// downloadclients.DefaultSettings holds the default value on creation for the settings field.
downloadclients.DefaultSettings = downloadclientsDescSettings.Default.(string)
// downloadclientsDescPriority is the schema descriptor for priority field.
downloadclientsDescPriority := downloadclientsFields[7].Descriptor()
// downloadclients.DefaultPriority holds the default value on creation for the priority field.
downloadclients.DefaultPriority = downloadclientsDescPriority.Default.(string)
// downloadclientsDescOrdering is the schema descriptor for ordering field.
downloadclientsDescOrdering := downloadclientsFields[7].Descriptor()
// downloadclients.DefaultOrdering holds the default value on creation for the ordering field.
downloadclients.DefaultOrdering = downloadclientsDescOrdering.Default.(int)
// downloadclients.OrderingValidator is a validator for the "ordering" field. It is called by the builders before save.
downloadclients.OrderingValidator = downloadclientsDescOrdering.Validators[0].(func(int) error)
// downloadclientsDescRemoveCompletedDownloads is the schema descriptor for remove_completed_downloads field.
downloadclientsDescRemoveCompletedDownloads := downloadclientsFields[8].Descriptor()
// downloadclients.DefaultRemoveCompletedDownloads holds the default value on creation for the remove_completed_downloads field.

View File

@@ -1,6 +1,8 @@
package schema
import (
"errors"
"entgo.io/ent"
"entgo.io/ent/schema/field"
)
@@ -15,12 +17,20 @@ func (DownloadClients) Fields() []ent.Field {
return []ent.Field{
field.Bool("enable"),
field.String("name"),
field.String("implementation"),
field.Enum("implementation").Values("transmission", "qbittorrent"),
field.String("url"),
field.String("user").Default(""),
field.String("password").Default(""),
field.String("settings").Default(""),
field.String("priority").Default(""),
field.Int("ordering").Default(1).Validate(func(i int) error {
if i > 50 {
return errors.ErrUnsupported
}
if i <= 0 {
return errors.ErrUnsupported
}
return nil
}),
field.Bool("remove_completed_downloads").Default(true),
field.Bool("remove_failed_downloads").Default(true),
field.String("tags").Default(""),