You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
75 lines
2.2 KiB
75 lines
2.2 KiB
package com.example.demo.controller;
|
|
|
|
|
|
|
|
import com.example.demo.domain.entity.Rate;
|
|
import com.example.demo.domain.vo.Page;
|
|
import com.example.demo.domain.vo.Result;
|
|
import com.example.demo.sevice.RateService;
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import org.springframework.util.ObjectUtils;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import java.util.Arrays;
|
|
|
|
@RestController
|
|
@RequestMapping("/rates")
|
|
@RequiredArgsConstructor
|
|
@Slf4j
|
|
@CrossOrigin
|
|
public class RateController {
|
|
private final RateService rateService;
|
|
|
|
@PostMapping("/add")
|
|
public Result add(@RequestBody Rate rate) {
|
|
try {
|
|
rateService.add(rate);
|
|
return Result.success();
|
|
} catch (Exception e) {
|
|
log.warn(Arrays.toString(e.getStackTrace()));
|
|
return Result.error(e.getMessage());
|
|
}
|
|
}
|
|
@PostMapping("/update") // 将 PUT 改为 POST
|
|
public Result update(@RequestBody Rate rate) throws Exception {
|
|
rateService.edit(rate);
|
|
return Result.success();
|
|
}
|
|
|
|
|
|
@PostMapping("/delete/{rateId}") // 将 DELETE 改为 POST
|
|
public Result delete(@PathVariable("rateId") Integer rateId) {
|
|
try {
|
|
rateService.softDelete(rateId);
|
|
return Result.success();
|
|
} catch (Exception e) {
|
|
log.warn(Arrays.toString(e.getStackTrace()));
|
|
return Result.error(e.getMessage());
|
|
}
|
|
}
|
|
|
|
@PostMapping("/status")
|
|
public Result status(@RequestBody Rate rate) throws Exception {
|
|
return Result.success(rateService.selectByStatus(rate));
|
|
}
|
|
@PostMapping("/searchById")
|
|
public Result searchById(@RequestParam Integer rateId) {
|
|
|
|
return Result.success(rateService.getById(rateId));
|
|
}
|
|
|
|
@PostMapping("/search") // 改为 POST 请求
|
|
public Result search(@RequestBody Page page) {
|
|
Integer pageNum = page.getPageNum();
|
|
Integer pageSize = page.getPageSize();
|
|
Rate rate = page.getRate();
|
|
|
|
if (ObjectUtils.isEmpty(pageNum)) {
|
|
return Result.success(rateService.search(rate));
|
|
} else {
|
|
return Result.success(rateService.searchForPage(pageNum, pageSize, rate));
|
|
}
|
|
}
|
|
}
|