From 74b252550b8018627da9b09d1275a2962488e660 Mon Sep 17 00:00:00 2001 From: Blizzard Date: Thu, 5 Mar 2026 10:30:29 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BA=92=E5=8A=A8=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/v1/radio/interaction.go | 95 ++++- api/v1/radio/program.go | 4 +- docs/docs.go | 566 +++++++++++++-------------- docs/swagger.json | 566 +++++++++++++-------------- docs/swagger.yaml | 364 +++++++++-------- initialize/gorm.go | 5 + model/radio/radio_program.go | 2 + model/radio/request/interaction.go | 4 + router/radio/interaction_router.go | 3 + service/radio/interaction_service.go | 14 + service/radio/program_service.go | 13 +- 11 files changed, 846 insertions(+), 790 deletions(-) diff --git a/api/v1/radio/interaction.go b/api/v1/radio/interaction.go index 39fe50e..9786a13 100644 --- a/api/v1/radio/interaction.go +++ b/api/v1/radio/interaction.go @@ -15,10 +15,10 @@ type InteractionApi struct{} // AddHistory 添加收听历史 // @Tags 用户互动 // @Summary 添加收听历史 -// @Produce json +// @Produce application/json // @Param data body request.AddHistory true "收听信息" // @Success 200 {object} response.Response -// @Router /radio/history/add [post] +// @Router /history/add [post] func (a *InteractionApi) AddHistory(c *gin.Context) { userId := auth.GetUserId(c) var req request.AddHistory @@ -37,13 +37,54 @@ func (a *InteractionApi) AddHistory(c *gin.Context) { 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 获取收听历史列表 // @Tags 用户互动 // @Summary 获取收听历史列表 -// @Produce json +// @Produce application/json // @Param data body request.GetHistoryList true "分页查询" // @Success 200 {object} response.Response -// @Router /radio/history/list [post] +// @Router /history/list [post] func (a *InteractionApi) GetHistoryList(c *gin.Context) { userId := auth.GetUserId(c) var req request.GetHistoryList @@ -70,10 +111,10 @@ func (a *InteractionApi) GetHistoryList(c *gin.Context) { // ToggleLike 切换点赞状态 // @Tags 用户互动 // @Summary 切换点赞状态 -// @Produce json +// @Produce application/json // @Param data body request.ToggleLike true "节目ID" // @Success 200 {object} response.Response -// @Router /radio/like/toggle [post] +// @Router /like/toggle [post] func (a *InteractionApi) ToggleLike(c *gin.Context) { userId := auth.GetUserId(c) var req request.ToggleLike @@ -96,10 +137,10 @@ func (a *InteractionApi) ToggleLike(c *gin.Context) { // GetFavoriteList 获取收藏列表 // @Tags 用户互动 // @Summary 获取收藏列表 -// @Produce json +// @Produce application/json // @Param data body request.GetFavoriteList true "分页查询" // @Success 200 {object} response.Response -// @Router /radio/favorite/list [post] +// @Router /favorite/list [post] func (a *InteractionApi) GetFavoriteList(c *gin.Context) { userId := auth.GetUserId(c) var req request.GetFavoriteList @@ -126,10 +167,10 @@ func (a *InteractionApi) GetFavoriteList(c *gin.Context) { // AddFavorite 添加收藏 // @Tags 用户互动 // @Summary 添加收藏 -// @Produce json +// @Produce application/json // @Param data body request.AddFavorite true "节目ID" // @Success 200 {object} response.Response -// @Router /radio/favorite/add [post] +// @Router /favorite/add [post] func (a *InteractionApi) AddFavorite(c *gin.Context) { userId := auth.GetUserId(c) var req request.AddFavorite @@ -151,10 +192,10 @@ func (a *InteractionApi) AddFavorite(c *gin.Context) { // RemoveFavorite 取消收藏 // @Tags 用户互动 // @Summary 取消收藏 -// @Produce json +// @Produce application/json // @Param data body request.RemoveFavorite true "节目ID" // @Success 200 {object} response.Response -// @Router /radio/favorite/remove [post] +// @Router /favorite/remove [post] func (a *InteractionApi) RemoveFavorite(c *gin.Context) { userId := auth.GetUserId(c) var req request.RemoveFavorite @@ -173,13 +214,31 @@ func (a *InteractionApi) RemoveFavorite(c *gin.Context) { 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 获取评论列表 // @Tags 用户互动 // @Summary 获取评论列表 -// @Produce json +// @Produce application/json // @Param data body request.GetCommentList true "分页查询" // @Success 200 {object} response.Response -// @Router /radio/comment/list [post] +// @Router /comment/list [post] func (a *InteractionApi) GetCommentList(c *gin.Context) { var req request.GetCommentList err := c.ShouldBindJSON(&req) @@ -205,10 +264,10 @@ func (a *InteractionApi) GetCommentList(c *gin.Context) { // AddComment 添加评论 // @Tags 用户互动 // @Summary 添加评论 -// @Produce json +// @Produce application/json // @Param data body request.AddComment true "评论信息" // @Success 200 {object} response.Response -// @Router /radio/comment/add [post] +// @Router /comment/add [post] func (a *InteractionApi) AddComment(c *gin.Context) { userId := auth.GetUserId(c) var req request.AddComment @@ -230,10 +289,10 @@ func (a *InteractionApi) AddComment(c *gin.Context) { // DeleteComment 删除评论 // @Tags 用户互动 // @Summary 删除评论 -// @Produce json +// @Produce application/json // @Param data body request.DeleteComment true "评论ID" // @Success 200 {object} response.Response -// @Router /radio/comment/delete [post] +// @Router /comment/delete [post] func (a *InteractionApi) DeleteComment(c *gin.Context) { userId := auth.GetUserId(c) var req request.DeleteComment diff --git a/api/v1/radio/program.go b/api/v1/radio/program.go index 59f3d50..c85ed93 100644 --- a/api/v1/radio/program.go +++ b/api/v1/radio/program.go @@ -5,6 +5,7 @@ import ( common "sundynix-go/model/commom/request" "sundynix-go/model/commom/response" "sundynix-go/model/radio/request" + "sundynix-go/utils/auth" "github.com/gin-gonic/gin" "go.uber.org/zap" @@ -55,7 +56,8 @@ func (a *ProgramApi) GetProgramDetail(c *gin.Context) { response.FailWithMsg("参数错误: id不能为空", c) return } - program, err := programService.GetProgramById(id) + userId := auth.GetUserId(c) + program, err := programService.GetProgramById(id, userId) if err != nil { global.Logger.Error("获取节目详情失败!", zap.Error(err)) response.FailWithMsg(err.Error(), c) diff --git a/docs/docs.go b/docs/docs.go index 5fbe23b..dd172d9 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -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": { "get": { "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": { "post": { "produces": [ @@ -1933,7 +1933,7 @@ const docTemplate = `{ } }, "/radio/subscription/unlock": { - "get": { + "post": { "produces": [ "application/json" ], @@ -2977,18 +2977,10 @@ const docTemplate = `{ "name" ], "properties": { - "coverId": { - "description": "封面图URL", - "type": "string" - }, "description": { "description": "分类描述", "type": "string" }, - "iconId": { - "description": "图标URL", - "type": "string" - }, "name": { "description": "分类名称", "type": "string" @@ -3018,7 +3010,7 @@ const docTemplate = `{ "description": "分类ID", "type": "string" }, - "coverId": { + "cover": { "description": "封面图URL", "type": "string" }, @@ -3078,7 +3070,7 @@ const docTemplate = `{ "content": { "type": "string" }, - "coverId": { + "cover": { "description": "封面图URL", "type": "string" }, @@ -3122,18 +3114,10 @@ const docTemplate = `{ "id" ], "properties": { - "coverId": { - "description": "封面图URL", - "type": "string" - }, "description": { "description": "分类描述", "type": "string" }, - "iconId": { - "description": "图标URL", - "type": "string" - }, "id": { "description": "分类ID", "type": "string" @@ -3166,7 +3150,7 @@ const docTemplate = `{ "description": "分类ID", "type": "string" }, - "coverId": { + "cover": { "description": "封面图URL", "type": "string" }, @@ -3228,7 +3212,7 @@ const docTemplate = `{ "content": { "type": "string" }, - "coverId": { + "cover": { "description": "封面图URL", "type": "string" }, diff --git a/docs/swagger.json b/docs/swagger.json index c752a3c..137de74 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -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": { "get": { "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": { "post": { "produces": [ @@ -1926,7 +1926,7 @@ } }, "/radio/subscription/unlock": { - "get": { + "post": { "produces": [ "application/json" ], @@ -2970,18 +2970,10 @@ "name" ], "properties": { - "coverId": { - "description": "封面图URL", - "type": "string" - }, "description": { "description": "分类描述", "type": "string" }, - "iconId": { - "description": "图标URL", - "type": "string" - }, "name": { "description": "分类名称", "type": "string" @@ -3011,7 +3003,7 @@ "description": "分类ID", "type": "string" }, - "coverId": { + "cover": { "description": "封面图URL", "type": "string" }, @@ -3071,7 +3063,7 @@ "content": { "type": "string" }, - "coverId": { + "cover": { "description": "封面图URL", "type": "string" }, @@ -3115,18 +3107,10 @@ "id" ], "properties": { - "coverId": { - "description": "封面图URL", - "type": "string" - }, "description": { "description": "分类描述", "type": "string" }, - "iconId": { - "description": "图标URL", - "type": "string" - }, "id": { "description": "分类ID", "type": "string" @@ -3159,7 +3143,7 @@ "description": "分类ID", "type": "string" }, - "coverId": { + "cover": { "description": "封面图URL", "type": "string" }, @@ -3221,7 +3205,7 @@ "content": { "type": "string" }, - "coverId": { + "cover": { "description": "封面图URL", "type": "string" }, diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 9b0cf4b..1108cb9 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -286,15 +286,9 @@ definitions: type: object request.SaveCategory: properties: - coverId: - description: 封面图URL - type: string description: description: 分类描述 type: string - iconId: - description: 图标URL - type: string name: description: 分类名称 type: string @@ -315,7 +309,7 @@ definitions: categoryId: description: 分类ID type: string - coverId: + cover: description: 封面图URL type: string description: @@ -359,7 +353,7 @@ definitions: type: string content: type: string - coverId: + cover: description: 封面图URL type: string description: @@ -391,15 +385,9 @@ definitions: type: object request.UpdateCategory: properties: - coverId: - description: 封面图URL - type: string description: description: 分类描述 type: string - iconId: - description: 图标URL - type: string id: description: 分类ID type: string @@ -423,7 +411,7 @@ definitions: categoryId: description: 分类ID type: string - coverId: + cover: description: 封面图URL type: string description: @@ -468,7 +456,7 @@ definitions: type: string content: type: string - coverId: + cover: description: 封面图URL type: string description: @@ -951,6 +939,177 @@ paths: summary: 更新client 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: get: description: 删除menu @@ -1532,177 +1691,6 @@ paths: summary: 更新频道 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: post: parameters: @@ -1823,7 +1811,7 @@ paths: tags: - 订阅管理 /radio/subscription/unlock: - get: + post: parameters: - description: id in: query diff --git a/initialize/gorm.go b/initialize/gorm.go index 3058a53..0970054 100644 --- a/initialize/gorm.go +++ b/initialize/gorm.go @@ -46,6 +46,11 @@ func MigrateTable() { radio.RadioUser{}, radio.Order{}, radio.PayNotify{}, + + radio.RadioComment{}, + radio.RadioHistory{}, + radio.RadioFavorite{}, + radio.RadioLike{}, ) if err != nil { global.Logger.Error("Migrate table failed,err:", zap.Error(err)) diff --git a/model/radio/radio_program.go b/model/radio/radio_program.go index 218f8bc..d18504d 100644 --- a/model/radio/radio_program.go +++ b/model/radio/radio_program.go @@ -21,6 +21,8 @@ type RadioProgram struct { LikeCount int `gorm:"default:0" json:"likeCount"` // 点赞次数 Status int `gorm:"default:1" json:"status"` // 状态 0:下架 1:上架 Channel *RadioChannel `gorm:"foreignKey:ChannelId" json:"channel"` + HasLiked int `gorm:"-" json:"hasLiked"` // 是否点赞 + HasFavorite int `gorm:"-" json:"HasFavorite"` // 是否收藏 } func (RadioProgram) TableName() string { diff --git a/model/radio/request/interaction.go b/model/radio/request/interaction.go index 79eb655..8fde8c8 100644 --- a/model/radio/request/interaction.go +++ b/model/radio/request/interaction.go @@ -19,6 +19,10 @@ type AddHistory struct { Duration int `json:"duration"` // 节目总时长(秒) } +type RemoveHistory struct { + ProgramId string `json:"programId" binding:"required"` // 节目ID +} + // ToggleLike 切换点赞请求 type ToggleLike struct { ProgramId string `json:"programId" binding:"required"` // 节目ID diff --git a/router/radio/interaction_router.go b/router/radio/interaction_router.go index db02c7a..19f415f 100644 --- a/router/radio/interaction_router.go +++ b/router/radio/interaction_router.go @@ -12,6 +12,8 @@ func (r *InteractionRouter) InitInteractionRouter(Router *gin.RouterGroup) { { historyRouter.POST("list", interactionApi.GetHistoryList) 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("add", interactionApi.AddFavorite) favoriteRouter.POST("remove", interactionApi.RemoveFavorite) + favoriteRouter.GET("removeAll", interactionApi.RemoveAllFavorite) } // 评论 diff --git a/service/radio/interaction_service.go b/service/radio/interaction_service.go index 72af6e1..142cbfe 100644 --- a/service/radio/interaction_service.go +++ b/service/radio/interaction_service.go @@ -11,6 +11,8 @@ import ( type InteractionService struct{} +var InteractionServiceApp = new(InteractionService) + // AddHistory 添加收听历史 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 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 +} diff --git a/service/radio/program_service.go b/service/radio/program_service.go index a4c93fc..ce0e7c3 100644 --- a/service/radio/program_service.go +++ b/service/radio/program_service.go @@ -37,9 +37,20 @@ func (s *ProgramService) GetProgramList(info radioReq.GetProgramList) ([]radio.R } // GetProgramById 获取节目详情 -func (s *ProgramService) GetProgramById(id string) (*radio.RadioProgram, error) { +func (s *ProgramService) GetProgramById(id, userId string) (*radio.RadioProgram, error) { var program radio.RadioProgram 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 }