package com.cyl.h5.controller;

import com.cyl.manager.act.domain.entity.ActivityApplyInfo;
import com.cyl.manager.act.domain.query.ActivityApplyInfoQuery;
import com.cyl.manager.act.domain.vo.ActivityApplyInfoSaveVo;
import com.cyl.manager.act.service.ActivityApplyInfoService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 活动报名信息Controller
 *
 * @author zcc
 * @date 2024-07-31
 */
@Api(description = "小程序-活动报名接口")
@RestController
@RequestMapping("/h5/activityApplyInfo")
public class H5ActivityApplyInfoController extends BaseController {
    @Autowired
    private ActivityApplyInfoService service;


    @ApiOperation("我的报名列表")
    @PostMapping("/list")
    public ResponseEntity<Page<ActivityApplyInfo>> list(@RequestBody ActivityApplyInfoQuery query, Pageable page) {
        List<ActivityApplyInfo> list = service.selectList(query, page);
        return ResponseEntity.ok(new PageImpl<>(list, page, ((com.github.pagehelper.Page) list).getTotal()));
    }

    @ApiOperation("获取活动报名信息详细信息")
    @GetMapping(value = "/{id}")
    public ResponseEntity<ActivityApplyInfo> getInfo(@PathVariable("id") Long id) {
        return ResponseEntity.ok(service.selectById(id));
    }

    @ApiOperation("修改活动报名信息")
    @Log(title = "活动报名信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public ResponseEntity<Integer> edit(@RequestBody ActivityApplyInfo activityApplyInfo) {
        return ResponseEntity.ok(service.update(activityApplyInfo));
    }

    @ApiOperation("新增活动报名信息")
    @Log(title = "活动报名信息", businessType = BusinessType.INSERT)
    @PostMapping
    public ResponseEntity<Integer> insert(@RequestBody ActivityApplyInfoSaveVo activityApplyInfoSaveVo) {
        return ResponseEntity.ok(service.insertAll(activityApplyInfoSaveVo));
    }
}
