-
-
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: Added StaffController for handling staff-rel
- Loading branch information
1 parent
b994710
commit d1a385b
Showing
1 changed file
with
47 additions
and
0 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
src/main/java/com/wsmsdemo/controller/StaffController.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,47 @@ | ||
package com.wsmsdemo.controller; | ||
|
||
import com.wsmsdemo.model.Staff; | ||
import com.wsmsdemo.service.StaffService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequestMapping("/staff") | ||
public class StaffController { | ||
|
||
@Autowired | ||
private StaffService staffService; | ||
|
||
@GetMapping | ||
public ResponseEntity<List<Staff>> listStaff() { | ||
List<Staff> staffList = staffService.findAll(); | ||
return ResponseEntity.ok(staffList); | ||
} | ||
|
||
@PostMapping | ||
public ResponseEntity<Staff> createStaff(@RequestBody Staff staff) { | ||
Staff createdStaff = staffService.create(staff); | ||
return ResponseEntity.ok(createdStaff); | ||
} | ||
|
||
@PutMapping("/{id}") | ||
public ResponseEntity<Staff> updateStaff(@PathVariable Long id, @RequestBody Staff staff) { | ||
Staff updatedStaff = staffService.update(id, staff); | ||
return ResponseEntity.ok(updatedStaff); | ||
} | ||
|
||
@DeleteMapping("/{id}") | ||
public ResponseEntity<Void> deleteStaff(@PathVariable Long id) { | ||
staffService.delete(id); | ||
return ResponseEntity.ok().build(); | ||
} | ||
|
||
@PatchMapping("/{id}") | ||
public ResponseEntity<Staff> partialUpdateStaff(@PathVariable Long id, @RequestBody Staff staff) { | ||
Staff updatedStaff = staffService.partialUpdate(id, staff); | ||
return ResponseEntity.ok(updatedStaff); | ||
} | ||
} |