mirror of
https://github.com/simon-ding/polaris.git
synced 2026-06-09 19:47:47 +08:00
feat: blacklist api
This commit is contained in:
@@ -3,11 +3,10 @@
|
||||
package ent
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"polaris/ent/blacklist"
|
||||
"polaris/ent/schema"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
@@ -20,8 +19,14 @@ type Blacklist struct {
|
||||
ID int `json:"id,omitempty"`
|
||||
// Type holds the value of the "type" field.
|
||||
Type blacklist.Type `json:"type,omitempty"`
|
||||
// Value holds the value of the "value" field.
|
||||
Value schema.BlacklistValue `json:"value,omitempty"`
|
||||
// TorrentHash holds the value of the "torrent_hash" field.
|
||||
TorrentHash string `json:"torrent_hash,omitempty"`
|
||||
// TorrentName holds the value of the "torrent_name" field.
|
||||
TorrentName string `json:"torrent_name,omitempty"`
|
||||
// MediaID holds the value of the "media_id" field.
|
||||
MediaID int `json:"media_id,omitempty"`
|
||||
// CreateTime holds the value of the "create_time" field.
|
||||
CreateTime time.Time `json:"create_time,omitempty"`
|
||||
// Notes holds the value of the "notes" field.
|
||||
Notes string `json:"notes,omitempty"`
|
||||
selectValues sql.SelectValues
|
||||
@@ -32,12 +37,12 @@ func (*Blacklist) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case blacklist.FieldValue:
|
||||
values[i] = new([]byte)
|
||||
case blacklist.FieldID:
|
||||
case blacklist.FieldID, blacklist.FieldMediaID:
|
||||
values[i] = new(sql.NullInt64)
|
||||
case blacklist.FieldType, blacklist.FieldNotes:
|
||||
case blacklist.FieldType, blacklist.FieldTorrentHash, blacklist.FieldTorrentName, blacklist.FieldNotes:
|
||||
values[i] = new(sql.NullString)
|
||||
case blacklist.FieldCreateTime:
|
||||
values[i] = new(sql.NullTime)
|
||||
default:
|
||||
values[i] = new(sql.UnknownType)
|
||||
}
|
||||
@@ -65,13 +70,29 @@ func (b *Blacklist) assignValues(columns []string, values []any) error {
|
||||
} else if value.Valid {
|
||||
b.Type = blacklist.Type(value.String)
|
||||
}
|
||||
case blacklist.FieldValue:
|
||||
if value, ok := values[i].(*[]byte); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field value", values[i])
|
||||
} else if value != nil && len(*value) > 0 {
|
||||
if err := json.Unmarshal(*value, &b.Value); err != nil {
|
||||
return fmt.Errorf("unmarshal field value: %w", err)
|
||||
}
|
||||
case blacklist.FieldTorrentHash:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field torrent_hash", values[i])
|
||||
} else if value.Valid {
|
||||
b.TorrentHash = value.String
|
||||
}
|
||||
case blacklist.FieldTorrentName:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field torrent_name", values[i])
|
||||
} else if value.Valid {
|
||||
b.TorrentName = value.String
|
||||
}
|
||||
case blacklist.FieldMediaID:
|
||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field media_id", values[i])
|
||||
} else if value.Valid {
|
||||
b.MediaID = int(value.Int64)
|
||||
}
|
||||
case blacklist.FieldCreateTime:
|
||||
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field create_time", values[i])
|
||||
} else if value.Valid {
|
||||
b.CreateTime = value.Time
|
||||
}
|
||||
case blacklist.FieldNotes:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
@@ -86,9 +107,9 @@ func (b *Blacklist) assignValues(columns []string, values []any) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetValue returns the ent.Value that was dynamically selected and assigned to the Blacklist.
|
||||
// Value returns the ent.Value that was dynamically selected and assigned to the Blacklist.
|
||||
// This includes values selected through modifiers, order, etc.
|
||||
func (b *Blacklist) GetValue(name string) (ent.Value, error) {
|
||||
func (b *Blacklist) Value(name string) (ent.Value, error) {
|
||||
return b.selectValues.Get(name)
|
||||
}
|
||||
|
||||
@@ -118,8 +139,17 @@ func (b *Blacklist) String() string {
|
||||
builder.WriteString("type=")
|
||||
builder.WriteString(fmt.Sprintf("%v", b.Type))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("value=")
|
||||
builder.WriteString(fmt.Sprintf("%v", b.Value))
|
||||
builder.WriteString("torrent_hash=")
|
||||
builder.WriteString(b.TorrentHash)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("torrent_name=")
|
||||
builder.WriteString(b.TorrentName)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("media_id=")
|
||||
builder.WriteString(fmt.Sprintf("%v", b.MediaID))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("create_time=")
|
||||
builder.WriteString(b.CreateTime.Format(time.ANSIC))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("notes=")
|
||||
builder.WriteString(b.Notes)
|
||||
|
||||
@@ -4,7 +4,7 @@ package blacklist
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"polaris/ent/schema"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
)
|
||||
@@ -16,8 +16,14 @@ const (
|
||||
FieldID = "id"
|
||||
// FieldType holds the string denoting the type field in the database.
|
||||
FieldType = "type"
|
||||
// FieldValue holds the string denoting the value field in the database.
|
||||
FieldValue = "value"
|
||||
// FieldTorrentHash holds the string denoting the torrent_hash field in the database.
|
||||
FieldTorrentHash = "torrent_hash"
|
||||
// FieldTorrentName holds the string denoting the torrent_name field in the database.
|
||||
FieldTorrentName = "torrent_name"
|
||||
// FieldMediaID holds the string denoting the media_id field in the database.
|
||||
FieldMediaID = "media_id"
|
||||
// FieldCreateTime holds the string denoting the create_time field in the database.
|
||||
FieldCreateTime = "create_time"
|
||||
// FieldNotes holds the string denoting the notes field in the database.
|
||||
FieldNotes = "notes"
|
||||
// Table holds the table name of the blacklist in the database.
|
||||
@@ -28,7 +34,10 @@ const (
|
||||
var Columns = []string{
|
||||
FieldID,
|
||||
FieldType,
|
||||
FieldValue,
|
||||
FieldTorrentHash,
|
||||
FieldTorrentName,
|
||||
FieldMediaID,
|
||||
FieldCreateTime,
|
||||
FieldNotes,
|
||||
}
|
||||
|
||||
@@ -43,13 +52,16 @@ func ValidColumn(column string) bool {
|
||||
}
|
||||
|
||||
var (
|
||||
// DefaultValue holds the default value on creation for the "value" field.
|
||||
DefaultValue schema.BlacklistValue
|
||||
// DefaultCreateTime holds the default value on creation for the "create_time" field.
|
||||
DefaultCreateTime func() time.Time
|
||||
)
|
||||
|
||||
// Type defines the type for the "type" enum field.
|
||||
type Type string
|
||||
|
||||
// TypeTorrent is the default value of the Type enum.
|
||||
const DefaultType = TypeTorrent
|
||||
|
||||
// Type values.
|
||||
const (
|
||||
TypeMedia Type = "media"
|
||||
@@ -83,6 +95,26 @@ func ByType(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldType, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByTorrentHash orders the results by the torrent_hash field.
|
||||
func ByTorrentHash(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldTorrentHash, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByTorrentName orders the results by the torrent_name field.
|
||||
func ByTorrentName(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldTorrentName, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByMediaID orders the results by the media_id field.
|
||||
func ByMediaID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldMediaID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByCreateTime orders the results by the create_time field.
|
||||
func ByCreateTime(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldCreateTime, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByNotes orders the results by the notes field.
|
||||
func ByNotes(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldNotes, opts...).ToFunc()
|
||||
|
||||
@@ -4,6 +4,7 @@ package blacklist
|
||||
|
||||
import (
|
||||
"polaris/ent/predicate"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
)
|
||||
@@ -53,6 +54,26 @@ func IDLTE(id int) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldLTE(FieldID, id))
|
||||
}
|
||||
|
||||
// TorrentHash applies equality check predicate on the "torrent_hash" field. It's identical to TorrentHashEQ.
|
||||
func TorrentHash(v string) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldEQ(FieldTorrentHash, v))
|
||||
}
|
||||
|
||||
// TorrentName applies equality check predicate on the "torrent_name" field. It's identical to TorrentNameEQ.
|
||||
func TorrentName(v string) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldEQ(FieldTorrentName, v))
|
||||
}
|
||||
|
||||
// MediaID applies equality check predicate on the "media_id" field. It's identical to MediaIDEQ.
|
||||
func MediaID(v int) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldEQ(FieldMediaID, v))
|
||||
}
|
||||
|
||||
// CreateTime applies equality check predicate on the "create_time" field. It's identical to CreateTimeEQ.
|
||||
func CreateTime(v time.Time) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldEQ(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// Notes applies equality check predicate on the "notes" field. It's identical to NotesEQ.
|
||||
func Notes(v string) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldEQ(FieldNotes, v))
|
||||
@@ -78,6 +99,256 @@ func TypeNotIn(vs ...Type) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldNotIn(FieldType, vs...))
|
||||
}
|
||||
|
||||
// TorrentHashEQ applies the EQ predicate on the "torrent_hash" field.
|
||||
func TorrentHashEQ(v string) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldEQ(FieldTorrentHash, v))
|
||||
}
|
||||
|
||||
// TorrentHashNEQ applies the NEQ predicate on the "torrent_hash" field.
|
||||
func TorrentHashNEQ(v string) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldNEQ(FieldTorrentHash, v))
|
||||
}
|
||||
|
||||
// TorrentHashIn applies the In predicate on the "torrent_hash" field.
|
||||
func TorrentHashIn(vs ...string) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldIn(FieldTorrentHash, vs...))
|
||||
}
|
||||
|
||||
// TorrentHashNotIn applies the NotIn predicate on the "torrent_hash" field.
|
||||
func TorrentHashNotIn(vs ...string) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldNotIn(FieldTorrentHash, vs...))
|
||||
}
|
||||
|
||||
// TorrentHashGT applies the GT predicate on the "torrent_hash" field.
|
||||
func TorrentHashGT(v string) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldGT(FieldTorrentHash, v))
|
||||
}
|
||||
|
||||
// TorrentHashGTE applies the GTE predicate on the "torrent_hash" field.
|
||||
func TorrentHashGTE(v string) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldGTE(FieldTorrentHash, v))
|
||||
}
|
||||
|
||||
// TorrentHashLT applies the LT predicate on the "torrent_hash" field.
|
||||
func TorrentHashLT(v string) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldLT(FieldTorrentHash, v))
|
||||
}
|
||||
|
||||
// TorrentHashLTE applies the LTE predicate on the "torrent_hash" field.
|
||||
func TorrentHashLTE(v string) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldLTE(FieldTorrentHash, v))
|
||||
}
|
||||
|
||||
// TorrentHashContains applies the Contains predicate on the "torrent_hash" field.
|
||||
func TorrentHashContains(v string) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldContains(FieldTorrentHash, v))
|
||||
}
|
||||
|
||||
// TorrentHashHasPrefix applies the HasPrefix predicate on the "torrent_hash" field.
|
||||
func TorrentHashHasPrefix(v string) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldHasPrefix(FieldTorrentHash, v))
|
||||
}
|
||||
|
||||
// TorrentHashHasSuffix applies the HasSuffix predicate on the "torrent_hash" field.
|
||||
func TorrentHashHasSuffix(v string) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldHasSuffix(FieldTorrentHash, v))
|
||||
}
|
||||
|
||||
// TorrentHashIsNil applies the IsNil predicate on the "torrent_hash" field.
|
||||
func TorrentHashIsNil() predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldIsNull(FieldTorrentHash))
|
||||
}
|
||||
|
||||
// TorrentHashNotNil applies the NotNil predicate on the "torrent_hash" field.
|
||||
func TorrentHashNotNil() predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldNotNull(FieldTorrentHash))
|
||||
}
|
||||
|
||||
// TorrentHashEqualFold applies the EqualFold predicate on the "torrent_hash" field.
|
||||
func TorrentHashEqualFold(v string) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldEqualFold(FieldTorrentHash, v))
|
||||
}
|
||||
|
||||
// TorrentHashContainsFold applies the ContainsFold predicate on the "torrent_hash" field.
|
||||
func TorrentHashContainsFold(v string) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldContainsFold(FieldTorrentHash, v))
|
||||
}
|
||||
|
||||
// TorrentNameEQ applies the EQ predicate on the "torrent_name" field.
|
||||
func TorrentNameEQ(v string) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldEQ(FieldTorrentName, v))
|
||||
}
|
||||
|
||||
// TorrentNameNEQ applies the NEQ predicate on the "torrent_name" field.
|
||||
func TorrentNameNEQ(v string) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldNEQ(FieldTorrentName, v))
|
||||
}
|
||||
|
||||
// TorrentNameIn applies the In predicate on the "torrent_name" field.
|
||||
func TorrentNameIn(vs ...string) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldIn(FieldTorrentName, vs...))
|
||||
}
|
||||
|
||||
// TorrentNameNotIn applies the NotIn predicate on the "torrent_name" field.
|
||||
func TorrentNameNotIn(vs ...string) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldNotIn(FieldTorrentName, vs...))
|
||||
}
|
||||
|
||||
// TorrentNameGT applies the GT predicate on the "torrent_name" field.
|
||||
func TorrentNameGT(v string) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldGT(FieldTorrentName, v))
|
||||
}
|
||||
|
||||
// TorrentNameGTE applies the GTE predicate on the "torrent_name" field.
|
||||
func TorrentNameGTE(v string) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldGTE(FieldTorrentName, v))
|
||||
}
|
||||
|
||||
// TorrentNameLT applies the LT predicate on the "torrent_name" field.
|
||||
func TorrentNameLT(v string) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldLT(FieldTorrentName, v))
|
||||
}
|
||||
|
||||
// TorrentNameLTE applies the LTE predicate on the "torrent_name" field.
|
||||
func TorrentNameLTE(v string) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldLTE(FieldTorrentName, v))
|
||||
}
|
||||
|
||||
// TorrentNameContains applies the Contains predicate on the "torrent_name" field.
|
||||
func TorrentNameContains(v string) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldContains(FieldTorrentName, v))
|
||||
}
|
||||
|
||||
// TorrentNameHasPrefix applies the HasPrefix predicate on the "torrent_name" field.
|
||||
func TorrentNameHasPrefix(v string) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldHasPrefix(FieldTorrentName, v))
|
||||
}
|
||||
|
||||
// TorrentNameHasSuffix applies the HasSuffix predicate on the "torrent_name" field.
|
||||
func TorrentNameHasSuffix(v string) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldHasSuffix(FieldTorrentName, v))
|
||||
}
|
||||
|
||||
// TorrentNameIsNil applies the IsNil predicate on the "torrent_name" field.
|
||||
func TorrentNameIsNil() predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldIsNull(FieldTorrentName))
|
||||
}
|
||||
|
||||
// TorrentNameNotNil applies the NotNil predicate on the "torrent_name" field.
|
||||
func TorrentNameNotNil() predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldNotNull(FieldTorrentName))
|
||||
}
|
||||
|
||||
// TorrentNameEqualFold applies the EqualFold predicate on the "torrent_name" field.
|
||||
func TorrentNameEqualFold(v string) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldEqualFold(FieldTorrentName, v))
|
||||
}
|
||||
|
||||
// TorrentNameContainsFold applies the ContainsFold predicate on the "torrent_name" field.
|
||||
func TorrentNameContainsFold(v string) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldContainsFold(FieldTorrentName, v))
|
||||
}
|
||||
|
||||
// MediaIDEQ applies the EQ predicate on the "media_id" field.
|
||||
func MediaIDEQ(v int) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldEQ(FieldMediaID, v))
|
||||
}
|
||||
|
||||
// MediaIDNEQ applies the NEQ predicate on the "media_id" field.
|
||||
func MediaIDNEQ(v int) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldNEQ(FieldMediaID, v))
|
||||
}
|
||||
|
||||
// MediaIDIn applies the In predicate on the "media_id" field.
|
||||
func MediaIDIn(vs ...int) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldIn(FieldMediaID, vs...))
|
||||
}
|
||||
|
||||
// MediaIDNotIn applies the NotIn predicate on the "media_id" field.
|
||||
func MediaIDNotIn(vs ...int) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldNotIn(FieldMediaID, vs...))
|
||||
}
|
||||
|
||||
// MediaIDGT applies the GT predicate on the "media_id" field.
|
||||
func MediaIDGT(v int) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldGT(FieldMediaID, v))
|
||||
}
|
||||
|
||||
// MediaIDGTE applies the GTE predicate on the "media_id" field.
|
||||
func MediaIDGTE(v int) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldGTE(FieldMediaID, v))
|
||||
}
|
||||
|
||||
// MediaIDLT applies the LT predicate on the "media_id" field.
|
||||
func MediaIDLT(v int) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldLT(FieldMediaID, v))
|
||||
}
|
||||
|
||||
// MediaIDLTE applies the LTE predicate on the "media_id" field.
|
||||
func MediaIDLTE(v int) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldLTE(FieldMediaID, v))
|
||||
}
|
||||
|
||||
// MediaIDIsNil applies the IsNil predicate on the "media_id" field.
|
||||
func MediaIDIsNil() predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldIsNull(FieldMediaID))
|
||||
}
|
||||
|
||||
// MediaIDNotNil applies the NotNil predicate on the "media_id" field.
|
||||
func MediaIDNotNil() predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldNotNull(FieldMediaID))
|
||||
}
|
||||
|
||||
// CreateTimeEQ applies the EQ predicate on the "create_time" field.
|
||||
func CreateTimeEQ(v time.Time) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldEQ(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeNEQ applies the NEQ predicate on the "create_time" field.
|
||||
func CreateTimeNEQ(v time.Time) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldNEQ(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeIn applies the In predicate on the "create_time" field.
|
||||
func CreateTimeIn(vs ...time.Time) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldIn(FieldCreateTime, vs...))
|
||||
}
|
||||
|
||||
// CreateTimeNotIn applies the NotIn predicate on the "create_time" field.
|
||||
func CreateTimeNotIn(vs ...time.Time) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldNotIn(FieldCreateTime, vs...))
|
||||
}
|
||||
|
||||
// CreateTimeGT applies the GT predicate on the "create_time" field.
|
||||
func CreateTimeGT(v time.Time) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldGT(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeGTE applies the GTE predicate on the "create_time" field.
|
||||
func CreateTimeGTE(v time.Time) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldGTE(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeLT applies the LT predicate on the "create_time" field.
|
||||
func CreateTimeLT(v time.Time) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldLT(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeLTE applies the LTE predicate on the "create_time" field.
|
||||
func CreateTimeLTE(v time.Time) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldLTE(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeIsNil applies the IsNil predicate on the "create_time" field.
|
||||
func CreateTimeIsNil() predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldIsNull(FieldCreateTime))
|
||||
}
|
||||
|
||||
// CreateTimeNotNil applies the NotNil predicate on the "create_time" field.
|
||||
func CreateTimeNotNil() predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldNotNull(FieldCreateTime))
|
||||
}
|
||||
|
||||
// NotesEQ applies the EQ predicate on the "notes" field.
|
||||
func NotesEQ(v string) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldEQ(FieldNotes, v))
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"polaris/ent/blacklist"
|
||||
"polaris/ent/schema"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
@@ -26,16 +26,66 @@ func (bc *BlacklistCreate) SetType(b blacklist.Type) *BlacklistCreate {
|
||||
return bc
|
||||
}
|
||||
|
||||
// SetValue sets the "value" field.
|
||||
func (bc *BlacklistCreate) SetValue(sv schema.BlacklistValue) *BlacklistCreate {
|
||||
bc.mutation.SetValue(sv)
|
||||
// SetNillableType sets the "type" field if the given value is not nil.
|
||||
func (bc *BlacklistCreate) SetNillableType(b *blacklist.Type) *BlacklistCreate {
|
||||
if b != nil {
|
||||
bc.SetType(*b)
|
||||
}
|
||||
return bc
|
||||
}
|
||||
|
||||
// SetNillableValue sets the "value" field if the given value is not nil.
|
||||
func (bc *BlacklistCreate) SetNillableValue(sv *schema.BlacklistValue) *BlacklistCreate {
|
||||
if sv != nil {
|
||||
bc.SetValue(*sv)
|
||||
// SetTorrentHash sets the "torrent_hash" field.
|
||||
func (bc *BlacklistCreate) SetTorrentHash(s string) *BlacklistCreate {
|
||||
bc.mutation.SetTorrentHash(s)
|
||||
return bc
|
||||
}
|
||||
|
||||
// SetNillableTorrentHash sets the "torrent_hash" field if the given value is not nil.
|
||||
func (bc *BlacklistCreate) SetNillableTorrentHash(s *string) *BlacklistCreate {
|
||||
if s != nil {
|
||||
bc.SetTorrentHash(*s)
|
||||
}
|
||||
return bc
|
||||
}
|
||||
|
||||
// SetTorrentName sets the "torrent_name" field.
|
||||
func (bc *BlacklistCreate) SetTorrentName(s string) *BlacklistCreate {
|
||||
bc.mutation.SetTorrentName(s)
|
||||
return bc
|
||||
}
|
||||
|
||||
// SetNillableTorrentName sets the "torrent_name" field if the given value is not nil.
|
||||
func (bc *BlacklistCreate) SetNillableTorrentName(s *string) *BlacklistCreate {
|
||||
if s != nil {
|
||||
bc.SetTorrentName(*s)
|
||||
}
|
||||
return bc
|
||||
}
|
||||
|
||||
// SetMediaID sets the "media_id" field.
|
||||
func (bc *BlacklistCreate) SetMediaID(i int) *BlacklistCreate {
|
||||
bc.mutation.SetMediaID(i)
|
||||
return bc
|
||||
}
|
||||
|
||||
// SetNillableMediaID sets the "media_id" field if the given value is not nil.
|
||||
func (bc *BlacklistCreate) SetNillableMediaID(i *int) *BlacklistCreate {
|
||||
if i != nil {
|
||||
bc.SetMediaID(*i)
|
||||
}
|
||||
return bc
|
||||
}
|
||||
|
||||
// SetCreateTime sets the "create_time" field.
|
||||
func (bc *BlacklistCreate) SetCreateTime(t time.Time) *BlacklistCreate {
|
||||
bc.mutation.SetCreateTime(t)
|
||||
return bc
|
||||
}
|
||||
|
||||
// SetNillableCreateTime sets the "create_time" field if the given value is not nil.
|
||||
func (bc *BlacklistCreate) SetNillableCreateTime(t *time.Time) *BlacklistCreate {
|
||||
if t != nil {
|
||||
bc.SetCreateTime(*t)
|
||||
}
|
||||
return bc
|
||||
}
|
||||
@@ -89,9 +139,13 @@ func (bc *BlacklistCreate) ExecX(ctx context.Context) {
|
||||
|
||||
// defaults sets the default values of the builder before save.
|
||||
func (bc *BlacklistCreate) defaults() {
|
||||
if _, ok := bc.mutation.Value(); !ok {
|
||||
v := blacklist.DefaultValue
|
||||
bc.mutation.SetValue(v)
|
||||
if _, ok := bc.mutation.GetType(); !ok {
|
||||
v := blacklist.DefaultType
|
||||
bc.mutation.SetType(v)
|
||||
}
|
||||
if _, ok := bc.mutation.CreateTime(); !ok {
|
||||
v := blacklist.DefaultCreateTime()
|
||||
bc.mutation.SetCreateTime(v)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,9 +159,6 @@ func (bc *BlacklistCreate) check() error {
|
||||
return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "Blacklist.type": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _, ok := bc.mutation.Value(); !ok {
|
||||
return &ValidationError{Name: "value", err: errors.New(`ent: missing required field "Blacklist.value"`)}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -138,9 +189,21 @@ func (bc *BlacklistCreate) createSpec() (*Blacklist, *sqlgraph.CreateSpec) {
|
||||
_spec.SetField(blacklist.FieldType, field.TypeEnum, value)
|
||||
_node.Type = value
|
||||
}
|
||||
if value, ok := bc.mutation.Value(); ok {
|
||||
_spec.SetField(blacklist.FieldValue, field.TypeJSON, value)
|
||||
_node.Value = value
|
||||
if value, ok := bc.mutation.TorrentHash(); ok {
|
||||
_spec.SetField(blacklist.FieldTorrentHash, field.TypeString, value)
|
||||
_node.TorrentHash = value
|
||||
}
|
||||
if value, ok := bc.mutation.TorrentName(); ok {
|
||||
_spec.SetField(blacklist.FieldTorrentName, field.TypeString, value)
|
||||
_node.TorrentName = value
|
||||
}
|
||||
if value, ok := bc.mutation.MediaID(); ok {
|
||||
_spec.SetField(blacklist.FieldMediaID, field.TypeInt, value)
|
||||
_node.MediaID = value
|
||||
}
|
||||
if value, ok := bc.mutation.CreateTime(); ok {
|
||||
_spec.SetField(blacklist.FieldCreateTime, field.TypeTime, value)
|
||||
_node.CreateTime = value
|
||||
}
|
||||
if value, ok := bc.mutation.Notes(); ok {
|
||||
_spec.SetField(blacklist.FieldNotes, field.TypeString, value)
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"fmt"
|
||||
"polaris/ent/blacklist"
|
||||
"polaris/ent/predicate"
|
||||
"polaris/ent/schema"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
@@ -42,20 +41,73 @@ func (bu *BlacklistUpdate) SetNillableType(b *blacklist.Type) *BlacklistUpdate {
|
||||
return bu
|
||||
}
|
||||
|
||||
// SetValue sets the "value" field.
|
||||
func (bu *BlacklistUpdate) SetValue(sv schema.BlacklistValue) *BlacklistUpdate {
|
||||
bu.mutation.SetValue(sv)
|
||||
// SetTorrentHash sets the "torrent_hash" field.
|
||||
func (bu *BlacklistUpdate) SetTorrentHash(s string) *BlacklistUpdate {
|
||||
bu.mutation.SetTorrentHash(s)
|
||||
return bu
|
||||
}
|
||||
|
||||
// SetNillableValue sets the "value" field if the given value is not nil.
|
||||
func (bu *BlacklistUpdate) SetNillableValue(sv *schema.BlacklistValue) *BlacklistUpdate {
|
||||
if sv != nil {
|
||||
bu.SetValue(*sv)
|
||||
// SetNillableTorrentHash sets the "torrent_hash" field if the given value is not nil.
|
||||
func (bu *BlacklistUpdate) SetNillableTorrentHash(s *string) *BlacklistUpdate {
|
||||
if s != nil {
|
||||
bu.SetTorrentHash(*s)
|
||||
}
|
||||
return bu
|
||||
}
|
||||
|
||||
// ClearTorrentHash clears the value of the "torrent_hash" field.
|
||||
func (bu *BlacklistUpdate) ClearTorrentHash() *BlacklistUpdate {
|
||||
bu.mutation.ClearTorrentHash()
|
||||
return bu
|
||||
}
|
||||
|
||||
// SetTorrentName sets the "torrent_name" field.
|
||||
func (bu *BlacklistUpdate) SetTorrentName(s string) *BlacklistUpdate {
|
||||
bu.mutation.SetTorrentName(s)
|
||||
return bu
|
||||
}
|
||||
|
||||
// SetNillableTorrentName sets the "torrent_name" field if the given value is not nil.
|
||||
func (bu *BlacklistUpdate) SetNillableTorrentName(s *string) *BlacklistUpdate {
|
||||
if s != nil {
|
||||
bu.SetTorrentName(*s)
|
||||
}
|
||||
return bu
|
||||
}
|
||||
|
||||
// ClearTorrentName clears the value of the "torrent_name" field.
|
||||
func (bu *BlacklistUpdate) ClearTorrentName() *BlacklistUpdate {
|
||||
bu.mutation.ClearTorrentName()
|
||||
return bu
|
||||
}
|
||||
|
||||
// SetMediaID sets the "media_id" field.
|
||||
func (bu *BlacklistUpdate) SetMediaID(i int) *BlacklistUpdate {
|
||||
bu.mutation.ResetMediaID()
|
||||
bu.mutation.SetMediaID(i)
|
||||
return bu
|
||||
}
|
||||
|
||||
// SetNillableMediaID sets the "media_id" field if the given value is not nil.
|
||||
func (bu *BlacklistUpdate) SetNillableMediaID(i *int) *BlacklistUpdate {
|
||||
if i != nil {
|
||||
bu.SetMediaID(*i)
|
||||
}
|
||||
return bu
|
||||
}
|
||||
|
||||
// AddMediaID adds i to the "media_id" field.
|
||||
func (bu *BlacklistUpdate) AddMediaID(i int) *BlacklistUpdate {
|
||||
bu.mutation.AddMediaID(i)
|
||||
return bu
|
||||
}
|
||||
|
||||
// ClearMediaID clears the value of the "media_id" field.
|
||||
func (bu *BlacklistUpdate) ClearMediaID() *BlacklistUpdate {
|
||||
bu.mutation.ClearMediaID()
|
||||
return bu
|
||||
}
|
||||
|
||||
// SetNotes sets the "notes" field.
|
||||
func (bu *BlacklistUpdate) SetNotes(s string) *BlacklistUpdate {
|
||||
bu.mutation.SetNotes(s)
|
||||
@@ -133,8 +185,29 @@ func (bu *BlacklistUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
if value, ok := bu.mutation.GetType(); ok {
|
||||
_spec.SetField(blacklist.FieldType, field.TypeEnum, value)
|
||||
}
|
||||
if value, ok := bu.mutation.Value(); ok {
|
||||
_spec.SetField(blacklist.FieldValue, field.TypeJSON, value)
|
||||
if value, ok := bu.mutation.TorrentHash(); ok {
|
||||
_spec.SetField(blacklist.FieldTorrentHash, field.TypeString, value)
|
||||
}
|
||||
if bu.mutation.TorrentHashCleared() {
|
||||
_spec.ClearField(blacklist.FieldTorrentHash, field.TypeString)
|
||||
}
|
||||
if value, ok := bu.mutation.TorrentName(); ok {
|
||||
_spec.SetField(blacklist.FieldTorrentName, field.TypeString, value)
|
||||
}
|
||||
if bu.mutation.TorrentNameCleared() {
|
||||
_spec.ClearField(blacklist.FieldTorrentName, field.TypeString)
|
||||
}
|
||||
if value, ok := bu.mutation.MediaID(); ok {
|
||||
_spec.SetField(blacklist.FieldMediaID, field.TypeInt, value)
|
||||
}
|
||||
if value, ok := bu.mutation.AddedMediaID(); ok {
|
||||
_spec.AddField(blacklist.FieldMediaID, field.TypeInt, value)
|
||||
}
|
||||
if bu.mutation.MediaIDCleared() {
|
||||
_spec.ClearField(blacklist.FieldMediaID, field.TypeInt)
|
||||
}
|
||||
if bu.mutation.CreateTimeCleared() {
|
||||
_spec.ClearField(blacklist.FieldCreateTime, field.TypeTime)
|
||||
}
|
||||
if value, ok := bu.mutation.Notes(); ok {
|
||||
_spec.SetField(blacklist.FieldNotes, field.TypeString, value)
|
||||
@@ -176,20 +249,73 @@ func (buo *BlacklistUpdateOne) SetNillableType(b *blacklist.Type) *BlacklistUpda
|
||||
return buo
|
||||
}
|
||||
|
||||
// SetValue sets the "value" field.
|
||||
func (buo *BlacklistUpdateOne) SetValue(sv schema.BlacklistValue) *BlacklistUpdateOne {
|
||||
buo.mutation.SetValue(sv)
|
||||
// SetTorrentHash sets the "torrent_hash" field.
|
||||
func (buo *BlacklistUpdateOne) SetTorrentHash(s string) *BlacklistUpdateOne {
|
||||
buo.mutation.SetTorrentHash(s)
|
||||
return buo
|
||||
}
|
||||
|
||||
// SetNillableValue sets the "value" field if the given value is not nil.
|
||||
func (buo *BlacklistUpdateOne) SetNillableValue(sv *schema.BlacklistValue) *BlacklistUpdateOne {
|
||||
if sv != nil {
|
||||
buo.SetValue(*sv)
|
||||
// SetNillableTorrentHash sets the "torrent_hash" field if the given value is not nil.
|
||||
func (buo *BlacklistUpdateOne) SetNillableTorrentHash(s *string) *BlacklistUpdateOne {
|
||||
if s != nil {
|
||||
buo.SetTorrentHash(*s)
|
||||
}
|
||||
return buo
|
||||
}
|
||||
|
||||
// ClearTorrentHash clears the value of the "torrent_hash" field.
|
||||
func (buo *BlacklistUpdateOne) ClearTorrentHash() *BlacklistUpdateOne {
|
||||
buo.mutation.ClearTorrentHash()
|
||||
return buo
|
||||
}
|
||||
|
||||
// SetTorrentName sets the "torrent_name" field.
|
||||
func (buo *BlacklistUpdateOne) SetTorrentName(s string) *BlacklistUpdateOne {
|
||||
buo.mutation.SetTorrentName(s)
|
||||
return buo
|
||||
}
|
||||
|
||||
// SetNillableTorrentName sets the "torrent_name" field if the given value is not nil.
|
||||
func (buo *BlacklistUpdateOne) SetNillableTorrentName(s *string) *BlacklistUpdateOne {
|
||||
if s != nil {
|
||||
buo.SetTorrentName(*s)
|
||||
}
|
||||
return buo
|
||||
}
|
||||
|
||||
// ClearTorrentName clears the value of the "torrent_name" field.
|
||||
func (buo *BlacklistUpdateOne) ClearTorrentName() *BlacklistUpdateOne {
|
||||
buo.mutation.ClearTorrentName()
|
||||
return buo
|
||||
}
|
||||
|
||||
// SetMediaID sets the "media_id" field.
|
||||
func (buo *BlacklistUpdateOne) SetMediaID(i int) *BlacklistUpdateOne {
|
||||
buo.mutation.ResetMediaID()
|
||||
buo.mutation.SetMediaID(i)
|
||||
return buo
|
||||
}
|
||||
|
||||
// SetNillableMediaID sets the "media_id" field if the given value is not nil.
|
||||
func (buo *BlacklistUpdateOne) SetNillableMediaID(i *int) *BlacklistUpdateOne {
|
||||
if i != nil {
|
||||
buo.SetMediaID(*i)
|
||||
}
|
||||
return buo
|
||||
}
|
||||
|
||||
// AddMediaID adds i to the "media_id" field.
|
||||
func (buo *BlacklistUpdateOne) AddMediaID(i int) *BlacklistUpdateOne {
|
||||
buo.mutation.AddMediaID(i)
|
||||
return buo
|
||||
}
|
||||
|
||||
// ClearMediaID clears the value of the "media_id" field.
|
||||
func (buo *BlacklistUpdateOne) ClearMediaID() *BlacklistUpdateOne {
|
||||
buo.mutation.ClearMediaID()
|
||||
return buo
|
||||
}
|
||||
|
||||
// SetNotes sets the "notes" field.
|
||||
func (buo *BlacklistUpdateOne) SetNotes(s string) *BlacklistUpdateOne {
|
||||
buo.mutation.SetNotes(s)
|
||||
@@ -297,8 +423,29 @@ func (buo *BlacklistUpdateOne) sqlSave(ctx context.Context) (_node *Blacklist, e
|
||||
if value, ok := buo.mutation.GetType(); ok {
|
||||
_spec.SetField(blacklist.FieldType, field.TypeEnum, value)
|
||||
}
|
||||
if value, ok := buo.mutation.Value(); ok {
|
||||
_spec.SetField(blacklist.FieldValue, field.TypeJSON, value)
|
||||
if value, ok := buo.mutation.TorrentHash(); ok {
|
||||
_spec.SetField(blacklist.FieldTorrentHash, field.TypeString, value)
|
||||
}
|
||||
if buo.mutation.TorrentHashCleared() {
|
||||
_spec.ClearField(blacklist.FieldTorrentHash, field.TypeString)
|
||||
}
|
||||
if value, ok := buo.mutation.TorrentName(); ok {
|
||||
_spec.SetField(blacklist.FieldTorrentName, field.TypeString, value)
|
||||
}
|
||||
if buo.mutation.TorrentNameCleared() {
|
||||
_spec.ClearField(blacklist.FieldTorrentName, field.TypeString)
|
||||
}
|
||||
if value, ok := buo.mutation.MediaID(); ok {
|
||||
_spec.SetField(blacklist.FieldMediaID, field.TypeInt, value)
|
||||
}
|
||||
if value, ok := buo.mutation.AddedMediaID(); ok {
|
||||
_spec.AddField(blacklist.FieldMediaID, field.TypeInt, value)
|
||||
}
|
||||
if buo.mutation.MediaIDCleared() {
|
||||
_spec.ClearField(blacklist.FieldMediaID, field.TypeInt)
|
||||
}
|
||||
if buo.mutation.CreateTimeCleared() {
|
||||
_spec.ClearField(blacklist.FieldCreateTime, field.TypeTime)
|
||||
}
|
||||
if value, ok := buo.mutation.Notes(); ok {
|
||||
_spec.SetField(blacklist.FieldNotes, field.TypeString, value)
|
||||
|
||||
@@ -36,7 +36,7 @@ type History struct {
|
||||
DownloadClientID int `json:"download_client_id,omitempty"`
|
||||
// IndexerID holds the value of the "indexer_id" field.
|
||||
IndexerID int `json:"indexer_id,omitempty"`
|
||||
// deprecated, use hash instead
|
||||
// torrent link
|
||||
Link string `json:"link,omitempty"`
|
||||
// torrent hash
|
||||
Hash string `json:"hash,omitempty"`
|
||||
|
||||
@@ -11,8 +11,11 @@ var (
|
||||
// BlacklistsColumns holds the columns for the "blacklists" table.
|
||||
BlacklistsColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt, Increment: true},
|
||||
{Name: "type", Type: field.TypeEnum, Enums: []string{"media", "torrent"}},
|
||||
{Name: "value", Type: field.TypeJSON},
|
||||
{Name: "type", Type: field.TypeEnum, Enums: []string{"media", "torrent"}, Default: "torrent"},
|
||||
{Name: "torrent_hash", Type: field.TypeString, Nullable: true},
|
||||
{Name: "torrent_name", Type: field.TypeString, Nullable: true},
|
||||
{Name: "media_id", Type: field.TypeInt, Nullable: true},
|
||||
{Name: "create_time", Type: field.TypeTime, Nullable: true},
|
||||
{Name: "notes", Type: field.TypeString, Nullable: true},
|
||||
}
|
||||
// BlacklistsTable holds the schema information for the "blacklists" table.
|
||||
|
||||
333
ent/mutation.go
333
ent/mutation.go
@@ -53,7 +53,11 @@ type BlacklistMutation struct {
|
||||
typ string
|
||||
id *int
|
||||
_type *blacklist.Type
|
||||
value *schema.BlacklistValue
|
||||
torrent_hash *string
|
||||
torrent_name *string
|
||||
media_id *int
|
||||
addmedia_id *int
|
||||
create_time *time.Time
|
||||
notes *string
|
||||
clearedFields map[string]struct{}
|
||||
done bool
|
||||
@@ -195,40 +199,221 @@ func (m *BlacklistMutation) ResetType() {
|
||||
m._type = nil
|
||||
}
|
||||
|
||||
// SetValue sets the "value" field.
|
||||
func (m *BlacklistMutation) SetValue(sv schema.BlacklistValue) {
|
||||
m.value = &sv
|
||||
// SetTorrentHash sets the "torrent_hash" field.
|
||||
func (m *BlacklistMutation) SetTorrentHash(s string) {
|
||||
m.torrent_hash = &s
|
||||
}
|
||||
|
||||
// Value returns the value of the "value" field in the mutation.
|
||||
func (m *BlacklistMutation) Value() (r schema.BlacklistValue, exists bool) {
|
||||
v := m.value
|
||||
// TorrentHash returns the value of the "torrent_hash" field in the mutation.
|
||||
func (m *BlacklistMutation) TorrentHash() (r string, exists bool) {
|
||||
v := m.torrent_hash
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// OldValue returns the old "value" field's value of the Blacklist entity.
|
||||
// OldTorrentHash returns the old "torrent_hash" field's value of the Blacklist entity.
|
||||
// If the Blacklist 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 *BlacklistMutation) OldValue(ctx context.Context) (v schema.BlacklistValue, err error) {
|
||||
func (m *BlacklistMutation) OldTorrentHash(ctx context.Context) (v string, err error) {
|
||||
if !m.op.Is(OpUpdateOne) {
|
||||
return v, errors.New("OldValue is only allowed on UpdateOne operations")
|
||||
return v, errors.New("OldTorrentHash is only allowed on UpdateOne operations")
|
||||
}
|
||||
if m.id == nil || m.oldValue == nil {
|
||||
return v, errors.New("OldValue requires an ID field in the mutation")
|
||||
return v, errors.New("OldTorrentHash requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldValue: %w", err)
|
||||
return v, fmt.Errorf("querying old value for OldTorrentHash: %w", err)
|
||||
}
|
||||
return oldValue.Value, nil
|
||||
return oldValue.TorrentHash, nil
|
||||
}
|
||||
|
||||
// ResetValue resets all changes to the "value" field.
|
||||
func (m *BlacklistMutation) ResetValue() {
|
||||
m.value = nil
|
||||
// ClearTorrentHash clears the value of the "torrent_hash" field.
|
||||
func (m *BlacklistMutation) ClearTorrentHash() {
|
||||
m.torrent_hash = nil
|
||||
m.clearedFields[blacklist.FieldTorrentHash] = struct{}{}
|
||||
}
|
||||
|
||||
// TorrentHashCleared returns if the "torrent_hash" field was cleared in this mutation.
|
||||
func (m *BlacklistMutation) TorrentHashCleared() bool {
|
||||
_, ok := m.clearedFields[blacklist.FieldTorrentHash]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ResetTorrentHash resets all changes to the "torrent_hash" field.
|
||||
func (m *BlacklistMutation) ResetTorrentHash() {
|
||||
m.torrent_hash = nil
|
||||
delete(m.clearedFields, blacklist.FieldTorrentHash)
|
||||
}
|
||||
|
||||
// SetTorrentName sets the "torrent_name" field.
|
||||
func (m *BlacklistMutation) SetTorrentName(s string) {
|
||||
m.torrent_name = &s
|
||||
}
|
||||
|
||||
// TorrentName returns the value of the "torrent_name" field in the mutation.
|
||||
func (m *BlacklistMutation) TorrentName() (r string, exists bool) {
|
||||
v := m.torrent_name
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// OldTorrentName returns the old "torrent_name" field's value of the Blacklist entity.
|
||||
// If the Blacklist 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 *BlacklistMutation) OldTorrentName(ctx context.Context) (v string, err error) {
|
||||
if !m.op.Is(OpUpdateOne) {
|
||||
return v, errors.New("OldTorrentName is only allowed on UpdateOne operations")
|
||||
}
|
||||
if m.id == nil || m.oldValue == nil {
|
||||
return v, errors.New("OldTorrentName requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldTorrentName: %w", err)
|
||||
}
|
||||
return oldValue.TorrentName, nil
|
||||
}
|
||||
|
||||
// ClearTorrentName clears the value of the "torrent_name" field.
|
||||
func (m *BlacklistMutation) ClearTorrentName() {
|
||||
m.torrent_name = nil
|
||||
m.clearedFields[blacklist.FieldTorrentName] = struct{}{}
|
||||
}
|
||||
|
||||
// TorrentNameCleared returns if the "torrent_name" field was cleared in this mutation.
|
||||
func (m *BlacklistMutation) TorrentNameCleared() bool {
|
||||
_, ok := m.clearedFields[blacklist.FieldTorrentName]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ResetTorrentName resets all changes to the "torrent_name" field.
|
||||
func (m *BlacklistMutation) ResetTorrentName() {
|
||||
m.torrent_name = nil
|
||||
delete(m.clearedFields, blacklist.FieldTorrentName)
|
||||
}
|
||||
|
||||
// SetMediaID sets the "media_id" field.
|
||||
func (m *BlacklistMutation) SetMediaID(i int) {
|
||||
m.media_id = &i
|
||||
m.addmedia_id = nil
|
||||
}
|
||||
|
||||
// MediaID returns the value of the "media_id" field in the mutation.
|
||||
func (m *BlacklistMutation) MediaID() (r int, exists bool) {
|
||||
v := m.media_id
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// OldMediaID returns the old "media_id" field's value of the Blacklist entity.
|
||||
// If the Blacklist 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 *BlacklistMutation) OldMediaID(ctx context.Context) (v int, err error) {
|
||||
if !m.op.Is(OpUpdateOne) {
|
||||
return v, errors.New("OldMediaID is only allowed on UpdateOne operations")
|
||||
}
|
||||
if m.id == nil || m.oldValue == nil {
|
||||
return v, errors.New("OldMediaID requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldMediaID: %w", err)
|
||||
}
|
||||
return oldValue.MediaID, nil
|
||||
}
|
||||
|
||||
// AddMediaID adds i to the "media_id" field.
|
||||
func (m *BlacklistMutation) AddMediaID(i int) {
|
||||
if m.addmedia_id != nil {
|
||||
*m.addmedia_id += i
|
||||
} else {
|
||||
m.addmedia_id = &i
|
||||
}
|
||||
}
|
||||
|
||||
// AddedMediaID returns the value that was added to the "media_id" field in this mutation.
|
||||
func (m *BlacklistMutation) AddedMediaID() (r int, exists bool) {
|
||||
v := m.addmedia_id
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// ClearMediaID clears the value of the "media_id" field.
|
||||
func (m *BlacklistMutation) ClearMediaID() {
|
||||
m.media_id = nil
|
||||
m.addmedia_id = nil
|
||||
m.clearedFields[blacklist.FieldMediaID] = struct{}{}
|
||||
}
|
||||
|
||||
// MediaIDCleared returns if the "media_id" field was cleared in this mutation.
|
||||
func (m *BlacklistMutation) MediaIDCleared() bool {
|
||||
_, ok := m.clearedFields[blacklist.FieldMediaID]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ResetMediaID resets all changes to the "media_id" field.
|
||||
func (m *BlacklistMutation) ResetMediaID() {
|
||||
m.media_id = nil
|
||||
m.addmedia_id = nil
|
||||
delete(m.clearedFields, blacklist.FieldMediaID)
|
||||
}
|
||||
|
||||
// SetCreateTime sets the "create_time" field.
|
||||
func (m *BlacklistMutation) SetCreateTime(t time.Time) {
|
||||
m.create_time = &t
|
||||
}
|
||||
|
||||
// CreateTime returns the value of the "create_time" field in the mutation.
|
||||
func (m *BlacklistMutation) CreateTime() (r time.Time, exists bool) {
|
||||
v := m.create_time
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// OldCreateTime returns the old "create_time" field's value of the Blacklist entity.
|
||||
// If the Blacklist 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 *BlacklistMutation) OldCreateTime(ctx context.Context) (v time.Time, err error) {
|
||||
if !m.op.Is(OpUpdateOne) {
|
||||
return v, errors.New("OldCreateTime is only allowed on UpdateOne operations")
|
||||
}
|
||||
if m.id == nil || m.oldValue == nil {
|
||||
return v, errors.New("OldCreateTime requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldCreateTime: %w", err)
|
||||
}
|
||||
return oldValue.CreateTime, nil
|
||||
}
|
||||
|
||||
// ClearCreateTime clears the value of the "create_time" field.
|
||||
func (m *BlacklistMutation) ClearCreateTime() {
|
||||
m.create_time = nil
|
||||
m.clearedFields[blacklist.FieldCreateTime] = struct{}{}
|
||||
}
|
||||
|
||||
// CreateTimeCleared returns if the "create_time" field was cleared in this mutation.
|
||||
func (m *BlacklistMutation) CreateTimeCleared() bool {
|
||||
_, ok := m.clearedFields[blacklist.FieldCreateTime]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ResetCreateTime resets all changes to the "create_time" field.
|
||||
func (m *BlacklistMutation) ResetCreateTime() {
|
||||
m.create_time = nil
|
||||
delete(m.clearedFields, blacklist.FieldCreateTime)
|
||||
}
|
||||
|
||||
// SetNotes sets the "notes" field.
|
||||
@@ -314,12 +499,21 @@ func (m *BlacklistMutation) Type() string {
|
||||
// order to get all numeric fields that were incremented/decremented, call
|
||||
// AddedFields().
|
||||
func (m *BlacklistMutation) Fields() []string {
|
||||
fields := make([]string, 0, 3)
|
||||
fields := make([]string, 0, 6)
|
||||
if m._type != nil {
|
||||
fields = append(fields, blacklist.FieldType)
|
||||
}
|
||||
if m.value != nil {
|
||||
fields = append(fields, blacklist.FieldValue)
|
||||
if m.torrent_hash != nil {
|
||||
fields = append(fields, blacklist.FieldTorrentHash)
|
||||
}
|
||||
if m.torrent_name != nil {
|
||||
fields = append(fields, blacklist.FieldTorrentName)
|
||||
}
|
||||
if m.media_id != nil {
|
||||
fields = append(fields, blacklist.FieldMediaID)
|
||||
}
|
||||
if m.create_time != nil {
|
||||
fields = append(fields, blacklist.FieldCreateTime)
|
||||
}
|
||||
if m.notes != nil {
|
||||
fields = append(fields, blacklist.FieldNotes)
|
||||
@@ -334,8 +528,14 @@ func (m *BlacklistMutation) Field(name string) (ent.Value, bool) {
|
||||
switch name {
|
||||
case blacklist.FieldType:
|
||||
return m.GetType()
|
||||
case blacklist.FieldValue:
|
||||
return m.Value()
|
||||
case blacklist.FieldTorrentHash:
|
||||
return m.TorrentHash()
|
||||
case blacklist.FieldTorrentName:
|
||||
return m.TorrentName()
|
||||
case blacklist.FieldMediaID:
|
||||
return m.MediaID()
|
||||
case blacklist.FieldCreateTime:
|
||||
return m.CreateTime()
|
||||
case blacklist.FieldNotes:
|
||||
return m.Notes()
|
||||
}
|
||||
@@ -349,8 +549,14 @@ func (m *BlacklistMutation) OldField(ctx context.Context, name string) (ent.Valu
|
||||
switch name {
|
||||
case blacklist.FieldType:
|
||||
return m.OldType(ctx)
|
||||
case blacklist.FieldValue:
|
||||
return m.OldValue(ctx)
|
||||
case blacklist.FieldTorrentHash:
|
||||
return m.OldTorrentHash(ctx)
|
||||
case blacklist.FieldTorrentName:
|
||||
return m.OldTorrentName(ctx)
|
||||
case blacklist.FieldMediaID:
|
||||
return m.OldMediaID(ctx)
|
||||
case blacklist.FieldCreateTime:
|
||||
return m.OldCreateTime(ctx)
|
||||
case blacklist.FieldNotes:
|
||||
return m.OldNotes(ctx)
|
||||
}
|
||||
@@ -369,12 +575,33 @@ func (m *BlacklistMutation) SetField(name string, value ent.Value) error {
|
||||
}
|
||||
m.SetType(v)
|
||||
return nil
|
||||
case blacklist.FieldValue:
|
||||
v, ok := value.(schema.BlacklistValue)
|
||||
case blacklist.FieldTorrentHash:
|
||||
v, ok := value.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetValue(v)
|
||||
m.SetTorrentHash(v)
|
||||
return nil
|
||||
case blacklist.FieldTorrentName:
|
||||
v, ok := value.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetTorrentName(v)
|
||||
return nil
|
||||
case blacklist.FieldMediaID:
|
||||
v, ok := value.(int)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetMediaID(v)
|
||||
return nil
|
||||
case blacklist.FieldCreateTime:
|
||||
v, ok := value.(time.Time)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetCreateTime(v)
|
||||
return nil
|
||||
case blacklist.FieldNotes:
|
||||
v, ok := value.(string)
|
||||
@@ -390,13 +617,21 @@ func (m *BlacklistMutation) SetField(name string, value ent.Value) error {
|
||||
// AddedFields returns all numeric fields that were incremented/decremented during
|
||||
// this mutation.
|
||||
func (m *BlacklistMutation) AddedFields() []string {
|
||||
return nil
|
||||
var fields []string
|
||||
if m.addmedia_id != nil {
|
||||
fields = append(fields, blacklist.FieldMediaID)
|
||||
}
|
||||
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 *BlacklistMutation) AddedField(name string) (ent.Value, bool) {
|
||||
switch name {
|
||||
case blacklist.FieldMediaID:
|
||||
return m.AddedMediaID()
|
||||
}
|
||||
return nil, false
|
||||
}
|
||||
|
||||
@@ -405,6 +640,13 @@ func (m *BlacklistMutation) AddedField(name string) (ent.Value, bool) {
|
||||
// type.
|
||||
func (m *BlacklistMutation) AddField(name string, value ent.Value) error {
|
||||
switch name {
|
||||
case blacklist.FieldMediaID:
|
||||
v, ok := value.(int)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.AddMediaID(v)
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Blacklist numeric field %s", name)
|
||||
}
|
||||
@@ -413,6 +655,18 @@ func (m *BlacklistMutation) AddField(name string, value ent.Value) error {
|
||||
// mutation.
|
||||
func (m *BlacklistMutation) ClearedFields() []string {
|
||||
var fields []string
|
||||
if m.FieldCleared(blacklist.FieldTorrentHash) {
|
||||
fields = append(fields, blacklist.FieldTorrentHash)
|
||||
}
|
||||
if m.FieldCleared(blacklist.FieldTorrentName) {
|
||||
fields = append(fields, blacklist.FieldTorrentName)
|
||||
}
|
||||
if m.FieldCleared(blacklist.FieldMediaID) {
|
||||
fields = append(fields, blacklist.FieldMediaID)
|
||||
}
|
||||
if m.FieldCleared(blacklist.FieldCreateTime) {
|
||||
fields = append(fields, blacklist.FieldCreateTime)
|
||||
}
|
||||
if m.FieldCleared(blacklist.FieldNotes) {
|
||||
fields = append(fields, blacklist.FieldNotes)
|
||||
}
|
||||
@@ -430,6 +684,18 @@ func (m *BlacklistMutation) FieldCleared(name string) bool {
|
||||
// error if the field is not defined in the schema.
|
||||
func (m *BlacklistMutation) ClearField(name string) error {
|
||||
switch name {
|
||||
case blacklist.FieldTorrentHash:
|
||||
m.ClearTorrentHash()
|
||||
return nil
|
||||
case blacklist.FieldTorrentName:
|
||||
m.ClearTorrentName()
|
||||
return nil
|
||||
case blacklist.FieldMediaID:
|
||||
m.ClearMediaID()
|
||||
return nil
|
||||
case blacklist.FieldCreateTime:
|
||||
m.ClearCreateTime()
|
||||
return nil
|
||||
case blacklist.FieldNotes:
|
||||
m.ClearNotes()
|
||||
return nil
|
||||
@@ -444,8 +710,17 @@ func (m *BlacklistMutation) ResetField(name string) error {
|
||||
case blacklist.FieldType:
|
||||
m.ResetType()
|
||||
return nil
|
||||
case blacklist.FieldValue:
|
||||
m.ResetValue()
|
||||
case blacklist.FieldTorrentHash:
|
||||
m.ResetTorrentHash()
|
||||
return nil
|
||||
case blacklist.FieldTorrentName:
|
||||
m.ResetTorrentName()
|
||||
return nil
|
||||
case blacklist.FieldMediaID:
|
||||
m.ResetMediaID()
|
||||
return nil
|
||||
case blacklist.FieldCreateTime:
|
||||
m.ResetCreateTime()
|
||||
return nil
|
||||
case blacklist.FieldNotes:
|
||||
m.ResetNotes()
|
||||
|
||||
@@ -21,10 +21,10 @@ import (
|
||||
func init() {
|
||||
blacklistFields := schema.Blacklist{}.Fields()
|
||||
_ = blacklistFields
|
||||
// blacklistDescValue is the schema descriptor for value field.
|
||||
blacklistDescValue := blacklistFields[1].Descriptor()
|
||||
// blacklist.DefaultValue holds the default value on creation for the value field.
|
||||
blacklist.DefaultValue = blacklistDescValue.Default.(schema.BlacklistValue)
|
||||
// blacklistDescCreateTime is the schema descriptor for create_time field.
|
||||
blacklistDescCreateTime := blacklistFields[4].Descriptor()
|
||||
// blacklist.DefaultCreateTime holds the default value on creation for the create_time field.
|
||||
blacklist.DefaultCreateTime = blacklistDescCreateTime.Default.(func() time.Time)
|
||||
downloadclientsFields := schema.DownloadClients{}.Fields()
|
||||
_ = downloadclientsFields
|
||||
// downloadclientsDescUser is the schema descriptor for user field.
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
@@ -13,8 +15,11 @@ type Blacklist struct {
|
||||
// Fields of the Blacklist.
|
||||
func (Blacklist) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Enum("type").Values("media", "torrent"),
|
||||
field.JSON("value", BlacklistValue{}).Default(BlacklistValue{}),
|
||||
field.Enum("type").Values("media", "torrent").Default("torrent"),
|
||||
field.String("torrent_hash").Optional(),
|
||||
field.String("torrent_name").Optional(),
|
||||
field.Int("media_id").Optional(),
|
||||
field.Time("create_time").Optional().Default(time.Now).Immutable(),
|
||||
field.String("notes").Optional(),
|
||||
}
|
||||
}
|
||||
@@ -23,8 +28,3 @@ func (Blacklist) Fields() []ent.Field {
|
||||
func (Blacklist) Edges() []ent.Edge {
|
||||
return nil
|
||||
}
|
||||
|
||||
type BlacklistValue struct {
|
||||
TmdbID int `json:"tmdb_id"`
|
||||
TorrentHash string `json:"torrent_hash"`
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ func (History) Fields() []ent.Field {
|
||||
field.Int("size").Default(0),
|
||||
field.Int("download_client_id").Optional(),
|
||||
field.Int("indexer_id").Optional(),
|
||||
field.String("link").Optional().Comment("deprecated, use hash instead"), //should be magnet link
|
||||
field.String("link").Optional().Comment("torrent link"), //should be magnet link
|
||||
field.String("hash").Optional().Comment("torrent hash"),
|
||||
field.Enum("status").Values("running", "success", "fail", "uploading", "seeding", "removed"),
|
||||
field.Time("create_time").Optional().Default(time.Now).Immutable(),
|
||||
|
||||
Reference in New Issue
Block a user