mirror of
https://gitee.com/mlogclub/bbs-go.git
synced 2025-12-06 13:59:05 +08:00
整理搜藏接口
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/kataras/iris/v12"
|
||||
"github.com/mlogclub/simple/web"
|
||||
"github.com/mlogclub/simple/web/params"
|
||||
|
||||
"bbs-go/model/constants"
|
||||
"bbs-go/pkg/errs"
|
||||
"bbs-go/services"
|
||||
)
|
||||
@@ -13,11 +16,37 @@ type FavoriteController struct {
|
||||
Ctx iris.Context
|
||||
}
|
||||
|
||||
func (c *FavoriteController) PostAdd() *web.JsonResult {
|
||||
var (
|
||||
user = services.UserTokenService.GetCurrent(c.Ctx)
|
||||
entityType = params.FormValue(c.Ctx, "entityType")
|
||||
entityId = params.FormValueInt64Default(c.Ctx, "entityId", 0)
|
||||
)
|
||||
if user == nil {
|
||||
return web.JsonError(errs.NotLogin)
|
||||
}
|
||||
var err error
|
||||
if entityType == constants.EntityTopic {
|
||||
err = services.FavoriteService.AddTopicFavorite(user.Id, entityId)
|
||||
} else if entityType == constants.EntityArticle {
|
||||
err = services.FavoriteService.AddArticleFavorite(user.Id, entityId)
|
||||
} else {
|
||||
err = errors.New("unsupproted")
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return web.JsonError(err)
|
||||
}
|
||||
return web.JsonSuccess()
|
||||
}
|
||||
|
||||
// 取消收藏
|
||||
func (c *FavoriteController) GetDelete() *web.JsonResult {
|
||||
user := services.UserTokenService.GetCurrent(c.Ctx)
|
||||
entityType := params.FormValue(c.Ctx, "entityType")
|
||||
entityId := params.FormValueInt64Default(c.Ctx, "entityId", 0)
|
||||
func (c *FavoriteController) PostDelete() *web.JsonResult {
|
||||
var (
|
||||
user = services.UserTokenService.GetCurrent(c.Ctx)
|
||||
entityType = params.FormValue(c.Ctx, "entityType")
|
||||
entityId = params.FormValueInt64Default(c.Ctx, "entityId", 0)
|
||||
)
|
||||
if user == nil {
|
||||
return web.JsonError(errs.NotLogin)
|
||||
}
|
||||
|
||||
@@ -223,7 +223,7 @@ export default {
|
||||
async addFavorite(articleId) {
|
||||
try {
|
||||
if (this.article.favorited) {
|
||||
await this.$axios.get('/api/favorite/delete', {
|
||||
await this.$axios.post('/api/favorite/delete', {
|
||||
params: {
|
||||
entityType: 'article',
|
||||
entityId: articleId,
|
||||
@@ -232,7 +232,10 @@ export default {
|
||||
this.article.favorited = false
|
||||
this.$message.success('已取消收藏')
|
||||
} else {
|
||||
await this.$axios.post('/api/article/favorite/' + articleId)
|
||||
await this.$axios.post('/api/favorite/add', {
|
||||
entityType: 'article',
|
||||
entityId: articleId,
|
||||
})
|
||||
this.article.favorited = true
|
||||
this.$message.success('收藏成功')
|
||||
}
|
||||
|
||||
@@ -259,7 +259,7 @@ export default {
|
||||
async addFavorite(topicId) {
|
||||
try {
|
||||
if (this.topic.favorited) {
|
||||
await this.$axios.get('/api/favorite/delete', {
|
||||
await this.$axios.post('/api/favorite/delete', {
|
||||
params: {
|
||||
entityType: 'topic',
|
||||
entityId: topicId,
|
||||
@@ -268,7 +268,10 @@ export default {
|
||||
this.topic.favorited = false
|
||||
this.$message.success('已取消收藏')
|
||||
} else {
|
||||
await this.$axios.get('/api/topic/favorite/' + topicId)
|
||||
await this.$axios.post('/api/favorite/add', {
|
||||
entityType: 'topic',
|
||||
entityId: topicId,
|
||||
})
|
||||
this.topic.favorited = true
|
||||
this.$message.success('收藏成功')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user