diff --git a/app/sephirah/internal/data/internal/converter/biz_to_ent.go b/app/sephirah/internal/data/internal/converter/biz_to_ent.go index c34b31d..26ef050 100644 --- a/app/sephirah/internal/data/internal/converter/biz_to_ent.go +++ b/app/sephirah/internal/data/internal/converter/biz_to_ent.go @@ -4,6 +4,7 @@ import ( "github.com/tuihub/librarian/app/sephirah/internal/data/internal/ent" "github.com/tuihub/librarian/app/sephirah/internal/data/internal/ent/app" "github.com/tuihub/librarian/app/sephirah/internal/data/internal/ent/apppackage" + "github.com/tuihub/librarian/app/sephirah/internal/data/internal/ent/deviceinfo" "github.com/tuihub/librarian/app/sephirah/internal/data/internal/ent/feedconfig" "github.com/tuihub/librarian/app/sephirah/internal/data/internal/ent/image" "github.com/tuihub/librarian/app/sephirah/internal/data/internal/ent/notifyflow" @@ -27,6 +28,7 @@ import ( // goverter:extend ToEntAppPackageSource // goverter:extend ToEntFeedConfigStatus // goverter:extend ToEntNotifyTargetStatus +// goverter:extend ToEntSystemType type toEntConverter interface { //nolint:unused // used by generator ToEntUserTypeList([]libauth.UserType) []user.Type ToEntUserStatusList([]modeltiphereth.UserStatus) []user.Status @@ -160,3 +162,24 @@ func ToEntImageStatus(s modelchesed.ImageStatus) image.Status { return "" } } + +func ToEntSystemType(s modeltiphereth.SystemType) deviceinfo.SystemType { + switch s { + case modeltiphereth.SystemTypeUnspecified: + return deviceinfo.SystemTypeUnknown + case modeltiphereth.SystemTypeIOS: + return deviceinfo.SystemTypeIos + case modeltiphereth.SystemTypeAndroid: + return deviceinfo.SystemTypeAndroid + case modeltiphereth.SystemTypeWindows: + return deviceinfo.SystemTypeWindows + case modeltiphereth.SystemTypeMacOS: + return deviceinfo.SystemTypeMacos + case modeltiphereth.SystemTypeLinux: + return deviceinfo.SystemTypeLinux + case modeltiphereth.SystemTypeWeb: + return deviceinfo.SystemTypeWeb + default: + return deviceinfo.SystemTypeUnknown + } +} diff --git a/app/sephirah/internal/data/internal/converter/ent_to_biz.go b/app/sephirah/internal/data/internal/converter/ent_to_biz.go index 8278901..b799d74 100644 --- a/app/sephirah/internal/data/internal/converter/ent_to_biz.go +++ b/app/sephirah/internal/data/internal/converter/ent_to_biz.go @@ -6,6 +6,7 @@ import ( "github.com/tuihub/librarian/app/sephirah/internal/data/internal/ent" "github.com/tuihub/librarian/app/sephirah/internal/data/internal/ent/app" "github.com/tuihub/librarian/app/sephirah/internal/data/internal/ent/apppackage" + "github.com/tuihub/librarian/app/sephirah/internal/data/internal/ent/deviceinfo" "github.com/tuihub/librarian/app/sephirah/internal/data/internal/ent/feedconfig" "github.com/tuihub/librarian/app/sephirah/internal/data/internal/ent/image" "github.com/tuihub/librarian/app/sephirah/internal/data/internal/ent/notifyflow" @@ -41,6 +42,7 @@ type toBizConverter interface { //nolint:unused // used by generator ToBizUserSessionList([]*ent.UserSession) []*modeltiphereth.UserSession // goverter:matchIgnoreCase + // goverter:map SystemType | ToBizSystemType ToBizDeviceInfo(*ent.DeviceInfo) *modeltiphereth.DeviceInfo // goverter:matchIgnoreCase @@ -50,6 +52,7 @@ type toBizConverter interface { //nolint:unused // used by generator // goverter:matchIgnoreCase // goverter:map Status | ToBizPorterStatus + // goverter:ignore ConnectionStatus ToBizPorter(*ent.PorterInstance) *modeltiphereth.PorterInstance ToBizPorterList([]*ent.PorterInstance) []*modeltiphereth.PorterInstance @@ -210,3 +213,24 @@ func ToBizImageStatus(s image.Status) modelchesed.ImageStatus { return modelchesed.ImageStatusUnspecified } } + +func ToBizSystemType(s deviceinfo.SystemType) modeltiphereth.SystemType { + switch s { + case deviceinfo.SystemTypeUnknown: + return modeltiphereth.SystemTypeUnspecified + case deviceinfo.SystemTypeIos: + return modeltiphereth.SystemTypeIOS + case deviceinfo.SystemTypeAndroid: + return modeltiphereth.SystemTypeAndroid + case deviceinfo.SystemTypeWeb: + return modeltiphereth.SystemTypeWeb + case deviceinfo.SystemTypeWindows: + return modeltiphereth.SystemTypeWindows + case deviceinfo.SystemTypeMacos: + return modeltiphereth.SystemTypeMacOS + case deviceinfo.SystemTypeLinux: + return modeltiphereth.SystemTypeLinux + default: + return modeltiphereth.SystemTypeUnspecified + } +} diff --git a/app/sephirah/internal/data/internal/converter/generated.go b/app/sephirah/internal/data/internal/converter/generated.go index a956b7e..f983926 100755 --- a/app/sephirah/internal/data/internal/converter/generated.go +++ b/app/sephirah/internal/data/internal/converter/generated.go @@ -123,7 +123,8 @@ func (c *toBizConverterImpl) ToBizDeviceInfo(source *ent.DeviceInfo) *modeltiphe if source != nil { var modeltipherethDeviceInfo modeltiphereth.DeviceInfo modeltipherethDeviceInfo.ID = c.modelInternalIDToModelInternalID((*source).ID) - modeltipherethDeviceInfo.DeviceModel = (*source).DeviceModel + modeltipherethDeviceInfo.DeviceName = (*source).DeviceName + modeltipherethDeviceInfo.SystemType = ToBizSystemType((*source).SystemType) modeltipherethDeviceInfo.SystemVersion = (*source).SystemVersion modeltipherethDeviceInfo.ClientName = (*source).ClientName modeltipherethDeviceInfo.ClientSourceCodeAddress = (*source).ClientSourceCodeAddress diff --git a/app/sephirah/internal/data/internal/ent/deviceinfo.go b/app/sephirah/internal/data/internal/ent/deviceinfo.go index ba108dc..6274796 100644 --- a/app/sephirah/internal/data/internal/ent/deviceinfo.go +++ b/app/sephirah/internal/data/internal/ent/deviceinfo.go @@ -18,8 +18,10 @@ type DeviceInfo struct { config `json:"-"` // ID of the ent. ID model.InternalID `json:"id,omitempty"` - // DeviceModel holds the value of the "device_model" field. - DeviceModel string `json:"device_model,omitempty"` + // DeviceName holds the value of the "device_name" field. + DeviceName string `json:"device_name,omitempty"` + // SystemType holds the value of the "system_type" field. + SystemType deviceinfo.SystemType `json:"system_type,omitempty"` // SystemVersion holds the value of the "system_version" field. SystemVersion string `json:"system_version,omitempty"` // ClientName holds the value of the "client_name" field. @@ -64,7 +66,7 @@ func (*DeviceInfo) scanValues(columns []string) ([]any, error) { switch columns[i] { case deviceinfo.FieldID: values[i] = new(sql.NullInt64) - case deviceinfo.FieldDeviceModel, deviceinfo.FieldSystemVersion, deviceinfo.FieldClientName, deviceinfo.FieldClientSourceCodeAddress, deviceinfo.FieldClientVersion: + case deviceinfo.FieldDeviceName, deviceinfo.FieldSystemType, deviceinfo.FieldSystemVersion, deviceinfo.FieldClientName, deviceinfo.FieldClientSourceCodeAddress, deviceinfo.FieldClientVersion: values[i] = new(sql.NullString) case deviceinfo.FieldUpdatedAt, deviceinfo.FieldCreatedAt: values[i] = new(sql.NullTime) @@ -91,11 +93,17 @@ func (di *DeviceInfo) assignValues(columns []string, values []any) error { } else if value.Valid { di.ID = model.InternalID(value.Int64) } - case deviceinfo.FieldDeviceModel: + case deviceinfo.FieldDeviceName: if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field device_model", values[i]) + return fmt.Errorf("unexpected type %T for field device_name", values[i]) } else if value.Valid { - di.DeviceModel = value.String + di.DeviceName = value.String + } + case deviceinfo.FieldSystemType: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field system_type", values[i]) + } else if value.Valid { + di.SystemType = deviceinfo.SystemType(value.String) } case deviceinfo.FieldSystemVersion: if value, ok := values[i].(*sql.NullString); !ok { @@ -181,8 +189,11 @@ func (di *DeviceInfo) String() string { var builder strings.Builder builder.WriteString("DeviceInfo(") builder.WriteString(fmt.Sprintf("id=%v, ", di.ID)) - builder.WriteString("device_model=") - builder.WriteString(di.DeviceModel) + builder.WriteString("device_name=") + builder.WriteString(di.DeviceName) + builder.WriteString(", ") + builder.WriteString("system_type=") + builder.WriteString(fmt.Sprintf("%v", di.SystemType)) builder.WriteString(", ") builder.WriteString("system_version=") builder.WriteString(di.SystemVersion) diff --git a/app/sephirah/internal/data/internal/ent/deviceinfo/deviceinfo.go b/app/sephirah/internal/data/internal/ent/deviceinfo/deviceinfo.go index 8233cd5..4cf459e 100644 --- a/app/sephirah/internal/data/internal/ent/deviceinfo/deviceinfo.go +++ b/app/sephirah/internal/data/internal/ent/deviceinfo/deviceinfo.go @@ -3,6 +3,7 @@ package deviceinfo import ( + "fmt" "time" "entgo.io/ent/dialect/sql" @@ -14,8 +15,10 @@ const ( Label = "device_info" // FieldID holds the string denoting the id field in the database. FieldID = "id" - // FieldDeviceModel holds the string denoting the device_model field in the database. - FieldDeviceModel = "device_model" + // FieldDeviceName holds the string denoting the device_name field in the database. + FieldDeviceName = "device_name" + // FieldSystemType holds the string denoting the system_type field in the database. + FieldSystemType = "system_type" // FieldSystemVersion holds the string denoting the system_version field in the database. FieldSystemVersion = "system_version" // FieldClientName holds the string denoting the client_name field in the database. @@ -44,7 +47,8 @@ const ( // Columns holds all SQL columns for deviceinfo fields. var Columns = []string{ FieldID, - FieldDeviceModel, + FieldDeviceName, + FieldSystemType, FieldSystemVersion, FieldClientName, FieldClientSourceCodeAddress, @@ -83,6 +87,34 @@ var ( DefaultCreatedAt func() time.Time ) +// SystemType defines the type for the "system_type" enum field. +type SystemType string + +// SystemType values. +const ( + SystemTypeIos SystemType = "ios" + SystemTypeAndroid SystemType = "android" + SystemTypeWeb SystemType = "web" + SystemTypeWindows SystemType = "windows" + SystemTypeMacos SystemType = "macos" + SystemTypeLinux SystemType = "linux" + SystemTypeUnknown SystemType = "unknown" +) + +func (st SystemType) String() string { + return string(st) +} + +// SystemTypeValidator is a validator for the "system_type" field enum values. It is called by the builders before save. +func SystemTypeValidator(st SystemType) error { + switch st { + case SystemTypeIos, SystemTypeAndroid, SystemTypeWeb, SystemTypeWindows, SystemTypeMacos, SystemTypeLinux, SystemTypeUnknown: + return nil + default: + return fmt.Errorf("deviceinfo: invalid enum value for system_type field: %q", st) + } +} + // OrderOption defines the ordering options for the DeviceInfo queries. type OrderOption func(*sql.Selector) @@ -91,9 +123,14 @@ func ByID(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldID, opts...).ToFunc() } -// ByDeviceModel orders the results by the device_model field. -func ByDeviceModel(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldDeviceModel, opts...).ToFunc() +// ByDeviceName orders the results by the device_name field. +func ByDeviceName(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldDeviceName, opts...).ToFunc() +} + +// BySystemType orders the results by the system_type field. +func BySystemType(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldSystemType, opts...).ToFunc() } // BySystemVersion orders the results by the system_version field. diff --git a/app/sephirah/internal/data/internal/ent/deviceinfo/where.go b/app/sephirah/internal/data/internal/ent/deviceinfo/where.go index 0f7c104..7210816 100644 --- a/app/sephirah/internal/data/internal/ent/deviceinfo/where.go +++ b/app/sephirah/internal/data/internal/ent/deviceinfo/where.go @@ -56,9 +56,9 @@ func IDLTE(id model.InternalID) predicate.DeviceInfo { return predicate.DeviceInfo(sql.FieldLTE(FieldID, id)) } -// DeviceModel applies equality check predicate on the "device_model" field. It's identical to DeviceModelEQ. -func DeviceModel(v string) predicate.DeviceInfo { - return predicate.DeviceInfo(sql.FieldEQ(FieldDeviceModel, v)) +// DeviceName applies equality check predicate on the "device_name" field. It's identical to DeviceNameEQ. +func DeviceName(v string) predicate.DeviceInfo { + return predicate.DeviceInfo(sql.FieldEQ(FieldDeviceName, v)) } // SystemVersion applies equality check predicate on the "system_version" field. It's identical to SystemVersionEQ. @@ -91,69 +91,89 @@ func CreatedAt(v time.Time) predicate.DeviceInfo { return predicate.DeviceInfo(sql.FieldEQ(FieldCreatedAt, v)) } -// DeviceModelEQ applies the EQ predicate on the "device_model" field. -func DeviceModelEQ(v string) predicate.DeviceInfo { - return predicate.DeviceInfo(sql.FieldEQ(FieldDeviceModel, v)) +// DeviceNameEQ applies the EQ predicate on the "device_name" field. +func DeviceNameEQ(v string) predicate.DeviceInfo { + return predicate.DeviceInfo(sql.FieldEQ(FieldDeviceName, v)) } -// DeviceModelNEQ applies the NEQ predicate on the "device_model" field. -func DeviceModelNEQ(v string) predicate.DeviceInfo { - return predicate.DeviceInfo(sql.FieldNEQ(FieldDeviceModel, v)) +// DeviceNameNEQ applies the NEQ predicate on the "device_name" field. +func DeviceNameNEQ(v string) predicate.DeviceInfo { + return predicate.DeviceInfo(sql.FieldNEQ(FieldDeviceName, v)) } -// DeviceModelIn applies the In predicate on the "device_model" field. -func DeviceModelIn(vs ...string) predicate.DeviceInfo { - return predicate.DeviceInfo(sql.FieldIn(FieldDeviceModel, vs...)) +// DeviceNameIn applies the In predicate on the "device_name" field. +func DeviceNameIn(vs ...string) predicate.DeviceInfo { + return predicate.DeviceInfo(sql.FieldIn(FieldDeviceName, vs...)) } -// DeviceModelNotIn applies the NotIn predicate on the "device_model" field. -func DeviceModelNotIn(vs ...string) predicate.DeviceInfo { - return predicate.DeviceInfo(sql.FieldNotIn(FieldDeviceModel, vs...)) +// DeviceNameNotIn applies the NotIn predicate on the "device_name" field. +func DeviceNameNotIn(vs ...string) predicate.DeviceInfo { + return predicate.DeviceInfo(sql.FieldNotIn(FieldDeviceName, vs...)) } -// DeviceModelGT applies the GT predicate on the "device_model" field. -func DeviceModelGT(v string) predicate.DeviceInfo { - return predicate.DeviceInfo(sql.FieldGT(FieldDeviceModel, v)) +// DeviceNameGT applies the GT predicate on the "device_name" field. +func DeviceNameGT(v string) predicate.DeviceInfo { + return predicate.DeviceInfo(sql.FieldGT(FieldDeviceName, v)) } -// DeviceModelGTE applies the GTE predicate on the "device_model" field. -func DeviceModelGTE(v string) predicate.DeviceInfo { - return predicate.DeviceInfo(sql.FieldGTE(FieldDeviceModel, v)) +// DeviceNameGTE applies the GTE predicate on the "device_name" field. +func DeviceNameGTE(v string) predicate.DeviceInfo { + return predicate.DeviceInfo(sql.FieldGTE(FieldDeviceName, v)) } -// DeviceModelLT applies the LT predicate on the "device_model" field. -func DeviceModelLT(v string) predicate.DeviceInfo { - return predicate.DeviceInfo(sql.FieldLT(FieldDeviceModel, v)) +// DeviceNameLT applies the LT predicate on the "device_name" field. +func DeviceNameLT(v string) predicate.DeviceInfo { + return predicate.DeviceInfo(sql.FieldLT(FieldDeviceName, v)) } -// DeviceModelLTE applies the LTE predicate on the "device_model" field. -func DeviceModelLTE(v string) predicate.DeviceInfo { - return predicate.DeviceInfo(sql.FieldLTE(FieldDeviceModel, v)) +// DeviceNameLTE applies the LTE predicate on the "device_name" field. +func DeviceNameLTE(v string) predicate.DeviceInfo { + return predicate.DeviceInfo(sql.FieldLTE(FieldDeviceName, v)) } -// DeviceModelContains applies the Contains predicate on the "device_model" field. -func DeviceModelContains(v string) predicate.DeviceInfo { - return predicate.DeviceInfo(sql.FieldContains(FieldDeviceModel, v)) +// DeviceNameContains applies the Contains predicate on the "device_name" field. +func DeviceNameContains(v string) predicate.DeviceInfo { + return predicate.DeviceInfo(sql.FieldContains(FieldDeviceName, v)) } -// DeviceModelHasPrefix applies the HasPrefix predicate on the "device_model" field. -func DeviceModelHasPrefix(v string) predicate.DeviceInfo { - return predicate.DeviceInfo(sql.FieldHasPrefix(FieldDeviceModel, v)) +// DeviceNameHasPrefix applies the HasPrefix predicate on the "device_name" field. +func DeviceNameHasPrefix(v string) predicate.DeviceInfo { + return predicate.DeviceInfo(sql.FieldHasPrefix(FieldDeviceName, v)) } -// DeviceModelHasSuffix applies the HasSuffix predicate on the "device_model" field. -func DeviceModelHasSuffix(v string) predicate.DeviceInfo { - return predicate.DeviceInfo(sql.FieldHasSuffix(FieldDeviceModel, v)) +// DeviceNameHasSuffix applies the HasSuffix predicate on the "device_name" field. +func DeviceNameHasSuffix(v string) predicate.DeviceInfo { + return predicate.DeviceInfo(sql.FieldHasSuffix(FieldDeviceName, v)) } -// DeviceModelEqualFold applies the EqualFold predicate on the "device_model" field. -func DeviceModelEqualFold(v string) predicate.DeviceInfo { - return predicate.DeviceInfo(sql.FieldEqualFold(FieldDeviceModel, v)) +// DeviceNameEqualFold applies the EqualFold predicate on the "device_name" field. +func DeviceNameEqualFold(v string) predicate.DeviceInfo { + return predicate.DeviceInfo(sql.FieldEqualFold(FieldDeviceName, v)) } -// DeviceModelContainsFold applies the ContainsFold predicate on the "device_model" field. -func DeviceModelContainsFold(v string) predicate.DeviceInfo { - return predicate.DeviceInfo(sql.FieldContainsFold(FieldDeviceModel, v)) +// DeviceNameContainsFold applies the ContainsFold predicate on the "device_name" field. +func DeviceNameContainsFold(v string) predicate.DeviceInfo { + return predicate.DeviceInfo(sql.FieldContainsFold(FieldDeviceName, v)) +} + +// SystemTypeEQ applies the EQ predicate on the "system_type" field. +func SystemTypeEQ(v SystemType) predicate.DeviceInfo { + return predicate.DeviceInfo(sql.FieldEQ(FieldSystemType, v)) +} + +// SystemTypeNEQ applies the NEQ predicate on the "system_type" field. +func SystemTypeNEQ(v SystemType) predicate.DeviceInfo { + return predicate.DeviceInfo(sql.FieldNEQ(FieldSystemType, v)) +} + +// SystemTypeIn applies the In predicate on the "system_type" field. +func SystemTypeIn(vs ...SystemType) predicate.DeviceInfo { + return predicate.DeviceInfo(sql.FieldIn(FieldSystemType, vs...)) +} + +// SystemTypeNotIn applies the NotIn predicate on the "system_type" field. +func SystemTypeNotIn(vs ...SystemType) predicate.DeviceInfo { + return predicate.DeviceInfo(sql.FieldNotIn(FieldSystemType, vs...)) } // SystemVersionEQ applies the EQ predicate on the "system_version" field. diff --git a/app/sephirah/internal/data/internal/ent/deviceinfo_create.go b/app/sephirah/internal/data/internal/ent/deviceinfo_create.go index 563c729..443b248 100644 --- a/app/sephirah/internal/data/internal/ent/deviceinfo_create.go +++ b/app/sephirah/internal/data/internal/ent/deviceinfo_create.go @@ -24,9 +24,15 @@ type DeviceInfoCreate struct { conflict []sql.ConflictOption } -// SetDeviceModel sets the "device_model" field. -func (dic *DeviceInfoCreate) SetDeviceModel(s string) *DeviceInfoCreate { - dic.mutation.SetDeviceModel(s) +// SetDeviceName sets the "device_name" field. +func (dic *DeviceInfoCreate) SetDeviceName(s string) *DeviceInfoCreate { + dic.mutation.SetDeviceName(s) + return dic +} + +// SetSystemType sets the "system_type" field. +func (dic *DeviceInfoCreate) SetSystemType(dt deviceinfo.SystemType) *DeviceInfoCreate { + dic.mutation.SetSystemType(dt) return dic } @@ -150,8 +156,16 @@ func (dic *DeviceInfoCreate) defaults() { // check runs all checks and user-defined validators on the builder. func (dic *DeviceInfoCreate) check() error { - if _, ok := dic.mutation.DeviceModel(); !ok { - return &ValidationError{Name: "device_model", err: errors.New(`ent: missing required field "DeviceInfo.device_model"`)} + if _, ok := dic.mutation.DeviceName(); !ok { + return &ValidationError{Name: "device_name", err: errors.New(`ent: missing required field "DeviceInfo.device_name"`)} + } + if _, ok := dic.mutation.SystemType(); !ok { + return &ValidationError{Name: "system_type", err: errors.New(`ent: missing required field "DeviceInfo.system_type"`)} + } + if v, ok := dic.mutation.SystemType(); ok { + if err := deviceinfo.SystemTypeValidator(v); err != nil { + return &ValidationError{Name: "system_type", err: fmt.Errorf(`ent: validator failed for field "DeviceInfo.system_type": %w`, err)} + } } if _, ok := dic.mutation.SystemVersion(); !ok { return &ValidationError{Name: "system_version", err: errors.New(`ent: missing required field "DeviceInfo.system_version"`)} @@ -204,9 +218,13 @@ func (dic *DeviceInfoCreate) createSpec() (*DeviceInfo, *sqlgraph.CreateSpec) { _node.ID = id _spec.ID.Value = id } - if value, ok := dic.mutation.DeviceModel(); ok { - _spec.SetField(deviceinfo.FieldDeviceModel, field.TypeString, value) - _node.DeviceModel = value + if value, ok := dic.mutation.DeviceName(); ok { + _spec.SetField(deviceinfo.FieldDeviceName, field.TypeString, value) + _node.DeviceName = value + } + if value, ok := dic.mutation.SystemType(); ok { + _spec.SetField(deviceinfo.FieldSystemType, field.TypeEnum, value) + _node.SystemType = value } if value, ok := dic.mutation.SystemVersion(); ok { _spec.SetField(deviceinfo.FieldSystemVersion, field.TypeString, value) @@ -255,7 +273,7 @@ func (dic *DeviceInfoCreate) createSpec() (*DeviceInfo, *sqlgraph.CreateSpec) { // of the `INSERT` statement. For example: // // client.DeviceInfo.Create(). -// SetDeviceModel(v). +// SetDeviceName(v). // OnConflict( // // Update the row with the new values // // the was proposed for insertion. @@ -264,7 +282,7 @@ func (dic *DeviceInfoCreate) createSpec() (*DeviceInfo, *sqlgraph.CreateSpec) { // // Override some of the fields with custom // // update values. // Update(func(u *ent.DeviceInfoUpsert) { -// SetDeviceModel(v+v). +// SetDeviceName(v+v). // }). // Exec(ctx) func (dic *DeviceInfoCreate) OnConflict(opts ...sql.ConflictOption) *DeviceInfoUpsertOne { @@ -300,15 +318,27 @@ type ( } ) -// SetDeviceModel sets the "device_model" field. -func (u *DeviceInfoUpsert) SetDeviceModel(v string) *DeviceInfoUpsert { - u.Set(deviceinfo.FieldDeviceModel, v) +// SetDeviceName sets the "device_name" field. +func (u *DeviceInfoUpsert) SetDeviceName(v string) *DeviceInfoUpsert { + u.Set(deviceinfo.FieldDeviceName, v) return u } -// UpdateDeviceModel sets the "device_model" field to the value that was provided on create. -func (u *DeviceInfoUpsert) UpdateDeviceModel() *DeviceInfoUpsert { - u.SetExcluded(deviceinfo.FieldDeviceModel) +// UpdateDeviceName sets the "device_name" field to the value that was provided on create. +func (u *DeviceInfoUpsert) UpdateDeviceName() *DeviceInfoUpsert { + u.SetExcluded(deviceinfo.FieldDeviceName) + return u +} + +// SetSystemType sets the "system_type" field. +func (u *DeviceInfoUpsert) SetSystemType(v deviceinfo.SystemType) *DeviceInfoUpsert { + u.Set(deviceinfo.FieldSystemType, v) + return u +} + +// UpdateSystemType sets the "system_type" field to the value that was provided on create. +func (u *DeviceInfoUpsert) UpdateSystemType() *DeviceInfoUpsert { + u.SetExcluded(deviceinfo.FieldSystemType) return u } @@ -432,17 +462,31 @@ func (u *DeviceInfoUpsertOne) Update(set func(*DeviceInfoUpsert)) *DeviceInfoUps return u } -// SetDeviceModel sets the "device_model" field. -func (u *DeviceInfoUpsertOne) SetDeviceModel(v string) *DeviceInfoUpsertOne { +// SetDeviceName sets the "device_name" field. +func (u *DeviceInfoUpsertOne) SetDeviceName(v string) *DeviceInfoUpsertOne { return u.Update(func(s *DeviceInfoUpsert) { - s.SetDeviceModel(v) + s.SetDeviceName(v) }) } -// UpdateDeviceModel sets the "device_model" field to the value that was provided on create. -func (u *DeviceInfoUpsertOne) UpdateDeviceModel() *DeviceInfoUpsertOne { +// UpdateDeviceName sets the "device_name" field to the value that was provided on create. +func (u *DeviceInfoUpsertOne) UpdateDeviceName() *DeviceInfoUpsertOne { return u.Update(func(s *DeviceInfoUpsert) { - s.UpdateDeviceModel() + s.UpdateDeviceName() + }) +} + +// SetSystemType sets the "system_type" field. +func (u *DeviceInfoUpsertOne) SetSystemType(v deviceinfo.SystemType) *DeviceInfoUpsertOne { + return u.Update(func(s *DeviceInfoUpsert) { + s.SetSystemType(v) + }) +} + +// UpdateSystemType sets the "system_type" field to the value that was provided on create. +func (u *DeviceInfoUpsertOne) UpdateSystemType() *DeviceInfoUpsertOne { + return u.Update(func(s *DeviceInfoUpsert) { + s.UpdateSystemType() }) } @@ -665,7 +709,7 @@ func (dicb *DeviceInfoCreateBulk) ExecX(ctx context.Context) { // // Override some of the fields with custom // // update values. // Update(func(u *ent.DeviceInfoUpsert) { -// SetDeviceModel(v+v). +// SetDeviceName(v+v). // }). // Exec(ctx) func (dicb *DeviceInfoCreateBulk) OnConflict(opts ...sql.ConflictOption) *DeviceInfoUpsertBulk { @@ -744,17 +788,31 @@ func (u *DeviceInfoUpsertBulk) Update(set func(*DeviceInfoUpsert)) *DeviceInfoUp return u } -// SetDeviceModel sets the "device_model" field. -func (u *DeviceInfoUpsertBulk) SetDeviceModel(v string) *DeviceInfoUpsertBulk { +// SetDeviceName sets the "device_name" field. +func (u *DeviceInfoUpsertBulk) SetDeviceName(v string) *DeviceInfoUpsertBulk { + return u.Update(func(s *DeviceInfoUpsert) { + s.SetDeviceName(v) + }) +} + +// UpdateDeviceName sets the "device_name" field to the value that was provided on create. +func (u *DeviceInfoUpsertBulk) UpdateDeviceName() *DeviceInfoUpsertBulk { + return u.Update(func(s *DeviceInfoUpsert) { + s.UpdateDeviceName() + }) +} + +// SetSystemType sets the "system_type" field. +func (u *DeviceInfoUpsertBulk) SetSystemType(v deviceinfo.SystemType) *DeviceInfoUpsertBulk { return u.Update(func(s *DeviceInfoUpsert) { - s.SetDeviceModel(v) + s.SetSystemType(v) }) } -// UpdateDeviceModel sets the "device_model" field to the value that was provided on create. -func (u *DeviceInfoUpsertBulk) UpdateDeviceModel() *DeviceInfoUpsertBulk { +// UpdateSystemType sets the "system_type" field to the value that was provided on create. +func (u *DeviceInfoUpsertBulk) UpdateSystemType() *DeviceInfoUpsertBulk { return u.Update(func(s *DeviceInfoUpsert) { - s.UpdateDeviceModel() + s.UpdateSystemType() }) } diff --git a/app/sephirah/internal/data/internal/ent/deviceinfo_query.go b/app/sephirah/internal/data/internal/ent/deviceinfo_query.go index d46c0b9..340aa5d 100644 --- a/app/sephirah/internal/data/internal/ent/deviceinfo_query.go +++ b/app/sephirah/internal/data/internal/ent/deviceinfo_query.go @@ -300,12 +300,12 @@ func (diq *DeviceInfoQuery) WithUserSession(opts ...func(*UserSessionQuery)) *De // Example: // // var v []struct { -// DeviceModel string `json:"device_model,omitempty"` +// DeviceName string `json:"device_name,omitempty"` // Count int `json:"count,omitempty"` // } // // client.DeviceInfo.Query(). -// GroupBy(deviceinfo.FieldDeviceModel). +// GroupBy(deviceinfo.FieldDeviceName). // Aggregate(ent.Count()). // Scan(ctx, &v) func (diq *DeviceInfoQuery) GroupBy(field string, fields ...string) *DeviceInfoGroupBy { @@ -323,11 +323,11 @@ func (diq *DeviceInfoQuery) GroupBy(field string, fields ...string) *DeviceInfoG // Example: // // var v []struct { -// DeviceModel string `json:"device_model,omitempty"` +// DeviceName string `json:"device_name,omitempty"` // } // // client.DeviceInfo.Query(). -// Select(deviceinfo.FieldDeviceModel). +// Select(deviceinfo.FieldDeviceName). // Scan(ctx, &v) func (diq *DeviceInfoQuery) Select(fields ...string) *DeviceInfoSelect { diq.ctx.Fields = append(diq.ctx.Fields, fields...) diff --git a/app/sephirah/internal/data/internal/ent/deviceinfo_update.go b/app/sephirah/internal/data/internal/ent/deviceinfo_update.go index d2727fe..ddc3c45 100644 --- a/app/sephirah/internal/data/internal/ent/deviceinfo_update.go +++ b/app/sephirah/internal/data/internal/ent/deviceinfo_update.go @@ -30,16 +30,30 @@ func (diu *DeviceInfoUpdate) Where(ps ...predicate.DeviceInfo) *DeviceInfoUpdate return diu } -// SetDeviceModel sets the "device_model" field. -func (diu *DeviceInfoUpdate) SetDeviceModel(s string) *DeviceInfoUpdate { - diu.mutation.SetDeviceModel(s) +// SetDeviceName sets the "device_name" field. +func (diu *DeviceInfoUpdate) SetDeviceName(s string) *DeviceInfoUpdate { + diu.mutation.SetDeviceName(s) return diu } -// SetNillableDeviceModel sets the "device_model" field if the given value is not nil. -func (diu *DeviceInfoUpdate) SetNillableDeviceModel(s *string) *DeviceInfoUpdate { +// SetNillableDeviceName sets the "device_name" field if the given value is not nil. +func (diu *DeviceInfoUpdate) SetNillableDeviceName(s *string) *DeviceInfoUpdate { if s != nil { - diu.SetDeviceModel(*s) + diu.SetDeviceName(*s) + } + return diu +} + +// SetSystemType sets the "system_type" field. +func (diu *DeviceInfoUpdate) SetSystemType(dt deviceinfo.SystemType) *DeviceInfoUpdate { + diu.mutation.SetSystemType(dt) + return diu +} + +// SetNillableSystemType sets the "system_type" field if the given value is not nil. +func (diu *DeviceInfoUpdate) SetNillableSystemType(dt *deviceinfo.SystemType) *DeviceInfoUpdate { + if dt != nil { + diu.SetSystemType(*dt) } return diu } @@ -197,7 +211,20 @@ func (diu *DeviceInfoUpdate) defaults() { } } +// check runs all checks and user-defined validators on the builder. +func (diu *DeviceInfoUpdate) check() error { + if v, ok := diu.mutation.SystemType(); ok { + if err := deviceinfo.SystemTypeValidator(v); err != nil { + return &ValidationError{Name: "system_type", err: fmt.Errorf(`ent: validator failed for field "DeviceInfo.system_type": %w`, err)} + } + } + return nil +} + func (diu *DeviceInfoUpdate) sqlSave(ctx context.Context) (n int, err error) { + if err := diu.check(); err != nil { + return n, err + } _spec := sqlgraph.NewUpdateSpec(deviceinfo.Table, deviceinfo.Columns, sqlgraph.NewFieldSpec(deviceinfo.FieldID, field.TypeInt64)) if ps := diu.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { @@ -206,8 +233,11 @@ func (diu *DeviceInfoUpdate) sqlSave(ctx context.Context) (n int, err error) { } } } - if value, ok := diu.mutation.DeviceModel(); ok { - _spec.SetField(deviceinfo.FieldDeviceModel, field.TypeString, value) + if value, ok := diu.mutation.DeviceName(); ok { + _spec.SetField(deviceinfo.FieldDeviceName, field.TypeString, value) + } + if value, ok := diu.mutation.SystemType(); ok { + _spec.SetField(deviceinfo.FieldSystemType, field.TypeEnum, value) } if value, ok := diu.mutation.SystemVersion(); ok { _spec.SetField(deviceinfo.FieldSystemVersion, field.TypeString, value) @@ -292,16 +322,30 @@ type DeviceInfoUpdateOne struct { mutation *DeviceInfoMutation } -// SetDeviceModel sets the "device_model" field. -func (diuo *DeviceInfoUpdateOne) SetDeviceModel(s string) *DeviceInfoUpdateOne { - diuo.mutation.SetDeviceModel(s) +// SetDeviceName sets the "device_name" field. +func (diuo *DeviceInfoUpdateOne) SetDeviceName(s string) *DeviceInfoUpdateOne { + diuo.mutation.SetDeviceName(s) return diuo } -// SetNillableDeviceModel sets the "device_model" field if the given value is not nil. -func (diuo *DeviceInfoUpdateOne) SetNillableDeviceModel(s *string) *DeviceInfoUpdateOne { +// SetNillableDeviceName sets the "device_name" field if the given value is not nil. +func (diuo *DeviceInfoUpdateOne) SetNillableDeviceName(s *string) *DeviceInfoUpdateOne { if s != nil { - diuo.SetDeviceModel(*s) + diuo.SetDeviceName(*s) + } + return diuo +} + +// SetSystemType sets the "system_type" field. +func (diuo *DeviceInfoUpdateOne) SetSystemType(dt deviceinfo.SystemType) *DeviceInfoUpdateOne { + diuo.mutation.SetSystemType(dt) + return diuo +} + +// SetNillableSystemType sets the "system_type" field if the given value is not nil. +func (diuo *DeviceInfoUpdateOne) SetNillableSystemType(dt *deviceinfo.SystemType) *DeviceInfoUpdateOne { + if dt != nil { + diuo.SetSystemType(*dt) } return diuo } @@ -472,7 +516,20 @@ func (diuo *DeviceInfoUpdateOne) defaults() { } } +// check runs all checks and user-defined validators on the builder. +func (diuo *DeviceInfoUpdateOne) check() error { + if v, ok := diuo.mutation.SystemType(); ok { + if err := deviceinfo.SystemTypeValidator(v); err != nil { + return &ValidationError{Name: "system_type", err: fmt.Errorf(`ent: validator failed for field "DeviceInfo.system_type": %w`, err)} + } + } + return nil +} + func (diuo *DeviceInfoUpdateOne) sqlSave(ctx context.Context) (_node *DeviceInfo, err error) { + if err := diuo.check(); err != nil { + return _node, err + } _spec := sqlgraph.NewUpdateSpec(deviceinfo.Table, deviceinfo.Columns, sqlgraph.NewFieldSpec(deviceinfo.FieldID, field.TypeInt64)) id, ok := diuo.mutation.ID() if !ok { @@ -498,8 +555,11 @@ func (diuo *DeviceInfoUpdateOne) sqlSave(ctx context.Context) (_node *DeviceInfo } } } - if value, ok := diuo.mutation.DeviceModel(); ok { - _spec.SetField(deviceinfo.FieldDeviceModel, field.TypeString, value) + if value, ok := diuo.mutation.DeviceName(); ok { + _spec.SetField(deviceinfo.FieldDeviceName, field.TypeString, value) + } + if value, ok := diuo.mutation.SystemType(); ok { + _spec.SetField(deviceinfo.FieldSystemType, field.TypeEnum, value) } if value, ok := diuo.mutation.SystemVersion(); ok { _spec.SetField(deviceinfo.FieldSystemVersion, field.TypeString, value) diff --git a/app/sephirah/internal/data/internal/ent/migrate/schema.go b/app/sephirah/internal/data/internal/ent/migrate/schema.go index b147d6b..482db65 100644 --- a/app/sephirah/internal/data/internal/ent/migrate/schema.go +++ b/app/sephirah/internal/data/internal/ent/migrate/schema.go @@ -154,7 +154,8 @@ var ( // DeviceInfosColumns holds the columns for the "device_infos" table. DeviceInfosColumns = []*schema.Column{ {Name: "id", Type: field.TypeInt64}, - {Name: "device_model", Type: field.TypeString}, + {Name: "device_name", Type: field.TypeString}, + {Name: "system_type", Type: field.TypeEnum, Enums: []string{"ios", "android", "web", "windows", "macos", "linux", "unknown"}}, {Name: "system_version", Type: field.TypeString}, {Name: "client_name", Type: field.TypeString}, {Name: "client_source_code_address", Type: field.TypeString}, @@ -171,7 +172,7 @@ var ( ForeignKeys: []*schema.ForeignKey{ { Symbol: "device_infos_users_device_info", - Columns: []*schema.Column{DeviceInfosColumns[8]}, + Columns: []*schema.Column{DeviceInfosColumns[9]}, RefColumns: []*schema.Column{UsersColumns[0]}, OnDelete: schema.SetNull, }, diff --git a/app/sephirah/internal/data/internal/ent/mutation.go b/app/sephirah/internal/data/internal/ent/mutation.go index 4e1365d..3f5ff38 100644 --- a/app/sephirah/internal/data/internal/ent/mutation.go +++ b/app/sephirah/internal/data/internal/ent/mutation.go @@ -4513,7 +4513,8 @@ type DeviceInfoMutation struct { op Op typ string id *model.InternalID - device_model *string + device_name *string + system_type *deviceinfo.SystemType system_version *string client_name *string client_source_code_address *string @@ -4633,40 +4634,76 @@ func (m *DeviceInfoMutation) IDs(ctx context.Context) ([]model.InternalID, error } } -// SetDeviceModel sets the "device_model" field. -func (m *DeviceInfoMutation) SetDeviceModel(s string) { - m.device_model = &s +// SetDeviceName sets the "device_name" field. +func (m *DeviceInfoMutation) SetDeviceName(s string) { + m.device_name = &s } -// DeviceModel returns the value of the "device_model" field in the mutation. -func (m *DeviceInfoMutation) DeviceModel() (r string, exists bool) { - v := m.device_model +// DeviceName returns the value of the "device_name" field in the mutation. +func (m *DeviceInfoMutation) DeviceName() (r string, exists bool) { + v := m.device_name if v == nil { return } return *v, true } -// OldDeviceModel returns the old "device_model" field's value of the DeviceInfo entity. +// OldDeviceName returns the old "device_name" field's value of the DeviceInfo entity. // If the DeviceInfo 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 *DeviceInfoMutation) OldDeviceModel(ctx context.Context) (v string, err error) { +func (m *DeviceInfoMutation) OldDeviceName(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldDeviceModel is only allowed on UpdateOne operations") + return v, errors.New("OldDeviceName is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldDeviceModel requires an ID field in the mutation") + return v, errors.New("OldDeviceName requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldDeviceModel: %w", err) + return v, fmt.Errorf("querying old value for OldDeviceName: %w", err) } - return oldValue.DeviceModel, nil + return oldValue.DeviceName, nil } -// ResetDeviceModel resets all changes to the "device_model" field. -func (m *DeviceInfoMutation) ResetDeviceModel() { - m.device_model = nil +// ResetDeviceName resets all changes to the "device_name" field. +func (m *DeviceInfoMutation) ResetDeviceName() { + m.device_name = nil +} + +// SetSystemType sets the "system_type" field. +func (m *DeviceInfoMutation) SetSystemType(dt deviceinfo.SystemType) { + m.system_type = &dt +} + +// SystemType returns the value of the "system_type" field in the mutation. +func (m *DeviceInfoMutation) SystemType() (r deviceinfo.SystemType, exists bool) { + v := m.system_type + if v == nil { + return + } + return *v, true +} + +// OldSystemType returns the old "system_type" field's value of the DeviceInfo entity. +// If the DeviceInfo 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 *DeviceInfoMutation) OldSystemType(ctx context.Context) (v deviceinfo.SystemType, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldSystemType is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldSystemType requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldSystemType: %w", err) + } + return oldValue.SystemType, nil +} + +// ResetSystemType resets all changes to the "system_type" field. +func (m *DeviceInfoMutation) ResetSystemType() { + m.system_type = nil } // SetSystemVersion sets the "system_version" field. @@ -4973,9 +5010,12 @@ func (m *DeviceInfoMutation) Type() string { // order to get all numeric fields that were incremented/decremented, call // AddedFields(). func (m *DeviceInfoMutation) Fields() []string { - fields := make([]string, 0, 7) - if m.device_model != nil { - fields = append(fields, deviceinfo.FieldDeviceModel) + fields := make([]string, 0, 8) + if m.device_name != nil { + fields = append(fields, deviceinfo.FieldDeviceName) + } + if m.system_type != nil { + fields = append(fields, deviceinfo.FieldSystemType) } if m.system_version != nil { fields = append(fields, deviceinfo.FieldSystemVersion) @@ -5003,8 +5043,10 @@ func (m *DeviceInfoMutation) Fields() []string { // schema. func (m *DeviceInfoMutation) Field(name string) (ent.Value, bool) { switch name { - case deviceinfo.FieldDeviceModel: - return m.DeviceModel() + case deviceinfo.FieldDeviceName: + return m.DeviceName() + case deviceinfo.FieldSystemType: + return m.SystemType() case deviceinfo.FieldSystemVersion: return m.SystemVersion() case deviceinfo.FieldClientName: @@ -5026,8 +5068,10 @@ func (m *DeviceInfoMutation) Field(name string) (ent.Value, bool) { // database failed. func (m *DeviceInfoMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { - case deviceinfo.FieldDeviceModel: - return m.OldDeviceModel(ctx) + case deviceinfo.FieldDeviceName: + return m.OldDeviceName(ctx) + case deviceinfo.FieldSystemType: + return m.OldSystemType(ctx) case deviceinfo.FieldSystemVersion: return m.OldSystemVersion(ctx) case deviceinfo.FieldClientName: @@ -5049,12 +5093,19 @@ func (m *DeviceInfoMutation) OldField(ctx context.Context, name string) (ent.Val // type. func (m *DeviceInfoMutation) SetField(name string, value ent.Value) error { switch name { - case deviceinfo.FieldDeviceModel: + case deviceinfo.FieldDeviceName: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetDeviceModel(v) + m.SetDeviceName(v) + return nil + case deviceinfo.FieldSystemType: + v, ok := value.(deviceinfo.SystemType) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetSystemType(v) return nil case deviceinfo.FieldSystemVersion: v, ok := value.(string) @@ -5147,8 +5198,11 @@ func (m *DeviceInfoMutation) ClearField(name string) error { // It returns an error if the field is not defined in the schema. func (m *DeviceInfoMutation) ResetField(name string) error { switch name { - case deviceinfo.FieldDeviceModel: - m.ResetDeviceModel() + case deviceinfo.FieldDeviceName: + m.ResetDeviceName() + return nil + case deviceinfo.FieldSystemType: + m.ResetSystemType() return nil case deviceinfo.FieldSystemVersion: m.ResetSystemVersion() diff --git a/app/sephirah/internal/data/internal/ent/runtime.go b/app/sephirah/internal/data/internal/ent/runtime.go index bd6a725..25f0e9c 100644 --- a/app/sephirah/internal/data/internal/ent/runtime.go +++ b/app/sephirah/internal/data/internal/ent/runtime.go @@ -81,13 +81,13 @@ func init() { deviceinfoFields := schema.DeviceInfo{}.Fields() _ = deviceinfoFields // deviceinfoDescUpdatedAt is the schema descriptor for updated_at field. - deviceinfoDescUpdatedAt := deviceinfoFields[6].Descriptor() + deviceinfoDescUpdatedAt := deviceinfoFields[7].Descriptor() // deviceinfo.DefaultUpdatedAt holds the default value on creation for the updated_at field. deviceinfo.DefaultUpdatedAt = deviceinfoDescUpdatedAt.Default.(func() time.Time) // deviceinfo.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field. deviceinfo.UpdateDefaultUpdatedAt = deviceinfoDescUpdatedAt.UpdateDefault.(func() time.Time) // deviceinfoDescCreatedAt is the schema descriptor for created_at field. - deviceinfoDescCreatedAt := deviceinfoFields[7].Descriptor() + deviceinfoDescCreatedAt := deviceinfoFields[8].Descriptor() // deviceinfo.DefaultCreatedAt holds the default value on creation for the created_at field. deviceinfo.DefaultCreatedAt = deviceinfoDescCreatedAt.Default.(func() time.Time) feedFields := schema.Feed{}.Fields() diff --git a/app/sephirah/internal/data/internal/ent/schema/device_info.go b/app/sephirah/internal/data/internal/ent/schema/device_info.go index a391c6e..875b59f 100644 --- a/app/sephirah/internal/data/internal/ent/schema/device_info.go +++ b/app/sephirah/internal/data/internal/ent/schema/device_info.go @@ -15,7 +15,8 @@ type DeviceInfo struct { func (DeviceInfo) Fields() []ent.Field { return []ent.Field{ defaultPrimaryKey(), - field.String("device_model"), + field.String("device_name"), + field.Enum("system_type").Values("ios", "android", "web", "windows", "macos", "linux", "unknown"), field.String("system_version"), field.String("client_name"), field.String("client_source_code_address"), diff --git a/app/sephirah/internal/data/tiphereth.go b/app/sephirah/internal/data/tiphereth.go index f59aa47..14e29e3 100644 --- a/app/sephirah/internal/data/tiphereth.go +++ b/app/sephirah/internal/data/tiphereth.go @@ -51,7 +51,8 @@ func (t tipherethRepo) CreateDevice( ) error { return t.data.db.DeviceInfo.Create(). SetID(info.ID). - SetDeviceModel(info.DeviceModel). + SetDeviceName(info.DeviceName). + SetSystemType(converter.ToEntSystemType(info.SystemType)). SetSystemVersion(info.SystemVersion). SetClientName(info.ClientName). SetClientSourceCodeAddress(info.ClientSourceCodeAddress). diff --git a/app/sephirah/internal/model/converter/biz_to_pb.go b/app/sephirah/internal/model/converter/biz_to_pb.go index ff7b2b8..6bae9ec 100644 --- a/app/sephirah/internal/model/converter/biz_to_pb.go +++ b/app/sephirah/internal/model/converter/biz_to_pb.go @@ -31,6 +31,7 @@ type toPBConverter interface { //nolint:unused // used by generator // goverter:matchIgnoreCase // goverter:map ID DeviceId + // goverter:map SystemType | ToPBSystemType ToPBDeviceInfo(*modeltiphereth.DeviceInfo) *pb.DeviceInfo ToPBDeviceInfoList([]*modeltiphereth.DeviceInfo) []*pb.DeviceInfo @@ -53,6 +54,7 @@ type toPBConverter interface { //nolint:unused // used by generator // goverter:matchIgnoreCase // goverter:map Status | ToPBPorterStatus + // goverter:map ConnectionStatus | ToPBPorterConnectionStatus // goverter:ignore FeatureSummary ToPBPorter(*modeltiphereth.PorterInstance) *pb.Porter ToPBPorterList([]*modeltiphereth.PorterInstance) []*pb.Porter @@ -244,3 +246,41 @@ func ToPBNotifyFlowStatus(s modelnetzach.NotifyFlowStatus) pb.NotifyFlowStatus { return pb.NotifyFlowStatus_NOTIFY_FLOW_STATUS_UNSPECIFIED } } + +func ToPBSystemType(s modeltiphereth.SystemType) pb.SystemType { + switch s { + case modeltiphereth.SystemTypeUnspecified: + return pb.SystemType_SYSTEM_TYPE_UNSPECIFIED + case modeltiphereth.SystemTypeIOS: + return pb.SystemType_SYSTEM_TYPE_IOS + case modeltiphereth.SystemTypeAndroid: + return pb.SystemType_SYSTEM_TYPE_ANDROID + case modeltiphereth.SystemTypeWeb: + return pb.SystemType_SYSTEM_TYPE_WEB + case modeltiphereth.SystemTypeWindows: + return pb.SystemType_SYSTEM_TYPE_WINDOWS + case modeltiphereth.SystemTypeMacOS: + return pb.SystemType_SYSTEM_TYPE_MACOS + case modeltiphereth.SystemTypeLinux: + return pb.SystemType_SYSTEM_TYPE_LINUX + default: + return pb.SystemType_SYSTEM_TYPE_UNSPECIFIED + } +} + +func ToPBPorterConnectionStatus(s modeltiphereth.PorterConnectionStatus) pb.PorterConnectionStatus { + switch s { + case modeltiphereth.PorterConnectionStatusUnspecified: + return pb.PorterConnectionStatus_PORTER_CONNECTION_STATUS_UNSPECIFIED + case modeltiphereth.PorterConnectionStatusConnected: + return pb.PorterConnectionStatus_PORTER_CONNECTION_STATUS_CONNECTED + case modeltiphereth.PorterConnectionStatusDisconnected: + return pb.PorterConnectionStatus_PORTER_CONNECTION_STATUS_DISCONNECTED + case modeltiphereth.PorterConnectionStatusActive: + return pb.PorterConnectionStatus_PORTER_CONNECTION_STATUS_ACTIVE + case modeltiphereth.PorterConnectionStatusActivationFailed: + return pb.PorterConnectionStatus_PORTER_CONNECTION_STATUS_ACTIVATION_FAILED + default: + return pb.PorterConnectionStatus_PORTER_CONNECTION_STATUS_UNSPECIFIED + } +} diff --git a/app/sephirah/internal/model/converter/generated.go b/app/sephirah/internal/model/converter/generated.go index 353b53e..f17584e 100755 --- a/app/sephirah/internal/model/converter/generated.go +++ b/app/sephirah/internal/model/converter/generated.go @@ -151,7 +151,8 @@ func (c *toBizConverterImpl) ToBizDeviceInfo(source *v11.DeviceInfo) *modeltiphe if source != nil { var modeltipherethDeviceInfo modeltiphereth.DeviceInfo modeltipherethDeviceInfo.ID = ToBizInternalID((*source).DeviceId) - modeltipherethDeviceInfo.DeviceModel = (*source).DeviceModel + modeltipherethDeviceInfo.DeviceName = (*source).DeviceName + modeltipherethDeviceInfo.SystemType = ToBizSystemType((*source).SystemType) modeltipherethDeviceInfo.SystemVersion = (*source).SystemVersion modeltipherethDeviceInfo.ClientName = (*source).ClientName modeltipherethDeviceInfo.ClientSourceCodeAddress = (*source).ClientSourceCodeAddress @@ -587,7 +588,8 @@ func (c *toPBConverterImpl) ToPBDeviceInfo(source *modeltiphereth.DeviceInfo) *v if source != nil { var v1DeviceInfo v11.DeviceInfo v1DeviceInfo.DeviceId = ToPBInternalID((*source).ID) - v1DeviceInfo.DeviceModel = (*source).DeviceModel + v1DeviceInfo.DeviceName = (*source).DeviceName + v1DeviceInfo.SystemType = ToPBSystemType((*source).SystemType) v1DeviceInfo.SystemVersion = (*source).SystemVersion v1DeviceInfo.ClientName = (*source).ClientName v1DeviceInfo.ClientSourceCodeAddress = (*source).ClientSourceCodeAddress @@ -874,6 +876,7 @@ func (c *toPBConverterImpl) ToPBPorter(source *modeltiphereth.PorterInstance) *v v1Porter.Version = (*source).Version v1Porter.GlobalName = (*source).GlobalName v1Porter.Status = ToPBPorterStatus((*source).Status) + v1Porter.ConnectionStatus = ToPBPorterConnectionStatus((*source).ConnectionStatus) pV1Porter = &v1Porter } return pV1Porter diff --git a/app/sephirah/internal/model/converter/pb_to_biz.go b/app/sephirah/internal/model/converter/pb_to_biz.go index 3db0108..ffaf8b2 100644 --- a/app/sephirah/internal/model/converter/pb_to_biz.go +++ b/app/sephirah/internal/model/converter/pb_to_biz.go @@ -35,6 +35,8 @@ import ( // goverter:extend ToBizNotifyFlowStatus // goverter:extend ToBizFileType // goverter:extend ToBizAccountAppRelationType +// goverter:extend ToBizSystemType +// goverter:extend ToBizPorterConnectionStatus type toBizConverter interface { //nolint:unused // used by generator ToBizTimeRange(*librarian.TimeRange) *model.TimeRange // goverter:matchIgnoreCase @@ -266,3 +268,41 @@ func ToBizAccountAppRelationType(t librarian.AccountAppRelationType) model.Accou return model.AccountAppRelationTypeUnspecified } } + +func ToBizSystemType(t pb.SystemType) modeltiphereth.SystemType { + switch t { + case pb.SystemType_SYSTEM_TYPE_UNSPECIFIED: + return modeltiphereth.SystemTypeUnspecified + case pb.SystemType_SYSTEM_TYPE_IOS: + return modeltiphereth.SystemTypeIOS + case pb.SystemType_SYSTEM_TYPE_ANDROID: + return modeltiphereth.SystemTypeAndroid + case pb.SystemType_SYSTEM_TYPE_WEB: + return modeltiphereth.SystemTypeWeb + case pb.SystemType_SYSTEM_TYPE_WINDOWS: + return modeltiphereth.SystemTypeWindows + case pb.SystemType_SYSTEM_TYPE_MACOS: + return modeltiphereth.SystemTypeMacOS + case pb.SystemType_SYSTEM_TYPE_LINUX: + return modeltiphereth.SystemTypeLinux + default: + return modeltiphereth.SystemTypeUnspecified + } +} + +func ToBizPorterConnectionStatus(s pb.PorterConnectionStatus) modeltiphereth.PorterConnectionStatus { + switch s { + case pb.PorterConnectionStatus_PORTER_CONNECTION_STATUS_UNSPECIFIED: + return modeltiphereth.PorterConnectionStatusUnspecified + case pb.PorterConnectionStatus_PORTER_CONNECTION_STATUS_CONNECTED: + return modeltiphereth.PorterConnectionStatusConnected + case pb.PorterConnectionStatus_PORTER_CONNECTION_STATUS_DISCONNECTED: + return modeltiphereth.PorterConnectionStatusDisconnected + case pb.PorterConnectionStatus_PORTER_CONNECTION_STATUS_ACTIVE: + return modeltiphereth.PorterConnectionStatusActive + case pb.PorterConnectionStatus_PORTER_CONNECTION_STATUS_ACTIVATION_FAILED: + return modeltiphereth.PorterConnectionStatusActivationFailed + default: + return modeltiphereth.PorterConnectionStatusUnspecified + } +} diff --git a/app/sephirah/internal/model/modeltiphereth/modelsupervisor.go b/app/sephirah/internal/model/modeltiphereth/modelsupervisor.go index e9e2834..2d6db6b 100644 --- a/app/sephirah/internal/model/modeltiphereth/modelsupervisor.go +++ b/app/sephirah/internal/model/modeltiphereth/modelsupervisor.go @@ -5,13 +5,14 @@ import ( ) type PorterInstance struct { - ID model.InternalID - Name string - Version string - GlobalName string - Address string - FeatureSummary *PorterFeatureSummary - Status PorterInstanceStatus + ID model.InternalID + Name string + Version string + GlobalName string + Address string + FeatureSummary *PorterFeatureSummary + Status PorterInstanceStatus + ConnectionStatus PorterConnectionStatus } type PorterFeatureSummary struct { @@ -43,3 +44,13 @@ type ServerFeatureSummary struct { SupportedFeedSources []string SupportedNotifyDestinations []string } + +type PorterConnectionStatus int + +const ( + PorterConnectionStatusUnspecified PorterConnectionStatus = iota + PorterConnectionStatusConnected + PorterConnectionStatusDisconnected + PorterConnectionStatusActive + PorterConnectionStatusActivationFailed +) diff --git a/app/sephirah/internal/model/modeltiphereth/modeltiphereth.go b/app/sephirah/internal/model/modeltiphereth/modeltiphereth.go index 9ca8995..e128731 100644 --- a/app/sephirah/internal/model/modeltiphereth/modeltiphereth.go +++ b/app/sephirah/internal/model/modeltiphereth/modeltiphereth.go @@ -53,9 +53,22 @@ type UserSession struct { type DeviceInfo struct { ID model.InternalID - DeviceModel string + DeviceName string + SystemType SystemType SystemVersion string ClientName string ClientSourceCodeAddress string ClientVersion string } + +type SystemType int + +const ( + SystemTypeUnspecified SystemType = iota + SystemTypeAndroid + SystemTypeIOS + SystemTypeWindows + SystemTypeMacOS + SystemTypeLinux + SystemTypeWeb +) diff --git a/app/sephirah/internal/service/librariansephirahservice.go b/app/sephirah/internal/service/librariansephirahservice.go index 4224ff5..05d28f9 100644 --- a/app/sephirah/internal/service/librariansephirahservice.go +++ b/app/sephirah/internal/service/librariansephirahservice.go @@ -75,7 +75,8 @@ func (s *LibrarianSephirahServiceService) GetServerInformation(_ context.Context ProtocolSummary: &pb.ServerProtocolSummary{ Version: s.app.ProtoVersion, }, - CurrentTime: timestamppb.New(time.Now()), - FeatureSummary: converter.ToPBServerFeatureSummary(s.s.GetFeatureSummary()), + CurrentTime: timestamppb.New(time.Now()), + FeatureSummary: converter.ToPBServerFeatureSummary(s.s.GetFeatureSummary()), + ServerInstanceSummary: nil, }, nil } diff --git a/app/sephirah/internal/supervisor/supervisor.go b/app/sephirah/internal/supervisor/supervisor.go index e6817b1..794c227 100644 --- a/app/sephirah/internal/supervisor/supervisor.go +++ b/app/sephirah/internal/supervisor/supervisor.go @@ -127,13 +127,14 @@ func (s *Supervisor) RefreshAliveInstances( //nolint:gocognit // TODO } else { // new instance ins = &modeltiphereth.PorterInstance{ - ID: 0, - Name: info.GetName(), - Version: info.GetVersion(), - GlobalName: info.GetGlobalName(), - Address: address, - FeatureSummary: feature, - Status: modeltiphereth.PorterInstanceStatusUnspecified, + ID: 0, + Name: info.GetName(), + Version: info.GetVersion(), + GlobalName: info.GetGlobalName(), + Address: address, + FeatureSummary: feature, + Status: modeltiphereth.PorterInstanceStatusUnspecified, + ConnectionStatus: modeltiphereth.PorterConnectionStatusUnspecified, } } // new instance or feature changed diff --git a/go.mod b/go.mod index 44d6656..1d925d2 100644 --- a/go.mod +++ b/go.mod @@ -31,7 +31,7 @@ require ( github.com/redis/go-redis/v9 v9.4.0 github.com/sony/sonyflake v1.2.0 github.com/stretchr/testify v1.8.4 - github.com/tuihub/protos v0.3.8 + github.com/tuihub/protos v0.3.9 github.com/zhihu/norm v0.1.11 go.uber.org/ratelimit v0.3.0 go.uber.org/zap v1.26.0 diff --git a/go.sum b/go.sum index f6dbef8..b8d9371 100644 --- a/go.sum +++ b/go.sum @@ -926,8 +926,8 @@ github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+F github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY= github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= -github.com/tuihub/protos v0.3.8 h1:SMd+Ggi8e/66xGhhTxRTGag1RTNlI+X9boVhnwqbPec= -github.com/tuihub/protos v0.3.8/go.mod h1:oEU+QANr6l/E9StiEBW0W0vrnfGSjsQAVQGbFHPZOPc= +github.com/tuihub/protos v0.3.9 h1:ySvCGHi/k5e/i9XREPWel0U1B4EeBku7cuVHfbuDa0s= +github.com/tuihub/protos v0.3.9/go.mod h1:FvaMeevw4RUzHy5kNgbCHWk3fH25ApXEaNmPvDhXozc= github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM= github.com/tylertreat/BoomFilters v0.0.0-20181028192813-611b3dbe80e8/go.mod h1:OYRfF6eb5wY9VRFkXJH8FFBi3plw2v+giaIu7P054pM= github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc=