Commit 78f35215 authored by shajiaiming's avatar shajiaiming

fix

parent 2e664c09
......@@ -82,9 +82,9 @@ func AddLiveInfo(data map[string]interface{}) (error) {
Attendance: data["attendance"].(uint32),
Mode: data["mode"].(uint8),
ApplyId: data["apply_id"].(uint32),
Status: data["status"].(uint8),
Sort: data["sort"].(uint8),
}
if err := db.Create(&live).Error; err != nil {
return err
}
......
......@@ -3,51 +3,48 @@ package backend
import (
"bwallet/pkg/errno"
"bwallet/pkg/handler"
"bwallet/pkg/util"
"bwallet/service/live_info_service"
"bwallet/validate_service"
"github.com/Unknwon/com"
"github.com/astaxie/beego/validation"
"github.com/gin-gonic/gin"
"strings"
)
func GetLiveInfo(c *gin.Context) {
token := c.Request.Header.Get("Token")
user, _ := util.ParseToken(token)
group := user.UserInfo.Group
var platform_id int
platform_id = user.UserInfo.PlatformId
if ("administrator" == group) {
if arg := c.Query("platform_id"); arg != "" {
platform_id = com.StrTo(c.Query("platform_id")).MustInt()
}
}
infoService := live_info_service.LiveInfo{
PlatformId: int64(platform_id),
PageNum: util.GetPage(c),
PageSize: util.GetLimit(c),
}
total, err := infoService.Count()
if err != nil {
handler.SendResponse(c, errno.ErrCountLiveInfo, nil)
return
}
info, err := infoService.GetAll()
if err != nil {
handler.SendResponse(c, errno.InternalServerError, nil)
return
}
data := make(map[string]interface{})
data["items"] = info
data["total"] = total
handler.SendResponse(c, nil, data)
//token := c.Request.Header.Get("Token")
//user, _ := util.ParseToken(token)
//group := user.UserInfo.Group
//
//var platform_id int
//platform_id = user.UserInfo.PlatformId
//if ("administrator" == group) {
// if arg := c.Query("platform_id"); arg != "" {
// platform_id = com.StrTo(c.Query("platform_id")).MustInt()
// }
//}
//
//infoService := live_info_service.LiveInfo{
// PlatformId: int64(platform_id),
// PageNum: util.GetPage(c),
// PageSize: util.GetLimit(c),
//}
//
//total, err := infoService.Count()
//if err != nil {
// handler.SendResponse(c, errno.ErrCountLiveInfo, nil)
// return
//}
//
//info, err := infoService.GetAll()
//if err != nil {
// handler.SendResponse(c, errno.InternalServerError, nil)
// return
//}
//
//data := make(map[string]interface{})
//data["items"] = info
//data["total"] = total
//
//handler.SendResponse(c, nil, data)
}
func AddLiveInfo(c *gin.Context) {
......@@ -111,41 +108,41 @@ func EditLiveInfo(c *gin.Context) {
}
func DeleteLiveInfo(c *gin.Context) {
id := com.StrTo(c.DefaultQuery("id", "0")).MustInt()
valid := validation.Validation{}
valid.Min(id, 1, "id").Message("Id必须大于0")
if valid.HasErrors() {
handler.SendResponse(c, valid.Errors[0], nil)
return
}
infoService := live_info_service.LiveInfo{Id: id}
exists, err := infoService.ExistById()
if err != nil {
handler.SendResponse(c, errno.ErrLiveInfoNotFound, nil)
return
}
if !exists {
handler.SendResponse(c, errno.ErrLiveInfoNotFound, nil)
return
}
token := c.Request.Header.Get("Token")
user, _ := util.ParseToken(token)
group := user.UserInfo.Group
if ("administrator" != group) {
info, _ := infoService.GetOneLiveInfo()
if info.PlatformId != int64(user.UserInfo.PlatformId) {
handler.SendResponse(c, errno.ErrUserAuthIncorrect, nil)
return
}
}
err = infoService.Delete()
if err != nil {
handler.SendResponse(c, errno.ErrDeleteLiveInfo, nil)
return
}
handler.SendResponse(c, nil, nil)
//id := com.StrTo(c.DefaultQuery("id", "0")).MustInt()
//valid := validation.Validation{}
//valid.Min(id, 1, "id").Message("Id必须大于0")
//if valid.HasErrors() {
// handler.SendResponse(c, valid.Errors[0], nil)
// return
//}
//
//infoService := live_info_service.LiveInfo{Id: id}
//exists, err := infoService.ExistById()
//if err != nil {
// handler.SendResponse(c, errno.ErrLiveInfoNotFound, nil)
// return
//}
//
//if !exists {
// handler.SendResponse(c, errno.ErrLiveInfoNotFound, nil)
// return
//}
//
//token := c.Request.Header.Get("Token")
//user, _ := util.ParseToken(token)
//group := user.UserInfo.Group
//if ("administrator" != group) {
// info, _ := infoService.GetOneLiveInfo()
// if info.PlatformId != int64(user.UserInfo.PlatformId) {
// handler.SendResponse(c, errno.ErrUserAuthIncorrect, nil)
// return
// }
//}
//err = infoService.Delete()
//if err != nil {
// handler.SendResponse(c, errno.ErrDeleteLiveInfo, nil)
// return
//}
//
//handler.SendResponse(c, nil, nil)
}
......@@ -2,8 +2,6 @@ package routers
import (
"bwallet/middleware/jwt"
"bwallet/middleware/log"
"bwallet/pkg/e"
"github.com/gin-gonic/gin"
"bwallet/pkg/upload"
......@@ -39,7 +37,7 @@ func InitRouter() *gin.Engine {
api.Use(jwt.JWT())
api.POST("/log", backend.AddOperationLog)
api.GET("/logs", backend.GetOperationLogs)
api.Use(log.LogMiddleware(e.HandleTableName))
//api.Use(log.LogMiddleware(e.HandleTableName))
{
//api.POST("/upload",backend.Upload)
api.GET("/coins", backend.GetCoins)
......@@ -111,6 +109,8 @@ func InitRouter() *gin.Engine {
api.POST("/live-category", backend.AddLiveCategory)
api.PUT("/live-category", backend.EditLiveCategory)
api.DELETE("/live-category", backend.DeleteLiveCategory)
api.POST("/live", backend.AddLiveInfo)
}
return r
......
......@@ -41,7 +41,7 @@ func (l *LiveInfo) GetAll() ([]*models.LiveInfo, error) {
}
func (l *LiveInfo) Add() error {
category := map[string]interface{}{
live := map[string]interface{}{
"title": l.Title,
"cover": l.Cover,
"category_id": l.CategoryId,
......@@ -52,7 +52,7 @@ func (l *LiveInfo) Add() error {
"sort": l.Sort,
}
if err := models.AddLiveInfo(category); err != nil {
if err := models.AddLiveInfo(live); err != nil {
return err
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment