import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import your.package.name.model.LostItem; // Suppose your lost property model class is called LostItem
import your.package.name.service.LostItemService; // Suppose your service is called LostItemService
import org.springframework.beans.factory.annotation.Autowired;
@RestController
@RequestMapping("/lostItems")
public class LostItemController {
@Autowired
private LostItemService lostItemService;
// Get a list of all lost items
@GetMapping
public Page<LostItem> getAllLostItems(
@RequestParam(defaultValue = "1") Integer page,
@RequestParam(defaultValue = "10") Integer size) {
Page<LostItem> lostItemsPage = new Page<>(page, size);
QueryWrapper<LostItem> queryWrapper = new QueryWrapper<>();
// You can add query conditions here
return lostItemService.page(lostItemsPage, queryWrapper);
}
// Obtain single lost property information based on ID
@GetMapping("/{id}")
public LostItem getLostItemById(@PathVariable Long id) {
return lostItemService.getById(id);
}
// Create new lost information
@PostMapping
public void createLostItem(@RequestBody LostItem lostItem) {
lostItemService.save(lostItem);
}
// Update lost property information
@PutMapping("/{id}")
public void updateLostItem(@PathVariable Long id, @RequestBody LostItem lostItem) {
lostItem.setId(id);
lostItemService.updateById(lostItem);
}
// Delete lost property information
@DeleteMapping("/{id}")
public void deleteLostItem(@PathVariable Long id) {
lostItemService.removeById(id);
}
}