Fix: room list resp model

pull/24/head
zijiren233 2 years ago
parent 12b90a15f2
commit 6378b89a91

@ -25,13 +25,13 @@ func (m *Movie) BeforeCreate(tx *gorm.DB) error {
}
type BaseMovie struct {
Url string `json:"url,omitempty"`
Url string `json:"url"`
Name string `gorm:"not null" json:"name"`
Live bool `json:"live,omitempty"`
Proxy bool `json:"proxy,omitempty"`
RtmpSource bool `json:"rtmpSource,omitempty"`
Type string `json:"type,omitempty"`
Headers map[string]string `gorm:"serializer:fastjson" json:"headers,omitempty"`
Live bool `json:"live"`
Proxy bool `json:"proxy"`
RtmpSource bool `json:"rtmpSource"`
Type string `json:"type"`
Headers map[string]string `gorm:"serializer:fastjson" json:"headers"`
VendorInfo `gorm:"embedded;embeddedPrefix:vendor_info_" json:"vendorInfo,omitempty"`
}
@ -42,8 +42,8 @@ type VendorInfo struct {
}
type BilibiliVendorInfo struct {
Bvid string `json:"bvid,omitempty"`
Cid uint `json:"cid,omitempty"`
Epid uint `json:"epid,omitempty"`
Quality uint `json:"quality,omitempty"`
Bvid string `json:"bvid"`
Cid uint `json:"cid"`
Epid uint `json:"epid"`
Quality uint `json:"quality"`
}

@ -165,12 +165,12 @@ func GetAllRoomsInCacheWithoutHidden() []*Room {
}
type RoomHeapItem struct {
ID string
RoomName string
ClientNum int64
NeedPassword bool
CreatorID string
CreatedAt time.Time
RoomId string `json:"roomId"`
RoomName string `json:"roomName"`
PeopleNum int64 `json:"peopleNum"`
NeedPassword bool `json:"needPassword"`
Creator string `json:"creator"`
CreatedAt int64 `json:"createdAt"`
}
type RoomHeap []*RoomHeapItem
@ -180,7 +180,7 @@ func (h RoomHeap) Len() int {
}
func (h RoomHeap) Less(i, j int) bool {
return h[i].ClientNum < h[j].ClientNum
return h[i].PeopleNum < h[j].PeopleNum
}
func (h RoomHeap) Swap(i, j int) {
@ -205,12 +205,12 @@ func GetRoomHeapInCacheWithoutHidden() RoomHeap {
v := value.Value()
if !v.Settings.Hidden {
heap.Push[*RoomHeapItem](&rooms, &RoomHeapItem{
ID: v.ID,
RoomId: v.ID,
RoomName: v.Name,
ClientNum: v.ClientNum(),
PeopleNum: v.ClientNum(),
NeedPassword: v.NeedPassword(),
CreatorID: v.CreatorID,
CreatedAt: v.CreatedAt,
Creator: v.CreatorID,
CreatedAt: v.CreatedAt.UnixMilli(),
})
}
return true

@ -42,13 +42,11 @@ func CreateRoom(ctx *gin.Context) {
return
}
CreateRoomNeedReview := settings.CreateRoomNeedReview.Get()
var (
r *dbModel.Room
err error
)
if CreateRoomNeedReview {
if settings.CreateRoomNeedReview.Get() {
r, err = user.CreateRoom(req.RoomName, req.Password, db.WithSetting(req.Setting), db.WithStatus(dbModel.RoomStatusPending))
} else {
r, err = user.CreateRoom(req.RoomName, req.Password, db.WithSetting(req.Setting), db.WithStatus(dbModel.RoomStatusActive))
@ -81,17 +79,6 @@ func RoomHotList(ctx *gin.Context) {
r := op.GetRoomHeapInCacheWithoutHidden()
rs := utils.GetPageItems(r, page, pageSize)
resp := make([]*model.RoomListResp, len(rs))
for i, v := range rs {
resp[i] = &model.RoomListResp{
RoomId: v.ID,
RoomName: v.RoomName,
PeopleNum: v.ClientNum,
NeedPassword: v.NeedPassword,
Creator: op.GetUserName(v.CreatorID),
CreatedAt: v.CreatedAt.UnixMilli(),
}
}
ctx.JSON(http.StatusOK, model.NewApiDataResp(gin.H{
"total": len(r),

@ -7,6 +7,7 @@ import (
json "github.com/json-iterator/go"
"github.com/synctv-org/synctv/internal/model"
"github.com/synctv-org/synctv/internal/op"
"github.com/synctv-org/synctv/internal/settings"
"github.com/gin-gonic/gin"
@ -70,14 +71,7 @@ func (c *CreateRoomReq) Validate() error {
return nil
}
type RoomListResp struct {
RoomId string `json:"roomId"`
RoomName string `json:"roomName"`
PeopleNum int64 `json:"peopleNum"`
NeedPassword bool `json:"needPassword"`
Creator string `json:"creator"`
CreatedAt int64 `json:"createdAt"`
}
type RoomListResp = op.RoomHeapItem
type LoginRoomReq struct {
RoomId string `json:"roomId"`

Loading…
Cancel
Save