Skip to content

Commit

Permalink
fix: Doesn't meet the "no source" principle, see #1
Browse files Browse the repository at this point in the history
  • Loading branch information
excing committed Feb 7, 2021
1 parent 701b595 commit 4a6f65a
Show file tree
Hide file tree
Showing 15 changed files with 301 additions and 167 deletions.
41 changes: 41 additions & 0 deletions ent/schema/archive.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package schema

import (
"time"

"github.com/facebook/ent"
"github.com/facebook/ent/schema/edge"
"github.com/facebook/ent/schema/field"
)

// Archive holds the schema definition for the Archive entity.
type Archive struct {
ent.Schema
}

// Fields of the Archive.
func (Archive) Fields() []ent.Field {
return []ent.Field{
field.Enum("status").
Values("star", "watch", "self").
Default("star").
Comment("star: a node favored by the user; watch: a node followed by the user; self: a private node created by the user."),
field.Time("created_at").Default(time.Now),
}
}

// Edges of the Archive.
func (Archive) Edges() []ent.Edge {
return []ent.Edge{
edge.From("user", User.Type).
Ref("archives").
Unique().
Required().
Comment("The owner of the archive"),
edge.From("node", Node.Type).
Ref("archives").
Unique().
Required(),
edge.To("assets", Asset.Type),
}
}
11 changes: 7 additions & 4 deletions ent/schema/article.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,20 @@ type Article struct {
// Fields of the Article.
func (Article) Fields() []ent.Field {
return []ent.Field{
field.Enum("status").Values("private", "public").Default("private"),
field.Int("id"),
field.Enum("status").
Values("private", "public").
Default("public").
Comment("public: all users can access; private: only the source user can access."),
}
}

// Edges of the Article.
func (Article) Edges() []ent.Edge {
return []ent.Edge{
edge.To("versions", Content.Type),
edge.To("main", Article.Type).Unique(),
edge.To("versions", Version.Type),
edge.To("reactions", Reaction.Type),
edge.To("quote", Quote.Type).Unique(),
edge.To("stars", Star.Type),
edge.To("assets", Asset.Type),
}
}
45 changes: 45 additions & 0 deletions ent/schema/asset.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package schema

import (
"time"

"github.com/facebook/ent"
"github.com/facebook/ent/schema/edge"
"github.com/facebook/ent/schema/field"
)

// Asset holds the schema definition for the Asset entity.
type Asset struct {
ent.Schema
}

// Fields of the Asset.
func (Asset) Fields() []ent.Field {
return []ent.Field{
field.Enum("status").
Values("browse", "star", "watch", "self").
Default("browse").
Comment("browse: Articles visited by users.").
Comment("star: a article favored by the user.").
Comment("watch: a article followed by the user.").
Comment("self: a private article created by the user."),
field.Time("created_at").Default(time.Now),
}
}

// Edges of the Asset.
func (Asset) Edges() []ent.Edge {
return []ent.Edge{
edge.From("user", User.Type).
Ref("assets").
Unique().
Required().
Comment("The owner of the asset"),
edge.From("article", Article.Type).
Ref("assets").
Unique().
Required(),
edge.From("archives", Archive.Type).
Ref("assets"),
}
}
8 changes: 2 additions & 6 deletions ent/schema/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,15 @@ func (Content) Fields() []ent.Field {
field.String("title").Optional(),
field.String("gist").Optional(),
field.String("body").Default(""),
field.Int("version").Default(1),
field.String("versionName").Optional().Unique(),
field.String("seo").Optional(),
field.Time("created_at").Default(time.Now),
}
}

// Edges of the Content.
func (Content) Edges() []ent.Edge {
return []ent.Edge{
edge.From("tags", Tag.Type).Ref("contents"),
edge.From("article", Article.Type).Ref("versions").Unique().Required(),
edge.To("lang", Language.Type).Unique().Required(),
edge.To("main", Content.Type).Unique().Comment("Main is a copy of the main branch of the current copy."),
edge.From("version", Version.Type).Ref("content").Unique().Required(),
edge.To("sections", Section.Type),
}
}
3 changes: 2 additions & 1 deletion ent/schema/language.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ type Language struct {
// Fields of the Language.
func (Language) Fields() []ent.Field {
return []ent.Field{
field.String("id").
field.String("code").
MaxLen(3).
NotEmpty().
Unique().
Immutable().Comment("Codes for the Representation of Names of Languages"),
field.String("name"),
field.Enum("direction").Values("ltr", "rtl").Default("ltr").Comment("Text writing direction"),
field.String("comment").Optional(),
}
}

Expand Down
22 changes: 16 additions & 6 deletions ent/schema/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,31 @@ type Node struct {
// Fields of the Node.
func (Node) Fields() []ent.Field {
return []ent.Field{
field.String("cover").Optional(),
field.Int("level"),
field.Enum("status").
Values("private", "public").
Default("private").
Comment("public: all tags on the node path are public; private: there is at least one private tag on the path."),
}
}

// Edges of the Node.
func (Node) Edges() []ent.Edge {
return []ent.Edge{
edge.From("tag", Tag.Type).Ref("nodes").Unique().Required(),
edge.To("fork", Node.Type).
From("form").
edge.From("tag", Tag.Type).
Ref("nodes").
Unique().
Required(),
edge.To("subnodes", Node.Type).
Comment("subnodes: the next subdivision node of this node").
From("belong").
Comment("belong: belong to which node").
Unique(),
edge.To("nodes", Node.Type).
edge.To("branches", Node.Type).
Comment("branches: root node attribute, which means all branch nodes under the root node.").
From("root").
Comment("root: the root node of the current node.").
Unique(),
edge.To("stars", Star.Type),
edge.To("archives", Archive.Type),
}
}
2 changes: 1 addition & 1 deletion ent/schema/ras.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (RAS) Fields() []ent.Field {
// Edges of the RAS.
func (RAS) Edges() []ent.Edge {
return []ent.Edge{
edge.To("content", Content.Type).Unique().Required().
edge.To("version", Version.Type).Unique().Required().
Comment("The content is being voted, if allowed, it will be redirected to the content where published to the public space"),
edge.To("voters", User.Type).Required().
Comment("Voters are randomly selected and they will vote anonymously."),
Expand Down
5 changes: 3 additions & 2 deletions ent/schema/reaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ type Reaction struct {
// Fields of the Reaction.
func (Reaction) Fields() []ent.Field {
return []ent.Field{
field.String("name"),
field.String("emoji"),
field.Enum("status").
Values("up", "down", "laugh", "hooray", "confused", "heart", "rocket", "eyes").
Comment("Refer to the Reaction list on GitHub"),
field.Int("count"),
}
}
Expand Down
32 changes: 32 additions & 0 deletions ent/schema/section.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package schema

import (
"github.com/facebook/ent"
"github.com/facebook/ent/schema/edge"
"github.com/facebook/ent/schema/field"
)

// Section holds the schema definition for the Section entity.
type Section struct {
ent.Schema
}

// Fields of the Section.
func (Section) Fields() []ent.Field {
return []ent.Field{
field.Int("index"),
field.String("text"),
field.Enum("type").Values("title", "text", "gist", "case").Default("text"),
}
}

// Edges of the Section.
func (Section) Edges() []ent.Edge {
return []ent.Edge{
edge.To("subsections", Section.Type).
Comment("subsections: the next subdivision sections of this section").
From("belong").
Comment("belong: belong to which pact").
Unique(),
}
}
37 changes: 0 additions & 37 deletions ent/schema/star.go

This file was deleted.

6 changes: 5 additions & 1 deletion ent/schema/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@ type Tag struct {
func (Tag) Fields() []ent.Field {
return []ent.Field{
field.String("name"),
field.Enum("status").
Values("private", "public").
Default("private").
Comment("public: tags associated with public articles; private: tags associated with private articles and not associated with public articles."),
}
}

// Edges of the Tag.
func (Tag) Edges() []ent.Edge {
return []ent.Edge{
edge.To("contents", Content.Type),
edge.To("versions", Version.Type),
edge.To("nodes", Node.Type),
}
}
5 changes: 3 additions & 2 deletions ent/schema/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ func (User) Fields() []ent.Field {
// Edges of the User.
func (User) Edges() []ent.Edge {
return []ent.Edge{
edge.To("stars", Star.Type),
edge.To("articles", Article.Type),
edge.To("assets", Asset.Type),
edge.To("archives", Archive.Type),
edge.To("drafts", Version.Type),
}
}
35 changes: 35 additions & 0 deletions ent/schema/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package schema

import (
"github.com/facebook/ent"
"github.com/facebook/ent/schema/edge"
"github.com/facebook/ent/schema/field"
)

// Version holds the schema definition for the Version entity.
type Version struct {
ent.Schema
}

// Fields of the Version.
func (Version) Fields() []ent.Field {
return []ent.Field{
field.Enum("status").
Values("editing", "voting", "published").
Default("editing").
Comment("editing: The article version is in the editing state. Other users can't access and except the editor.").
Comment("voting: The article version is in voting status. Except for editors and voters, no other users can access. Editors can't edit, but they can withdraw publish.").
Comment("published: The article version is in the published state. If the article is public, everyone can access it, and if the article is private, only the source user can access it."),
field.String("seo").Optional(),
}
}

// Edges of the Version.
func (Version) Edges() []ent.Edge {
return []ent.Edge{
edge.To("content", Content.Type).Unique(),
edge.From("tags", Tag.Type).Ref("versions"),
edge.From("article", Article.Type).Ref("versions").Unique().Required(),
edge.To("lang", Language.Type).Unique().Required(),
}
}
4 changes: 3 additions & 1 deletion ent/schema/vote.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ type Vote struct {
func (Vote) Fields() []ent.Field {
return []ent.Field{
field.Enum("status").Values("allowed", "rejected", "abstained"),
field.String("response").Optional().Comment("Response to voting content"),
field.Time("created_at").Default(time.Now),
}
}

// Edges of the Vote.
func (Vote) Edges() []ent.Edge {
return []ent.Edge{
edge.To("feedback", Section.Type).
Unique().
Comment("feedback to voting content"),
edge.To("ras", RAS.Type).Unique(),
}
}
Loading

0 comments on commit 4a6f65a

Please sign in to comment.