package com.playlet.web.controller.app;

import com.github.pagehelper.PageInfo;
import com.playlet.common.core.domain.Result;
import com.playlet.system.domain.PlayletUserItem;
import com.playlet.web.service.app.PlayletUserItemAppService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Api(tags = "短剧视频*短剧用户推广")
@RestController
@RequestMapping(value = "/app/userItem")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class PlayletUserItemAppController {

    private final PlayletUserItemAppService playletUserItemAppService;

    @ResponseBody
    @PostMapping("/addUserItem")
    @ApiOperation(value = "新增用户推广短剧")
    public Result<String> addUserItem(@RequestBody PlayletUserItem playletUserItem){
        try {
            return Result.success(playletUserItemAppService.addUserItem(playletUserItem), "操作成功");
        }catch (Exception e){
            log.error("新增用户推广短剧,异常:{}", e.getMessage(), e);
            return Result.error();
        }
    }

    @ResponseBody
    @PostMapping("/getUserItemPage")
    @ApiOperation(value = "分页查询我推广的短剧")
    public Result<PageInfo<PlayletUserItem>> getUserItemPage(@RequestBody PlayletUserItem playletUserItem,
                                                             @RequestParam(value = "pageNum") Integer pageNum,
                                                             @RequestParam(value = "pageSize") Integer pageSize){
        try {
            return Result.success(playletUserItemAppService.getUserItemPage(playletUserItem, pageNum, pageSize));
        }catch (Exception e){
            log.error("新增用户推广短剧,异常:{}", e.getMessage(), e);
            return Result.error();
        }
    }


}
