package rd.controller.activity;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckRole;
import rd.data.db.table.Activity;
import rd.data.model.request.admin.ActivityInfoDto;
import rd.data.model.response.Response;

import rd.service.activity.ActivityService;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/activity")
public class AdminActivityController {

    private final ActivityService activityService;

    public AdminActivityController(ActivityService activityService) {
        this.activityService = activityService;
    }

    @SaCheckLogin
    @SaCheckRole("ADMIN")
    @PostMapping("/add")
    public Response<Activity> add(@RequestBody ActivityInfoDto request) {
        activityService.addActivity(request);
        return Response.success();
    }

    @SaCheckLogin
    @SaCheckRole("ADMIN")
    @PostMapping("/update")
    public Response<Activity> update(@RequestParam("id") Long id, @RequestBody ActivityInfoDto request) {
        var activity = activityService.update(id, request);
        return Response.success(activity);
    }

    @SaCheckRole("ADMIN")
    @PostMapping("/delete")
    public Response<Activity> delete(@RequestParam("id") Long id) {
        activityService.delete(id);
        return Response.success();
    }
}
