♻️ User dealer's BaseModel
This commit is contained in:
parent
6c5a99e867
commit
98036b18b7
@ -1,8 +1,10 @@
|
|||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"gorm.io/datatypes"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"git.solsynth.dev/hydrogen/dealer/pkg/hyper"
|
||||||
|
"gorm.io/datatypes"
|
||||||
)
|
)
|
||||||
|
|
||||||
type AttachmentDst = int8
|
type AttachmentDst = int8
|
||||||
@ -13,7 +15,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Attachment struct {
|
type Attachment struct {
|
||||||
BaseModel
|
hyper.BaseModel
|
||||||
|
|
||||||
// Random ID is for accessing (appear in URL)
|
// Random ID is for accessing (appear in URL)
|
||||||
Rid string `json:"rid" gorm:"uniqueIndex"`
|
Rid string `json:"rid" gorm:"uniqueIndex"`
|
||||||
|
@ -1,17 +0,0 @@
|
|||||||
package models
|
|
||||||
|
|
||||||
import (
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"gorm.io/datatypes"
|
|
||||||
"gorm.io/gorm"
|
|
||||||
)
|
|
||||||
|
|
||||||
type JSONMap = datatypes.JSONType[map[string]any]
|
|
||||||
|
|
||||||
type BaseModel struct {
|
|
||||||
ID uint `json:"id" gorm:"primaryKey"`
|
|
||||||
CreatedAt time.Time `json:"created_at"`
|
|
||||||
UpdatedAt time.Time `json:"updated_at"`
|
|
||||||
DeletedAt gorm.DeletedAt `json:"deleted_at" gorm:"index"`
|
|
||||||
}
|
|
@ -1,9 +1,12 @@
|
|||||||
package models
|
package models
|
||||||
|
|
||||||
import "gorm.io/datatypes"
|
import (
|
||||||
|
"git.solsynth.dev/hydrogen/dealer/pkg/hyper"
|
||||||
|
"gorm.io/datatypes"
|
||||||
|
)
|
||||||
|
|
||||||
type AttachmentPool struct {
|
type AttachmentPool struct {
|
||||||
BaseModel
|
hyper.BaseModel
|
||||||
|
|
||||||
Alias string `json:"alias"`
|
Alias string `json:"alias"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
package models
|
package models
|
||||||
|
|
||||||
|
import "git.solsynth.dev/hydrogen/dealer/pkg/hyper"
|
||||||
|
|
||||||
type Sticker struct {
|
type Sticker struct {
|
||||||
BaseModel
|
hyper.BaseModel
|
||||||
|
|
||||||
Alias string `json:"alias"`
|
Alias string `json:"alias"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
@ -14,7 +16,7 @@ type Sticker struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type StickerPack struct {
|
type StickerPack struct {
|
||||||
BaseModel
|
hyper.BaseModel
|
||||||
|
|
||||||
Prefix string `json:"prefix"`
|
Prefix string `json:"prefix"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
|
@ -2,8 +2,6 @@ package services
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/spf13/viper"
|
|
||||||
"gorm.io/datatypes"
|
|
||||||
"math"
|
"math"
|
||||||
"mime"
|
"mime"
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
@ -12,6 +10,10 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"github.com/spf13/viper"
|
||||||
|
"gorm.io/datatypes"
|
||||||
|
|
||||||
|
"git.solsynth.dev/hydrogen/dealer/pkg/hyper"
|
||||||
"git.solsynth.dev/hydrogen/paperclip/pkg/internal/database"
|
"git.solsynth.dev/hydrogen/paperclip/pkg/internal/database"
|
||||||
|
|
||||||
"git.solsynth.dev/hydrogen/paperclip/pkg/internal/models"
|
"git.solsynth.dev/hydrogen/paperclip/pkg/internal/models"
|
||||||
@ -26,9 +28,10 @@ var metadataCache sync.Map
|
|||||||
|
|
||||||
func GetAttachmentByID(id uint) (models.Attachment, error) {
|
func GetAttachmentByID(id uint) (models.Attachment, error) {
|
||||||
var attachment models.Attachment
|
var attachment models.Attachment
|
||||||
if err := database.C.Where(models.Attachment{
|
if err := database.C.
|
||||||
BaseModel: models.BaseModel{ID: id},
|
Where(&hyper.BaseModel{ID: id}).
|
||||||
}).Preload("Pool").Preload("Account").First(&attachment).Error; err != nil {
|
Preload("Pool").Preload("Account").
|
||||||
|
First(&attachment).Error; err != nil {
|
||||||
return attachment, err
|
return attachment, err
|
||||||
} else {
|
} else {
|
||||||
CacheAttachment(attachment)
|
CacheAttachment(attachment)
|
||||||
@ -200,7 +203,7 @@ func DeleteAttachment(item models.Attachment) error {
|
|||||||
if item.RefID != nil {
|
if item.RefID != nil {
|
||||||
var refTarget models.Attachment
|
var refTarget models.Attachment
|
||||||
if err := database.C.Where(models.Attachment{
|
if err := database.C.Where(models.Attachment{
|
||||||
BaseModel: models.BaseModel{ID: *item.RefID},
|
BaseModel: hyper.BaseModel{ID: *item.RefID},
|
||||||
}).First(&refTarget).Error; err == nil {
|
}).First(&refTarget).Error; err == nil {
|
||||||
refTarget.RefCount--
|
refTarget.RefCount--
|
||||||
if err := tx.Save(&refTarget).Error; err != nil {
|
if err := tx.Save(&refTarget).Error; err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user