Skip to content

Commit

Permalink
Merge pull request #62 from PLADI-ALM/feat/PDS-106-getBookingResources
Browse files Browse the repository at this point in the history
[PDS-106/feat] 관리자 자원 예약 목록 조회
  • Loading branch information
dangnak2 authored Oct 8, 2023
2 parents 3243e40 + 3b9f7c8 commit ea98c48
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ public ResponseCustom<OfficeBookingDetailRes> getOfficeBookingDetail(@Parameter(
}


/**
* 관리자 자원 예약 목록을 조회
*/


/**
* 관리자 자원 예약 반려
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.example.pladialmserver.booking.repository.resourceBooking;

import com.example.pladialmserver.booking.entity.ResourceBooking;
import com.example.pladialmserver.global.entity.BookingStatus;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
Expand All @@ -15,4 +18,5 @@ public interface ResourceBookingRepository extends JpaRepository<ResourceBooking
@Query("SELECT rb.resource.resourceId FROM ResourceBooking rb WHERE (rb.startDate <= :endDate AND rb.endDate >= :startDate) AND rb.resource.name LIKE %:resourceName%")
List<Long> findBookedResourceIdsByDateAndResourceName(@Param("startDate") LocalDate startDate, @Param("endDate") LocalDate endDate, @Param("resourceName") String resourceName);

Page<ResourceBooking> findByStatusIn(List<BookingStatus> list, Pageable pageable);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.example.pladialmserver.resource.controller;

import com.example.pladialmserver.global.response.ResponseCustom;
import com.example.pladialmserver.resource.dto.response.AdminResourceRes;
import com.example.pladialmserver.resource.service.ResourceService;
import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "관리자 자원 API")
@RestController
@RequiredArgsConstructor
@RequestMapping("/admin/resources")
public class ResourceAdminController {
private final ResourceService resourceService;

/**
* 관리자 자원 예약 목록을 조회
*/
@Operation(summary = "관리자 자원 예약 목록 조회", description = "관리자 페이지에서 자원 예약 내역을 전체 조회한다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "(S0001)요청에 성공했습니다."),
})
@GetMapping("/resources")
public ResponseCustom<Page<AdminResourceRes>> getBookingResources(
@PageableDefault(size = 8) Pageable pageable){
return ResponseCustom.OK(resourceService.getBookingResources(pageable));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.example.pladialmserver.resource.dto.response;

import com.example.pladialmserver.booking.entity.ResourceBooking;
import com.example.pladialmserver.global.utils.DateTimeUtil;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Data;

@Data
@Builder
public class AdminResourceRes {
@Schema(type = "Long", description = "자원 Id", example = "1")
private Long id;
@Schema(type = "String", description = "자원 이름", example = "'벤츠'")
private String name;
@Schema(type = "String", description = "카테고리", example = "'차량'")
private String category;
@Schema(type = "String", description = "예약일자(시작일)", example = "'2023-10-01 12:00' / '2023-10-01'")
private String startDateTime;
@Schema(type = "String", description = "예약일자(종료일)", example = "'2023-10-01 13:00' / '2023-10-03'")
private String endDateTime;
@Schema(type = "String", description = "요청자", example = "이승학(부장)")
private String requester;
@Schema(type = "String", description = "상태", example = "'예약중' / '사용중'")
private String status;

public static AdminResourceRes toDto(ResourceBooking resourceBooking){
return AdminResourceRes.builder()
.id(resourceBooking.getResourceBookingId())
.name(resourceBooking.getResource().getName())
.category(resourceBooking.getResource().getCategory().getValue())
.startDateTime(DateTimeUtil.dateToString(resourceBooking.getStartDate()))
.endDateTime(DateTimeUtil.dateToString(resourceBooking.getEndDate()))
.requester(resourceBooking.getUser().getPosition().getName())
.status(resourceBooking.getStatus().getValue())
.build();

}



}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@


import com.example.pladialmserver.booking.entity.ResourceBooking;
import com.example.pladialmserver.global.entity.BookingStatus;
import com.example.pladialmserver.global.exception.BaseException;
import com.example.pladialmserver.global.exception.BaseResponseCode;
import com.example.pladialmserver.resource.dto.request.ResourceReq;
import com.example.pladialmserver.global.utils.DateTimeUtil;
import com.example.pladialmserver.resource.dto.response.AdminResourceRes;
import com.example.pladialmserver.resource.dto.response.ResourceDetailRes;
import com.example.pladialmserver.resource.dto.response.ResourceRes;
import com.example.pladialmserver.resource.entity.Resource;
Expand All @@ -15,11 +17,14 @@
import com.example.pladialmserver.user.repository.UserRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.util.Arrays;
import java.util.List;

@Service
Expand Down Expand Up @@ -96,4 +101,19 @@ public void bookResource(Long userId, Long resourceId, ResourceReq resourceReq)

}

/**
* 관리자 자원 예약 목록을 조회
*/
public Page<AdminResourceRes> getBookingResources(Pageable pageable) {
Pageable sortedByDateAsc = PageRequest.of(pageable.getPageNumber(), pageable.getPageSize(),
Sort.by(Sort.Order.asc("startDate")));

Page<ResourceBooking> resourceBookings=resourceBookingRepository.findByStatusIn(
Arrays.asList(BookingStatus.BOOKED, BookingStatus.USING,BookingStatus.WAITING),
sortedByDateAsc
);

return resourceBookings.map(AdminResourceRes::toDto);
}

}

0 comments on commit ea98c48

Please sign in to comment.