Skip to content

Commit

Permalink
feat: Add ListModelController for CRUD operations
Browse files Browse the repository at this point in the history
  • Loading branch information
sweep-ai[bot] committed Apr 17, 2024
1 parent 20674fb commit 86f0900
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/main/java/com/example/demo/controller/ListModelController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.example.demo.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.example.demo.service.ListModelService;
import com.example.demo.entity.ListModel;
import java.util.List;
import java.util.Optional;

@RestController
@RequestMapping("/listModels")
public class ListModelController {

private final ListModelService listModelService;

@Autowired
public ListModelController(ListModelService listModelService) {
this.listModelService = listModelService;
}

@GetMapping
public List<ListModel> findAll() {
return listModelService.findAll();
}

@GetMapping("/{id}")
public Optional<ListModel> findById(@PathVariable Long id) {
return listModelService.findById(id);
}

@PostMapping
public ListModel create(@RequestBody ListModel listModel) {
return listModelService.save(listModel);
}

@PutMapping("/{id}")
public ListModel update(@PathVariable Long id, @RequestBody ListModel listModel) {
listModel.setId(id);
return listModelService.save(listModel);
}

@DeleteMapping("/{id}")
public void delete(@PathVariable Long id) {
listModelService.deleteById(id);
}
}

0 comments on commit 86f0900

Please sign in to comment.