🔊 Adding logs into posting process
This commit is contained in:
parent
0c686d7f06
commit
8cd154f0de
@ -223,12 +223,17 @@ func EnsurePostCategoriesAndTags(item models.Post) (models.Post, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewPost(user models.Account, item models.Post) (models.Post, error) {
|
func NewPost(user models.Account, item models.Post) (models.Post, error) {
|
||||||
|
log.Debug().Any("body", item.Body).Msg("Posting a post...")
|
||||||
|
start := time.Now()
|
||||||
|
|
||||||
|
log.Debug().Any("tags", item.Tags).Any("categories", item.Categories).Msg("Preparing categories and tags...")
|
||||||
item, err := EnsurePostCategoriesAndTags(item)
|
item, err := EnsurePostCategoriesAndTags(item)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return item, err
|
return item, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if item.RealmID != nil {
|
if item.RealmID != nil {
|
||||||
|
log.Debug().Uint("id", *item.RealmID).Msg("Looking for post author realm...")
|
||||||
_, err := GetRealmMember(*item.RealmID, user.ExternalID)
|
_, err := GetRealmMember(*item.RealmID, user.ExternalID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return item, fmt.Errorf("you aren't a part of that realm: %v", err)
|
return item, fmt.Errorf("you aren't a part of that realm: %v", err)
|
||||||
@ -239,6 +244,7 @@ func NewPost(user models.Account, item models.Post) (models.Post, error) {
|
|||||||
item.PublishedAt = lo.ToPtr(time.Now())
|
item.PublishedAt = lo.ToPtr(time.Now())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Debug().Msg("Saving post record into database...")
|
||||||
if err := database.C.Save(&item).Error; err != nil {
|
if err := database.C.Save(&item).Error; err != nil {
|
||||||
return item, err
|
return item, err
|
||||||
}
|
}
|
||||||
@ -251,6 +257,7 @@ func NewPost(user models.Account, item models.Post) (models.Post, error) {
|
|||||||
Preload("Author").
|
Preload("Author").
|
||||||
First(&op).Error; err == nil {
|
First(&op).Error; err == nil {
|
||||||
if op.Author.ID != user.ID {
|
if op.Author.ID != user.ID {
|
||||||
|
log.Debug().Uint("user", op.AuthorID).Msg("Notifying the original poster their post got replied...")
|
||||||
err = NotifyPosterAccount(
|
err = NotifyPosterAccount(
|
||||||
op.Author,
|
op.Author,
|
||||||
"Post got replied",
|
"Post got replied",
|
||||||
@ -264,6 +271,7 @@ func NewPost(user models.Account, item models.Post) (models.Post, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Debug().Dur("elapsed", time.Since(start)).Msg("The post is posted.")
|
||||||
return item, nil
|
return item, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,13 +12,6 @@ print_routes = false
|
|||||||
[dealer]
|
[dealer]
|
||||||
addr = "127.0.0.1:7442"
|
addr = "127.0.0.1:7442"
|
||||||
|
|
||||||
[mailer]
|
|
||||||
name = "Alphabot <alphabot@smartsheep.studio>"
|
|
||||||
smtp_host = "smtp.exmail.qq.com"
|
|
||||||
smtp_port = 465
|
|
||||||
username = "alphabot@smartsheep.studio"
|
|
||||||
password = "gz937Zxxzfcd9SeH"
|
|
||||||
|
|
||||||
[security]
|
[security]
|
||||||
cookie_domain = "localhost"
|
cookie_domain = "localhost"
|
||||||
cookie_samesite = "Lax"
|
cookie_samesite = "Lax"
|
||||||
|
Loading…
Reference in New Issue
Block a user