package com.izouma.wenlvju.web;

import com.izouma.wenlvju.domain.District;
import com.izouma.wenlvju.enums.DistrictLevel;
import com.izouma.wenlvju.repo.DistrictRepo;
import com.izouma.wenlvju.service.DistrictService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/district")
@AllArgsConstructor
public class DistrictController extends BaseController {
    private final DistrictRepo districtRepo;
    private final DistrictService districtService;

    @GetMapping({"/", ""})
    public List<District> get(@RequestParam(required = false) DistrictLevel level,
                              @RequestParam(required = false) DistrictLevel maxLevel,
                              @RequestParam(required = false) Long parent) {
        return districtService.get(level, maxLevel, parent);
    }

    @GetMapping("/NJ")
    public List<District> NJ(){
        return districtRepo.findAllByParent(320100L);
    }
}

