From 2b54f25eeacae08b7f9f0f1234d8d321a8d9a454 Mon Sep 17 00:00:00 2001 From: SoXX Date: Sun, 11 Aug 2024 00:13:46 +0200 Subject: [PATCH] feat(database): added all missing functions --- pkg/database/post.go | 127 +++++++++++++++++++++++++++++++ pkg/database/source.go | 151 ++++++++++++++++++++++++------------- pkg/database/tag.go | 81 ++++++++++++++++++++ pkg/database/tagAlias.go | 80 ++++++++++++++++++++ pkg/database/tagGroup.go | 80 ++++++++++++++++++++ pkg/database/userSource.go | 108 ++++++++++++++++++++++++++ pkg/error/validation.go | 33 ++++++-- pkg/models/const.go | 20 ++--- pkg/models/tag.go | 10 +-- 9 files changed, 615 insertions(+), 75 deletions(-) create mode 100644 pkg/database/post.go create mode 100644 pkg/database/tag.go create mode 100644 pkg/database/tagAlias.go create mode 100644 pkg/database/tagGroup.go create mode 100644 pkg/database/userSource.go diff --git a/pkg/database/post.go b/pkg/database/post.go new file mode 100644 index 0000000..989c39a --- /dev/null +++ b/pkg/database/post.go @@ -0,0 +1,127 @@ +package database + +import ( + "context" + "errors" + otterError "git.anthrove.art/Anthrove/otter-space-sdk/v2/pkg/error" + "git.anthrove.art/Anthrove/otter-space-sdk/v2/pkg/models" + "gorm.io/gorm" +) + +func CreatePost(ctx context.Context, post models.Post) (models.Post, error) { + if client == nil { + return models.Post{}, &otterError.Database{Reason: otterError.DatabaseIsNotConnected} + } + + result := client.WithContext(ctx).Create(&post) + if result.Error != nil { + if errors.Is(result.Error, gorm.ErrDuplicatedKey) { + return models.Post{}, &otterError.Database{Reason: otterError.DuplicateKey} + } + return models.Post{}, result.Error + } + + return post, nil +} + +func CreatePostInBatch(ctx context.Context, post []models.Post, batchSize int) error { + if client == nil { + return &otterError.Database{Reason: otterError.DatabaseIsNotConnected} + } + + if post == nil { + return &otterError.EntityValidationFailed{Reason: otterError.PostListIsEmpty} + } + + if len(post) == 0 { + return &otterError.EntityValidationFailed{Reason: otterError.PostListIsEmpty} + } + + if batchSize == 0 { + return &otterError.EntityValidationFailed{Reason: otterError.BatchSizeIsEmpty} + } + + result := client.WithContext(ctx).CreateInBatches(&post, batchSize) + if result.Error != nil { + if errors.Is(result.Error, gorm.ErrDuplicatedKey) { + return &otterError.Database{Reason: otterError.DuplicateKey} + } + return result.Error + } + + return nil +} + +func GetPostByID(ctx context.Context, id models.PostID) (models.Post, error) { + var post models.Post + + if client == nil { + return models.Post{}, &otterError.Database{Reason: otterError.DatabaseIsNotConnected} + } + + if len(id) == 0 { + return models.Post{}, &otterError.EntityValidationFailed{Reason: otterError.PostIDIsEmpty} + } + + result := client.WithContext(ctx).First(&post, "id = ?", id) + if result.Error != nil { + if errors.Is(result.Error, gorm.ErrRecordNotFound) { + return models.Post{}, &otterError.Database{Reason: otterError.NoDataFound} + } + return models.Post{}, result.Error + } + + return post, nil +} + +func UpdatePost(ctx context.Context, anthrovePost models.Post) error { + if client == nil { + return &otterError.Database{Reason: otterError.DatabaseIsNotConnected} + } + + if len(anthrovePost.ID) == 0 { + return &otterError.EntityValidationFailed{Reason: otterError.PostIDIsEmpty} + } + + updatePost := models.Post{ + Rating: anthrovePost.Rating, + Tags: anthrovePost.Tags, + References: anthrovePost.References, + } + + result := client.WithContext(ctx).Model(&updatePost).Update("deleted_at", gorm.DeletedAt{}) + if result.Error != nil { + if errors.Is(result.Error, gorm.ErrRecordNotFound) { + return &otterError.Database{Reason: otterError.NoDataFound} + } + return result.Error + } + + return nil +} + +func DeletePost(ctx context.Context, id models.PostID) error { + var userFavorite models.UserFavorite + + if client == nil { + return &otterError.Database{Reason: otterError.DatabaseIsNotConnected} + } + + if len(id) == 0 { + return &otterError.EntityValidationFailed{Reason: otterError.PostIDIsEmpty} + } + + if len(id) != 25 { + return &otterError.EntityValidationFailed{Reason: otterError.PostIDToShort} + } + + result := client.WithContext(ctx).Delete(&userFavorite, "id = ?", id) + if result.Error != nil { + if errors.Is(result.Error, gorm.ErrRecordNotFound) { + return &otterError.Database{Reason: otterError.NoDataFound} + } + return result.Error + } + + return nil +} diff --git a/pkg/database/source.go b/pkg/database/source.go index d808b74..89116a2 100644 --- a/pkg/database/source.go +++ b/pkg/database/source.go @@ -8,43 +8,40 @@ import ( "gorm.io/gorm" ) -func CreateUserSource(ctx context.Context, userSource models.UserSource) (models.UserSource, error) { +func CreateSource(ctx context.Context, source models.Source) (models.Source, error) { if client == nil { - return models.UserSource{}, &otterError.Database{Reason: otterError.DatabaseIsNotConnected} + return models.Source{}, &otterError.Database{Reason: otterError.DatabaseIsNotConnected} } - result := client.WithContext(ctx).Create(&userSource) + result := client.WithContext(ctx).Create(&source) if result.Error != nil { if errors.Is(result.Error, gorm.ErrDuplicatedKey) { - return models.UserSource{}, &otterError.Database{Reason: otterError.DuplicateKey} + return models.Source{}, &otterError.Database{Reason: otterError.DuplicateKey} } - return models.UserSource{}, result.Error + return models.Source{}, result.Error } - return userSource, nil + return source, nil } -func UpdateUserSource(ctx context.Context, userSource models.UserSource) error { +func CreateSourceInBatch(ctx context.Context, source []models.Source, batchSize int) error { if client == nil { return &otterError.Database{Reason: otterError.DatabaseIsNotConnected} } - if len(userSource.ID) == 0 { - return &otterError.EntityValidationFailed{Reason: otterError.UserSourceIDEmpty} + if source == nil { + return &otterError.EntityValidationFailed{Reason: otterError.SourceListIsEmpty} } - updatedUserSource := models.UserSource{ - BaseModel: models.BaseModel[models.UserSourceID]{ - ID: userSource.ID, - }, - ScrapeTimeInterval: userSource.ScrapeTimeInterval, - AccountUsername: userSource.AccountUsername, - AccountID: userSource.AccountID, - LastScrapeTime: userSource.LastScrapeTime, - AccountValidate: userSource.AccountValidate, + if len(source) == 0 { + return &otterError.EntityValidationFailed{Reason: otterError.SourceListIsEmpty} } - result := client.WithContext(ctx).Updates(&updatedUserSource) + if batchSize == 0 { + return &otterError.EntityValidationFailed{Reason: otterError.BatchSizeIsEmpty} + } + + result := client.WithContext(ctx).CreateInBatches(&source, batchSize) if result.Error != nil { if errors.Is(result.Error, gorm.ErrDuplicatedKey) { return &otterError.Database{Reason: otterError.DuplicateKey} @@ -55,48 +52,96 @@ func UpdateUserSource(ctx context.Context, userSource models.UserSource) error { return nil } -func GetUserSourceByID(ctx context.Context, id models.UserSourceID) (models.UserSource, error) { - var user models.UserSource - - if client == nil { - return models.UserSource{}, &otterError.Database{Reason: otterError.DatabaseIsNotConnected} - } - - if len(id) == 0 { - return models.UserSource{}, &otterError.EntityValidationFailed{Reason: otterError.UserSourceIDEmpty} - } - - if len(id) != 25 { - return models.UserSource{}, &otterError.EntityValidationFailed{Reason: otterError.UserSourceIDToShort} - } - - result := client.WithContext(ctx).First(&user, "id = ?", id) - if result.Error != nil { - if errors.Is(result.Error, gorm.ErrRecordNotFound) { - return models.UserSource{}, &otterError.Database{Reason: otterError.NoDataFound} - } - return models.UserSource{}, result.Error - } - - return user, nil -} - -func DeleteUserSource(ctx context.Context, id models.UserSourceID) error { - var user models.UserSource - +func UpdateSource(ctx context.Context, source models.Source) error { if client == nil { return &otterError.Database{Reason: otterError.DatabaseIsNotConnected} } - if len(id) == 0 { - return &otterError.EntityValidationFailed{Reason: otterError.UserSourceIDEmpty} + if len(source.ID) == 0 { + return &otterError.EntityValidationFailed{Reason: otterError.SourceIDIsEmpty} } - if len(id) != 25 { - return &otterError.EntityValidationFailed{Reason: otterError.UserSourceIDToShort} + updateSource := models.Source{ + DisplayName: source.DisplayName, + Domain: source.Domain, + Icon: source.Icon, } - result := client.WithContext(ctx).Delete(&user, id) + result := client.WithContext(ctx).Model(&updateSource).Update("deleted_at", gorm.DeletedAt{}) + if result.Error != nil { + if errors.Is(result.Error, gorm.ErrRecordNotFound) { + return &otterError.Database{Reason: otterError.NoDataFound} + } + return result.Error + } + + return nil +} + +func GetSourceByID(ctx context.Context, id models.SourceID) (models.Source, error) { + var source models.Source + + if client == nil { + return models.Source{}, &otterError.Database{Reason: otterError.DatabaseIsNotConnected} + } + + if len(id) == 0 { + return models.Source{}, &otterError.EntityValidationFailed{Reason: otterError.SourceIDIsEmpty} + } + + if len(id) != 25 { + return models.Source{}, &otterError.EntityValidationFailed{Reason: otterError.SourceIDToShort} + } + + result := client.WithContext(ctx).First(&source, "id = ?", id) + if result.Error != nil { + if errors.Is(result.Error, gorm.ErrRecordNotFound) { + return models.Source{}, &otterError.Database{Reason: otterError.NoDataFound} + } + return models.Source{}, result.Error + } + + return source, nil +} + +func GetSourceByDomain(ctx context.Context, sourceDomain models.SourceDomain) (models.Source, error) { + var source models.Source + + if client == nil { + return models.Source{}, &otterError.Database{Reason: otterError.DatabaseIsNotConnected} + } + + if len(sourceDomain) == 0 { + return models.Source{}, &otterError.EntityValidationFailed{Reason: otterError.SourceDomainIsEmpty} + } + + result := client.WithContext(ctx).First(&source, "domain = ?", sourceDomain) + if result.Error != nil { + if errors.Is(result.Error, gorm.ErrRecordNotFound) { + return models.Source{}, &otterError.Database{Reason: otterError.NoDataFound} + } + return models.Source{}, result.Error + } + + return source, nil +} + +func DeleteSource(ctx context.Context, id models.SourceID) error { + var source models.Source + + if client == nil { + return &otterError.Database{Reason: otterError.DatabaseIsNotConnected} + } + + if len(id) == 0 { + return &otterError.EntityValidationFailed{Reason: otterError.SourceIDIsEmpty} + } + + if len(id) != 25 { + return &otterError.EntityValidationFailed{Reason: otterError.SourceIDToShort} + } + + result := client.WithContext(ctx).Delete(&source, id) if result.Error != nil { if errors.Is(result.Error, gorm.ErrRecordNotFound) { return &otterError.Database{Reason: otterError.NoDataFound} diff --git a/pkg/database/tag.go b/pkg/database/tag.go new file mode 100644 index 0000000..50fe70a --- /dev/null +++ b/pkg/database/tag.go @@ -0,0 +1,81 @@ +package database + +import ( + "context" + "errors" + otterError "git.anthrove.art/Anthrove/otter-space-sdk/v2/pkg/error" + "git.anthrove.art/Anthrove/otter-space-sdk/v2/pkg/models" + "gorm.io/gorm" +) + +func CreateTag(ctx context.Context, tagName models.TagName, tagType models.TagType) error { + + if client == nil { + return &otterError.Database{Reason: otterError.DatabaseIsNotConnected} + } + + tag := models.Tag{ + Name: tagName, + Type: tagType, + } + + result := client.WithContext(ctx).Create(&tag) + if result.Error != nil { + if errors.Is(result.Error, gorm.ErrDuplicatedKey) { + return &otterError.Database{Reason: otterError.DuplicateKey} + } + return result.Error + } + + return nil +} + +func CreateTagInBatch(ctx context.Context, tags []models.Tag, batchSize int) error { + if client == nil { + return &otterError.Database{Reason: otterError.DatabaseIsNotConnected} + } + + if tags == nil { + return &otterError.EntityValidationFailed{Reason: otterError.TagListIsEmpty} + } + + if len(tags) == 0 { + return &otterError.EntityValidationFailed{Reason: otterError.TagListIsEmpty} + } + + if batchSize == 0 { + return &otterError.EntityValidationFailed{Reason: otterError.BatchSizeIsEmpty} + } + + result := client.WithContext(ctx).CreateInBatches(&tags, batchSize) + if result.Error != nil { + if errors.Is(result.Error, gorm.ErrDuplicatedKey) { + return &otterError.Database{Reason: otterError.DuplicateKey} + } + return result.Error + } + + return nil +} + +func DeleteTag(ctx context.Context, tagName models.TagName) error { + var tag models.Tag + + if client == nil { + return &otterError.Database{Reason: otterError.DatabaseIsNotConnected} + } + + if len(tagName) == 0 { + return &otterError.EntityValidationFailed{Reason: otterError.TagNameIsEmpty} + } + + result := client.WithContext(ctx).Delete(&tag, tagName) + if result.Error != nil { + if errors.Is(result.Error, gorm.ErrRecordNotFound) { + return &otterError.Database{Reason: otterError.NoDataFound} + } + return result.Error + } + + return nil +} diff --git a/pkg/database/tagAlias.go b/pkg/database/tagAlias.go new file mode 100644 index 0000000..58d231b --- /dev/null +++ b/pkg/database/tagAlias.go @@ -0,0 +1,80 @@ +package database + +import ( + "context" + "errors" + otterError "git.anthrove.art/Anthrove/otter-space-sdk/v2/pkg/error" + "git.anthrove.art/Anthrove/otter-space-sdk/v2/pkg/models" + "gorm.io/gorm" +) + +func CreateTagAlias(ctx context.Context, tagAliasName models.TagAliasName, tagName models.TagName) error { + if client == nil { + return &otterError.Database{Reason: otterError.DatabaseIsNotConnected} + } + + tag := models.TagAlias{ + Name: tagAliasName, + TagID: tagName, + } + + result := client.WithContext(ctx).Create(&tag) + if result.Error != nil { + if errors.Is(result.Error, gorm.ErrDuplicatedKey) { + return &otterError.Database{Reason: otterError.DuplicateKey} + } + return result.Error + } + + return nil +} + +func CreateTagAliasInBatch(ctx context.Context, tagsAliases []models.TagAlias, batchSize int) error { + if client == nil { + return &otterError.Database{Reason: otterError.DatabaseIsNotConnected} + } + + if tagsAliases == nil { + return &otterError.EntityValidationFailed{Reason: otterError.TagAliasListIsEmpty} + } + + if len(tagsAliases) == 0 { + return &otterError.EntityValidationFailed{Reason: otterError.TagAliasListIsEmpty} + } + + if batchSize == 0 { + return &otterError.EntityValidationFailed{Reason: otterError.BatchSizeIsEmpty} + } + + result := client.WithContext(ctx).CreateInBatches(&tagsAliases, batchSize) + if result.Error != nil { + if errors.Is(result.Error, gorm.ErrDuplicatedKey) { + return &otterError.Database{Reason: otterError.DuplicateKey} + } + return result.Error + } + + return nil +} + +func DeleteTagAlias(ctx context.Context, tagAliasName models.TagAliasName) error { + var tagAlias models.TagAlias + + if client == nil { + return &otterError.Database{Reason: otterError.DatabaseIsNotConnected} + } + + if len(tagAliasName) == 0 { + return &otterError.EntityValidationFailed{Reason: otterError.TagAliasNameIsEmpty} + } + + result := client.WithContext(ctx).Delete(&tagAlias, tagAliasName) + if result.Error != nil { + if errors.Is(result.Error, gorm.ErrRecordNotFound) { + return &otterError.Database{Reason: otterError.NoDataFound} + } + return result.Error + } + + return nil +} diff --git a/pkg/database/tagGroup.go b/pkg/database/tagGroup.go new file mode 100644 index 0000000..287cb60 --- /dev/null +++ b/pkg/database/tagGroup.go @@ -0,0 +1,80 @@ +package database + +import ( + "context" + "errors" + otterError "git.anthrove.art/Anthrove/otter-space-sdk/v2/pkg/error" + "git.anthrove.art/Anthrove/otter-space-sdk/v2/pkg/models" + "gorm.io/gorm" +) + +func CreateTagGroup(ctx context.Context, tagGroupName models.TagGroupName, tagName models.TagName) error { + if client == nil { + return &otterError.Database{Reason: otterError.DatabaseIsNotConnected} + } + + tag := models.TagGroup{ + Name: tagGroupName, + TagID: tagName, + } + + result := client.WithContext(ctx).Create(&tag) + if result.Error != nil { + if errors.Is(result.Error, gorm.ErrDuplicatedKey) { + return &otterError.Database{Reason: otterError.DuplicateKey} + } + return result.Error + } + + return nil +} + +func CreateTagGroupInBatch(ctx context.Context, tagsGroups []models.TagGroup, batchSize int) error { + if client == nil { + return &otterError.Database{Reason: otterError.DatabaseIsNotConnected} + } + + if tagsGroups == nil { + return &otterError.EntityValidationFailed{Reason: otterError.TagGroupListIsEmpty} + } + + if len(tagsGroups) == 0 { + return &otterError.EntityValidationFailed{Reason: otterError.TagGroupListIsEmpty} + } + + if batchSize == 0 { + return &otterError.EntityValidationFailed{Reason: otterError.BatchSizeIsEmpty} + } + + result := client.WithContext(ctx).CreateInBatches(&tagsGroups, batchSize) + if result.Error != nil { + if errors.Is(result.Error, gorm.ErrDuplicatedKey) { + return &otterError.Database{Reason: otterError.DuplicateKey} + } + return result.Error + } + + return nil +} + +func DeleteTagGroup(ctx context.Context, tagGroupName models.TagGroupName) error { + var tagGroup models.TagGroup + + if client == nil { + return &otterError.Database{Reason: otterError.DatabaseIsNotConnected} + } + + if len(tagGroupName) == 0 { + return &otterError.EntityValidationFailed{Reason: otterError.TagGroupNameIsEmpty} + } + + result := client.WithContext(ctx).Delete(&tagGroup, tagGroupName) + if result.Error != nil { + if errors.Is(result.Error, gorm.ErrRecordNotFound) { + return &otterError.Database{Reason: otterError.NoDataFound} + } + return result.Error + } + + return nil +} diff --git a/pkg/database/userSource.go b/pkg/database/userSource.go new file mode 100644 index 0000000..bf1879d --- /dev/null +++ b/pkg/database/userSource.go @@ -0,0 +1,108 @@ +package database + +import ( + "context" + "errors" + otterError "git.anthrove.art/Anthrove/otter-space-sdk/v2/pkg/error" + "git.anthrove.art/Anthrove/otter-space-sdk/v2/pkg/models" + "gorm.io/gorm" +) + +func CreateUserSource(ctx context.Context, userSource models.UserSource) (models.UserSource, error) { + if client == nil { + return models.UserSource{}, &otterError.Database{Reason: otterError.DatabaseIsNotConnected} + } + + result := client.WithContext(ctx).Create(&userSource) + if result.Error != nil { + if errors.Is(result.Error, gorm.ErrDuplicatedKey) { + return models.UserSource{}, &otterError.Database{Reason: otterError.DuplicateKey} + } + return models.UserSource{}, result.Error + } + + return userSource, nil +} + +func UpdateUserSource(ctx context.Context, userSource models.UserSource) error { + if client == nil { + return &otterError.Database{Reason: otterError.DatabaseIsNotConnected} + } + + if len(userSource.ID) == 0 { + return &otterError.EntityValidationFailed{Reason: otterError.UserSourceIDIsEmpty} + } + + updatedUserSource := models.UserSource{ + BaseModel: models.BaseModel[models.UserSourceID]{ + ID: userSource.ID, + }, + ScrapeTimeInterval: userSource.ScrapeTimeInterval, + AccountUsername: userSource.AccountUsername, + AccountID: userSource.AccountID, + LastScrapeTime: userSource.LastScrapeTime, + AccountValidate: userSource.AccountValidate, + } + + result := client.WithContext(ctx).Updates(&updatedUserSource) + if result.Error != nil { + if errors.Is(result.Error, gorm.ErrDuplicatedKey) { + return &otterError.Database{Reason: otterError.DuplicateKey} + } + return result.Error + } + + return nil +} + +func GetUserSourceByID(ctx context.Context, id models.UserSourceID) (models.UserSource, error) { + var user models.UserSource + + if client == nil { + return models.UserSource{}, &otterError.Database{Reason: otterError.DatabaseIsNotConnected} + } + + if len(id) == 0 { + return models.UserSource{}, &otterError.EntityValidationFailed{Reason: otterError.UserSourceIDIsEmpty} + } + + if len(id) != 25 { + return models.UserSource{}, &otterError.EntityValidationFailed{Reason: otterError.UserSourceIDToShort} + } + + result := client.WithContext(ctx).First(&user, "id = ?", id) + if result.Error != nil { + if errors.Is(result.Error, gorm.ErrRecordNotFound) { + return models.UserSource{}, &otterError.Database{Reason: otterError.NoDataFound} + } + return models.UserSource{}, result.Error + } + + return user, nil +} + +func DeleteUserSource(ctx context.Context, id models.UserSourceID) error { + var user models.UserSource + + if client == nil { + return &otterError.Database{Reason: otterError.DatabaseIsNotConnected} + } + + if len(id) == 0 { + return &otterError.EntityValidationFailed{Reason: otterError.UserSourceIDIsEmpty} + } + + if len(id) != 25 { + return &otterError.EntityValidationFailed{Reason: otterError.UserSourceIDToShort} + } + + result := client.WithContext(ctx).Delete(&user, id) + if result.Error != nil { + if errors.Is(result.Error, gorm.ErrRecordNotFound) { + return &otterError.Database{Reason: otterError.NoDataFound} + } + return result.Error + } + + return nil +} diff --git a/pkg/error/validation.go b/pkg/error/validation.go index 360e40b..0e27823 100644 --- a/pkg/error/validation.go +++ b/pkg/error/validation.go @@ -3,16 +3,33 @@ package error import "fmt" const ( - UserIDIsEmpty = "PostID cannot be empty" - UserIDToShort = "PostID needs to be 25 characters long" - SourceIDEmpty = "SourceID cannot be empty" - SourceIDToShort = "SourceID needs to be 25 characters long" - UserSourceIDEmpty = "UserSourceID cannot be empty" - UserSourceIDToShort = "UserSourceID needs to be 25 characters long" - TagIDEmpty = "tagID cannot be empty" + UserIDIsEmpty = "postID cannot be empty" + UserIDToShort = "postID needs to be 25 characters long" + + SourceListIsEmpty = "sourceList cannot be empty" + SourceIDIsEmpty = "SourceID cannot be empty" + SourceIDToShort = "sourceID needs to be 25 characters long" + SourceDomainIsEmpty = "source Domain cannot be empty" + + UserSourceIDIsEmpty = "userSourceID cannot be empty" + UserSourceIDToShort = "userSourceID needs to be 25 characters long" + + TagListIsEmpty = "tagList cannot be empty" + TagNameIsEmpty = "tagName cannot be empty" + + TagAliasListIsEmpty = "tagAliasList cannot be empty" + TagAliasNameIsEmpty = "tagAliasName cannot be empty" + + TagGroupListIsEmpty = "tagGroupList cannot be empty" + TagGroupNameIsEmpty = "tagGroupName cannot be empty" + UserFavoriteListIsEmpty = "userFavoriteList cannot be empty" UserFavoriteIDIsEmpty = "userFavoriteID cannot be empty" - UserFavoriteIDToShort = "UserFavoriteID needs to be 25 characters long" + UserFavoriteIDToShort = "userFavoriteID needs to be 25 characters long" + + PostListIsEmpty = "userFavoriteList cannot be empty" + PostIDIsEmpty = "userFavoriteID cannot be empty" + PostIDToShort = "PostID needs to be 25 characters long" BatchSizeIsEmpty = "batchSize cannot be empty" ) diff --git a/pkg/models/const.go b/pkg/models/const.go index 4f690a4..a6f25bc 100644 --- a/pkg/models/const.go +++ b/pkg/models/const.go @@ -3,17 +3,19 @@ package models import "time" type ( - UserID string - PostID string - SourceID string - SourceDomain string - PostURL string - TagGroupName string - TagAliasName string - TagID string + UserID string + PostID string + PostURL string + + SourceID string + SourceDomain string + + TagName string + TagGroupName string + TagAliasName string + ScrapeTimeInterval int UserLastScrapeTime time.Time - TagName string Rating string TagType string diff --git a/pkg/models/tag.go b/pkg/models/tag.go index 09fafb9..53b5c1a 100644 --- a/pkg/models/tag.go +++ b/pkg/models/tag.go @@ -2,7 +2,7 @@ package models // Tag models type Tag struct { - Name string `json:"name" gorm:"primaryKey"` + Name TagName `json:"name" gorm:"primaryKey"` Type TagType `json:"type" gorm:"column:tag_type"` Aliases []TagAlias `json:"aliases" gorm:"foreignKey:TagID"` Groups []TagGroup `json:"groups" gorm:"foreignKey:TagID"` @@ -15,8 +15,8 @@ func (Tag) TableName() string { // TagAlias model type TagAlias struct { - Name string `json:"name" gorm:"primaryKey"` - TagID string `json:"tag_id"` + Name TagAliasName `json:"name" gorm:"primaryKey"` + TagID TagName `json:"tag_id"` } func (TagAlias) TableName() string { @@ -25,8 +25,8 @@ func (TagAlias) TableName() string { // TagGroup model type TagGroup struct { - Name string `json:"name" gorm:"primaryKey"` - TagID string `json:"tag_id"` + Name TagGroupName `json:"name" gorm:"primaryKey"` + TagID TagName `json:"tag_id"` } func (TagGroup) TableName() string {