81 lines
2.0 KiB
Go
81 lines
2.0 KiB
Go
package user
|
||
|
||
import (
|
||
"nl-video-api/internal/service"
|
||
"github.com/gogf/gf/v2/net/ghttp"
|
||
)
|
||
|
||
// UserWatchHistoryController 用户观看历史控制器
|
||
type UserWatchHistoryController struct{}
|
||
|
||
var UserWatchHistory = &UserWatchHistoryController{}
|
||
|
||
// Add 添加观看历史
|
||
func (c *UserWatchHistoryController) Add(r *ghttp.Request) {
|
||
service.NewUserWatchHistoryService().Add(r)
|
||
}
|
||
|
||
// GetList 获取观看历史列表
|
||
func (c *UserWatchHistoryController) GetList(r *ghttp.Request) {
|
||
service.NewUserWatchHistoryService().GetList(r)
|
||
}
|
||
|
||
// Delete 删除观看历史
|
||
func (c *UserWatchHistoryController) Delete(r *ghttp.Request) {
|
||
service.NewUserWatchHistoryService().Delete(r)
|
||
}
|
||
|
||
// Clear 清空观看历史
|
||
func (c *UserWatchHistoryController) Clear(r *ghttp.Request) {
|
||
// 获取用户ID(需要实现GetUserIdFromContext函数)
|
||
userId := service.GetUserIdFromContext(r.Context())
|
||
if userId == 0 {
|
||
r.Response.WriteJson(map[string]interface{}{
|
||
"code": 401,
|
||
"message": "请先登录",
|
||
})
|
||
return
|
||
}
|
||
|
||
err := service.NewUserWatchHistoryService().Clear(r.Context(), &service.UserWatchHistoryClearReq{
|
||
UserId: uint(userId),
|
||
})
|
||
if err != nil {
|
||
r.Response.WriteJson(map[string]interface{}{
|
||
"code": 1002,
|
||
"message": err.Error(),
|
||
})
|
||
return
|
||
}
|
||
|
||
r.Response.WriteJson(map[string]interface{}{
|
||
"code": 0,
|
||
"message": "清空成功",
|
||
})
|
||
}
|
||
|
||
// GetProgress 获取观看进度
|
||
func (c *UserWatchHistoryController) GetProgress(r *ghttp.Request) {
|
||
service.NewUserWatchHistoryService().GetProgress(r)
|
||
}
|
||
|
||
// List 获取观看历史列表(别名方法)
|
||
func (c *UserWatchHistoryController) List(r *ghttp.Request) {
|
||
c.GetList(r)
|
||
}
|
||
|
||
// Get 获取单个观看历史记录
|
||
func (c *UserWatchHistoryController) Get(r *ghttp.Request) {
|
||
// TODO: 实现获取单个观看历史记录逻辑
|
||
r.Response.WriteJson(map[string]interface{}{
|
||
"code": 0,
|
||
"message": "获取成功",
|
||
"data": map[string]interface{}{
|
||
"id": 1,
|
||
"movie_id": 1,
|
||
"progress": 50,
|
||
"watch_time": 3600,
|
||
},
|
||
})
|
||
}
|