refactor:将request结构体写到entity,并为video添加username字段
This commit is contained in:
@@ -5,6 +5,7 @@ import "time"
|
|||||||
type Video struct {
|
type Video struct {
|
||||||
ID uint `gorm:"primaryKey"`
|
ID uint `gorm:"primaryKey"`
|
||||||
AuthorID uint `gorm:"index;not null"`
|
AuthorID uint `gorm:"index;not null"`
|
||||||
|
Username string `gorm:"type:varchar(255);not null"`
|
||||||
Title string `gorm:"type:varchar(255);not null"`
|
Title string `gorm:"type:varchar(255);not null"`
|
||||||
Description string `gorm:"type:varchar(255);"`
|
Description string `gorm:"type:varchar(255);"`
|
||||||
PlayURL string `gorm:"type:varchar(255);not null"`
|
PlayURL string `gorm:"type:varchar(255);not null"`
|
||||||
@@ -12,3 +13,23 @@ type Video struct {
|
|||||||
CreateTime time.Time `gorm:"autoCreateTime"`
|
CreateTime time.Time `gorm:"autoCreateTime"`
|
||||||
LikesCount int64 `gorm:"column:likes_count;not null;default:0" json:"likes_count"`
|
LikesCount int64 `gorm:"column:likes_count;not null;default:0" json:"likes_count"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type PublishVideoRequest struct {
|
||||||
|
Title string `json:"title"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
PlayURL string `json:"play_url"`
|
||||||
|
CoverURL string `json:"cover_url"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ListByAuthorIDRequest struct {
|
||||||
|
AuthorID uint `json:"author_id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetDetailRequest struct {
|
||||||
|
ID uint `json:"id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type UpdateLikesCountRequest struct {
|
||||||
|
ID uint `json:"id"`
|
||||||
|
LikesCount int64 `json:"likes_count"`
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,35 +3,18 @@ package video
|
|||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"feedsystem_video_go/internal/account"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
type VideoHandler struct {
|
type VideoHandler struct {
|
||||||
service *VideoService
|
service *VideoService
|
||||||
|
accountService *account.AccountService
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewVideoHandler(service *VideoService) *VideoHandler {
|
func NewVideoHandler(service *VideoService, accountService *account.AccountService) *VideoHandler {
|
||||||
return &VideoHandler{service: service}
|
return &VideoHandler{service: service, accountService: accountService}
|
||||||
}
|
|
||||||
|
|
||||||
type PublishVideoRequest struct {
|
|
||||||
Title string `json:"title"`
|
|
||||||
Description string `json:"description"`
|
|
||||||
PlayURL string `json:"play_url"`
|
|
||||||
CoverURL string `json:"cover_url"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type ListByAuthorIDRequest struct {
|
|
||||||
AuthorID uint `json:"author_id"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type GetDetailRequest struct {
|
|
||||||
ID uint `json:"id"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type UpdateLikesCountRequest struct {
|
|
||||||
ID uint `json:"id"`
|
|
||||||
LikesCount int64 `json:"likes_count"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (vh *VideoHandler) PublishVideo(c *gin.Context) {
|
func (vh *VideoHandler) PublishVideo(c *gin.Context) {
|
||||||
@@ -51,8 +34,14 @@ func (vh *VideoHandler) PublishVideo(c *gin.Context) {
|
|||||||
c.JSON(400, gin.H{"error": "accountID has invalid type"})
|
c.JSON(400, gin.H{"error": "accountID has invalid type"})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
user, err := vh.accountService.FindByID(c.Request.Context(), authorID)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(400, gin.H{"error": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
video := &Video{
|
video := &Video{
|
||||||
AuthorID: authorID,
|
AuthorID: authorID,
|
||||||
|
Username: user.Username,
|
||||||
Title: req.Title,
|
Title: req.Title,
|
||||||
Description: req.Description,
|
Description: req.Description,
|
||||||
PlayURL: req.PlayURL,
|
PlayURL: req.PlayURL,
|
||||||
|
|||||||
Reference in New Issue
Block a user