123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333 |
- // 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/consts"
- "xingjia-management-gateway/errors"
- "xingjia-management-gateway/impl/v1/jt"
- 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.JtContentAddBody true " "
- // @Success 200 {object} v1.JtContentAddResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/jt/program [post]
- func (c *Controller) JtProgramAdd(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.JtContentAddRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.JtContentAddBody)
- 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.JtContentAddResponse{}
- rpcReq := &apis.JtContentAddRequest{
- FirstPics: req.FirstPics,
- ContentType: consts.OperationModuleProgram,
- Content: req.Content,
- SelfId: tokenInfo.Uid,
- SelfName: tokenInfo.User,
- PublishStatus: req.PublishStatus,
- Title: req.Title,
- }
- _, err = jt.JtContentAdd(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "jt.JtContentAdd"),
- 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.JtContentUpdateBody true " "
- // @Success 200 {object} v1.JtContentUpdateResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/jt/program [put]
- func (c *Controller) JtProgramUpdate(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.JtContentUpdateRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.JtContentUpdateBody)
- 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.JtContentUpdateResponse{}
- rpcReq := &apis.JtContentUpdateRequest{
- FirstPics: req.FirstPics,
- ContentType: consts.OperationModuleProgram,
- Content: req.Content,
- SelfId: tokenInfo.Uid,
- SelfName: tokenInfo.User,
- Id: req.Id,
- PublishStatus: req.PublishStatus,
- Title: req.Title,
- }
- _, err = jt.JtContentUpdate(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "jt.JtContentUpdate"),
- 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.JtContentPublishBody true " "
- // @Success 200 {object} v1.JtContentPublishResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/jt/program/publish [put]
- func (c *Controller) JtProgramPublish(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.JtContentPublishRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.JtContentPublishBody)
- 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.JtContentPublishResponse{}
- rpcReq := &apis.JtContentPublishRequest{
- ContentType: consts.OperationModuleProgram,
- SelfId: tokenInfo.Uid,
- SelfName: tokenInfo.User,
- Id: req.Id,
- PublishStatus: req.PublishStatus,
- }
- _, err = jt.JtContentPublish(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "jt.JtContentPublish"),
- 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.JtContentDelResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/jt/program [delete]
- func (c *Controller) JtProgramDel(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.JtContentDelRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, &req.JtContentDelQuery, 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.JtContentDelResponse{}
- rpcReq := &apis.JtContentDelRequest{
- ContentType: consts.OperationModuleProgram,
- SelfId: tokenInfo.Uid,
- SelfName: tokenInfo.User,
- Id: req.Id,
- }
- _, err = jt.JtContentDel(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "jt.JtContentDel"),
- 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.JtContentListResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/jt/program [get]
- func (c *Controller) JtProgramList(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.JtContentListRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, &req.JtContentListQuery, 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.JtContentListResponse{}
- rpcReq := &apis.JtContentListRequest{
- ContentType: consts.OperationModuleProgram,
- PageSize: req.PageSize,
- Page: req.Page,
- SelfId: tokenInfo.Uid,
- }
- rpcRsp, err := jt.JtContentList(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "jt.JtContentList"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- if rpcRsp.List == nil {
- rpcRsp.List = make([]*apis.JtContentItem, 0)
- }
- resp.Data = *rpcRsp
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
|