package com.ly.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ly.controller.util.Result;
import com.ly.dao.CalendarDao;
import com.ly.domain.Calendar;
import com.ly.domain.User;
import com.ly.domain.Validation;
import com.ly.service.CalendarService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RequestMapping("/calendar")
@RestController
public class CalendarController {
    @Resource
    private CalendarService calendarService;
    @Resource
    private CalendarDao calendarDao;
    @PostMapping
    public Result save(@RequestBody Calendar calendar) {
        calendarService.saveOrUpdate(calendar);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) {
        calendarService.removeById(id);
        return Result.success();
    }



    @GetMapping
    public Result findAll() {

        return Result.success(calendarService.list());
    }

        @GetMapping("/date/{date}")
        public Result date(@PathVariable String date) {
            QueryWrapper<Calendar> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("date", date);
            return Result.success(calendarService.getOne(queryWrapper));
        }

}
