-
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.
Merge pull request #25 from Tasty-Inventory/yongwook_schedule
employment merge
- Loading branch information
Showing
17 changed files
with
441 additions
and
20 deletions.
There are no files selected for viewing
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
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
2 changes: 0 additions & 2 deletions
2
src/main/java/net/skhu/tastyinventory_be/controller/employee/dto/EmployeeResponseDto.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
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
135 changes: 135 additions & 0 deletions
135
src/main/java/net/skhu/tastyinventory_be/controller/schedule/ScheduleController.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,135 @@ | ||
package net.skhu.tastyinventory_be.controller.schedule; | ||
|
||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import net.skhu.tastyinventory_be.common.dto.BaseResponse; | ||
import net.skhu.tastyinventory_be.controller.schedule.dto.ScheduleEdit; | ||
import net.skhu.tastyinventory_be.controller.schedule.dto.ScheduleResponseDto; | ||
import net.skhu.tastyinventory_be.domain.schedule.Schedule; | ||
import net.skhu.tastyinventory_be.exception.ErrorCode; | ||
import net.skhu.tastyinventory_be.exception.SuccessCode; | ||
import net.skhu.tastyinventory_be.service.ScheduleService; | ||
import net.skhu.tastyinventory_be.util.WeekUtils; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
@RequiredArgsConstructor | ||
@RestController | ||
@RequestMapping("schedule") | ||
@Slf4j | ||
public class ScheduleController { | ||
|
||
private final ScheduleService scheduleService; | ||
|
||
@GetMapping | ||
public ResponseEntity<BaseResponse<List<ScheduleResponseDto>>> findAll() { | ||
return ResponseEntity.ok(BaseResponse.success(SuccessCode.GET_SUCCESS, scheduleService.getSchedule())); | ||
} | ||
|
||
@PostMapping | ||
public ResponseEntity<?> createSchedule(@Valid @RequestBody ScheduleEdit scheduleEdit) { | ||
Schedule schedule = new Schedule(); | ||
schedule.setEmployeeId(scheduleEdit.getEmployeeId()); | ||
schedule.setDayOfWeek(scheduleEdit.getDayOfWeek()); | ||
schedule.setTimeSlot(scheduleEdit.getTimeSlot()); | ||
schedule.setDate(scheduleEdit.getDate()); | ||
scheduleService.save(schedule); | ||
|
||
return ResponseEntity.ok(BaseResponse.success(SuccessCode.SCHEDULE_CREATE_SUCCESS)); | ||
} | ||
|
||
@GetMapping("{id}") | ||
public ResponseEntity<?> getScheduleDetails(@PathVariable(name = "id") Long id) { | ||
ScheduleResponseDto schedule = scheduleService.getScheduleDetails(id); | ||
if (schedule != null) { | ||
return ResponseEntity.ok(BaseResponse.success(SuccessCode.GET_SUCCESS, schedule)); | ||
} else { | ||
return ResponseEntity.notFound().build(); | ||
} | ||
} | ||
|
||
@GetMapping("/employee/{employeeId}") | ||
public ResponseEntity<?> getEmployeeScheduleDetails(@PathVariable(name = "employeeId") Long employeeId) { | ||
List<ScheduleResponseDto> schedules = scheduleService.getEmployeeScheduleDetails(employeeId); | ||
if (!schedules.isEmpty()) { | ||
return ResponseEntity.ok(BaseResponse.success(SuccessCode.GET_SUCCESS, schedules)); | ||
} else { | ||
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(BaseResponse.error(ErrorCode.NOT_FOUND_EMPLOYEE_EXCEPTION)); | ||
} | ||
} | ||
|
||
@PatchMapping("{id}") | ||
public ResponseEntity<?> editScheduleDetails(@PathVariable(name ="id") Long id, @Valid @RequestBody ScheduleEdit scheduleEdit) { | ||
|
||
|
||
Optional<Schedule> scheduleOptional = scheduleService.findById(id); | ||
if (scheduleOptional.isPresent()) { | ||
Schedule schedule = scheduleOptional.get(); | ||
|
||
if (scheduleEdit.getDayOfWeek() != null) { | ||
schedule.setDayOfWeek(scheduleEdit.getDayOfWeek()); | ||
} | ||
if (scheduleEdit.getTimeSlot() != null) { | ||
schedule.setTimeSlot(scheduleEdit.getTimeSlot()); | ||
} | ||
if (scheduleEdit.getDate() != null) { | ||
schedule.setDate(scheduleEdit.getDate()); | ||
} | ||
|
||
|
||
|
||
scheduleService.save(schedule); | ||
return ResponseEntity.ok(BaseResponse.success(SuccessCode.SCHEDULE_PATCH_SUCCESS)); | ||
} else { | ||
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(BaseResponse.error(ErrorCode.NOT_FOUND_SCHEDULE_EXCEPTION)); | ||
} | ||
} | ||
|
||
@DeleteMapping("{id}") | ||
public ResponseEntity<?> deleteSchedule(@PathVariable(name ="id") Long id) { | ||
Optional<Schedule> scheduleOptional = scheduleService.findById(id); | ||
if (scheduleOptional.isPresent()) { | ||
scheduleService.deleteById(id); | ||
return ResponseEntity.ok(BaseResponse.success(SuccessCode.SCHEDULE_DELETE_SUCCESS)); | ||
} else { | ||
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(BaseResponse.error(ErrorCode.NOT_FOUND_SCHEDULE_EXCEPTION)); | ||
} | ||
} | ||
|
||
@GetMapping("/week") | ||
public ResponseEntity<BaseResponse<List<ScheduleResponseDto>>> getWeekSchedules( | ||
@RequestParam int year, | ||
@RequestParam int month, | ||
@RequestParam int week, | ||
@RequestParam(required = false) Long employeeId) { | ||
List<ScheduleResponseDto> schedules = scheduleService.getSchedulesForWeek(year, month, week, employeeId); | ||
return ResponseEntity.ok(BaseResponse.success(SuccessCode.GET_SUCCESS, schedules)); | ||
} | ||
|
||
@GetMapping("/week/next") | ||
public ResponseEntity<BaseResponse<List<ScheduleResponseDto>>> getNextWeekSchedules( | ||
@RequestParam int year, | ||
@RequestParam int month, | ||
@RequestParam int week, | ||
@RequestParam(required = false) Long employeeId) { | ||
int nextWeek = WeekUtils.changeWeek(year, month, week, 1); | ||
List<ScheduleResponseDto> schedules = scheduleService.getSchedulesForWeek(year, month, nextWeek, employeeId); | ||
return ResponseEntity.ok(BaseResponse.success(SuccessCode.GET_SUCCESS, schedules)); | ||
} | ||
|
||
@GetMapping("/week/previous") | ||
public ResponseEntity<BaseResponse<List<ScheduleResponseDto>>> getPreviousWeekSchedules( | ||
@RequestParam int year, | ||
@RequestParam int month, | ||
@RequestParam int week, | ||
@RequestParam(required = false) Long employeeId) { | ||
int previousWeek = WeekUtils.changeWeek(year, month, week, -1); | ||
List<ScheduleResponseDto> schedules = scheduleService.getSchedulesForWeek(year, month, previousWeek, employeeId); | ||
return ResponseEntity.ok(BaseResponse.success(SuccessCode.GET_SUCCESS, schedules)); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/net/skhu/tastyinventory_be/controller/schedule/dto/ScheduleEdit.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,15 @@ | ||
package net.skhu.tastyinventory_be.controller.schedule.dto; | ||
import lombok.Data; | ||
import net.skhu.tastyinventory_be.domain.schedule.Schedule; | ||
import java.time.LocalDate; | ||
|
||
@Data | ||
public class ScheduleEdit { | ||
int id; | ||
|
||
Long employeeId; | ||
private Schedule.DayOfWeek dayOfWeek; | ||
private Schedule.TimeSlot timeSlot; | ||
private LocalDate date; | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/net/skhu/tastyinventory_be/controller/schedule/dto/ScheduleResponseDto.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,36 @@ | ||
package net.skhu.tastyinventory_be.controller.schedule.dto; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.RequiredArgsConstructor; | ||
import net.skhu.tastyinventory_be.domain.schedule.Schedule; | ||
|
||
import java.time.LocalDate; | ||
|
||
@Builder | ||
@Data | ||
@RequiredArgsConstructor | ||
@AllArgsConstructor | ||
public class ScheduleResponseDto { | ||
Long id; | ||
|
||
@JsonProperty("employee_id") | ||
Long employeeId; | ||
|
||
Schedule.DayOfWeek dayOfWeek; | ||
Schedule.TimeSlot timeSlot; | ||
LocalDate date; | ||
|
||
public static ScheduleResponseDto of(Schedule schedule) { | ||
return ScheduleResponseDto.builder() | ||
.id(schedule.getId()) | ||
.employeeId(schedule.getEmployeeId()) | ||
.dayOfWeek(schedule.getDayOfWeek()) | ||
.timeSlot(schedule.getTimeSlot()) | ||
.date(schedule.getDate()) | ||
.build(); | ||
|
||
} | ||
} |
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
1 change: 0 additions & 1 deletion
1
src/main/java/net/skhu/tastyinventory_be/domain/employee/EmployeeRepository.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
1 change: 0 additions & 1 deletion
1
src/main/java/net/skhu/tastyinventory_be/domain/salary/SalaryRepository.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
70 changes: 70 additions & 0 deletions
70
src/main/java/net/skhu/tastyinventory_be/domain/schedule/Schedule.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,70 @@ | ||
package net.skhu.tastyinventory_be.domain.schedule; | ||
import jakarta.persistence.*; | ||
import lombok.Data; | ||
import lombok.Getter; | ||
|
||
import java.time.LocalDate; | ||
|
||
@Data | ||
@Entity | ||
public class Schedule { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "scheduleId") | ||
private Long id; | ||
|
||
@Column(nullable = false) | ||
private Long employeeId; | ||
|
||
@Enumerated(EnumType.STRING) | ||
@Column(nullable = false) | ||
private DayOfWeek dayOfWeek; | ||
|
||
@Enumerated(EnumType.STRING) | ||
@Column(nullable = false) | ||
private TimeSlot timeSlot; | ||
|
||
@Column(nullable = false) | ||
private LocalDate date; | ||
|
||
@Getter | ||
public enum DayOfWeek { | ||
MONDAY("μμμΌ"), | ||
TUESDAY("νμμΌ"), | ||
WEDNESDAY("μμμΌ"), | ||
THURSDAY("λͺ©μμΌ"), | ||
FRIDAY("κΈμμΌ"), | ||
SATURDAY("ν μμΌ"), | ||
SUNDAY("μΌμμΌ"); | ||
|
||
private final String value; | ||
|
||
DayOfWeek(String value) { | ||
this.value = value; | ||
} | ||
|
||
} | ||
|
||
@Getter | ||
public enum TimeSlot { | ||
SLOT_09_10("09:00 - 10:00"), | ||
SLOT_10_11("10:00 - 11:00"), | ||
SLOT_11_12("11:00 - 12:00"), | ||
SLOT_12_13("12:00 - 13:00"), | ||
SLOT_13_14("13:00 - 14:00"), | ||
SLOT_14_15("14:00 - 15:00"), | ||
SLOT_15_16("15:00 - 16:00"), | ||
SLOT_16_17("16:00 - 17:00"), | ||
SLOT_17_18("17:00 - 18:00"), | ||
SLOT_18_19("18:00 - 19:00"), | ||
SLOT_19_20("19:00 - 20:00"), | ||
SLOT_20_21("20:00 - 21:00"); | ||
|
||
private final String value; | ||
|
||
TimeSlot(String value) { | ||
this.value = value; | ||
} | ||
|
||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/net/skhu/tastyinventory_be/domain/schedule/ScheduleRepository.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,15 @@ | ||
package net.skhu.tastyinventory_be.domain.schedule; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public interface ScheduleRepository extends JpaRepository<Schedule, Long> { | ||
Optional<Schedule> findById(Long id); | ||
List<Schedule> findByEmployeeId(Long employeeId); | ||
List<Schedule> findByDateBetweenAndEmployeeId(LocalDate startDate, LocalDate endDate, Long employeeId); | ||
|
||
List<Schedule> findByDateBetween(LocalDate startDate, LocalDate endDate); | ||
} |
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
Oops, something went wrong.