Skip to content

Commit

Permalink
Merge pull request #139 from PlanIt-Project/BE_fix#138
Browse files Browse the repository at this point in the history
Be fix#138
  • Loading branch information
moonjin-kim authored Apr 2, 2024
2 parents 203a88c + 627fcb0 commit 27a29a8
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,23 @@
import com.sideProject.PlanIT.domain.post.dto.response.BannerResponseDto;
import com.sideProject.PlanIT.domain.post.service.BannerService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("/admin/banner")
@Slf4j
@RequiredArgsConstructor
public class BannerAdminController {
private final BannerService bannerService;

@PostMapping
public ApiResponse<String> createBanner(@ModelAttribute BannerRequestDto bannerRequestDto) {
public ApiResponse<String> createBanner(@ModelAttribute BannerRequestDto bannerRequestDto
) {
log.info(bannerRequestDto.getTitle());
return ApiResponse.ok(bannerService.createBanner(bannerRequestDto));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
package com.sideProject.PlanIT.domain.post.dto.request;

import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.springframework.web.multipart.MultipartFile;

import java.io.Serializable;
import java.time.LocalDate;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class BannerRequestDto {
@Builder
public class BannerRequestDto implements Serializable {
private String title;
private LocalDate startAt;
private LocalDate endAt;
private MultipartFile image;

public BannerRequestDto(String title, LocalDate startAt, LocalDate endAt, MultipartFile image) {
this.title = title;
this.startAt = startAt;
this.endAt = endAt;
this.image = image;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.sideProject.PlanIT.domain.program.dto.response;

import com.sideProject.PlanIT.domain.product.entity.Product;
import com.sideProject.PlanIT.domain.product.entity.enums.ProductType;
import com.sideProject.PlanIT.domain.program.entity.enums.ProgramStatus;
import com.sideProject.PlanIT.domain.program.entity.Program;
import com.sideProject.PlanIT.domain.user.dto.member.response.EmployeeSemiResponseDto;
Expand All @@ -16,6 +17,7 @@
public class ProgramResponse {
long id;
String productName;
ProductType type;
int remainedNumber;
String startAt;
String endAt;
Expand Down Expand Up @@ -43,6 +45,7 @@ public ProgramResponse(
this.endAt = endAt;
this.status = status;
this.productName = product.getName();
this.type = product.getType();
this.member = MemberSemiResponseDto.of(member);
this.employee = EmployeeSemiResponseDto.of(employee);
this.suspendAt = suspendAt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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.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 @@ -12,6 +13,7 @@
import org.springframework.web.bind.annotation.*;

import java.security.Principal;
import java.util.List;

@Slf4j
@RestController
Expand All @@ -32,4 +34,10 @@ public ApiResponse<String> updateTrainerSchedule(@PathVariable("schedule_id") Lo

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));
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import com.sideProject.PlanIT.common.response.ApiResponse;
import com.sideProject.PlanIT.domain.user.dto.employee.response.TrainerScheduleResponseDto;
import com.sideProject.PlanIT.domain.user.dto.member.response.MemberResponseDto;
import com.sideProject.PlanIT.domain.user.service.WorktimeService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;
import com.sideProject.PlanIT.domain.user.dto.employee.request.TrainerScheduleRequestDto;

Expand All @@ -25,6 +27,11 @@ public ApiResponse<?> trainerScheduleRegistration(@RequestBody List<TrainerSched
return ApiResponse.ok(worktimeservice.trainerScheduleRegistration(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));
};



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

import com.sideProject.PlanIT.domain.user.entity.WorkTime;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import java.util.List;

@Repository
public interface WorktimeRepository extends JpaRepository<WorkTime,Long> {
List<WorkTime> findByEmployeeId(Long employee_id);
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.sideProject.PlanIT.domain.user.service;

import com.sideProject.PlanIT.domain.product.dto.response.ProductResponseDto;
import com.sideProject.PlanIT.domain.user.dto.employee.request.TrainerSchduleChangeRequestDto;
import com.sideProject.PlanIT.domain.user.dto.employee.request.TrainerScheduleRequestDto;
import com.sideProject.PlanIT.domain.user.dto.employee.response.TrainerScheduleRegistrationResponse;
import com.sideProject.PlanIT.domain.user.dto.employee.response.TrainerScheduleResponseDto;
import com.sideProject.PlanIT.domain.user.entity.WorkTime;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

Expand All @@ -17,5 +19,5 @@ public interface WorktimeService {
// 트레이너 출퇴근 전체 조회
public Page<TrainerScheduleResponseDto> findTrainerSchedule(Long id, Pageable pageable);
// 특정 트레이너 출퇴근 조회

public List<TrainerScheduleResponseDto> findoneTrianerSchedule(Long trainer_id, Long id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.sideProject.PlanIT.common.response.CustomException;
import com.sideProject.PlanIT.common.response.ErrorCode;

import com.sideProject.PlanIT.domain.post.dto.response.BannerResponseDto;
import com.sideProject.PlanIT.domain.product.dto.response.ProductResponseDto;
import com.sideProject.PlanIT.domain.user.dto.employee.request.TrainerSchduleChangeRequestDto;
import com.sideProject.PlanIT.domain.user.dto.employee.request.TrainerScheduleRequestDto;
import com.sideProject.PlanIT.domain.user.dto.employee.response.TrainerScheduleRegistrationResponse;
Expand All @@ -24,6 +26,7 @@
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.stream.Collectors;


@Slf4j
Expand Down Expand Up @@ -76,5 +79,21 @@ public Page<TrainerScheduleResponseDto> findTrainerSchedule(Long id, Pageable pa
return worktime.map(TrainerScheduleResponseDto::of);
}

// 특정 트레이너 출퇴근 조회 => 확인 후 진행
// 특정 트레이너 출퇴근 조회
@Override
public List<TrainerScheduleResponseDto> findoneTrianerSchedule(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);
}
List<WorkTime> worktime = worktimeRepository.findByEmployeeId(employee_id);
if (worktime.isEmpty()){
throw new CustomException("일정을 찾을 수 없습니다.",ErrorCode.TrainerSchedule_NOT_FOUND);
}
return worktime.stream()
.map(TrainerScheduleResponseDto::of)
.collect(Collectors.toList());

}

}

0 comments on commit 27a29a8

Please sign in to comment.