Internal error occurred but is skipped: FindTagsByCommitIDs

Files
VLoop/internal/video/video_handler.go

89 lines
1.9 KiB
Go
Raw Normal View History

2025-12-08 20:35:56 +08:00
package video
2025-12-07 16:45:00 +08:00
import (
"time"
"github.com/gin-gonic/gin"
)
type VideoHandler struct {
2025-12-08 20:35:56 +08:00
service *VideoService
2025-12-07 16:45:00 +08:00
}
2025-12-08 20:35:56 +08:00
func NewVideoHandler(service *VideoService) *VideoHandler {
2025-12-07 16:45:00 +08:00
return &VideoHandler{service: service}
}
type PublishVideoRequest struct {
Title string `json:"title"`
Description string `json:"description"`
PlayURL string `json:"play_url"`
}
type ListByAuthorIDRequest struct {
AuthorID uint `json:"author_id"`
}
type GetDetailRequest struct {
ID uint `json:"id"`
}
func (vh *VideoHandler) PublishVideo(c *gin.Context) {
var req PublishVideoRequest
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(400, gin.H{"error": err.Error()})
return
}
uidValue, exists := c.Get("accountID")
2025-12-07 16:45:00 +08:00
if !exists {
c.JSON(400, gin.H{"error": "accountID not found"})
2025-12-07 16:45:00 +08:00
return
}
authorID, ok := uidValue.(uint)
if !ok {
c.JSON(400, gin.H{"error": "accountID has invalid type"})
2025-12-07 16:45:00 +08:00
return
}
2025-12-08 20:35:56 +08:00
video := &Video{
2025-12-07 16:45:00 +08:00
AuthorID: authorID,
Title: req.Title,
Description: req.Description,
PlayURL: req.PlayURL,
CreateTime: time.Now(),
}
if err := vh.service.Publish(c.Request.Context(), video); err != nil {
2025-12-07 16:45:00 +08:00
c.JSON(400, gin.H{"error": err.Error()})
return
}
c.JSON(200, video)
}
func (vh *VideoHandler) ListByAuthorID(c *gin.Context) {
var req ListByAuthorIDRequest
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(400, gin.H{"error": err.Error()})
return
}
videos, err := vh.service.ListByAuthorID(c.Request.Context(), req.AuthorID)
2025-12-07 16:45:00 +08:00
if err != nil {
c.JSON(400, gin.H{"error": err.Error()})
return
}
c.JSON(200, videos)
}
func (vh *VideoHandler) GetDetail(c *gin.Context) {
var req GetDetailRequest
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(400, gin.H{"error": err.Error()})
return
}
video, err := vh.service.GetDetail(c.Request.Context(), req.ID)
2025-12-07 16:45:00 +08:00
if err != nil {
c.JSON(400, gin.H{"error": err.Error()})
return
}
c.JSON(200, video)
}