Первый прототип с основными возможностями

This commit is contained in:
2024-07-31 07:58:22 +03:00
parent 423cff473f
commit cf036565c4
41 changed files with 6969 additions and 2 deletions

44
ent/schema/link.go Normal file
View File

@@ -0,0 +1,44 @@
package schema
import (
"entgo.io/ent"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/index"
"github.com/google/uuid"
)
// URL holds the schema definition for the URL entity.
type Link struct {
ent.Schema
}
// Fields of the URL.
func (Link) Fields() []ent.Field {
return []ent.Field{
field.UUID("id", uuid.UUID{}).
Default(uuid.New).
Unique().
Immutable(),
field.String("key").
Unique(),
field.String("original_url").
NotEmpty(),
}
}
func (Link) Indexes() []ent.Index {
return []ent.Index{
index.Fields("key").
Unique(),
}
}
// Edges of the URL.
func (Link) Edges() []ent.Edge {
return []ent.Edge{
edge.From("owner", User.Type).
Required().
Ref("links"),
}
}

33
ent/schema/user.go Normal file
View File

@@ -0,0 +1,33 @@
package schema
import (
"entgo.io/ent"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
"github.com/google/uuid"
)
// User holds the schema definition for the User entity.
type User struct {
ent.Schema
}
// Fields of the User.
func (User) Fields() []ent.Field {
return []ent.Field{
field.UUID("id", uuid.UUID{}).
Default(uuid.New).
Unique().
Immutable(),
field.Int64("telegram_id").
Immutable().
Unique(),
}
}
// Edges of the User.
func (User) Edges() []ent.Edge {
return []ent.Edge{
edge.To("links", Link.Type),
}
}