Commit 5df49b2f authored by Phạm Duy Phi's avatar Phạm Duy Phi

no message

parent 9f0b15b1
...@@ -22,8 +22,8 @@ public class LeaveFormBusiness { ...@@ -22,8 +22,8 @@ public class LeaveFormBusiness {
@Autowired @Autowired
EmployeeRepository employeeRepository; EmployeeRepository employeeRepository;
public List<LeaveForm> findAllLeaveForm() { public List<LeaveForm> findAll() {
return leaveFormRepository.findAllLeaveForm(); return leaveFormRepository.findAll();
} }
public String insertLeaveForm(LeaveFormDTO leaveFormDTO) { public String insertLeaveForm(LeaveFormDTO leaveFormDTO) {
......
...@@ -12,14 +12,14 @@ import javax.validation.Valid; ...@@ -12,14 +12,14 @@ import javax.validation.Valid;
import java.util.List; import java.util.List;
@RestController @RestController
@RequestMapping(path = "/leave") @RequestMapping(path = "/employee")
public class LeaveFormController { public class LeaveFormController {
@Autowired @Autowired
LeaveFormBusiness leaveFormBusiness; LeaveFormBusiness leaveFormBusiness;
@GetMapping(path = "/index") @GetMapping(path = "/leaveform")
public ResponseEntity<List<LeaveForm>> showLeaveFormList() { public ResponseEntity<List<LeaveForm>> showAllLeaveForm() {
return ResponseEntity.ok(leaveFormBusiness.findAllLeaveForm()); return ResponseEntity.ok(leaveFormBusiness.findAll());
} }
@PostMapping(path = "/insert", consumes = "application/json", produces = "application/json") @PostMapping(path = "/insert", consumes = "application/json", produces = "application/json")
......
...@@ -10,8 +10,8 @@ import org.springframework.data.jpa.repository.Query; ...@@ -10,8 +10,8 @@ import org.springframework.data.jpa.repository.Query;
import java.util.List; import java.util.List;
public interface LeaveFormRepository extends JpaRepository<LeaveForm, Integer> { public interface LeaveFormRepository extends JpaRepository<LeaveForm, Integer> {
@Query("select lf from LeaveForm lf") // @Query("select lf from LeaveForm lf")
List<LeaveForm> findAllLeaveForm(); // List<LeaveForm> findAll();
LeaveForm findLeaveFormByEmployeeAndId(Employee employee, int id); LeaveForm findLeaveFormByEmployeeAndId(Employee employee, int id);
......
...@@ -77,47 +77,47 @@ public class TimeSheetBusiness { ...@@ -77,47 +77,47 @@ public class TimeSheetBusiness {
Employee employee = employeeRepository.findEmployeeById(employee_Id); Employee employee = employeeRepository.findEmployeeById(employee_Id);
Eproject eproject = eProjectRepository.findEprojectByEmployee(employee); Eproject eproject = eProjectRepository.findEprojectByEmployee(employee);
TimeSheet timeSheet = timeSheetRepository.findTimeSheetByEprojectAndId(eproject, timesheet_Id); TimeSheet timeSheet = timeSheetRepository.findTimeSheetByEprojectAndId(eproject, timesheet_Id);
if (timeSheet != null) {
if (eproject != null) { if (eproject != null) {
if (timeSheet != null) {
int i = timeSheetRepository.updateTimeSheet(timeSheetDTO.getTitle(), timeSheetDTO.getContent() int i = timeSheetRepository.updateTimeSheet(timeSheetDTO.getTitle(), timeSheetDTO.getContent()
, timeSheetDTO.getNote(), eproject, timeSheetDTO.getId()); , timeSheetDTO.getNote(), timesheet_Id);
if (i == 1) { if (i == 1) {
message = "Update success"; message = "Update success";
} else { } else {
message = "Update failed"; message = "Update failed";
} }
} else {
message = "Eproject does not exist";
}
} else { } else {
message = "TimeSheet does not exist"; message = "TimeSheet does not exist";
} }
return message;
}
@Transactional
public String updateLeaveFormStatus(TimeSheetDTO timeSheetDTO) {
String message;
TimeSheet timeSheet = timeSheetRepository.findTimeSheetById(timeSheetDTO.getId());
if (timeSheet != null) {
int i = timeSheetRepository.updateTimeSheetStatus(timeSheetDTO.isStatus(), timeSheetDTO.getId());
if (i == 1) {
message = "Update status success";
} else { } else {
message = "Update status failed"; message = "Eproject does not exist";
}
} else {
message = "TimeSheet does not exist";
} }
return message; return message;
} }
public List<TimeSheet> findTimeSheetById(int id) { // @Transactional
Employee employee = employeeRepository.findEmployeeById(id); // public String updateLeaveFormStatus(TimeSheetDTO timeSheetDTO) {
// String message;
// TimeSheet timeSheet = timeSheetRepository.findTimeSheetById(timeSheetDTO.getId());
// if (timeSheet != null) {
// int i = timeSheetRepository.updateTimeSheetStatus(timeSheetDTO.isStatus(), timeSheetDTO.getId());
// if (i == 1) {
// message = "Update status success";
// } else {
// message = "Update status failed";
// }
// } else {
// message = "TimeSheet does not exist";
// }
//
// return message;
// }
public List<TimeSheet> findTimeSheetById(int employee_Id) {
Employee employee = employeeRepository.findEmployeeById(employee_Id);
Eproject eproject = eProjectRepository.findEprojectByEmployee(employee); Eproject eproject = eProjectRepository.findEprojectByEmployee(employee);
if (employee != null && eproject != null && timeSheetRepository.timeSheetListById(eproject) != null) { if (employee != null && eproject != null && timeSheetRepository.showTimeSheetByEproject(eproject) != null) {
return timeSheetRepository.timeSheetListById(eproject); return timeSheetRepository.showTimeSheetByEproject(eproject);
} else { } else {
return null; return null;
} }
......
...@@ -35,19 +35,19 @@ public class TimeSheetController { ...@@ -35,19 +35,19 @@ public class TimeSheetController {
return ResponseEntity.ok(timeSheetBusiness.deleteTimeSheet(employee_Id, timesheet_Id)); return ResponseEntity.ok(timeSheetBusiness.deleteTimeSheet(employee_Id, timesheet_Id));
} }
@GetMapping(path = "/index") @GetMapping(path = "/eproject/leaveform")
public List<TimeSheet> showAllTimeSheet() { public List<TimeSheet> showAllTimeSheet() {
return timeSheetBusiness.findAll(); return timeSheetBusiness.findAll();
} }
@PostMapping(path = "/update", consumes = "application/json", produces = "application/json") @PostMapping(path = "/{employee_Id}/timesheet/{timesheet_Id}", consumes = "application/json", produces = "application/json")
public ResponseEntity<String> updateLeaveForm(@RequestBody TimeSheetDTO timeSheetDTO) { public ResponseEntity<String> updateTimeSheet(@PathVariable int employee_Id, @PathVariable int timesheet_Id, @Valid @RequestBody TimeSheetDTO timeSheetDTO) {
String message; String message;
try { try {
if (timeSheetDTO.getTitle().trim().equals("")) throw new InputException("Tiêu đề không được để trống"); if (timeSheetDTO.getTitle().trim().equals("")) throw new InputException("Tiêu đề không được để trống");
if (timeSheetDTO.getContent().trim().equals("")) throw new InputException("Nội dung không được để trống"); if (timeSheetDTO.getContent().trim().equals("")) throw new InputException("Nội dung không được để trống");
message = timeSheetBusiness.updateTimeSheet(timeSheetDTO); message = timeSheetBusiness.updateTimeSheet(employee_Id, timeSheetDTO, timesheet_Id);
} catch (InputException e) { } catch (InputException e) {
message = e.getMessage(); message = e.getMessage();
} }
...@@ -55,15 +55,15 @@ public class TimeSheetController { ...@@ -55,15 +55,15 @@ public class TimeSheetController {
return ResponseEntity.ok(message); return ResponseEntity.ok(message);
} }
@PostMapping(path = "/update-status", consumes = "application/json", produces = "application/json") // @PostMapping(path = "/update-status", consumes = "application/json", produces = "application/json")
public ResponseEntity<String> updateLeaveFormStatus(@RequestBody TimeSheetDTO timeSheetDTO) { // public ResponseEntity<String> updateLeaveFormStatus(@RequestBody TimeSheetDTO timeSheetDTO) {
String message; // String message;
message = timeSheetBusiness.updateLeaveFormStatus(timeSheetDTO); // message = timeSheetBusiness.updateLeaveFormStatus(timeSheetDTO);
return ResponseEntity.ok(message); // return ResponseEntity.ok(message);
} // }
@GetMapping("/index/{id}") @GetMapping("/{employee_Id}/show")
public ResponseEntity<List<TimeSheet>> showTimeSheetById(@PathVariable int id) { public ResponseEntity<List<TimeSheet>> showTimeSheetById(@PathVariable int employee_Id) {
return ResponseEntity.ok(timeSheetBusiness.findTimeSheetById(id)); return ResponseEntity.ok(timeSheetBusiness.findTimeSheetById(employee_Id));
} }
} }
\ No newline at end of file
...@@ -5,7 +5,7 @@ import com.itsol.quantrivanphong.model.Eproject; ...@@ -5,7 +5,7 @@ import com.itsol.quantrivanphong.model.Eproject;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
public interface EProjectRepository extends JpaRepository<Eproject, Integer> { public interface EProjectRepository extends JpaRepository<Eproject, Integer> {
Eproject findEprojectById(int id); // Eproject findEprojectById(int id);
Eproject findEprojectByEmployee(Employee employee); Eproject findEprojectByEmployee(Employee employee);
Eproject findEprojectByIdAndEmployee(int eProject_Id, Employee employee); Eproject findEprojectByIdAndEmployee(int eProject_Id, Employee employee);
......
...@@ -9,21 +9,21 @@ import org.springframework.data.jpa.repository.Query; ...@@ -9,21 +9,21 @@ import org.springframework.data.jpa.repository.Query;
import java.util.List; import java.util.List;
public interface TimeSheetRepository extends JpaRepository<TimeSheet, Integer> { public interface TimeSheetRepository extends JpaRepository<TimeSheet, Integer> {
TimeSheet findTimeSheetById(int id); // TimeSheet findTimeSheetById(int id);
// @Query("select ts from TimeSheet ts order by ts.createdAt desc") // @Query("select ts from TimeSheet ts order by ts.createdAt desc")
// List<TimeSheet> getAllTimeSheet(); // List<TimeSheet> getAllTimeSheet();
@Modifying @Modifying
@Query("update TimeSheet ts set ts.title = ?1, ts.content = ?2, ts.note = ?3, ts.eproject = ?4 where ts.id = ?5") @Query("update TimeSheet ts set ts.title = ?1, ts.content = ?2, ts.note = ?3 where ts.id = ?4")
int updateTimeSheet(String title, String content, String note, Eproject eproject, int id); int updateTimeSheet(String title, String content, String note, int timesheet_Id);
@Modifying // @Modifying
@Query("update TimeSheet ts set ts.status = ?1 where ts.id = ?2") // @Query("update TimeSheet ts set ts.status = ?1 where ts.id = ?2")
int updateTimeSheetStatus(boolean status, int id); // int updateTimeSheetStatus(boolean status, int id);
@Query("select ts from TimeSheet ts where ts.eproject = ?1") @Query("select ts from TimeSheet ts where ts.eproject = ?1")
List<TimeSheet> timeSheetListById(Eproject eproject); List<TimeSheet> showTimeSheetByEproject(Eproject eproject);
TimeSheet findTimeSheetByEprojectAndId(Eproject eproject, int timeSheet_Id); TimeSheet findTimeSheetByEprojectAndId(Eproject eproject, int timeSheet_Id);
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment