feat: 互动处理

This commit is contained in:
Blizzard
2026-03-05 10:30:29 +08:00
parent 172e5f791f
commit 74b252550b
11 changed files with 846 additions and 790 deletions
+77 -18
View File
@@ -15,10 +15,10 @@ type InteractionApi struct{}
// AddHistory 添加收听历史 // AddHistory 添加收听历史
// @Tags 用户互动 // @Tags 用户互动
// @Summary 添加收听历史 // @Summary 添加收听历史
// @Produce json // @Produce application/json
// @Param data body request.AddHistory true "收听信息" // @Param data body request.AddHistory true "收听信息"
// @Success 200 {object} response.Response // @Success 200 {object} response.Response
// @Router /radio/history/add [post] // @Router /history/add [post]
func (a *InteractionApi) AddHistory(c *gin.Context) { func (a *InteractionApi) AddHistory(c *gin.Context) {
userId := auth.GetUserId(c) userId := auth.GetUserId(c)
var req request.AddHistory var req request.AddHistory
@@ -37,13 +37,54 @@ func (a *InteractionApi) AddHistory(c *gin.Context) {
response.OkWithMsg("添加成功", c) response.OkWithMsg("添加成功", c)
} }
// DeleteHistory 删除收听历史
// @Tags 用户互动
// @Summary 删除收听历史
// @Produce application/json
// @Param id query string true "节目ID"
// @Success 200 {object} response.Response
// @Router /history/delete [post]
func (a *InteractionApi) DeleteHistory(c *gin.Context) {
var req request.RemoveHistory
err := c.ShouldBindJSON(&req)
if err != nil {
response.FailWithMsg("参数错误: "+err.Error(), c)
return
}
userId := auth.GetUserId(c)
err = interactionService.DeleteHistory(userId, req.ProgramId)
if err != nil {
global.Logger.Error("删除收听历史失败!", zap.Error(err))
response.FailWithMsg(err.Error(), c)
return
}
response.OkWithMsg("删除成功", c)
}
// DeleteAllHistory 删除所有收听历史
// @Tags 用户互动
// @Summary 删除所有收听历史
// @Produce application/json
// @Success 200 {object} response.Response
// @Router /history/deleteAllHistory [get]
func (a *InteractionApi) DeleteAllHistory(c *gin.Context) {
userId := auth.GetUserId(c)
err := interactionService.DeleteAllHistory(userId)
if err != nil {
global.Logger.Error("删除所有收听历史失败!", zap.Error(err))
response.FailWithMsg(err.Error(), c)
return
}
response.OkWithMsg("删除成功", c)
}
// GetHistoryList 获取收听历史列表 // GetHistoryList 获取收听历史列表
// @Tags 用户互动 // @Tags 用户互动
// @Summary 获取收听历史列表 // @Summary 获取收听历史列表
// @Produce json // @Produce application/json
// @Param data body request.GetHistoryList true "分页查询" // @Param data body request.GetHistoryList true "分页查询"
// @Success 200 {object} response.Response // @Success 200 {object} response.Response
// @Router /radio/history/list [post] // @Router /history/list [post]
func (a *InteractionApi) GetHistoryList(c *gin.Context) { func (a *InteractionApi) GetHistoryList(c *gin.Context) {
userId := auth.GetUserId(c) userId := auth.GetUserId(c)
var req request.GetHistoryList var req request.GetHistoryList
@@ -70,10 +111,10 @@ func (a *InteractionApi) GetHistoryList(c *gin.Context) {
// ToggleLike 切换点赞状态 // ToggleLike 切换点赞状态
// @Tags 用户互动 // @Tags 用户互动
// @Summary 切换点赞状态 // @Summary 切换点赞状态
// @Produce json // @Produce application/json
// @Param data body request.ToggleLike true "节目ID" // @Param data body request.ToggleLike true "节目ID"
// @Success 200 {object} response.Response // @Success 200 {object} response.Response
// @Router /radio/like/toggle [post] // @Router /like/toggle [post]
func (a *InteractionApi) ToggleLike(c *gin.Context) { func (a *InteractionApi) ToggleLike(c *gin.Context) {
userId := auth.GetUserId(c) userId := auth.GetUserId(c)
var req request.ToggleLike var req request.ToggleLike
@@ -96,10 +137,10 @@ func (a *InteractionApi) ToggleLike(c *gin.Context) {
// GetFavoriteList 获取收藏列表 // GetFavoriteList 获取收藏列表
// @Tags 用户互动 // @Tags 用户互动
// @Summary 获取收藏列表 // @Summary 获取收藏列表
// @Produce json // @Produce application/json
// @Param data body request.GetFavoriteList true "分页查询" // @Param data body request.GetFavoriteList true "分页查询"
// @Success 200 {object} response.Response // @Success 200 {object} response.Response
// @Router /radio/favorite/list [post] // @Router /favorite/list [post]
func (a *InteractionApi) GetFavoriteList(c *gin.Context) { func (a *InteractionApi) GetFavoriteList(c *gin.Context) {
userId := auth.GetUserId(c) userId := auth.GetUserId(c)
var req request.GetFavoriteList var req request.GetFavoriteList
@@ -126,10 +167,10 @@ func (a *InteractionApi) GetFavoriteList(c *gin.Context) {
// AddFavorite 添加收藏 // AddFavorite 添加收藏
// @Tags 用户互动 // @Tags 用户互动
// @Summary 添加收藏 // @Summary 添加收藏
// @Produce json // @Produce application/json
// @Param data body request.AddFavorite true "节目ID" // @Param data body request.AddFavorite true "节目ID"
// @Success 200 {object} response.Response // @Success 200 {object} response.Response
// @Router /radio/favorite/add [post] // @Router /favorite/add [post]
func (a *InteractionApi) AddFavorite(c *gin.Context) { func (a *InteractionApi) AddFavorite(c *gin.Context) {
userId := auth.GetUserId(c) userId := auth.GetUserId(c)
var req request.AddFavorite var req request.AddFavorite
@@ -151,10 +192,10 @@ func (a *InteractionApi) AddFavorite(c *gin.Context) {
// RemoveFavorite 取消收藏 // RemoveFavorite 取消收藏
// @Tags 用户互动 // @Tags 用户互动
// @Summary 取消收藏 // @Summary 取消收藏
// @Produce json // @Produce application/json
// @Param data body request.RemoveFavorite true "节目ID" // @Param data body request.RemoveFavorite true "节目ID"
// @Success 200 {object} response.Response // @Success 200 {object} response.Response
// @Router /radio/favorite/remove [post] // @Router /favorite/remove [post]
func (a *InteractionApi) RemoveFavorite(c *gin.Context) { func (a *InteractionApi) RemoveFavorite(c *gin.Context) {
userId := auth.GetUserId(c) userId := auth.GetUserId(c)
var req request.RemoveFavorite var req request.RemoveFavorite
@@ -173,13 +214,31 @@ func (a *InteractionApi) RemoveFavorite(c *gin.Context) {
response.OkWithMsg("取消收藏成功", c) response.OkWithMsg("取消收藏成功", c)
} }
// RemoveAllFavorite 清空所有收藏
// @Tags 用户互动
// @Summary 清空所有收藏
// @Produce application/json
// @Param data body request.RemoveFavorite true "节目ID"
// @Success 200 {object} response.Response
// @Router /favorite/removeAll [get]
func (a *InteractionApi) RemoveAllFavorite(c *gin.Context) {
userId := auth.GetUserId(c)
err := interactionService.RemoveAllFavorite(userId)
if err != nil {
global.Logger.Error("清空所有收藏失败!", zap.Error(err))
response.FailWithMsg(err.Error(), c)
return
}
response.OkWithMsg("清空所有收藏成功", c)
}
// GetCommentList 获取评论列表 // GetCommentList 获取评论列表
// @Tags 用户互动 // @Tags 用户互动
// @Summary 获取评论列表 // @Summary 获取评论列表
// @Produce json // @Produce application/json
// @Param data body request.GetCommentList true "分页查询" // @Param data body request.GetCommentList true "分页查询"
// @Success 200 {object} response.Response // @Success 200 {object} response.Response
// @Router /radio/comment/list [post] // @Router /comment/list [post]
func (a *InteractionApi) GetCommentList(c *gin.Context) { func (a *InteractionApi) GetCommentList(c *gin.Context) {
var req request.GetCommentList var req request.GetCommentList
err := c.ShouldBindJSON(&req) err := c.ShouldBindJSON(&req)
@@ -205,10 +264,10 @@ func (a *InteractionApi) GetCommentList(c *gin.Context) {
// AddComment 添加评论 // AddComment 添加评论
// @Tags 用户互动 // @Tags 用户互动
// @Summary 添加评论 // @Summary 添加评论
// @Produce json // @Produce application/json
// @Param data body request.AddComment true "评论信息" // @Param data body request.AddComment true "评论信息"
// @Success 200 {object} response.Response // @Success 200 {object} response.Response
// @Router /radio/comment/add [post] // @Router /comment/add [post]
func (a *InteractionApi) AddComment(c *gin.Context) { func (a *InteractionApi) AddComment(c *gin.Context) {
userId := auth.GetUserId(c) userId := auth.GetUserId(c)
var req request.AddComment var req request.AddComment
@@ -230,10 +289,10 @@ func (a *InteractionApi) AddComment(c *gin.Context) {
// DeleteComment 删除评论 // DeleteComment 删除评论
// @Tags 用户互动 // @Tags 用户互动
// @Summary 删除评论 // @Summary 删除评论
// @Produce json // @Produce application/json
// @Param data body request.DeleteComment true "评论ID" // @Param data body request.DeleteComment true "评论ID"
// @Success 200 {object} response.Response // @Success 200 {object} response.Response
// @Router /radio/comment/delete [post] // @Router /comment/delete [post]
func (a *InteractionApi) DeleteComment(c *gin.Context) { func (a *InteractionApi) DeleteComment(c *gin.Context) {
userId := auth.GetUserId(c) userId := auth.GetUserId(c)
var req request.DeleteComment var req request.DeleteComment
+3 -1
View File
@@ -5,6 +5,7 @@ import (
common "sundynix-go/model/commom/request" common "sundynix-go/model/commom/request"
"sundynix-go/model/commom/response" "sundynix-go/model/commom/response"
"sundynix-go/model/radio/request" "sundynix-go/model/radio/request"
"sundynix-go/utils/auth"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"go.uber.org/zap" "go.uber.org/zap"
@@ -55,7 +56,8 @@ func (a *ProgramApi) GetProgramDetail(c *gin.Context) {
response.FailWithMsg("参数错误: id不能为空", c) response.FailWithMsg("参数错误: id不能为空", c)
return return
} }
program, err := programService.GetProgramById(id) userId := auth.GetUserId(c)
program, err := programService.GetProgramById(id, userId)
if err != nil { if err != nil {
global.Logger.Error("获取节目详情失败!", zap.Error(err)) global.Logger.Error("获取节目详情失败!", zap.Error(err))
response.FailWithMsg(err.Error(), c) response.FailWithMsg(err.Error(), c)
+275 -291
View File
@@ -496,6 +496,276 @@ const docTemplate = `{
} }
} }
}, },
"/comment/add": {
"post": {
"produces": [
"application/json"
],
"tags": [
"用户互动"
],
"summary": "添加评论",
"parameters": [
{
"description": "评论信息",
"name": "data",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/request.AddComment"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/response.Response"
}
}
}
}
},
"/comment/delete": {
"post": {
"produces": [
"application/json"
],
"tags": [
"用户互动"
],
"summary": "删除评论",
"parameters": [
{
"description": "评论ID",
"name": "data",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/request.DeleteComment"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/response.Response"
}
}
}
}
},
"/comment/list": {
"post": {
"produces": [
"application/json"
],
"tags": [
"用户互动"
],
"summary": "获取评论列表",
"parameters": [
{
"description": "分页查询",
"name": "data",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/request.GetCommentList"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/response.Response"
}
}
}
}
},
"/favorite/add": {
"post": {
"produces": [
"application/json"
],
"tags": [
"用户互动"
],
"summary": "添加收藏",
"parameters": [
{
"description": "节目ID",
"name": "data",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/request.AddFavorite"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/response.Response"
}
}
}
}
},
"/favorite/list": {
"post": {
"produces": [
"application/json"
],
"tags": [
"用户互动"
],
"summary": "获取收藏列表",
"parameters": [
{
"description": "分页查询",
"name": "data",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/request.GetFavoriteList"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/response.Response"
}
}
}
}
},
"/favorite/remove": {
"post": {
"produces": [
"application/json"
],
"tags": [
"用户互动"
],
"summary": "取消收藏",
"parameters": [
{
"description": "节目ID",
"name": "data",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/request.RemoveFavorite"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/response.Response"
}
}
}
}
},
"/history/add": {
"post": {
"produces": [
"application/json"
],
"tags": [
"用户互动"
],
"summary": "添加收听历史",
"parameters": [
{
"description": "收听信息",
"name": "data",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/request.AddHistory"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/response.Response"
}
}
}
}
},
"/history/list": {
"post": {
"produces": [
"application/json"
],
"tags": [
"用户互动"
],
"summary": "获取收听历史列表",
"parameters": [
{
"description": "分页查询",
"name": "data",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/request.GetHistoryList"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/response.Response"
}
}
}
}
},
"/like/toggle": {
"post": {
"produces": [
"application/json"
],
"tags": [
"用户互动"
],
"summary": "切换点赞状态",
"parameters": [
{
"description": "节目ID",
"name": "data",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/request.ToggleLike"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/response.Response"
}
}
}
}
},
"/menu/delete": { "/menu/delete": {
"get": { "get": {
"security": [ "security": [
@@ -1475,276 +1745,6 @@ const docTemplate = `{
} }
} }
}, },
"/radio/comment/add": {
"post": {
"produces": [
"application/json"
],
"tags": [
"用户互动"
],
"summary": "添加评论",
"parameters": [
{
"description": "评论信息",
"name": "data",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/request.AddComment"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/response.Response"
}
}
}
}
},
"/radio/comment/delete": {
"post": {
"produces": [
"application/json"
],
"tags": [
"用户互动"
],
"summary": "删除评论",
"parameters": [
{
"description": "评论ID",
"name": "data",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/request.DeleteComment"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/response.Response"
}
}
}
}
},
"/radio/comment/list": {
"post": {
"produces": [
"application/json"
],
"tags": [
"用户互动"
],
"summary": "获取评论列表",
"parameters": [
{
"description": "分页查询",
"name": "data",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/request.GetCommentList"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/response.Response"
}
}
}
}
},
"/radio/favorite/add": {
"post": {
"produces": [
"application/json"
],
"tags": [
"用户互动"
],
"summary": "添加收藏",
"parameters": [
{
"description": "节目ID",
"name": "data",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/request.AddFavorite"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/response.Response"
}
}
}
}
},
"/radio/favorite/list": {
"post": {
"produces": [
"application/json"
],
"tags": [
"用户互动"
],
"summary": "获取收藏列表",
"parameters": [
{
"description": "分页查询",
"name": "data",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/request.GetFavoriteList"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/response.Response"
}
}
}
}
},
"/radio/favorite/remove": {
"post": {
"produces": [
"application/json"
],
"tags": [
"用户互动"
],
"summary": "取消收藏",
"parameters": [
{
"description": "节目ID",
"name": "data",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/request.RemoveFavorite"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/response.Response"
}
}
}
}
},
"/radio/history/add": {
"post": {
"produces": [
"application/json"
],
"tags": [
"用户互动"
],
"summary": "添加收听历史",
"parameters": [
{
"description": "收听信息",
"name": "data",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/request.AddHistory"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/response.Response"
}
}
}
}
},
"/radio/history/list": {
"post": {
"produces": [
"application/json"
],
"tags": [
"用户互动"
],
"summary": "获取收听历史列表",
"parameters": [
{
"description": "分页查询",
"name": "data",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/request.GetHistoryList"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/response.Response"
}
}
}
}
},
"/radio/like/toggle": {
"post": {
"produces": [
"application/json"
],
"tags": [
"用户互动"
],
"summary": "切换点赞状态",
"parameters": [
{
"description": "节目ID",
"name": "data",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/request.ToggleLike"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/response.Response"
}
}
}
}
},
"/radio/program/delete": { "/radio/program/delete": {
"post": { "post": {
"produces": [ "produces": [
@@ -1933,7 +1933,7 @@ const docTemplate = `{
} }
}, },
"/radio/subscription/unlock": { "/radio/subscription/unlock": {
"get": { "post": {
"produces": [ "produces": [
"application/json" "application/json"
], ],
@@ -2977,18 +2977,10 @@ const docTemplate = `{
"name" "name"
], ],
"properties": { "properties": {
"coverId": {
"description": "封面图URL",
"type": "string"
},
"description": { "description": {
"description": "分类描述", "description": "分类描述",
"type": "string" "type": "string"
}, },
"iconId": {
"description": "图标URL",
"type": "string"
},
"name": { "name": {
"description": "分类名称", "description": "分类名称",
"type": "string" "type": "string"
@@ -3018,7 +3010,7 @@ const docTemplate = `{
"description": "分类ID", "description": "分类ID",
"type": "string" "type": "string"
}, },
"coverId": { "cover": {
"description": "封面图URL", "description": "封面图URL",
"type": "string" "type": "string"
}, },
@@ -3078,7 +3070,7 @@ const docTemplate = `{
"content": { "content": {
"type": "string" "type": "string"
}, },
"coverId": { "cover": {
"description": "封面图URL", "description": "封面图URL",
"type": "string" "type": "string"
}, },
@@ -3122,18 +3114,10 @@ const docTemplate = `{
"id" "id"
], ],
"properties": { "properties": {
"coverId": {
"description": "封面图URL",
"type": "string"
},
"description": { "description": {
"description": "分类描述", "description": "分类描述",
"type": "string" "type": "string"
}, },
"iconId": {
"description": "图标URL",
"type": "string"
},
"id": { "id": {
"description": "分类ID", "description": "分类ID",
"type": "string" "type": "string"
@@ -3166,7 +3150,7 @@ const docTemplate = `{
"description": "分类ID", "description": "分类ID",
"type": "string" "type": "string"
}, },
"coverId": { "cover": {
"description": "封面图URL", "description": "封面图URL",
"type": "string" "type": "string"
}, },
@@ -3228,7 +3212,7 @@ const docTemplate = `{
"content": { "content": {
"type": "string" "type": "string"
}, },
"coverId": { "cover": {
"description": "封面图URL", "description": "封面图URL",
"type": "string" "type": "string"
}, },
+275 -291
View File
@@ -489,6 +489,276 @@
} }
} }
}, },
"/comment/add": {
"post": {
"produces": [
"application/json"
],
"tags": [
"用户互动"
],
"summary": "添加评论",
"parameters": [
{
"description": "评论信息",
"name": "data",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/request.AddComment"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/response.Response"
}
}
}
}
},
"/comment/delete": {
"post": {
"produces": [
"application/json"
],
"tags": [
"用户互动"
],
"summary": "删除评论",
"parameters": [
{
"description": "评论ID",
"name": "data",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/request.DeleteComment"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/response.Response"
}
}
}
}
},
"/comment/list": {
"post": {
"produces": [
"application/json"
],
"tags": [
"用户互动"
],
"summary": "获取评论列表",
"parameters": [
{
"description": "分页查询",
"name": "data",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/request.GetCommentList"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/response.Response"
}
}
}
}
},
"/favorite/add": {
"post": {
"produces": [
"application/json"
],
"tags": [
"用户互动"
],
"summary": "添加收藏",
"parameters": [
{
"description": "节目ID",
"name": "data",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/request.AddFavorite"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/response.Response"
}
}
}
}
},
"/favorite/list": {
"post": {
"produces": [
"application/json"
],
"tags": [
"用户互动"
],
"summary": "获取收藏列表",
"parameters": [
{
"description": "分页查询",
"name": "data",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/request.GetFavoriteList"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/response.Response"
}
}
}
}
},
"/favorite/remove": {
"post": {
"produces": [
"application/json"
],
"tags": [
"用户互动"
],
"summary": "取消收藏",
"parameters": [
{
"description": "节目ID",
"name": "data",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/request.RemoveFavorite"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/response.Response"
}
}
}
}
},
"/history/add": {
"post": {
"produces": [
"application/json"
],
"tags": [
"用户互动"
],
"summary": "添加收听历史",
"parameters": [
{
"description": "收听信息",
"name": "data",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/request.AddHistory"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/response.Response"
}
}
}
}
},
"/history/list": {
"post": {
"produces": [
"application/json"
],
"tags": [
"用户互动"
],
"summary": "获取收听历史列表",
"parameters": [
{
"description": "分页查询",
"name": "data",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/request.GetHistoryList"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/response.Response"
}
}
}
}
},
"/like/toggle": {
"post": {
"produces": [
"application/json"
],
"tags": [
"用户互动"
],
"summary": "切换点赞状态",
"parameters": [
{
"description": "节目ID",
"name": "data",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/request.ToggleLike"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/response.Response"
}
}
}
}
},
"/menu/delete": { "/menu/delete": {
"get": { "get": {
"security": [ "security": [
@@ -1468,276 +1738,6 @@
} }
} }
}, },
"/radio/comment/add": {
"post": {
"produces": [
"application/json"
],
"tags": [
"用户互动"
],
"summary": "添加评论",
"parameters": [
{
"description": "评论信息",
"name": "data",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/request.AddComment"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/response.Response"
}
}
}
}
},
"/radio/comment/delete": {
"post": {
"produces": [
"application/json"
],
"tags": [
"用户互动"
],
"summary": "删除评论",
"parameters": [
{
"description": "评论ID",
"name": "data",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/request.DeleteComment"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/response.Response"
}
}
}
}
},
"/radio/comment/list": {
"post": {
"produces": [
"application/json"
],
"tags": [
"用户互动"
],
"summary": "获取评论列表",
"parameters": [
{
"description": "分页查询",
"name": "data",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/request.GetCommentList"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/response.Response"
}
}
}
}
},
"/radio/favorite/add": {
"post": {
"produces": [
"application/json"
],
"tags": [
"用户互动"
],
"summary": "添加收藏",
"parameters": [
{
"description": "节目ID",
"name": "data",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/request.AddFavorite"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/response.Response"
}
}
}
}
},
"/radio/favorite/list": {
"post": {
"produces": [
"application/json"
],
"tags": [
"用户互动"
],
"summary": "获取收藏列表",
"parameters": [
{
"description": "分页查询",
"name": "data",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/request.GetFavoriteList"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/response.Response"
}
}
}
}
},
"/radio/favorite/remove": {
"post": {
"produces": [
"application/json"
],
"tags": [
"用户互动"
],
"summary": "取消收藏",
"parameters": [
{
"description": "节目ID",
"name": "data",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/request.RemoveFavorite"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/response.Response"
}
}
}
}
},
"/radio/history/add": {
"post": {
"produces": [
"application/json"
],
"tags": [
"用户互动"
],
"summary": "添加收听历史",
"parameters": [
{
"description": "收听信息",
"name": "data",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/request.AddHistory"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/response.Response"
}
}
}
}
},
"/radio/history/list": {
"post": {
"produces": [
"application/json"
],
"tags": [
"用户互动"
],
"summary": "获取收听历史列表",
"parameters": [
{
"description": "分页查询",
"name": "data",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/request.GetHistoryList"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/response.Response"
}
}
}
}
},
"/radio/like/toggle": {
"post": {
"produces": [
"application/json"
],
"tags": [
"用户互动"
],
"summary": "切换点赞状态",
"parameters": [
{
"description": "节目ID",
"name": "data",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/request.ToggleLike"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/response.Response"
}
}
}
}
},
"/radio/program/delete": { "/radio/program/delete": {
"post": { "post": {
"produces": [ "produces": [
@@ -1926,7 +1926,7 @@
} }
}, },
"/radio/subscription/unlock": { "/radio/subscription/unlock": {
"get": { "post": {
"produces": [ "produces": [
"application/json" "application/json"
], ],
@@ -2970,18 +2970,10 @@
"name" "name"
], ],
"properties": { "properties": {
"coverId": {
"description": "封面图URL",
"type": "string"
},
"description": { "description": {
"description": "分类描述", "description": "分类描述",
"type": "string" "type": "string"
}, },
"iconId": {
"description": "图标URL",
"type": "string"
},
"name": { "name": {
"description": "分类名称", "description": "分类名称",
"type": "string" "type": "string"
@@ -3011,7 +3003,7 @@
"description": "分类ID", "description": "分类ID",
"type": "string" "type": "string"
}, },
"coverId": { "cover": {
"description": "封面图URL", "description": "封面图URL",
"type": "string" "type": "string"
}, },
@@ -3071,7 +3063,7 @@
"content": { "content": {
"type": "string" "type": "string"
}, },
"coverId": { "cover": {
"description": "封面图URL", "description": "封面图URL",
"type": "string" "type": "string"
}, },
@@ -3115,18 +3107,10 @@
"id" "id"
], ],
"properties": { "properties": {
"coverId": {
"description": "封面图URL",
"type": "string"
},
"description": { "description": {
"description": "分类描述", "description": "分类描述",
"type": "string" "type": "string"
}, },
"iconId": {
"description": "图标URL",
"type": "string"
},
"id": { "id": {
"description": "分类ID", "description": "分类ID",
"type": "string" "type": "string"
@@ -3159,7 +3143,7 @@
"description": "分类ID", "description": "分类ID",
"type": "string" "type": "string"
}, },
"coverId": { "cover": {
"description": "封面图URL", "description": "封面图URL",
"type": "string" "type": "string"
}, },
@@ -3221,7 +3205,7 @@
"content": { "content": {
"type": "string" "type": "string"
}, },
"coverId": { "cover": {
"description": "封面图URL", "description": "封面图URL",
"type": "string" "type": "string"
}, },
+176 -188
View File
@@ -286,15 +286,9 @@ definitions:
type: object type: object
request.SaveCategory: request.SaveCategory:
properties: properties:
coverId:
description: 封面图URL
type: string
description: description:
description: 分类描述 description: 分类描述
type: string type: string
iconId:
description: 图标URL
type: string
name: name:
description: 分类名称 description: 分类名称
type: string type: string
@@ -315,7 +309,7 @@ definitions:
categoryId: categoryId:
description: 分类ID description: 分类ID
type: string type: string
coverId: cover:
description: 封面图URL description: 封面图URL
type: string type: string
description: description:
@@ -359,7 +353,7 @@ definitions:
type: string type: string
content: content:
type: string type: string
coverId: cover:
description: 封面图URL description: 封面图URL
type: string type: string
description: description:
@@ -391,15 +385,9 @@ definitions:
type: object type: object
request.UpdateCategory: request.UpdateCategory:
properties: properties:
coverId:
description: 封面图URL
type: string
description: description:
description: 分类描述 description: 分类描述
type: string type: string
iconId:
description: 图标URL
type: string
id: id:
description: 分类ID description: 分类ID
type: string type: string
@@ -423,7 +411,7 @@ definitions:
categoryId: categoryId:
description: 分类ID description: 分类ID
type: string type: string
coverId: cover:
description: 封面图URL description: 封面图URL
type: string type: string
description: description:
@@ -468,7 +456,7 @@ definitions:
type: string type: string
content: content:
type: string type: string
coverId: cover:
description: 封面图URL description: 封面图URL
type: string type: string
description: description:
@@ -951,6 +939,177 @@ paths:
summary: 更新client summary: 更新client
tags: tags:
- 客户端管理 - 客户端管理
/comment/add:
post:
parameters:
- description: 评论信息
in: body
name: data
required: true
schema:
$ref: '#/definitions/request.AddComment'
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/response.Response'
summary: 添加评论
tags:
- 用户互动
/comment/delete:
post:
parameters:
- description: 评论ID
in: body
name: data
required: true
schema:
$ref: '#/definitions/request.DeleteComment'
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/response.Response'
summary: 删除评论
tags:
- 用户互动
/comment/list:
post:
parameters:
- description: 分页查询
in: body
name: data
required: true
schema:
$ref: '#/definitions/request.GetCommentList'
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/response.Response'
summary: 获取评论列表
tags:
- 用户互动
/favorite/add:
post:
parameters:
- description: 节目ID
in: body
name: data
required: true
schema:
$ref: '#/definitions/request.AddFavorite'
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/response.Response'
summary: 添加收藏
tags:
- 用户互动
/favorite/list:
post:
parameters:
- description: 分页查询
in: body
name: data
required: true
schema:
$ref: '#/definitions/request.GetFavoriteList'
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/response.Response'
summary: 获取收藏列表
tags:
- 用户互动
/favorite/remove:
post:
parameters:
- description: 节目ID
in: body
name: data
required: true
schema:
$ref: '#/definitions/request.RemoveFavorite'
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/response.Response'
summary: 取消收藏
tags:
- 用户互动
/history/add:
post:
parameters:
- description: 收听信息
in: body
name: data
required: true
schema:
$ref: '#/definitions/request.AddHistory'
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/response.Response'
summary: 添加收听历史
tags:
- 用户互动
/history/list:
post:
parameters:
- description: 分页查询
in: body
name: data
required: true
schema:
$ref: '#/definitions/request.GetHistoryList'
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/response.Response'
summary: 获取收听历史列表
tags:
- 用户互动
/like/toggle:
post:
parameters:
- description: 节目ID
in: body
name: data
required: true
schema:
$ref: '#/definitions/request.ToggleLike'
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/response.Response'
summary: 切换点赞状态
tags:
- 用户互动
/menu/delete: /menu/delete:
get: get:
description: 删除menu description: 删除menu
@@ -1532,177 +1691,6 @@ paths:
summary: 更新频道 summary: 更新频道
tags: tags:
- 频道管理 - 频道管理
/radio/comment/add:
post:
parameters:
- description: 评论信息
in: body
name: data
required: true
schema:
$ref: '#/definitions/request.AddComment'
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/response.Response'
summary: 添加评论
tags:
- 用户互动
/radio/comment/delete:
post:
parameters:
- description: 评论ID
in: body
name: data
required: true
schema:
$ref: '#/definitions/request.DeleteComment'
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/response.Response'
summary: 删除评论
tags:
- 用户互动
/radio/comment/list:
post:
parameters:
- description: 分页查询
in: body
name: data
required: true
schema:
$ref: '#/definitions/request.GetCommentList'
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/response.Response'
summary: 获取评论列表
tags:
- 用户互动
/radio/favorite/add:
post:
parameters:
- description: 节目ID
in: body
name: data
required: true
schema:
$ref: '#/definitions/request.AddFavorite'
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/response.Response'
summary: 添加收藏
tags:
- 用户互动
/radio/favorite/list:
post:
parameters:
- description: 分页查询
in: body
name: data
required: true
schema:
$ref: '#/definitions/request.GetFavoriteList'
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/response.Response'
summary: 获取收藏列表
tags:
- 用户互动
/radio/favorite/remove:
post:
parameters:
- description: 节目ID
in: body
name: data
required: true
schema:
$ref: '#/definitions/request.RemoveFavorite'
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/response.Response'
summary: 取消收藏
tags:
- 用户互动
/radio/history/add:
post:
parameters:
- description: 收听信息
in: body
name: data
required: true
schema:
$ref: '#/definitions/request.AddHistory'
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/response.Response'
summary: 添加收听历史
tags:
- 用户互动
/radio/history/list:
post:
parameters:
- description: 分页查询
in: body
name: data
required: true
schema:
$ref: '#/definitions/request.GetHistoryList'
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/response.Response'
summary: 获取收听历史列表
tags:
- 用户互动
/radio/like/toggle:
post:
parameters:
- description: 节目ID
in: body
name: data
required: true
schema:
$ref: '#/definitions/request.ToggleLike'
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/response.Response'
summary: 切换点赞状态
tags:
- 用户互动
/radio/program/delete: /radio/program/delete:
post: post:
parameters: parameters:
@@ -1823,7 +1811,7 @@ paths:
tags: tags:
- 订阅管理 - 订阅管理
/radio/subscription/unlock: /radio/subscription/unlock:
get: post:
parameters: parameters:
- description: id - description: id
in: query in: query
+5
View File
@@ -46,6 +46,11 @@ func MigrateTable() {
radio.RadioUser{}, radio.RadioUser{},
radio.Order{}, radio.Order{},
radio.PayNotify{}, radio.PayNotify{},
radio.RadioComment{},
radio.RadioHistory{},
radio.RadioFavorite{},
radio.RadioLike{},
) )
if err != nil { if err != nil {
global.Logger.Error("Migrate table failed,err:", zap.Error(err)) global.Logger.Error("Migrate table failed,err:", zap.Error(err))
+2
View File
@@ -21,6 +21,8 @@ type RadioProgram struct {
LikeCount int `gorm:"default:0" json:"likeCount"` // 点赞次数 LikeCount int `gorm:"default:0" json:"likeCount"` // 点赞次数
Status int `gorm:"default:1" json:"status"` // 状态 0:下架 1:上架 Status int `gorm:"default:1" json:"status"` // 状态 0:下架 1:上架
Channel *RadioChannel `gorm:"foreignKey:ChannelId" json:"channel"` Channel *RadioChannel `gorm:"foreignKey:ChannelId" json:"channel"`
HasLiked int `gorm:"-" json:"hasLiked"` // 是否点赞
HasFavorite int `gorm:"-" json:"HasFavorite"` // 是否收藏
} }
func (RadioProgram) TableName() string { func (RadioProgram) TableName() string {
+4
View File
@@ -19,6 +19,10 @@ type AddHistory struct {
Duration int `json:"duration"` // 节目总时长(秒) Duration int `json:"duration"` // 节目总时长(秒)
} }
type RemoveHistory struct {
ProgramId string `json:"programId" binding:"required"` // 节目ID
}
// ToggleLike 切换点赞请求 // ToggleLike 切换点赞请求
type ToggleLike struct { type ToggleLike struct {
ProgramId string `json:"programId" binding:"required"` // 节目ID ProgramId string `json:"programId" binding:"required"` // 节目ID
+3
View File
@@ -12,6 +12,8 @@ func (r *InteractionRouter) InitInteractionRouter(Router *gin.RouterGroup) {
{ {
historyRouter.POST("list", interactionApi.GetHistoryList) historyRouter.POST("list", interactionApi.GetHistoryList)
historyRouter.POST("add", interactionApi.AddHistory) historyRouter.POST("add", interactionApi.AddHistory)
historyRouter.POST("delete", interactionApi.DeleteHistory)
historyRouter.GET("deleteAll", interactionApi.DeleteAllHistory)
} }
// 点赞 // 点赞
@@ -26,6 +28,7 @@ func (r *InteractionRouter) InitInteractionRouter(Router *gin.RouterGroup) {
favoriteRouter.POST("list", interactionApi.GetFavoriteList) favoriteRouter.POST("list", interactionApi.GetFavoriteList)
favoriteRouter.POST("add", interactionApi.AddFavorite) favoriteRouter.POST("add", interactionApi.AddFavorite)
favoriteRouter.POST("remove", interactionApi.RemoveFavorite) favoriteRouter.POST("remove", interactionApi.RemoveFavorite)
favoriteRouter.GET("removeAll", interactionApi.RemoveAllFavorite)
} }
// 评论 // 评论
+14
View File
@@ -11,6 +11,8 @@ import (
type InteractionService struct{} type InteractionService struct{}
var InteractionServiceApp = new(InteractionService)
// AddHistory 添加收听历史 // AddHistory 添加收听历史
func (s *InteractionService) AddHistory(userId string, req radioReq.AddHistory) error { func (s *InteractionService) AddHistory(userId string, req radioReq.AddHistory) error {
// 先查找是否已存在记录 // 先查找是否已存在记录
@@ -174,3 +176,15 @@ func (s *InteractionService) GetCommentList(programId string, info radioReq.GetC
err = db.Offset(offset).Limit(info.PageSize).Order("created_at DESC").Find(&list).Error err = db.Offset(offset).Limit(info.PageSize).Order("created_at DESC").Find(&list).Error
return list, total, err return list, total, err
} }
func (s *InteractionService) DeleteHistory(userId, programId string) error {
return global.DB.Where("user_id = ? AND program_id = ?", userId, programId).Delete(&radio.RadioHistory{}).Error
}
func (s *InteractionService) DeleteAllHistory(userId string) error {
return global.DB.Where("user_id = ?", userId).Delete(&radio.RadioHistory{}).Error
}
func (s *InteractionService) RemoveAllFavorite(userId string) error {
return global.DB.Where("user_id = ?", userId).Delete(&radio.RadioFavorite{}).Error
}
+12 -1
View File
@@ -37,9 +37,20 @@ func (s *ProgramService) GetProgramList(info radioReq.GetProgramList) ([]radio.R
} }
// GetProgramById 获取节目详情 // GetProgramById 获取节目详情
func (s *ProgramService) GetProgramById(id string) (*radio.RadioProgram, error) { func (s *ProgramService) GetProgramById(id, userId string) (*radio.RadioProgram, error) {
var program radio.RadioProgram var program radio.RadioProgram
err := global.DB.Where("id = ?", id).Preload("Audio").First(&program).Error err := global.DB.Where("id = ?", id).Preload("Audio").First(&program).Error
program.HasLiked = 0
program.HasFavorite = 0
liked, err := InteractionServiceApp.IsLiked(userId, id)
if liked {
program.HasLiked = 1
}
favorite, err := InteractionServiceApp.IsFavorited(userId, id)
if favorite {
program.HasFavorite = 1
}
return &program, err return &program, err
} }