package com.playlet.web.controller.app;

import com.github.pagehelper.PageInfo;
import com.playlet.common.core.domain.Result;
import com.playlet.system.domain.PlayletMessage;
import com.playlet.web.service.app.PlayletMessageAppService;
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.*;

import java.util.List;

@Slf4j
@Api(tags = "小程序*短剧公告接口")
@RestController
@RequestMapping(value = "/app/message")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class PlayletMessageAppController {

    private final PlayletMessageAppService playletMessageAppService;

    @ResponseBody
    @PostMapping(value = "/getMessageList")
    @ApiOperation(value = "获取短剧公告列表", httpMethod = "POST")
    public Result<List<PlayletMessage>> getMessageList(@RequestBody PlayletMessage playletMessage){
        try {
            return Result.success(playletMessageAppService.getMessageList(playletMessage));
        }catch (Exception e){
            return Result.error(e.getMessage());
        }
    }

    @ResponseBody
    @PostMapping(value = "/getMessagePage")
    @ApiOperation(value = "获取短剧公告列表分页", httpMethod = "POST")
    public Result<PageInfo<PlayletMessage>> getMessagePage(@RequestBody PlayletMessage playletMessage,
                                                           @RequestParam(value = "pageNum")Integer pageNum,
                                                           @RequestParam(value = "pageSize")Integer pageSize){
        try {
            return Result.success(playletMessageAppService.getMessagePage(playletMessage, pageNum, pageSize));
        }catch (Exception e){
            return Result.error(e.getMessage());
        }
    }

}
