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 {
@Autowired
EmployeeRepository employeeRepository;
public List<LeaveForm> findAllLeaveForm() {
return leaveFormRepository.findAllLeaveForm();
public List<LeaveForm> findAll() {
return leaveFormRepository.findAll();
}
public String insertLeaveForm(LeaveFormDTO leaveFormDTO) {
......
......@@ -12,14 +12,14 @@ import javax.validation.Valid;
import java.util.List;
@RestController
@RequestMapping(path = "/leave")
@RequestMapping(path = "/employee")
public class LeaveFormController {
@Autowired
LeaveFormBusiness leaveFormBusiness;
@GetMapping(path = "/index")
public ResponseEntity<List<LeaveForm>> showLeaveFormList() {
return ResponseEntity.ok(leaveFormBusiness.findAllLeaveForm());
@GetMapping(path = "/leaveform")
public ResponseEntity<List<LeaveForm>> showAllLeaveForm() {
return ResponseEntity.ok(leaveFormBusiness.findAll());
}
@PostMapping(path = "/insert", consumes = "application/json", produces = "application/json")
......
......@@ -10,8 +10,8 @@ import org.springframework.data.jpa.repository.Query;
import java.util.List;
public interface LeaveFormRepository extends JpaRepository<LeaveForm, Integer> {
@Query("select lf from LeaveForm lf")
List<LeaveForm> findAllLeaveForm();
// @Query("select lf from LeaveForm lf")
// List<LeaveForm> findAll();
LeaveForm findLeaveFormByEmployeeAndId(Employee employee, int id);
......
......@@ -77,47 +77,47 @@ public class TimeSheetBusiness {
Employee employee = employeeRepository.findEmployeeById(employee_Id);
Eproject eproject = eProjectRepository.findEprojectByEmployee(employee);
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()
, timeSheetDTO.getNote(), eproject, timeSheetDTO.getId());
, timeSheetDTO.getNote(), timesheet_Id);
if (i == 1) {
message = "Update success";
} else {
message = "Update failed";
}
} else {
message = "Eproject does not exist";
message = "TimeSheet does not exist";
}
} else {
message = "TimeSheet does not exist";
message = "Eproject 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 {
message = "Update status failed";
}
} else {
message = "TimeSheet does not exist";
}
// @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 {
// message = "Update status failed";
// }
// } else {
// message = "TimeSheet does not exist";
// }
//
// return message;
// }
return message;
}
public List<TimeSheet> findTimeSheetById(int id) {
Employee employee = employeeRepository.findEmployeeById(id);
public List<TimeSheet> findTimeSheetById(int employee_Id) {
Employee employee = employeeRepository.findEmployeeById(employee_Id);
Eproject eproject = eProjectRepository.findEprojectByEmployee(employee);
if (employee != null && eproject != null && timeSheetRepository.timeSheetListById(eproject) != null) {
return timeSheetRepository.timeSheetListById(eproject);
if (employee != null && eproject != null && timeSheetRepository.showTimeSheetByEproject(eproject) != null) {
return timeSheetRepository.showTimeSheetByEproject(eproject);
} else {
return null;
}
......
......@@ -35,19 +35,19 @@ public class TimeSheetController {
return ResponseEntity.ok(timeSheetBusiness.deleteTimeSheet(employee_Id, timesheet_Id));
}
@GetMapping(path = "/index")
@GetMapping(path = "/eproject/leaveform")
public List<TimeSheet> showAllTimeSheet() {
return timeSheetBusiness.findAll();
}
@PostMapping(path = "/update", consumes = "application/json", produces = "application/json")
public ResponseEntity<String> updateLeaveForm(@RequestBody TimeSheetDTO timeSheetDTO) {
@PostMapping(path = "/{employee_Id}/timesheet/{timesheet_Id}", consumes = "application/json", produces = "application/json")
public ResponseEntity<String> updateTimeSheet(@PathVariable int employee_Id, @PathVariable int timesheet_Id, @Valid @RequestBody TimeSheetDTO timeSheetDTO) {
String message;
try {
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");
message = timeSheetBusiness.updateTimeSheet(timeSheetDTO);
message = timeSheetBusiness.updateTimeSheet(employee_Id, timeSheetDTO, timesheet_Id);
} catch (InputException e) {
message = e.getMessage();
}
......@@ -55,15 +55,15 @@ public class TimeSheetController {
return ResponseEntity.ok(message);
}
@PostMapping(path = "/update-status", consumes = "application/json", produces = "application/json")
public ResponseEntity<String> updateLeaveFormStatus(@RequestBody TimeSheetDTO timeSheetDTO) {
String message;
message = timeSheetBusiness.updateLeaveFormStatus(timeSheetDTO);
return ResponseEntity.ok(message);
}
// @PostMapping(path = "/update-status", consumes = "application/json", produces = "application/json")
// public ResponseEntity<String> updateLeaveFormStatus(@RequestBody TimeSheetDTO timeSheetDTO) {
// String message;
// message = timeSheetBusiness.updateLeaveFormStatus(timeSheetDTO);
// return ResponseEntity.ok(message);
// }
@GetMapping("/index/{id}")
public ResponseEntity<List<TimeSheet>> showTimeSheetById(@PathVariable int id) {
return ResponseEntity.ok(timeSheetBusiness.findTimeSheetById(id));
@GetMapping("/{employee_Id}/show")
public ResponseEntity<List<TimeSheet>> showTimeSheetById(@PathVariable int employee_Id) {
return ResponseEntity.ok(timeSheetBusiness.findTimeSheetById(employee_Id));
}
}
\ No newline at end of file
......@@ -5,7 +5,7 @@ import com.itsol.quantrivanphong.model.Eproject;
import org.springframework.data.jpa.repository.JpaRepository;
public interface EProjectRepository extends JpaRepository<Eproject, Integer> {
Eproject findEprojectById(int id);
// Eproject findEprojectById(int id);
Eproject findEprojectByEmployee(Employee employee);
Eproject findEprojectByIdAndEmployee(int eProject_Id, Employee employee);
......
......@@ -9,21 +9,21 @@ import org.springframework.data.jpa.repository.Query;
import java.util.List;
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")
// List<TimeSheet> getAllTimeSheet();
@Modifying
@Query("update TimeSheet ts set ts.title = ?1, ts.content = ?2, ts.note = ?3, ts.eproject = ?4 where ts.id = ?5")
int updateTimeSheet(String title, String content, String note, Eproject eproject, int id);
@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, int timesheet_Id);
@Modifying
@Query("update TimeSheet ts set ts.status = ?1 where ts.id = ?2")
int updateTimeSheetStatus(boolean status, int id);
// @Modifying
// @Query("update TimeSheet ts set ts.status = ?1 where ts.id = ?2")
// int updateTimeSheetStatus(boolean status, int id);
@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);
}
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