From 0d2b38110af629a4a1eab56f0b1192a48dec3ad9 Mon Sep 17 00:00:00 2001 From: Buravit Yenjit Date: Tue, 1 Apr 2025 13:39:25 +0700 Subject: [PATCH] feat: add knowledgeHub domain --- backend/internal/domain/knowledgeHub.go | 58 +++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 backend/internal/domain/knowledgeHub.go diff --git a/backend/internal/domain/knowledgeHub.go b/backend/internal/domain/knowledgeHub.go new file mode 100644 index 0000000..3a8a39f --- /dev/null +++ b/backend/internal/domain/knowledgeHub.go @@ -0,0 +1,58 @@ +package domain + +import ( + "context" + "time" + + validation "github.com/go-ozzo/ozzo-validation/v4" +) + +type KnowledgeArticle struct { + UUID string + Title string + Content string + Author string + PublishDate time.Time + ReadTime string + Categories []string + CreatedAt time.Time + UpdatedAt time.Time +} + +func (k *KnowledgeArticle) Validate() error { + return validation.ValidateStruct(k, + validation.Field(&k.Title, validation.Required), + validation.Field(&k.Content, validation.Required), + validation.Field(&k.Author, validation.Required), + validation.Field(&k.PublishDate, validation.Required), + ) +} + +type TableOfContent struct { + UUID string + ArticleID string + Title string + Order int + CreatedAt time.Time + UpdatedAt time.Time +} + +type RelatedArticle struct { + UUID string + ArticleID string + RelatedTitle string + RelatedTag string + CreatedAt time.Time + UpdatedAt time.Time +} + +type KnowledgeHubRepository interface { + GetArticleByID(context.Context, string) (KnowledgeArticle, error) + GetArticlesByCategory(ctx context.Context, category string) ([]KnowledgeArticle, error) + GetAllArticles(ctx context.Context) ([]KnowledgeArticle, error) + CreateOrUpdateArticle(context.Context, *KnowledgeArticle) error + DeleteArticle(context.Context, string) error + + GetTableOfContents(ctx context.Context, articleID string) ([]TableOfContent, error) + GetRelatedArticles(ctx context.Context, articleID string) ([]RelatedArticle, error) +}