Skip to content

Commit

Permalink
Merge pull request #151 from PlanIt-Project/BE
Browse files Browse the repository at this point in the history
Be
  • Loading branch information
moonjin-kim authored Apr 5, 2024
2 parents 00a2ed3 + b75f261 commit 430da5f
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public List<ReservationResponseDto> findReservationForDayByEmployee(LocalDate da

return reservations.stream()
.filter(reservation -> !reservation.isWithinEmployeeWorkTime(workTimes))
.map(ReservationResponse::of)
.map(ReservationResponseDto::of)
.toList();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.sideProject.PlanIT.domain.user.controller;

import com.sideProject.PlanIT.common.response.ApiResponse;
import com.sideProject.PlanIT.domain.user.dto.employee.request.TrainerSchduleChangeRequestDto;
import com.sideProject.PlanIT.domain.user.dto.employee.request.TrainerScheduleChangeRequestDto;
import com.sideProject.PlanIT.domain.user.dto.employee.response.TrainerScheduleResponseDto;
import com.sideProject.PlanIT.domain.user.entity.WorkTime;
import com.sideProject.PlanIT.domain.user.service.WorktimeService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -30,14 +29,14 @@ public ApiResponse<Page<TrainerScheduleResponseDto>> findallTrainerSchedule(@Pag

// 특정 직원 일정 수정(출퇴근)
@PutMapping("/trainerschedule/{schedule_id}")
public ApiResponse<String> updateTrainerSchedule(@PathVariable("schedule_id") Long id, @RequestBody TrainerSchduleChangeRequestDto request){
public ApiResponse<String> updateTrainerSchedule(@PathVariable("schedule_id") Long id, @RequestBody TrainerScheduleChangeRequestDto request){

return ApiResponse.ok(worktimeservice.trainerScheduleChange(request,id));
}
// 특정 직원 일정 조회
@GetMapping("/trainerschedule/{trainer_id}")
public ApiResponse<List<TrainerScheduleResponseDto>> findTrainerSchedule(@PathVariable("trainer_id") Long trainer_id, Principal principal, Pageable pageable){
Long id = Long.parseLong(principal.getName());
return ApiResponse.ok(worktimeservice.findoneTrianerSchedule(trainer_id,id));
return ApiResponse.ok(worktimeservice.findOneTrainerSchedule(trainer_id,id));
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@

public class TrainerScheduleController {
private final WorktimeService worktimeservice;
@PostMapping("/trainerschedule")
@PostMapping("/trainerSchedule")
public ApiResponse<?> trainerScheduleRegistration(@RequestBody List<TrainerScheduleRequestDto> request, Principal principal) {
Long id = Long.parseLong(principal.getName());
return ApiResponse.ok(worktimeservice.trainerScheduleRegistration(request,id));
}

@GetMapping("/trainerschedule/{trainer_id}")
@GetMapping("/trainerSchedule/{trainer_id}")
public ApiResponse<List<TrainerScheduleResponseDto>> findTrainerSchedule(@PathVariable("trainer_id") Long trainer_id, Principal principal, Pageable pageable){
Long id = Long.parseLong(principal.getName());
return ApiResponse.ok(worktimeservice.findoneTrianerSchedule(trainer_id,id));
return ApiResponse.ok(worktimeservice.findOneTrainerSchedule(trainer_id,id));
};


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)

public class TrainerSchduleChangeRequestDto {
public class TrainerScheduleChangeRequestDto {
private LocalTime startAt;
private LocalTime endAt;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.sideProject.PlanIT.domain.user.service;

import com.sideProject.PlanIT.domain.user.dto.employee.request.TrainerSchduleChangeRequestDto;
import com.sideProject.PlanIT.domain.user.dto.employee.request.TrainerScheduleChangeRequestDto;
import com.sideProject.PlanIT.domain.user.dto.employee.request.TrainerScheduleRequestDto;
import com.sideProject.PlanIT.domain.user.dto.employee.response.TrainerScheduleRegistrationResponseDto;
import com.sideProject.PlanIT.domain.user.dto.employee.response.TrainerScheduleResponseDto;
Expand All @@ -13,9 +13,9 @@ public interface WorktimeService {
// 트레이너 출퇴근 등록
public TrainerScheduleRegistrationResponseDto trainerScheduleRegistration(List<TrainerScheduleRequestDto> request, Long id);
// 트레이너 출퇴근 수정
public String trainerScheduleChange(TrainerSchduleChangeRequestDto request, Long schedule_id);
public String trainerScheduleChange(TrainerScheduleChangeRequestDto request, Long schedule_id);
// 트레이너 출퇴근 전체 조회
public Page<TrainerScheduleResponseDto> findTrainerSchedule(Long id, Pageable pageable);
// 특정 트레이너 출퇴근 조회
public List<TrainerScheduleResponseDto> findoneTrianerSchedule(Long trainer_id, Long id);
public List<TrainerScheduleResponseDto> findOneTrainerSchedule(Long trainer_id, Long id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.sideProject.PlanIT.common.response.CustomException;
import com.sideProject.PlanIT.common.response.ErrorCode;

import com.sideProject.PlanIT.domain.user.dto.employee.request.TrainerSchduleChangeRequestDto;
import com.sideProject.PlanIT.domain.user.dto.employee.request.TrainerScheduleChangeRequestDto;
import com.sideProject.PlanIT.domain.user.dto.employee.request.TrainerScheduleRequestDto;
import com.sideProject.PlanIT.domain.user.dto.employee.response.TrainerScheduleRegistrationResponseDto;
import com.sideProject.PlanIT.domain.user.dto.employee.response.TrainerScheduleResponseDto;
Expand Down Expand Up @@ -41,25 +41,28 @@ public TrainerScheduleRegistrationResponseDto trainerScheduleRegistration(List<T
Employee trainer = employeeRepository.findByMemberId(member.getId()).orElseThrow(() -> new CustomException("존재하지 않는 직원입니다", ErrorCode.EMPLOYEE_NOT_FOUND));


for (TrainerScheduleRequestDto requestdto : request){
for (TrainerScheduleRequestDto requestdto : request) {
worktimeRepository.save(WorkTime.builder()
.week(requestdto.getWeek())
.startAt(requestdto.getStartAt())
.endAt(requestdto.getEndAt())
.employee(trainer)
.build());

return TrainerScheduleRegistrationResponse.of(trainer.getId(),"출퇴근시간이 등록되었습니다.");
}

return TrainerScheduleRegistrationResponseDto.of(trainer.getId(),"출퇴근시간이 등록되었습니다.");
}

// 특정 일정 가져오기
private WorkTime getTrainerSchduleByID(Long schdule_id){
return worktimeRepository.findById(schdule_id).orElseThrow(() -> new CustomException("일정이 존재하지 않습니다.",ErrorCode.TrainerSchedule_NOT_FOUND));
private WorkTime getTrainerScheduleByID(Long schdule_id){
return worktimeRepository.findById(schdule_id).orElseThrow(() ->
new CustomException("일정이 존재하지 않습니다.",ErrorCode.TrainerSchedule_NOT_FOUND));
}
// 트레이너 출퇴근 수정
@Override
public String trainerScheduleChange(TrainerSchduleChangeRequestDto request, Long schedule_id){
WorkTime TrainerSchedule = getTrainerSchduleByID(schedule_id);
public String trainerScheduleChange(TrainerScheduleChangeRequestDto request, Long schedule_id){
WorkTime TrainerSchedule = getTrainerScheduleByID(schedule_id);
TrainerSchedule.ChageWorktime(request.getStartAt(),request.getEndAt());

worktimeRepository.save(TrainerSchedule);
Expand All @@ -81,7 +84,7 @@ public Page<TrainerScheduleResponseDto> findTrainerSchedule(Long id, Pageable pa

// 특정 트레이너 출퇴근 조회
@Override
public List<TrainerScheduleResponseDto> findoneTrianerSchedule(Long employee_id,Long id) {
public List<TrainerScheduleResponseDto> findOneTrainerSchedule(Long employee_id,Long id) {
Member member = memberRepository.findById(id).orElseThrow(()-> new CustomException("존재하지 않는 회원입니다.",ErrorCode.MEMBER_NOT_FOUND));
if(member.getRole() != MemberRole.ADMIN && member.getRole() != MemberRole.TRAINER){
throw new CustomException("권한이 없습니다.",ErrorCode.NO_AUTHORITY);
Expand Down

0 comments on commit 430da5f

Please sign in to comment.