Skip to content

Commit

Permalink
Merge pull request #25 from Tasty-Inventory/yongwook_schedule
Browse files Browse the repository at this point in the history
employment merge
  • Loading branch information
kimyongwook98 authored Jun 16, 2024
2 parents 3eeefd4 + da4476c commit d9899f5
Show file tree
Hide file tree
Showing 17 changed files with 441 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
.requestMatchers(HttpMethod.OPTIONS,"/**").permitAll()
.requestMatchers("/csrf-token").permitAll()
.requestMatchers(HttpMethod.POST, "/users", "/authorize").permitAll()

.requestMatchers(HttpMethod.GET, "/users").authenticated()
.anyRequest().permitAll())
.exceptionHandling(a -> a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import net.skhu.tastyinventory_be.service.EmployeeService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import net.skhu.tastyinventory_be.controller.employee.dto.EmployeeEdit;

Expand Down Expand Up @@ -104,11 +103,11 @@ public ResponseEntity<?> editEmployeeDetails(@PathVariable(name ="id") Long id,

employeeService.save(employee);

return ResponseEntity.ok(BaseResponse.success(SuccessCode.EMPLOYEE_PATCH_SUCCESS));
} else {
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(BaseResponse.error(ErrorCode.NOT_FOUND_EMPLOYEE_EXCEPTION));
}
return ResponseEntity.ok(BaseResponse.success(SuccessCode.EMPLOYEE_PATCH_SUCCESS));
} else {
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(BaseResponse.error(ErrorCode.NOT_FOUND_EMPLOYEE_EXCEPTION));
}
}



Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package net.skhu.tastyinventory_be.controller.employee.dto;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotEmpty;
import lombok.*;
import net.skhu.tastyinventory_be.domain.employee.Employee;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,20 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import net.skhu.tastyinventory_be.common.dto.BaseResponse;
import net.skhu.tastyinventory_be.controller.employee.dto.EmployeeResponseDto;
import net.skhu.tastyinventory_be.domain.salary.Salary;
import net.skhu.tastyinventory_be.controller.salary.dto.SalaryResponseDto;
import net.skhu.tastyinventory_be.exception.ErrorCode;
import net.skhu.tastyinventory_be.exception.SuccessCode;
import net.skhu.tastyinventory_be.service.SalaryService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import net.skhu.tastyinventory_be.controller.salary.dto.SalaryEdit;

import java.util.List;
import java.util.Optional;

// BOOLEAN μΆ”κ°€/μ‚­μ œ



@RequiredArgsConstructor
Expand Down
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));
}
}
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;

}
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();

}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
package net.skhu.tastyinventory_be.domain.employee;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotEmpty;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Data
@Entity
Expand All @@ -33,6 +29,4 @@ public class Employee {

String note; // νŠΉμ΄μ‚¬ν•­

// @OneToMany
// List<Schedule> schedules = new ArrayList<>();
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
package net.skhu.tastyinventory_be.domain.employee;
import net.skhu.tastyinventory_be.domain.employee.Employee;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.Optional;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
package net.skhu.tastyinventory_be.domain.salary;
import net.skhu.tastyinventory_be.domain.salary.Salary;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.Optional;
Expand Down
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;
}

}
}
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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public enum ErrorCode {
NOT_FOUND_INVENTORY_EXCEPTION(HttpStatus.NOT_FOUND, "μ‘΄μž¬ν•˜μ§€ μ•ŠλŠ” μž¬κ³ μž…λ‹ˆλ‹€"),
NOT_FOUND_MENU_EXCEPTION(HttpStatus.NOT_FOUND, "μ‘΄μž¬ν•˜μ§€ μ•ŠλŠ” λ©”λ‰΄μž…λ‹ˆλ‹€"),
NOT_FOUND_EMPLOYEE_EXCEPTION(HttpStatus.NOT_FOUND, "μ‘΄μž¬ν•˜μ§€ μ•ŠλŠ” μ§μ›μž…λ‹ˆλ‹€"),
NOT_FOUND_SCHEDULE_EXCEPTION(HttpStatus.NOT_FOUND, "μ‘΄μž¬ν•˜μ§€ μ•ŠλŠ” μŠ€μΌ€μ€„μž…λ‹ˆλ‹€"),

/**
* 500 INTERNAL SERVER ERROR
Expand Down
Loading

0 comments on commit d9899f5

Please sign in to comment.