123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256 |
- // Copyright 2019 github.com. All rights reserved.
- // Use of this source code is governed by github.com.
- package v1
- import (
- "net/http"
- "xingjia-management-gateway/apis"
- "xingjia-management-gateway/errors"
- "xingjia-management-gateway/impl/v1/page_pic"
- param_v1 "xingjia-management-gateway/param/v1"
- "xingjia-management-gateway/utils"
- "git.getensh.com/common/gopkgs/logger"
- "git.getensh.com/common/gopkgs/tasker/httptasker"
- "git.getensh.com/common/gopkgs/util"
- "github.com/gin-gonic/gin"
- "go.uber.org/zap"
- )
- //
- // @Summary 添加首页顶层图片
- // @Description 添加首页顶层图片
- // @Tags 首页顶层图片
- // @Accept json
- // @Produce json
- // @Param token header string true " "
- // @Param body body v1.PagePicAddBody true " "
- // @Success 200 {object} v1.PagePicAddResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/jt/page_pic [post]
- func (c *Controller) PagePicAdd(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.PagePicAddRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.PagePicAddBody)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- tokenInfo, err := utils.GetJwtTokenFromCtx(ctx)
- if err != nil {
- return err
- }
- // 响应数据
- resp := param_v1.PagePicAddResponse{}
- rpcReq := &apis.PagePicAddRequest{
- SelfId: tokenInfo.Uid,
- SelfName: tokenInfo.User,
- Pic: req.Pic,
- }
- _, err = page_pic.PagePicAdd(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "page_pic.PagePicAdd"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- //
- // @Summary 修改首页顶层图片
- // @Description 修改首页顶层图片
- // @Tags 首页顶层图片
- // @Accept json
- // @Produce json
- // @Param token header string true " "
- // @Param body body v1.PagePicUpdateBody true " "
- // @Success 200 {object} v1.PagePicUpdateResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/jt/page_pic [put]
- func (c *Controller) PagePicUpdate(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.PagePicUpdateRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.PagePicUpdateBody)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- tokenInfo, err := utils.GetJwtTokenFromCtx(ctx)
- if err != nil {
- return err
- }
- // 响应数据
- resp := param_v1.PagePicUpdateResponse{}
- rpcReq := &apis.PagePicUpdateRequest{
- Pic: req.Pic,
- SelfId: tokenInfo.Uid,
- SelfName: tokenInfo.User,
- Id: req.Id,
- }
- _, err = page_pic.PagePicUpdate(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "page_pic.PagePicUpdate"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- //
- // @Summary 删除首页顶层图片
- // @Description 删除首页顶层图片
- // @Tags 首页顶层图片
- // @Accept json
- // @Produce json
- // @Param token header string true " "
- // @Param id query int true " 记录id"
- // @Success 200 {object} v1.PagePicDelResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/jt/page_pic [delete]
- func (c *Controller) PagePicDel(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.PagePicDelRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, &req.PagePicDelQuery, nil)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- tokenInfo, err := utils.GetJwtTokenFromCtx(ctx)
- if err != nil {
- return err
- }
- // 响应数据
- resp := param_v1.PagePicDelResponse{}
- rpcReq := &apis.PagePicDelRequest{
- SelfId: tokenInfo.Uid,
- SelfName: tokenInfo.User,
- Id: req.Id,
- }
- _, err = page_pic.PagePicDel(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "page_pic.PagePicDel"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- //
- // @Summary 首页顶层图片列表
- // @Description 首页顶层图片列表
- // @Tags 首页顶层图片
- // @Accept json
- // @Produce json
- // @Param token header string true " "
- // @Param page query int false " "
- // @Param page_size query int false " "
- // @Success 200 {object} v1.PagePicListResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/jt/page_pic [get]
- func (c *Controller) PagePicList(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.PagePicListRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, &req.PagePicListQuery, nil)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- // 响应数据
- resp := param_v1.PagePicListResponse{}
- rpcReq := &apis.PagePicListRequest{
- PageSize: req.PageSize,
- Page: req.Page,
- }
- rpcRsp, err := page_pic.PagePicList(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "page_pic.PagePicList"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- if rpcRsp.List == nil {
- rpcRsp.List = make([]*apis.PagePicItem, 0)
- }
- resp.Data = *rpcRsp
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
|