🐛 Bug fixes of won't accept reply id
This commit is contained in:
parent
4709760edc
commit
80a8a31726
@ -83,7 +83,8 @@ func createPost(c *fiber.Ctx) error {
|
|||||||
Attachments []models.Attachment `json:"attachments" form:"attachments"`
|
Attachments []models.Attachment `json:"attachments" form:"attachments"`
|
||||||
PublishedAt *time.Time `json:"published_at" form:"published_at"`
|
PublishedAt *time.Time `json:"published_at" form:"published_at"`
|
||||||
RealmAlias string `json:"realm" form:"realm"`
|
RealmAlias string `json:"realm" form:"realm"`
|
||||||
RepostTo uint `json:"repost_to" form:"repost_to"`
|
ReplyTo *uint `json:"reply_to" form:"reply_to"`
|
||||||
|
RepostTo *uint `json:"repost_to" form:"repost_to"`
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := BindAndValidate(c, &data); err != nil {
|
if err := BindAndValidate(c, &data); err != nil {
|
||||||
@ -102,15 +103,20 @@ func createPost(c *fiber.Ctx) error {
|
|||||||
Content: data.Content,
|
Content: data.Content,
|
||||||
}
|
}
|
||||||
|
|
||||||
var relatedCount int64
|
if data.ReplyTo != nil {
|
||||||
if data.RepostTo > 0 {
|
var replyTo models.Post
|
||||||
if err := database.C.Where("id = ?", data.RepostTo).
|
if err := database.C.Where("id = ?", data.ReplyTo).First(&replyTo).Error; err != nil {
|
||||||
Model(&models.Post{}).Count(&relatedCount).Error; err != nil {
|
return fiber.NewError(fiber.StatusNotFound, fmt.Sprintf("related post was not found: %v", err))
|
||||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
|
||||||
} else if relatedCount <= 0 {
|
|
||||||
return fiber.NewError(fiber.StatusNotFound, "related post was not found")
|
|
||||||
} else {
|
} else {
|
||||||
item.RepostID = &data.RepostTo
|
item.ReplyID = &replyTo.ID
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if data.RepostTo != nil {
|
||||||
|
var repostTo models.Post
|
||||||
|
if err := database.C.Where("id = ?", data.RepostTo).First(&repostTo).Error; err != nil {
|
||||||
|
return fiber.NewError(fiber.StatusNotFound, fmt.Sprintf("related post was not found: %v", err))
|
||||||
|
} else {
|
||||||
|
item.RepostID = &repostTo.ID
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,6 +56,12 @@ func GetPostWithAlias(alias string, ignoreLimitation ...bool) (models.Post, erro
|
|||||||
Where("alias = ?", alias).
|
Where("alias = ?", alias).
|
||||||
Preload("Author").
|
Preload("Author").
|
||||||
Preload("Attachments").
|
Preload("Attachments").
|
||||||
|
Preload("ReplyTo").
|
||||||
|
Preload("ReplyTo.Author").
|
||||||
|
Preload("ReplyTo.Attachments").
|
||||||
|
Preload("RepostTo").
|
||||||
|
Preload("RepostTo.Author").
|
||||||
|
Preload("RepostTo.Attachments").
|
||||||
First(&item).Error; err != nil {
|
First(&item).Error; err != nil {
|
||||||
return item, err
|
return item, err
|
||||||
}
|
}
|
||||||
@ -74,6 +80,12 @@ func GetPost(id uint, ignoreLimitation ...bool) (models.Post, error) {
|
|||||||
Where("id = ?", id).
|
Where("id = ?", id).
|
||||||
Preload("Author").
|
Preload("Author").
|
||||||
Preload("Attachments").
|
Preload("Attachments").
|
||||||
|
Preload("ReplyTo").
|
||||||
|
Preload("ReplyTo.Author").
|
||||||
|
Preload("ReplyTo.Attachments").
|
||||||
|
Preload("RepostTo").
|
||||||
|
Preload("RepostTo.Author").
|
||||||
|
Preload("RepostTo.Attachments").
|
||||||
First(&item).Error; err != nil {
|
First(&item).Error; err != nil {
|
||||||
return item, err
|
return item, err
|
||||||
}
|
}
|
||||||
@ -146,6 +158,12 @@ func ListPost(tx *gorm.DB, take int, offset int, noReact ...bool) ([]models.Post
|
|||||||
Order("created_at DESC").
|
Order("created_at DESC").
|
||||||
Preload("Author").
|
Preload("Author").
|
||||||
Preload("Attachments").
|
Preload("Attachments").
|
||||||
|
Preload("ReplyTo").
|
||||||
|
Preload("ReplyTo.Author").
|
||||||
|
Preload("ReplyTo.Attachments").
|
||||||
|
Preload("RepostTo").
|
||||||
|
Preload("RepostTo.Author").
|
||||||
|
Preload("RepostTo.Attachments").
|
||||||
Find(&items).Error; err != nil {
|
Find(&items).Error; err != nil {
|
||||||
return items, err
|
return items, err
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ print_routes = false
|
|||||||
client_id = "solarplaza"
|
client_id = "solarplaza"
|
||||||
client_secret = "Z9k9AFTj^p"
|
client_secret = "Z9k9AFTj^p"
|
||||||
endpoint = "http://localhost:8444"
|
endpoint = "http://localhost:8444"
|
||||||
grpc_endpoint = "127.0.0.1:7444"
|
grpc_endpoint = "id.solsynth.dev:7444"
|
||||||
|
|
||||||
[mailer]
|
[mailer]
|
||||||
name = "Alphabot <alphabot@smartsheep.studio>"
|
name = "Alphabot <alphabot@smartsheep.studio>"
|
||||||
|
Loading…
Reference in New Issue
Block a user