fix(errors): added const
All checks were successful
Gitea Build Check / Build (push) Successful in 10m58s
All checks were successful
Gitea Build Check / Build (push) Successful in 10m58s
Signed-off-by: SoXX <soxx@fenpa.ws>
This commit is contained in:
parent
c550531a35
commit
4fa936d774
@ -3,6 +3,7 @@ package postgres
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
errors2 "git.dragse.it/anthrove/otter-space-sdk/pkg/errors"
|
errors2 "git.dragse.it/anthrove/otter-space-sdk/pkg/errors"
|
||||||
"git.dragse.it/anthrove/otter-space-sdk/pkg/models"
|
"git.dragse.it/anthrove/otter-space-sdk/pkg/models"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
@ -13,11 +14,11 @@ func CreateReferenceBetweenPostAndSource(ctx context.Context, db *gorm.DB, anthr
|
|||||||
var source models.Source
|
var source models.Source
|
||||||
|
|
||||||
if anthrovePostID == "" {
|
if anthrovePostID == "" {
|
||||||
return &errors2.EntityValidationFailed{Reason: "anthrovePostID cannot be empty"}
|
return &errors2.EntityValidationFailed{Reason: errors2.AnthroveUserIDIsEmpty}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(anthrovePostID) != 25 {
|
if len(anthrovePostID) != 25 {
|
||||||
return &errors2.EntityValidationFailed{Reason: "anthrovePostID needs to be 25 characters long"}
|
return &errors2.EntityValidationFailed{Reason: errors2.AnthroveUserIDToShort}
|
||||||
}
|
}
|
||||||
|
|
||||||
if sourceDomain == "" {
|
if sourceDomain == "" {
|
||||||
@ -62,11 +63,11 @@ func CreateReferenceBetweenPostAndSource(ctx context.Context, db *gorm.DB, anthr
|
|||||||
func CreateReferenceBetweenUserAndPost(ctx context.Context, db *gorm.DB, anthroveUserID models.AnthroveUserID, anthrovePostID models.AnthrovePostID) error {
|
func CreateReferenceBetweenUserAndPost(ctx context.Context, db *gorm.DB, anthroveUserID models.AnthroveUserID, anthrovePostID models.AnthrovePostID) error {
|
||||||
|
|
||||||
if anthrovePostID == "" {
|
if anthrovePostID == "" {
|
||||||
return &errors2.EntityValidationFailed{Reason: "anthrovePostID cannot be empty"}
|
return &errors2.EntityValidationFailed{Reason: errors2.AnthroveUserIDIsEmpty}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(anthrovePostID) != 25 {
|
if len(anthrovePostID) != 25 {
|
||||||
return &errors2.EntityValidationFailed{Reason: "anthrovePostID needs to be 25 characters long"}
|
return &errors2.EntityValidationFailed{Reason: errors2.AnthroveUserIDToShort}
|
||||||
}
|
}
|
||||||
|
|
||||||
if anthroveUserID == "" {
|
if anthroveUserID == "" {
|
||||||
@ -102,11 +103,11 @@ func CheckReferenceBetweenUserAndPost(ctx context.Context, db *gorm.DB, anthrove
|
|||||||
var count int64
|
var count int64
|
||||||
|
|
||||||
if anthrovePostID == "" {
|
if anthrovePostID == "" {
|
||||||
return false, &errors2.EntityValidationFailed{Reason: "anthrovePostID cannot be empty"}
|
return false, &errors2.EntityValidationFailed{Reason: errors2.AnthroveUserIDIsEmpty}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(anthrovePostID) != 25 {
|
if len(anthrovePostID) != 25 {
|
||||||
return false, &errors2.EntityValidationFailed{Reason: "anthrovePostID needs to be 25 characters long"}
|
return false, &errors2.EntityValidationFailed{Reason: errors2.AnthroveUserIDToShort}
|
||||||
}
|
}
|
||||||
|
|
||||||
if anthroveUserID == "" {
|
if anthroveUserID == "" {
|
||||||
|
@ -13,11 +13,11 @@ import (
|
|||||||
func CreateUser(ctx context.Context, db *gorm.DB, anthroveUserID models.AnthroveUserID) error {
|
func CreateUser(ctx context.Context, db *gorm.DB, anthroveUserID models.AnthroveUserID) error {
|
||||||
|
|
||||||
if anthroveUserID == "" {
|
if anthroveUserID == "" {
|
||||||
return &errors2.EntityValidationFailed{Reason: "anthroveUserID cannot be empty"}
|
return &errors2.EntityValidationFailed{Reason: errors2.AnthroveUserIDIsEmpty}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(anthroveUserID) != 25 {
|
if len(anthroveUserID) != 25 {
|
||||||
return &errors2.EntityValidationFailed{Reason: "anthroveUserID needs to be 25 characters long"}
|
return &errors2.EntityValidationFailed{Reason: errors2.AnthroveUserIDToShort}
|
||||||
}
|
}
|
||||||
|
|
||||||
user := models.User{
|
user := models.User{
|
||||||
@ -40,11 +40,11 @@ func CreateUser(ctx context.Context, db *gorm.DB, anthroveUserID models.Anthrove
|
|||||||
func CreateUserWithRelationToSource(ctx context.Context, db *gorm.DB, anthroveUserID models.AnthroveUserID, sourceID models.AnthroveSourceID, accountId string, accountUsername string) error {
|
func CreateUserWithRelationToSource(ctx context.Context, db *gorm.DB, anthroveUserID models.AnthroveUserID, sourceID models.AnthroveSourceID, accountId string, accountUsername string) error {
|
||||||
|
|
||||||
if anthroveUserID == "" {
|
if anthroveUserID == "" {
|
||||||
return &errors2.EntityValidationFailed{Reason: "anthroveUserID cannot be empty"}
|
return &errors2.EntityValidationFailed{Reason: errors2.AnthroveUserIDIsEmpty}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(anthroveUserID) != 25 {
|
if len(anthroveUserID) != 25 {
|
||||||
return &errors2.EntityValidationFailed{Reason: "anthroveUserID needs to be 25 characters long"}
|
return &errors2.EntityValidationFailed{Reason: errors2.AnthroveUserIDToShort}
|
||||||
}
|
}
|
||||||
|
|
||||||
if accountId == "" {
|
if accountId == "" {
|
||||||
@ -103,11 +103,11 @@ func GetUserFavoritesCount(ctx context.Context, db *gorm.DB, anthroveUserID mode
|
|||||||
var count int64
|
var count int64
|
||||||
|
|
||||||
if anthroveUserID == "" {
|
if anthroveUserID == "" {
|
||||||
return 0, &errors2.EntityValidationFailed{Reason: "anthroveUserID cannot be empty"}
|
return 0, &errors2.EntityValidationFailed{Reason: errors2.AnthroveUserIDIsEmpty}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(anthroveUserID) != 25 {
|
if len(anthroveUserID) != 25 {
|
||||||
return 0, &errors2.EntityValidationFailed{Reason: "anthroveUserID needs to be 25 characters long"}
|
return 0, &errors2.EntityValidationFailed{Reason: errors2.AnthroveUserIDToShort}
|
||||||
}
|
}
|
||||||
|
|
||||||
result := db.WithContext(ctx).Model(&models.UserFavorites{}).Where("user_id = ?", string(anthroveUserID)).Count(&count)
|
result := db.WithContext(ctx).Model(&models.UserFavorites{}).Where("user_id = ?", string(anthroveUserID)).Count(&count)
|
||||||
@ -131,11 +131,11 @@ func GetUserSourceLinks(ctx context.Context, db *gorm.DB, anthroveUserID models.
|
|||||||
userSourceMap := make(map[string]models.UserSource)
|
userSourceMap := make(map[string]models.UserSource)
|
||||||
|
|
||||||
if anthroveUserID == "" {
|
if anthroveUserID == "" {
|
||||||
return nil, &errors2.EntityValidationFailed{Reason: "anthroveUserID cannot be empty"}
|
return nil, &errors2.EntityValidationFailed{Reason: errors2.AnthroveUserIDIsEmpty}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(anthroveUserID) != 25 {
|
if len(anthroveUserID) != 25 {
|
||||||
return nil, &errors2.EntityValidationFailed{Reason: "anthroveUserID needs to be 25 characters long"}
|
return nil, &errors2.EntityValidationFailed{Reason: errors2.AnthroveUserIDToShort}
|
||||||
}
|
}
|
||||||
|
|
||||||
result := db.WithContext(ctx).Model(&models.UserSource{}).Where("user_id = ?", string(anthroveUserID)).Find(&userSources)
|
result := db.WithContext(ctx).Model(&models.UserSource{}).Where("user_id = ?", string(anthroveUserID)).Find(&userSources)
|
||||||
@ -179,11 +179,11 @@ func GetUserSourceBySourceID(ctx context.Context, db *gorm.DB, anthroveUserID mo
|
|||||||
userSourceMap := make(map[string]models.UserSource)
|
userSourceMap := make(map[string]models.UserSource)
|
||||||
|
|
||||||
if anthroveUserID == "" {
|
if anthroveUserID == "" {
|
||||||
return nil, &errors2.EntityValidationFailed{Reason: "anthroveUserID cannot be empty"}
|
return nil, &errors2.EntityValidationFailed{Reason: errors2.AnthroveUserIDIsEmpty}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(anthroveUserID) != 25 {
|
if len(anthroveUserID) != 25 {
|
||||||
return nil, &errors2.EntityValidationFailed{Reason: "anthroveUserID needs to be 25 characters long"}
|
return nil, &errors2.EntityValidationFailed{Reason: errors2.AnthroveUserIDToShort}
|
||||||
}
|
}
|
||||||
|
|
||||||
if sourceID == "" {
|
if sourceID == "" {
|
||||||
@ -259,11 +259,11 @@ func GetUserFavoriteWithPagination(ctx context.Context, db *gorm.DB, anthroveUse
|
|||||||
var favoritePosts []models.Post
|
var favoritePosts []models.Post
|
||||||
|
|
||||||
if anthroveUserID == "" {
|
if anthroveUserID == "" {
|
||||||
return nil, &errors2.EntityValidationFailed{Reason: "anthroveUserID cannot be empty"}
|
return nil, &errors2.EntityValidationFailed{Reason: errors2.AnthroveUserIDIsEmpty}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(anthroveUserID) != 25 {
|
if len(anthroveUserID) != 25 {
|
||||||
return nil, &errors2.EntityValidationFailed{Reason: "anthroveUserID needs to be 25 characters long"}
|
return nil, &errors2.EntityValidationFailed{Reason: errors2.AnthroveUserIDToShort}
|
||||||
}
|
}
|
||||||
|
|
||||||
err := db.WithContext(ctx).Model(&models.UserFavorites{}).Where("user_id = ?", string(anthroveUserID)).Offset(skip).Limit(limit).Find(&userFavorites).Error
|
err := db.WithContext(ctx).Model(&models.UserFavorites{}).Where("user_id = ?", string(anthroveUserID)).Offset(skip).Limit(limit).Find(&userFavorites).Error
|
||||||
@ -303,11 +303,11 @@ func GetUserTagWitRelationToFavedPosts(ctx context.Context, db *gorm.DB, anthrov
|
|||||||
var userFavorites []models.UserFavorites
|
var userFavorites []models.UserFavorites
|
||||||
|
|
||||||
if anthroveUserID == "" {
|
if anthroveUserID == "" {
|
||||||
return nil, &errors2.EntityValidationFailed{Reason: "anthroveUserID cannot be empty"}
|
return nil, &errors2.EntityValidationFailed{Reason: errors2.AnthroveUserIDIsEmpty}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(anthroveUserID) != 25 {
|
if len(anthroveUserID) != 25 {
|
||||||
return nil, &errors2.EntityValidationFailed{Reason: "anthroveUserID needs to be 25 characters long"}
|
return nil, &errors2.EntityValidationFailed{Reason: errors2.AnthroveUserIDToShort}
|
||||||
}
|
}
|
||||||
|
|
||||||
result := db.WithContext(ctx).Where("user_id = ?", string(anthroveUserID)).Find(&userFavorites)
|
result := db.WithContext(ctx).Where("user_id = ?", string(anthroveUserID)).Find(&userFavorites)
|
||||||
|
@ -2,6 +2,11 @@ package errors
|
|||||||
|
|
||||||
import "fmt"
|
import "fmt"
|
||||||
|
|
||||||
|
const (
|
||||||
|
AnthroveUserIDIsEmpty = "anthrovePostID cannot be empty"
|
||||||
|
AnthroveUserIDToShort = "anthrovePostID needs to be 25 characters long"
|
||||||
|
)
|
||||||
|
|
||||||
type EntityValidationFailed struct {
|
type EntityValidationFailed struct {
|
||||||
Reason string
|
Reason string
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user