feat: added controller
This commit is contained in:
		
							parent
							
								
									5a94e5cdcf
								
							
						
					
					
						commit
						54b4c4a42a
					
				| @ -0,0 +1,27 @@ | |||||||
|  | package com.example.nto.controller; | ||||||
|  | 
 | ||||||
|  | import com.example.nto.dto.entity.employee.EmployeeCreateDTO; | ||||||
|  | import com.example.nto.dto.entity.employee.EmployeeDTO; | ||||||
|  | import com.example.nto.service.EmployeeService; | ||||||
|  | import lombok.RequiredArgsConstructor; | ||||||
|  | import org.springframework.http.HttpStatus; | ||||||
|  | import org.springframework.http.ResponseEntity; | ||||||
|  | import org.springframework.security.core.Authentication; | ||||||
|  | import org.springframework.web.bind.annotation.*; | ||||||
|  | 
 | ||||||
|  | @RestController | ||||||
|  | @RequiredArgsConstructor | ||||||
|  | @RequestMapping("api/v1/authorization") | ||||||
|  | public class AuthorizationController { | ||||||
|  |     private final EmployeeService employeeService; | ||||||
|  | 
 | ||||||
|  |     @GetMapping("/login") | ||||||
|  |     public ResponseEntity<EmployeeDTO> login(Authentication authentication) { | ||||||
|  |         return ResponseEntity.ok(employeeService.getByEmail(authentication.getName())); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @PostMapping("/register") | ||||||
|  |     public ResponseEntity<EmployeeDTO> registerEmployee(@RequestBody EmployeeCreateDTO employeeCreateDTO) { | ||||||
|  |         return ResponseEntity.status(HttpStatus.CREATED).body(employeeService.create(employeeCreateDTO)); | ||||||
|  |     } | ||||||
|  | } | ||||||
| @ -0,0 +1,69 @@ | |||||||
|  | package com.example.nto.controller; | ||||||
|  | 
 | ||||||
|  | import com.example.nto.dto.entity.employee.EmployeeDTO; | ||||||
|  | import com.example.nto.dto.entity.employee.EmployeeItemDTO; | ||||||
|  | import com.example.nto.service.EmployeeService; | ||||||
|  | import com.example.nto.service.PhotoService; | ||||||
|  | import lombok.RequiredArgsConstructor; | ||||||
|  | import org.springframework.http.ResponseEntity; | ||||||
|  | import org.springframework.web.bind.annotation.*; | ||||||
|  | 
 | ||||||
|  | import java.util.List; | ||||||
|  | 
 | ||||||
|  | @RestController | ||||||
|  | @RequiredArgsConstructor | ||||||
|  | @RequestMapping("api/v1/employees") | ||||||
|  | public class EmployeeController { | ||||||
|  |     private final EmployeeService employeeService; | ||||||
|  |     private final PhotoService photoService; | ||||||
|  | 
 | ||||||
|  |     @GetMapping | ||||||
|  |     public ResponseEntity<List<EmployeeItemDTO>> getAll() { | ||||||
|  |         return ResponseEntity.ok(employeeService.getAll()); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @GetMapping("/working/{isWorking}") | ||||||
|  |     public ResponseEntity<List<EmployeeItemDTO>> getAllWorking(@PathVariable boolean isWorking) { | ||||||
|  |         return ResponseEntity.ok(employeeService.getWorkingEmployee(isWorking)); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @GetMapping("/{employeeId}") | ||||||
|  |     public ResponseEntity<EmployeeDTO> getEmployeeById(@PathVariable long employeeId) { | ||||||
|  |         return ResponseEntity.ok(employeeService.getById(employeeId)); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @GetMapping("/email/{email}") | ||||||
|  |     public ResponseEntity<EmployeeDTO> getEmployeeByEmail(@PathVariable String email) { | ||||||
|  |         return ResponseEntity.ok(employeeService.getByEmail(email)); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @GetMapping("/telephone/{telephone}") | ||||||
|  |     public ResponseEntity<EmployeeDTO> getEmployeeByTelephone(@PathVariable String telephone) { | ||||||
|  |         return ResponseEntity.ok(employeeService.getByTelephone(telephone)); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @PutMapping("/{id}") | ||||||
|  |     public ResponseEntity<EmployeeDTO> updateEmployee(@PathVariable long employeeId, @RequestBody EmployeeDTO employeeDTO) { | ||||||
|  |         return ResponseEntity.ok(employeeService.update(employeeId, employeeDTO)); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @DeleteMapping("/{id}") | ||||||
|  |     public ResponseEntity<EmployeeDTO> deleteEmployeeById(@PathVariable long employeeId) { | ||||||
|  |         employeeService.delete(employeeId); | ||||||
|  |         return ResponseEntity.noContent().build(); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @PatchMapping("/image/profile/{id}") | ||||||
|  |     public ResponseEntity<Void> patchImageProfile(@PathVariable long employeeId, @RequestBody byte[] photo) { | ||||||
|  |         String imageUrl = photoService.uploadProfilePhoto(employeeId, photo); | ||||||
|  |         employeeService.patchProfileImage(employeeId, imageUrl); | ||||||
|  |         return ResponseEntity.noContent().build(); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @PatchMapping("/block/{id}/{blockStatus}") | ||||||
|  |     public ResponseEntity<Void> patchImageProfile(@PathVariable long employeeId, @PathVariable boolean blockStatus) { | ||||||
|  |         employeeService.patchBlockEmployee(employeeId, blockStatus); | ||||||
|  |         return ResponseEntity.noContent().build(); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | } | ||||||
| @ -0,0 +1,50 @@ | |||||||
|  | package com.example.nto.controller; | ||||||
|  | 
 | ||||||
|  | import com.example.nto.dto.entity.OfficeDTO; | ||||||
|  | import com.example.nto.service.OfficeService; | ||||||
|  | import lombok.RequiredArgsConstructor; | ||||||
|  | import org.springframework.http.ResponseEntity; | ||||||
|  | import org.springframework.web.bind.annotation.*; | ||||||
|  | 
 | ||||||
|  | import java.util.List; | ||||||
|  | 
 | ||||||
|  | @RestController | ||||||
|  | @RequiredArgsConstructor | ||||||
|  | @RequestMapping("api/v1/offices") | ||||||
|  | public class OfficeController { | ||||||
|  |     private final OfficeService officeService; | ||||||
|  | 
 | ||||||
|  |     @GetMapping | ||||||
|  |     public ResponseEntity<List<OfficeDTO>> getAll() { | ||||||
|  |         return ResponseEntity.ok(officeService.getAllOffice()); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @GetMapping("/sorted/distance") | ||||||
|  |     public ResponseEntity<List<OfficeDTO>> getAllSortedByDistance( | ||||||
|  |             @RequestParam(name = "latitude") double latitude, | ||||||
|  |             @RequestParam(name = "longitude") double longitude | ||||||
|  |     ) { | ||||||
|  |         return ResponseEntity.ok(officeService.getAllSortedDistance(latitude, longitude)); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @GetMapping("/{officeId}") | ||||||
|  |     public ResponseEntity<OfficeDTO> getById(@PathVariable long officeId) { | ||||||
|  |         return ResponseEntity.ok(officeService.getById(officeId)); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @PostMapping | ||||||
|  |     public ResponseEntity<OfficeDTO> createOffice(@RequestBody OfficeDTO officeDTO) { | ||||||
|  |         return ResponseEntity.ok(officeService.create(officeDTO)); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @PutMapping("/{officeId}") | ||||||
|  |     public ResponseEntity<OfficeDTO> updateOffice(@PathVariable long officeId, @RequestBody OfficeDTO officeDTO) { | ||||||
|  |         return ResponseEntity.ok(officeService.update(officeId, officeDTO)); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @DeleteMapping("/{officeId}") | ||||||
|  |     public ResponseEntity<Void> deleteOffice(@PathVariable long officeId) { | ||||||
|  |         officeService.delete(officeId); | ||||||
|  |         return ResponseEntity.noContent().build(); | ||||||
|  |     } | ||||||
|  | } | ||||||
| @ -0,0 +1,47 @@ | |||||||
|  | package com.example.nto.controller; | ||||||
|  | 
 | ||||||
|  | import com.example.nto.dto.entity.TerminalDTO; | ||||||
|  | import com.example.nto.service.TerminalService; | ||||||
|  | import lombok.RequiredArgsConstructor; | ||||||
|  | import org.springframework.http.ResponseEntity; | ||||||
|  | import org.springframework.web.bind.annotation.*; | ||||||
|  | 
 | ||||||
|  | import java.util.List; | ||||||
|  | 
 | ||||||
|  | @RestController | ||||||
|  | @RequiredArgsConstructor | ||||||
|  | @RequestMapping("api/v1/terminals") | ||||||
|  | public class TerminalController { | ||||||
|  |     private final TerminalService terminalService; | ||||||
|  | 
 | ||||||
|  |     @GetMapping | ||||||
|  |     public ResponseEntity<List<TerminalDTO>> getAll() { | ||||||
|  |         return ResponseEntity.ok(terminalService.getAllTerminal()); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @GetMapping("/{terminalId}") | ||||||
|  |     public ResponseEntity<TerminalDTO> getTerminalById(@PathVariable long terminalId) { | ||||||
|  |         return ResponseEntity.ok(terminalService.getById(terminalId)); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @GetMapping("/check/{code}") | ||||||
|  |     public ResponseEntity<TerminalDTO> checkCode(@PathVariable String code) { | ||||||
|  |         return ResponseEntity.ok(terminalService.checkCode(code)); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @PostMapping | ||||||
|  |     public ResponseEntity<TerminalDTO> createTerminal(@RequestBody TerminalDTO terminalDTO) { | ||||||
|  |         return ResponseEntity.ok(terminalService.create(terminalDTO)); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @PutMapping("/{terminalId}") | ||||||
|  |     public ResponseEntity<TerminalDTO> updateTerminal(@PathVariable long terminalId, @RequestBody TerminalDTO terminalDTO) { | ||||||
|  |         return ResponseEntity.ok(terminalService.update(terminalId, terminalDTO)); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @DeleteMapping("/{terminalId}") | ||||||
|  |     public ResponseEntity<Void> deleteTerminal(@PathVariable long terminalId) { | ||||||
|  |         terminalService.delete(terminalId); | ||||||
|  |         return ResponseEntity.noContent().build(); | ||||||
|  |     } | ||||||
|  | } | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user