From b01900ee77c45ca9dc6b1a78e09a0abb506d7b1e Mon Sep 17 00:00:00 2001 From: Gustavo Ocanto Date: Sat, 12 Jul 2025 15:18:35 +0800 Subject: [PATCH 1/9] wip --- cli/main.go | 19 +++++++++---------- cli/posts/handler.go | 17 ++++++++++++----- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/cli/main.go b/cli/main.go index 57d9726b..e2470ea0 100644 --- a/cli/main.go +++ b/cli/main.go @@ -8,7 +8,6 @@ import ( "github.com/oullin/env" "github.com/oullin/pkg" "github.com/oullin/pkg/cli" - "os" "time" ) @@ -25,15 +24,15 @@ func init() { func main() { cli.ClearScreen() - if err := guard.CaptureInput(); err != nil { - cli.Errorln(err.Error()) - return - } - - if guard.Rejects() { - cli.Errorln("Invalid credentials") - os.Exit(1) - } + //if err := guard.CaptureInput(); err != nil { + // cli.Errorln(err.Error()) + // return + //} + // + //if guard.Rejects() { + // cli.Errorln("Invalid credentials") + // os.Exit(1) + //} menu := panel.MakeMenu() diff --git a/cli/posts/handler.go b/cli/posts/handler.go index f3767fee..b1f0805a 100644 --- a/cli/posts/handler.go +++ b/cli/posts/handler.go @@ -5,6 +5,7 @@ import ( "github.com/oullin/database" "github.com/oullin/pkg/cli" "github.com/oullin/pkg/markdown" + "strings" "time" ) @@ -32,10 +33,14 @@ func (h Handler) HandlePost(payload *markdown.Post) error { Excerpt: payload.Excerpt, Content: payload.Content, ImageURL: payload.ImageURL, - Categories: h.ParseCategories(payload), + Categories: h.ParseCategory(payload), Tags: h.ParseTags(payload), } + fmt.Printf("attrs: %v+n\n", attrs.Categories) + + panic("here ....") + if _, err = h.Posts.Create(attrs); err != nil { return fmt.Errorf("handler: error persiting the post [%s]: %s", attrs.Title, err.Error()) } @@ -45,13 +50,15 @@ func (h Handler) HandlePost(payload *markdown.Post) error { return nil } -func (h Handler) ParseCategories(payload *markdown.Post) []database.CategoriesAttrs { +// ParseCategory: Category is given like so (leadership:) +func (h Handler) ParseCategory(payload *markdown.Post) []database.CategoriesAttrs { var categories []database.CategoriesAttrs + parts := strings.Split(payload.Category, ":") + slice := append(categories, database.CategoriesAttrs{ - Slug: payload.CategorySlug, - Name: payload.Category, - Description: "", + Slug: strings.Trim(parts[0], " "), + Name: strings.Trim(parts[1], " "), }) return slice From b64955fca51a2e927b5b8c033cbc9f63101e22b4 Mon Sep 17 00:00:00 2001 From: Gustavo Ocanto Date: Sat, 12 Jul 2025 15:28:00 +0800 Subject: [PATCH 2/9] wip --- cli/posts/factory.go | 2 +- cli/posts/handler.go | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/cli/posts/factory.go b/cli/posts/factory.go index 822c4dbe..84c2dba6 100644 --- a/cli/posts/factory.go +++ b/cli/posts/factory.go @@ -81,7 +81,7 @@ func (h Handler) RenderArticle(post *markdown.Post) { fmt.Printf("Author: %s\n", post.Author) fmt.Printf("Image URL: %s\n", post.ImageURL) fmt.Printf("Image Alt: %s\n", post.ImageAlt) - fmt.Printf("Category: %s\n", post.Category) + fmt.Printf("Category: %s\n", post.Categories) fmt.Printf("Category Slug: %s\n", post.CategorySlug) fmt.Printf("Tags Alt: %s\n", post.Tags) fmt.Println("\n--- Content ---") diff --git a/cli/posts/handler.go b/cli/posts/handler.go index b1f0805a..5917c3ec 100644 --- a/cli/posts/handler.go +++ b/cli/posts/handler.go @@ -33,7 +33,7 @@ func (h Handler) HandlePost(payload *markdown.Post) error { Excerpt: payload.Excerpt, Content: payload.Content, ImageURL: payload.ImageURL, - Categories: h.ParseCategory(payload), + Categories: h.ParseCategories(payload), Tags: h.ParseTags(payload), } @@ -50,18 +50,18 @@ func (h Handler) HandlePost(payload *markdown.Post) error { return nil } -// ParseCategory: Category is given like so (leadership:) -func (h Handler) ParseCategory(payload *markdown.Post) []database.CategoriesAttrs { +func (h Handler) ParseCategories(payload *markdown.Post) []database.CategoriesAttrs { var categories []database.CategoriesAttrs - parts := strings.Split(payload.Category, ":") + parts := strings.Split(payload.Categories, ",") - slice := append(categories, database.CategoriesAttrs{ - Slug: strings.Trim(parts[0], " "), - Name: strings.Trim(parts[1], " "), - }) + for _, part := range parts { + categories = append(categories, database.CategoriesAttrs{ + Slug: strings.Trim(part, " "), + }) + } - return slice + return categories } func (h Handler) ParseTags(payload *markdown.Post) []database.TagAttrs { From 19c1fad7fcb36a09ec86786e32c483112408b181 Mon Sep 17 00:00:00 2001 From: Gustavo Ocanto Date: Mon, 14 Jul 2025 11:18:41 +0800 Subject: [PATCH 3/9] work on parser --- cli/posts/factory.go | 3 +-- cli/posts/handler.go | 23 ++++++++++++++++------- pkg/markdown/handler.go | 20 -------------------- pkg/markdown/schema.go | 9 ++++----- 4 files changed, 21 insertions(+), 34 deletions(-) diff --git a/cli/posts/factory.go b/cli/posts/factory.go index 84c2dba6..c4664285 100644 --- a/cli/posts/factory.go +++ b/cli/posts/factory.go @@ -81,8 +81,7 @@ func (h Handler) RenderArticle(post *markdown.Post) { fmt.Printf("Author: %s\n", post.Author) fmt.Printf("Image URL: %s\n", post.ImageURL) fmt.Printf("Image Alt: %s\n", post.ImageAlt) - fmt.Printf("Category: %s\n", post.Categories) - fmt.Printf("Category Slug: %s\n", post.CategorySlug) + fmt.Printf("Categories: %s\n", post.Categories) fmt.Printf("Tags Alt: %s\n", post.Tags) fmt.Println("\n--- Content ---") fmt.Println(post.Content) diff --git a/cli/posts/handler.go b/cli/posts/handler.go index 5917c3ec..bf846600 100644 --- a/cli/posts/handler.go +++ b/cli/posts/handler.go @@ -25,6 +25,11 @@ func (h Handler) HandlePost(payload *markdown.Post) error { return fmt.Errorf("handler: the given published_at [%s] date is invalid", payload.PublishedAt) } + categories := h.ParseCategories(payload) + if len(categories) == 0 { + return fmt.Errorf("handler: the given categories [%v] are empty", payload.Categories) + } + attrs := database.PostsAttrs{ AuthorID: author.ID, PublishedAt: publishedAt, @@ -33,11 +38,12 @@ func (h Handler) HandlePost(payload *markdown.Post) error { Excerpt: payload.Excerpt, Content: payload.Content, ImageURL: payload.ImageURL, - Categories: h.ParseCategories(payload), + Categories: categories, Tags: h.ParseTags(payload), } - fmt.Printf("attrs: %v+n\n", attrs.Categories) + fmt.Printf("categories: %v\n", attrs.Categories) + fmt.Printf("tags: %v\n", h.ParseTags(payload)) panic("here ....") @@ -52,13 +58,16 @@ func (h Handler) HandlePost(payload *markdown.Post) error { func (h Handler) ParseCategories(payload *markdown.Post) []database.CategoriesAttrs { var categories []database.CategoriesAttrs - parts := strings.Split(payload.Categories, ",") - for _, part := range parts { - categories = append(categories, database.CategoriesAttrs{ - Slug: strings.Trim(part, " "), - }) + for _, category := range parts { + cat := strings.TrimSpace(category) + + if cat != "" { + categories = append(categories, database.CategoriesAttrs{ + Slug: cat, + }) + } } return categories diff --git a/pkg/markdown/handler.go b/pkg/markdown/handler.go index 29ef074c..1a488ef2 100644 --- a/pkg/markdown/handler.go +++ b/pkg/markdown/handler.go @@ -85,25 +85,5 @@ func Parse(data string) (*Post, error) { post.Content = body } - parseCategory(&post) - return &post, nil } - -func parseCategory(post *Post) { - category := post.FrontMatter.Category - parts := strings.Split(category, ":") - - post.Category = parts[1] - post.CategorySlug = parts[0] - - if len(parts) >= 2 { - post.Category = parts[1] - post.CategorySlug = parts[0] - - return - } - - post.Category = category - post.Slug = strings.ToLower(category) -} diff --git a/pkg/markdown/schema.go b/pkg/markdown/schema.go index 784b56c2..2d14f39e 100644 --- a/pkg/markdown/schema.go +++ b/pkg/markdown/schema.go @@ -11,17 +11,16 @@ type FrontMatter struct { Excerpt string `yaml:"excerpt"` Slug string `yaml:"slug"` Author string `yaml:"author"` - Category string `yaml:"category"` + Categories string `yaml:"categories"` PublishedAt string `yaml:"published_at"` Tags []string `yaml:"tags"` } type Post struct { FrontMatter - ImageURL string - ImageAlt string - Content string - CategorySlug string + ImageURL string + ImageAlt string + Content string } type Parser struct { From f5f775e0cd5e52d7fe13ce985f076957efeaebc6 Mon Sep 17 00:00:00 2001 From: Gustavo Ocanto Date: Mon, 14 Jul 2025 11:44:25 +0800 Subject: [PATCH 4/9] validate category --- cli/posts/factory.go | 14 +++++--------- cli/posts/handler.go | 18 ++++++++---------- database/attrs.go | 1 + 3 files changed, 14 insertions(+), 19 deletions(-) diff --git a/cli/posts/factory.go b/cli/posts/factory.go index c4664285..103b4e94 100644 --- a/cli/posts/factory.go +++ b/cli/posts/factory.go @@ -17,25 +17,21 @@ type Handler struct { Client *pkg.Client Posts *repository.Posts Users *repository.Users + Categories *repository.Categories IsDebugging bool } func MakeHandler(input *Input, client *pkg.Client, env *env.Environment) Handler { db := boost.MakeDbConnection(env) + categoriesRepository := &repository.Categories{DB: db} return Handler{ Input: input, Client: client, IsDebugging: false, - Posts: &repository.Posts{ - DB: db, - Categories: &repository.Categories{ - DB: db, - }, - }, - Users: &repository.Users{ - DB: db, - }, + Categories: categoriesRepository, + Posts: &repository.Posts{DB: db, Categories: categoriesRepository}, + Users: &repository.Users{DB: db}, } } diff --git a/cli/posts/handler.go b/cli/posts/handler.go index bf846600..a8281f52 100644 --- a/cli/posts/handler.go +++ b/cli/posts/handler.go @@ -42,11 +42,6 @@ func (h Handler) HandlePost(payload *markdown.Post) error { Tags: h.ParseTags(payload), } - fmt.Printf("categories: %v\n", attrs.Categories) - fmt.Printf("tags: %v\n", h.ParseTags(payload)) - - panic("here ....") - if _, err = h.Posts.Create(attrs); err != nil { return fmt.Errorf("handler: error persiting the post [%s]: %s", attrs.Title, err.Error()) } @@ -61,11 +56,14 @@ func (h Handler) ParseCategories(payload *markdown.Post) []database.CategoriesAt parts := strings.Split(payload.Categories, ",") for _, category := range parts { - cat := strings.TrimSpace(category) + slug := strings.TrimSpace(strings.ToLower(category)) - if cat != "" { + if item := h.Categories.FindBy(slug); item != nil { categories = append(categories, database.CategoriesAttrs{ - Slug: cat, + Slug: item.Slug, + Name: item.Name, + Id: item.ID, + Description: item.Description, }) } } @@ -78,8 +76,8 @@ func (h Handler) ParseTags(payload *markdown.Post) []database.TagAttrs { for _, tag := range payload.Tags { slice = append(slice, database.TagAttrs{ - Slug: tag, - Name: tag, + Slug: strings.TrimSpace(strings.ToLower(tag)), + Name: strings.TrimSpace(strings.ToLower(tag)), }) } diff --git a/database/attrs.go b/database/attrs.go index 8dc884fa..9830f8e7 100644 --- a/database/attrs.go +++ b/database/attrs.go @@ -11,6 +11,7 @@ type UsersAttrs struct { } type CategoriesAttrs struct { + Id uint64 Slug string Name string Description string From ba17db25d61ddca60ed310960d598c3cc873adac Mon Sep 17 00:00:00 2001 From: Gustavo Ocanto Date: Mon, 14 Jul 2025 12:31:01 +0800 Subject: [PATCH 5/9] remove transaction --- database/repository/posts.go | 37 ++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/database/repository/posts.go b/database/repository/posts.go index d05ea95c..011ca192 100644 --- a/database/repository/posts.go +++ b/database/repository/posts.go @@ -6,7 +6,6 @@ import ( "github.com/oullin/database" "github.com/oullin/env" "github.com/oullin/pkg/gorm" - baseGorm "gorm.io/gorm" ) type Posts struct { @@ -27,24 +26,30 @@ func (p Posts) Create(attrs database.PostsAttrs) (*database.Post, error) { PublishedAt: attrs.PublishedAt, } - err := p.DB.Transaction(func(db *baseGorm.DB) error { - // --- Post. - if result := db.Create(&post); gorm.HasDbIssues(result.Error) { - return fmt.Errorf("issue creating posts: %s", result.Error) - } + if result := p.DB.Sql().Create(&post); gorm.HasDbIssues(result.Error) { + return nil, fmt.Errorf("issue creating posts: %s", result.Error) + } - // --- Categories. - if _, err := p.Categories.CreateOrUpdate(post, attrs); err != nil { - return fmt.Errorf("issue creating the given post [%s] category: %s", attrs.Slug, err.Error()) - } + if err := p.LinkCategories(post, attrs.Categories); err != nil { + return nil, fmt.Errorf("issue creating the given post [%s] category: %s", attrs.Slug, err.Error()) + } - // --- Returning [nil] commits the whole transaction. - return nil - }) + //@todo Add tags tracking - if err != nil { - return nil, fmt.Errorf("error creating posts [%s]: %s", attrs.Title, err.Error()) + return &post, nil +} + +func (p Posts) LinkCategories(post database.Post, categories []database.CategoriesAttrs) error { + for _, category := range categories { + trace := database.PostCategory{ + CategoryID: category.Id, + PostID: post.ID, + } + + if result := p.DB.Sql().Create(&trace); gorm.HasDbIssues(result.Error) { + return fmt.Errorf("error linking categories [%s:%s]: %s", category.Name, post.Title, result.Error) + } } - return &post, nil + return nil } From 3d791fe21633b792f34dd9fe7569a91a93946971 Mon Sep 17 00:00:00 2001 From: Gustavo Ocanto Date: Mon, 14 Jul 2025 14:06:50 +0800 Subject: [PATCH 6/9] wire tags --- cli/posts/factory.go | 10 +++++----- cli/posts/handler.go | 22 ++++++++++++++-------- database/attrs.go | 1 + database/repository/posts.go | 28 +++++++++++++++++++++++++++- database/repository/tags.go | 31 +++++++++++++++++++++++++++++++ 5 files changed, 78 insertions(+), 14 deletions(-) create mode 100644 database/repository/tags.go diff --git a/cli/posts/factory.go b/cli/posts/factory.go index 103b4e94..e4a1859f 100644 --- a/cli/posts/factory.go +++ b/cli/posts/factory.go @@ -17,21 +17,21 @@ type Handler struct { Client *pkg.Client Posts *repository.Posts Users *repository.Users - Categories *repository.Categories IsDebugging bool } func MakeHandler(input *Input, client *pkg.Client, env *env.Environment) Handler { db := boost.MakeDbConnection(env) - categoriesRepository := &repository.Categories{DB: db} + + tags := &repository.Tags{DB: db} + categories := &repository.Categories{DB: db} return Handler{ Input: input, - Client: client, IsDebugging: false, - Categories: categoriesRepository, - Posts: &repository.Posts{DB: db, Categories: categoriesRepository}, + Client: client, Users: &repository.Users{DB: db}, + Posts: &repository.Posts{DB: db, Categories: categories, Tags: tags}, } } diff --git a/cli/posts/handler.go b/cli/posts/handler.go index a8281f52..1fd36c8d 100644 --- a/cli/posts/handler.go +++ b/cli/posts/handler.go @@ -58,7 +58,7 @@ func (h Handler) ParseCategories(payload *markdown.Post) []database.CategoriesAt for _, category := range parts { slug := strings.TrimSpace(strings.ToLower(category)) - if item := h.Categories.FindBy(slug); item != nil { + if item := h.Posts.FindCategoryBy(slug); item != nil { categories = append(categories, database.CategoriesAttrs{ Slug: item.Slug, Name: item.Name, @@ -72,14 +72,20 @@ func (h Handler) ParseCategories(payload *markdown.Post) []database.CategoriesAt } func (h Handler) ParseTags(payload *markdown.Post) []database.TagAttrs { - var slice []database.TagAttrs + var tags []database.TagAttrs + parts := strings.Split(payload.Categories, ",") + + for _, category := range parts { + slug := strings.TrimSpace(strings.ToLower(category)) - for _, tag := range payload.Tags { - slice = append(slice, database.TagAttrs{ - Slug: strings.TrimSpace(strings.ToLower(tag)), - Name: strings.TrimSpace(strings.ToLower(tag)), - }) + if item := h.Posts.FindTagBy(slug); item != nil { + tags = append(tags, database.TagAttrs{ + Id: item.ID, + Slug: slug, + Name: slug, + }) + } } - return slice + return tags } diff --git a/database/attrs.go b/database/attrs.go index 9830f8e7..d905a42f 100644 --- a/database/attrs.go +++ b/database/attrs.go @@ -18,6 +18,7 @@ type CategoriesAttrs struct { } type TagAttrs struct { + Id uint64 Slug string Name string } diff --git a/database/repository/posts.go b/database/repository/posts.go index 011ca192..1ada25d0 100644 --- a/database/repository/posts.go +++ b/database/repository/posts.go @@ -12,6 +12,15 @@ type Posts struct { DB *database.Connection Env *env.Environment Categories *Categories + Tags *Tags +} + +func (p Posts) FindCategoryBy(slug string) *database.Category { + return p.Categories.FindBy(slug) +} + +func (p Posts) FindTagBy(slug string) *database.Tag { + return p.Tags.FindBy(slug) } func (p Posts) Create(attrs database.PostsAttrs) (*database.Post, error) { @@ -34,7 +43,9 @@ func (p Posts) Create(attrs database.PostsAttrs) (*database.Post, error) { return nil, fmt.Errorf("issue creating the given post [%s] category: %s", attrs.Slug, err.Error()) } - //@todo Add tags tracking + if err := p.LinkTags(post, attrs.Tags); err != nil { + return nil, fmt.Errorf("issue creating the given post [%s] tags: %s", attrs.Slug, err.Error()) + } return &post, nil } @@ -53,3 +64,18 @@ func (p Posts) LinkCategories(post database.Post, categories []database.Categori return nil } + +func (p Posts) LinkTags(post database.Post, tags []database.TagAttrs) error { + for _, tag := range tags { + trace := database.PostTag{ + TagID: tag.Id, + PostID: post.ID, + } + + if result := p.DB.Sql().Create(&trace); gorm.HasDbIssues(result.Error) { + return fmt.Errorf("error linking tags [%s:%s]: %s", tag.Name, post.Title, result.Error) + } + } + + return nil +} diff --git a/database/repository/tags.go b/database/repository/tags.go new file mode 100644 index 00000000..a7392416 --- /dev/null +++ b/database/repository/tags.go @@ -0,0 +1,31 @@ +package repository + +import ( + "github.com/oullin/database" + "github.com/oullin/env" + "github.com/oullin/pkg/gorm" + "strings" +) + +type Tags struct { + DB *database.Connection + Env *env.Environment +} + +func (t Tags) FindBy(slug string) *database.Tag { + tag := database.Tag{} + + result := t.DB.Sql(). + Where("LOWER(slug) = ?", strings.ToLower(slug)). + First(&tag) + + if gorm.HasDbIssues(result.Error) { + return nil + } + + if strings.Trim(tag.UUID, " ") != "" { + return &tag + } + + return nil +} From f25174fdb8090e2ebb26af430c34b11f9c9099b7 Mon Sep 17 00:00:00 2001 From: Gustavo Ocanto Date: Mon, 14 Jul 2025 14:36:20 +0800 Subject: [PATCH 7/9] case the tag title --- cli/posts/handler.go | 5 ++--- database/repository/posts.go | 8 +++++++- database/repository/tags.go | 24 ++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/cli/posts/handler.go b/cli/posts/handler.go index 1fd36c8d..fcf01b7c 100644 --- a/cli/posts/handler.go +++ b/cli/posts/handler.go @@ -73,10 +73,9 @@ func (h Handler) ParseCategories(payload *markdown.Post) []database.CategoriesAt func (h Handler) ParseTags(payload *markdown.Post) []database.TagAttrs { var tags []database.TagAttrs - parts := strings.Split(payload.Categories, ",") - for _, category := range parts { - slug := strings.TrimSpace(strings.ToLower(category)) + for _, tag := range payload.Tags { + slug := strings.TrimSpace(strings.ToLower(tag)) if item := h.Posts.FindTagBy(slug); item != nil { tags = append(tags, database.TagAttrs{ diff --git a/database/repository/posts.go b/database/repository/posts.go index 1ada25d0..09075f40 100644 --- a/database/repository/posts.go +++ b/database/repository/posts.go @@ -20,7 +20,13 @@ func (p Posts) FindCategoryBy(slug string) *database.Category { } func (p Posts) FindTagBy(slug string) *database.Tag { - return p.Tags.FindBy(slug) + tag, err := p.Tags.FindOrCreate(slug) + + if err != nil { + return nil + } + + return tag } func (p Posts) Create(attrs database.PostsAttrs) (*database.Post, error) { diff --git a/database/repository/tags.go b/database/repository/tags.go index a7392416..5b298715 100644 --- a/database/repository/tags.go +++ b/database/repository/tags.go @@ -1,9 +1,13 @@ package repository import ( + "fmt" + "github.com/google/uuid" "github.com/oullin/database" "github.com/oullin/env" "github.com/oullin/pkg/gorm" + "golang.org/x/text/cases" + "golang.org/x/text/language" "strings" ) @@ -12,6 +16,26 @@ type Tags struct { Env *env.Environment } +func (t Tags) FindOrCreate(slug string) (*database.Tag, error) { + if item := t.FindBy(slug); item != nil { + return item, nil + } + + caser := cases.Title(language.English, cases.NoLower) + + tag := database.Tag{ + UUID: uuid.NewString(), + Slug: slug, + Name: caser.String(strings.ToLower(slug)), + } + + if result := t.DB.Sql().Save(&tag); gorm.HasDbIssues(result.Error) { + return nil, fmt.Errorf("error creating tag [%s]: %s", slug, result.Error) + } + + return &tag, nil +} + func (t Tags) FindBy(slug string) *database.Tag { tag := database.Tag{} From 8ab929e4086a680028d1243e6e1bbba7e3326bd8 Mon Sep 17 00:00:00 2001 From: Gustavo Ocanto Date: Mon, 14 Jul 2025 14:39:01 +0800 Subject: [PATCH 8/9] token --- cli/main.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/cli/main.go b/cli/main.go index e2470ea0..57d9726b 100644 --- a/cli/main.go +++ b/cli/main.go @@ -8,6 +8,7 @@ import ( "github.com/oullin/env" "github.com/oullin/pkg" "github.com/oullin/pkg/cli" + "os" "time" ) @@ -24,15 +25,15 @@ func init() { func main() { cli.ClearScreen() - //if err := guard.CaptureInput(); err != nil { - // cli.Errorln(err.Error()) - // return - //} - // - //if guard.Rejects() { - // cli.Errorln("Invalid credentials") - // os.Exit(1) - //} + if err := guard.CaptureInput(); err != nil { + cli.Errorln(err.Error()) + return + } + + if guard.Rejects() { + cli.Errorln("Invalid credentials") + os.Exit(1) + } menu := panel.MakeMenu() From 8aaa28a60e8b9112e6c317361fc7c90bcdb74c79 Mon Sep 17 00:00:00 2001 From: Gustavo Ocanto Date: Mon, 14 Jul 2025 14:50:27 +0800 Subject: [PATCH 9/9] format --- database/repository/categories.go | 4 +--- database/repository/posts.go | 2 -- database/repository/tags.go | 4 +--- 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/database/repository/categories.go b/database/repository/categories.go index 75490b52..53739b1f 100644 --- a/database/repository/categories.go +++ b/database/repository/categories.go @@ -4,14 +4,12 @@ import ( "fmt" "github.com/google/uuid" "github.com/oullin/database" - "github.com/oullin/env" "github.com/oullin/pkg/gorm" "strings" ) type Categories struct { - DB *database.Connection - Env *env.Environment + DB *database.Connection } func (c Categories) FindBy(slug string) *database.Category { diff --git a/database/repository/posts.go b/database/repository/posts.go index 09075f40..12c2ef0c 100644 --- a/database/repository/posts.go +++ b/database/repository/posts.go @@ -4,13 +4,11 @@ import ( "fmt" "github.com/google/uuid" "github.com/oullin/database" - "github.com/oullin/env" "github.com/oullin/pkg/gorm" ) type Posts struct { DB *database.Connection - Env *env.Environment Categories *Categories Tags *Tags } diff --git a/database/repository/tags.go b/database/repository/tags.go index 5b298715..eba250f7 100644 --- a/database/repository/tags.go +++ b/database/repository/tags.go @@ -4,7 +4,6 @@ import ( "fmt" "github.com/google/uuid" "github.com/oullin/database" - "github.com/oullin/env" "github.com/oullin/pkg/gorm" "golang.org/x/text/cases" "golang.org/x/text/language" @@ -12,8 +11,7 @@ import ( ) type Tags struct { - DB *database.Connection - Env *env.Environment + DB *database.Connection } func (t Tags) FindOrCreate(slug string) (*database.Tag, error) {