feat: change history data field

This commit is contained in:
Simon Ding
2024-07-15 10:56:05 +08:00
parent f37a8eeb5f
commit b2c4b69d87
15 changed files with 178 additions and 142 deletions

View File

@@ -3,6 +3,8 @@
package history
import (
"fmt"
"entgo.io/ent/dialect/sql"
)
@@ -21,8 +23,8 @@ const (
FieldDate = "date"
// FieldTargetDir holds the string denoting the target_dir field in the database.
FieldTargetDir = "target_dir"
// FieldCompleted holds the string denoting the completed field in the database.
FieldCompleted = "completed"
// FieldStatus holds the string denoting the status field in the database.
FieldStatus = "status"
// FieldSaved holds the string denoting the saved field in the database.
FieldSaved = "saved"
// Table holds the table name of the history in the database.
@@ -37,7 +39,7 @@ var Columns = []string{
FieldSourceTitle,
FieldDate,
FieldTargetDir,
FieldCompleted,
FieldStatus,
FieldSaved,
}
@@ -51,11 +53,31 @@ func ValidColumn(column string) bool {
return false
}
var (
// DefaultCompleted holds the default value on creation for the "completed" field.
DefaultCompleted bool
// Status defines the type for the "status" enum field.
type Status string
// Status values.
const (
StatusRunning Status = "running"
StatusSuccess Status = "success"
StatusFail Status = "fail"
StatusUploading Status = "uploading"
)
func (s Status) String() string {
return string(s)
}
// StatusValidator is a validator for the "status" field enum values. It is called by the builders before save.
func StatusValidator(s Status) error {
switch s {
case StatusRunning, StatusSuccess, StatusFail, StatusUploading:
return nil
default:
return fmt.Errorf("history: invalid enum value for status field: %q", s)
}
}
// OrderOption defines the ordering options for the History queries.
type OrderOption func(*sql.Selector)
@@ -89,9 +111,9 @@ func ByTargetDir(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldTargetDir, opts...).ToFunc()
}
// ByCompleted orders the results by the completed field.
func ByCompleted(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldCompleted, opts...).ToFunc()
// ByStatus orders the results by the status field.
func ByStatus(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldStatus, opts...).ToFunc()
}
// BySaved orders the results by the saved field.

View File

@@ -79,11 +79,6 @@ func TargetDir(v string) predicate.History {
return predicate.History(sql.FieldEQ(FieldTargetDir, v))
}
// Completed applies equality check predicate on the "completed" field. It's identical to CompletedEQ.
func Completed(v bool) predicate.History {
return predicate.History(sql.FieldEQ(FieldCompleted, v))
}
// Saved applies equality check predicate on the "saved" field. It's identical to SavedEQ.
func Saved(v string) predicate.History {
return predicate.History(sql.FieldEQ(FieldSaved, v))
@@ -339,14 +334,24 @@ func TargetDirContainsFold(v string) predicate.History {
return predicate.History(sql.FieldContainsFold(FieldTargetDir, v))
}
// CompletedEQ applies the EQ predicate on the "completed" field.
func CompletedEQ(v bool) predicate.History {
return predicate.History(sql.FieldEQ(FieldCompleted, v))
// StatusEQ applies the EQ predicate on the "status" field.
func StatusEQ(v Status) predicate.History {
return predicate.History(sql.FieldEQ(FieldStatus, v))
}
// CompletedNEQ applies the NEQ predicate on the "completed" field.
func CompletedNEQ(v bool) predicate.History {
return predicate.History(sql.FieldNEQ(FieldCompleted, v))
// StatusNEQ applies the NEQ predicate on the "status" field.
func StatusNEQ(v Status) predicate.History {
return predicate.History(sql.FieldNEQ(FieldStatus, v))
}
// StatusIn applies the In predicate on the "status" field.
func StatusIn(vs ...Status) predicate.History {
return predicate.History(sql.FieldIn(FieldStatus, vs...))
}
// StatusNotIn applies the NotIn predicate on the "status" field.
func StatusNotIn(vs ...Status) predicate.History {
return predicate.History(sql.FieldNotIn(FieldStatus, vs...))
}
// SavedEQ applies the EQ predicate on the "saved" field.