Compare commits

...

3 Commits

Author SHA1 Message Date
9fe2d0edc3 fix(database): make function more coherent with the rest
Some checks failed
Gitea Build Check / Build (push) Failing after 29s
2024-08-11 00:24:02 +02:00
46e6cdfa52 feat(database): added user 2024-08-11 00:23:47 +02:00
2b54f25eea feat(database): added all missing functions 2024-08-11 00:13:46 +02:00
10 changed files with 694 additions and 75 deletions

127
pkg/database/post.go Normal file
View File

@ -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
}

View File

@ -8,43 +8,40 @@ import (
"gorm.io/gorm" "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 { 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 result.Error != nil {
if errors.Is(result.Error, gorm.ErrDuplicatedKey) { 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 { if client == nil {
return &otterError.Database{Reason: otterError.DatabaseIsNotConnected} return &otterError.Database{Reason: otterError.DatabaseIsNotConnected}
} }
if len(userSource.ID) == 0 { if source == nil {
return &otterError.EntityValidationFailed{Reason: otterError.UserSourceIDEmpty} return &otterError.EntityValidationFailed{Reason: otterError.SourceListIsEmpty}
} }
updatedUserSource := models.UserSource{ if len(source) == 0 {
BaseModel: models.BaseModel[models.UserSourceID]{ return &otterError.EntityValidationFailed{Reason: otterError.SourceListIsEmpty}
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 batchSize == 0 {
return &otterError.EntityValidationFailed{Reason: otterError.BatchSizeIsEmpty}
}
result := client.WithContext(ctx).CreateInBatches(&source, batchSize)
if result.Error != nil { if result.Error != nil {
if errors.Is(result.Error, gorm.ErrDuplicatedKey) { if errors.Is(result.Error, gorm.ErrDuplicatedKey) {
return &otterError.Database{Reason: otterError.DuplicateKey} return &otterError.Database{Reason: otterError.DuplicateKey}
@ -55,48 +52,96 @@ func UpdateUserSource(ctx context.Context, userSource models.UserSource) error {
return nil return nil
} }
func GetUserSourceByID(ctx context.Context, id models.UserSourceID) (models.UserSource, error) { func UpdateSource(ctx context.Context, source models.Source) 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
if client == nil { if client == nil {
return &otterError.Database{Reason: otterError.DatabaseIsNotConnected} return &otterError.Database{Reason: otterError.DatabaseIsNotConnected}
} }
if len(id) == 0 { if len(source.ID) == 0 {
return &otterError.EntityValidationFailed{Reason: otterError.UserSourceIDEmpty} return &otterError.EntityValidationFailed{Reason: otterError.SourceIDIsEmpty}
} }
if len(id) != 25 { updateSource := models.Source{
return &otterError.EntityValidationFailed{Reason: otterError.UserSourceIDToShort} 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 result.Error != nil {
if errors.Is(result.Error, gorm.ErrRecordNotFound) { if errors.Is(result.Error, gorm.ErrRecordNotFound) {
return &otterError.Database{Reason: otterError.NoDataFound} return &otterError.Database{Reason: otterError.NoDataFound}

81
pkg/database/tag.go Normal file
View File

@ -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) (models.Tag, error) {
if client == nil {
return models.Tag{}, &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 models.Tag{}, &otterError.Database{Reason: otterError.DuplicateKey}
}
return models.Tag{}, result.Error
}
return tag, 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
}

80
pkg/database/tagAlias.go Normal file
View File

@ -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) (models.TagAlias, error) {
if client == nil {
return models.TagAlias{}, &otterError.Database{Reason: otterError.DatabaseIsNotConnected}
}
tagAlias := models.TagAlias{
Name: tagAliasName,
TagID: tagName,
}
result := client.WithContext(ctx).Create(&tagAlias)
if result.Error != nil {
if errors.Is(result.Error, gorm.ErrDuplicatedKey) {
return models.TagAlias{}, &otterError.Database{Reason: otterError.DuplicateKey}
}
return models.TagAlias{}, result.Error
}
return tagAlias, 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
}

80
pkg/database/tagGroup.go Normal file
View File

@ -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) (models.TagGroup, error) {
if client == nil {
return models.TagGroup{}, &otterError.Database{Reason: otterError.DatabaseIsNotConnected}
}
tagGroup := models.TagGroup{
Name: tagGroupName,
TagID: tagName,
}
result := client.WithContext(ctx).Create(&tagGroup)
if result.Error != nil {
if errors.Is(result.Error, gorm.ErrDuplicatedKey) {
return models.TagGroup{}, &otterError.Database{Reason: otterError.DuplicateKey}
}
return models.TagGroup{}, result.Error
}
return tagGroup, 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
}

79
pkg/database/user.go Normal file
View File

@ -0,0 +1,79 @@
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 CreateUser(ctx context.Context, id models.UserID) (models.User, error) {
if client == nil {
return models.User{}, &otterError.Database{Reason: otterError.DatabaseIsNotConnected}
}
user := models.User{
BaseModel: models.BaseModel[models.UserID]{
ID: id,
},
}
result := client.WithContext(ctx).Create(&user)
if result.Error != nil {
if errors.Is(result.Error, gorm.ErrDuplicatedKey) {
return models.User{}, &otterError.Database{Reason: otterError.DuplicateKey}
}
return models.User{}, result.Error
}
return user, nil
}
func GetUserByID(ctx context.Context, id models.UserID) (models.User, error) {
var user models.User
if client == nil {
return models.User{}, &otterError.Database{Reason: otterError.DatabaseIsNotConnected}
}
if len(id) == 0 {
return models.User{}, &otterError.EntityValidationFailed{Reason: otterError.UserIDIsEmpty}
}
if len(id) != 25 {
return models.User{}, &otterError.EntityValidationFailed{Reason: otterError.UserIDToShort}
}
result := client.WithContext(ctx).First(&user, "id = ?", id)
if result.Error != nil {
if errors.Is(result.Error, gorm.ErrRecordNotFound) {
return models.User{}, &otterError.Database{Reason: otterError.NoDataFound}
}
return models.User{}, result.Error
}
return user, nil
}
func DeleteUser(ctx context.Context, id models.UserID) error {
var user models.User
if client == nil {
return &otterError.Database{Reason: otterError.DatabaseIsNotConnected}
}
if len(id) == 0 {
return &otterError.EntityValidationFailed{Reason: otterError.UserIDIsEmpty}
}
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
}

108
pkg/database/userSource.go Normal file
View File

@ -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
}

View File

@ -3,16 +3,33 @@ package error
import "fmt" import "fmt"
const ( const (
UserIDIsEmpty = "PostID cannot be empty" UserIDIsEmpty = "postID cannot be empty"
UserIDToShort = "PostID needs to be 25 characters long" UserIDToShort = "postID needs to be 25 characters long"
SourceIDEmpty = "SourceID cannot be empty"
SourceIDToShort = "SourceID needs to be 25 characters long" SourceListIsEmpty = "sourceList cannot be empty"
UserSourceIDEmpty = "UserSourceID cannot be empty" SourceIDIsEmpty = "SourceID cannot be empty"
UserSourceIDToShort = "UserSourceID needs to be 25 characters long" SourceIDToShort = "sourceID needs to be 25 characters long"
TagIDEmpty = "tagID cannot be empty" 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" UserFavoriteListIsEmpty = "userFavoriteList cannot be empty"
UserFavoriteIDIsEmpty = "userFavoriteID 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" BatchSizeIsEmpty = "batchSize cannot be empty"
) )

View File

@ -3,17 +3,19 @@ package models
import "time" import "time"
type ( type (
UserID string UserID string
PostID string PostID string
SourceID string PostURL string
SourceDomain string
PostURL string SourceID string
TagGroupName string SourceDomain string
TagAliasName string
TagID string TagName string
TagGroupName string
TagAliasName string
ScrapeTimeInterval int ScrapeTimeInterval int
UserLastScrapeTime time.Time UserLastScrapeTime time.Time
TagName string
Rating string Rating string
TagType string TagType string

View File

@ -2,7 +2,7 @@ package models
// Tag models // Tag models
type Tag struct { type Tag struct {
Name string `json:"name" gorm:"primaryKey"` Name TagName `json:"name" gorm:"primaryKey"`
Type TagType `json:"type" gorm:"column:tag_type"` Type TagType `json:"type" gorm:"column:tag_type"`
Aliases []TagAlias `json:"aliases" gorm:"foreignKey:TagID"` Aliases []TagAlias `json:"aliases" gorm:"foreignKey:TagID"`
Groups []TagGroup `json:"groups" gorm:"foreignKey:TagID"` Groups []TagGroup `json:"groups" gorm:"foreignKey:TagID"`
@ -15,8 +15,8 @@ func (Tag) TableName() string {
// TagAlias model // TagAlias model
type TagAlias struct { type TagAlias struct {
Name string `json:"name" gorm:"primaryKey"` Name TagAliasName `json:"name" gorm:"primaryKey"`
TagID string `json:"tag_id"` TagID TagName `json:"tag_id"`
} }
func (TagAlias) TableName() string { func (TagAlias) TableName() string {
@ -25,8 +25,8 @@ func (TagAlias) TableName() string {
// TagGroup model // TagGroup model
type TagGroup struct { type TagGroup struct {
Name string `json:"name" gorm:"primaryKey"` Name TagGroupName `json:"name" gorm:"primaryKey"`
TagID string `json:"tag_id"` TagID TagName `json:"tag_id"`
} }
func (TagGroup) TableName() string { func (TagGroup) TableName() string {