github.com/easysoft/zendata@v0.0.0-20240513203326-705bd5a7fd67/internal/server/controller/def.go (about)

     1  package controller
     2  
     3  import (
     4  	consts "github.com/easysoft/zendata/internal/pkg/const"
     5  	"github.com/easysoft/zendata/internal/pkg/model"
     6  	serverService "github.com/easysoft/zendata/internal/server/service"
     7  	"github.com/kataras/iris/v12"
     8  )
     9  
    10  type DefCtrl struct {
    11  	DefService     *serverService.DefService     `inject:""`
    12  	PreviewService *serverService.PreviewService `inject:""`
    13  	BaseCtrl
    14  }
    15  
    16  func (c *DefCtrl) List(ctx iris.Context) {
    17  	req := model.ReqData{}
    18  
    19  	err := ctx.ReadQuery(&req)
    20  	if err != nil {
    21  		ctx.JSON(c.ErrResp(consts.CommErr, err.Error()))
    22  		return
    23  	}
    24  
    25  	list, total := c.DefService.List(req.Keywords, req.Page)
    26  
    27  	ctx.JSON(c.SuccessResp(iris.Map{"list": list, "total": total}))
    28  }
    29  
    30  //func (c *DefCtrl) Get(ctx iris.Context) {
    31  //	//id, err := ctx.Params().GetInt("id")
    32  //	//if err != nil {
    33  //	//	ctx.JSON(c.ErrResp(commConsts.CommErr, err.Error()))
    34  //	//	return
    35  //	//}
    36  //	//
    37  //	//po, err := c.DefService.Get(uint(id))
    38  //	//if err != nil {
    39  //	//	ctx.JSON(c.ErrResp(commConsts.CommErr, err.Error()))
    40  //	//	return
    41  //	//}
    42  //	//ctx.JSON(c.SuccessResp(po))
    43  //}
    44  //
    45  //func (c *DefCtrl) Create(ctx iris.Context) {
    46  //	//req := model.Def{}
    47  //	//if err := ctx.ReadJSON(&req); err != nil {
    48  //	//	ctx.JSON(c.ErrResp(commConsts.ParamErr, err.Error()))
    49  //	//}
    50  //	//
    51  //	//id, err := c.DefService.Create(req)
    52  //	//if err != nil {
    53  //	//	ctx.JSON(c.ErrResp(commConsts.ErrZentaoConfig, err.Error()))
    54  //	//	return
    55  //	//}
    56  //	//
    57  //	//ctx.JSON(c.SuccessResp(iris.Map{"id": id}))
    58  //}
    59  //
    60  //func (c *DefCtrl) Update(ctx iris.Context) {
    61  //	//req := model.Def{}
    62  //	//if err := ctx.ReadJSON(&req); err != nil {
    63  //	//	ctx.JSON(c.ErrResp(commConsts.ParamErr, err.Error()))
    64  //	//}
    65  //	//
    66  //	//err := c.DefService.Update(req)
    67  //	//if err != nil {
    68  //	//	ctx.JSON(c.ErrResp(commConsts.ErrZentaoConfig, err.Error()))
    69  //	//	return
    70  //	//}
    71  //	//
    72  //	//ctx.JSON(c.SuccessResp(iris.Map{"id": req.ID}))
    73  //}
    74  //
    75  //func (c *DefCtrl) Delete(ctx iris.Context) {
    76  //	//id, err := ctx.Params().GetInt("id")
    77  //	//if err != nil {
    78  //	//	ctx.JSON(c.ErrResp(commConsts.CommErr, err.Error()))
    79  //	//	return
    80  //	//}
    81  //	//
    82  //	//err = c.DefService.Delete(uint(id))
    83  //	//if err != nil {
    84  //	//	ctx.JSON(c.ErrResp(commConsts.CommErr, err.Error()))
    85  //	//	return
    86  //	//}
    87  //	//
    88  //	//ctx.JSON(c.SuccessResp(nil))
    89  //}
    90  //
    91  //func (c *DefCtrl) PreviewData(ctx iris.Context) {
    92  //	defId, err := ctx.URLParamInt("defId")
    93  //	if err != nil {
    94  //		ctx.JSON(consts.ParamErr.Code)
    95  //	}
    96  //
    97  //	data := c.PreviewService.PreviewDefData(uint(defId))
    98  //
    99  //	ctx.JSON(c.SuccessResp(data))
   100  //}