增加获取数据详情
This commit is contained in:
parent
9f85db53ab
commit
b0ddc80d18
@ -3,6 +3,7 @@ package controller
|
|||||||
import (
|
import (
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"vote-api/api/dao"
|
"vote-api/api/dao"
|
||||||
|
"vote-api/api/dto"
|
||||||
"vote-api/api/responses"
|
"vote-api/api/responses"
|
||||||
"vote-api/global"
|
"vote-api/global"
|
||||||
"vote-api/utils"
|
"vote-api/utils"
|
||||||
@ -36,3 +37,19 @@ func (r *Public) AddBrowse(c *gin.Context) {
|
|||||||
tx.Commit()
|
tx.Commit()
|
||||||
responses.Ok(c)
|
responses.Ok(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetData 获取数据详情
|
||||||
|
func (r *Public) GetData(c *gin.Context) {
|
||||||
|
// 增加数据表-投票数量
|
||||||
|
dataDao := dao.DataDao{}
|
||||||
|
data, err := dataDao.GetDataById(1)
|
||||||
|
if err != nil {
|
||||||
|
responses.OkWithData(nil, c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理返回值
|
||||||
|
g := dto.GetDataDto(data)
|
||||||
|
|
||||||
|
responses.OkWithData(g, c)
|
||||||
|
}
|
||||||
|
|||||||
18
api/dto/Data.go
Normal file
18
api/dto/Data.go
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package dto
|
||||||
|
|
||||||
|
import (
|
||||||
|
"vote-api/api/model"
|
||||||
|
)
|
||||||
|
|
||||||
|
type DataDto struct {
|
||||||
|
ViewNum uint `json:"view_num"` // 浏览数量
|
||||||
|
VoteNum uint `json:"vote_num"` // 投票数量
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetDataDto 详情
|
||||||
|
func GetDataDto(m *model.Data) *DataDto {
|
||||||
|
return &DataDto{
|
||||||
|
ViewNum: m.ViewNum,
|
||||||
|
VoteNum: m.VoteNum,
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -84,6 +84,13 @@ func publicRouter(r *gin.Engine, api controller.Api) {
|
|||||||
// 获取协议详情
|
// 获取协议详情
|
||||||
articleGroup.GET("", api.Basic.GetBasicAgreement)
|
articleGroup.GET("", api.Basic.GetBasicAgreement)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 数据
|
||||||
|
dataGroup := r.Group("/data")
|
||||||
|
{
|
||||||
|
// 获取数据详情
|
||||||
|
dataGroup.GET("", api.Public.GetData)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// adminRouter 公共路由-验证权限
|
// adminRouter 公共路由-验证权限
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user