-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add ListModelController for CRUD operations
- Loading branch information
1 parent
20674fb
commit 86f0900
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
src/main/java/com/example/demo/controller/ListModelController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |