diff --git a/src/main/java/github/benjamin/equipreservebackend/controller/ReservationController.java b/src/main/java/github/benjamin/equipreservebackend/controller/ReservationController.java index 4669875..dbdf9fe 100644 --- a/src/main/java/github/benjamin/equipreservebackend/controller/ReservationController.java +++ b/src/main/java/github/benjamin/equipreservebackend/controller/ReservationController.java @@ -2,11 +2,9 @@ package github.benjamin.equipreservebackend.controller; import com.alibaba.excel.EasyExcel; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import github.benjamin.equipreservebackend.constant.ReservationStatus; import github.benjamin.equipreservebackend.entity.Reservation; import github.benjamin.equipreservebackend.response.ResponseResult; import github.benjamin.equipreservebackend.service.ReservationService; -import github.benjamin.equipreservebackend.vo.DeviceStatsVO; import github.benjamin.equipreservebackend.vo.ReservationStatsVO; import github.benjamin.equipreservebackend.vo.ReservationVO; import github.benjamin.equipreservebackend.vo.UserReservationVO; @@ -22,6 +20,7 @@ import java.nio.charset.StandardCharsets; import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.util.List; +import java.util.Map; @RestController @RequestMapping("/reservation") @@ -83,4 +82,12 @@ public class ReservationController { .doWrite(data); } + @PreAuthorize("hasRole('DEVICE_ADMIN')") + @PostMapping("/endTime/{reservationId}") + public ResponseResult updateEndTime(@PathVariable Long reservationId, + @RequestBody Map body) { + LocalDate endTime = LocalDate.parse(body.get("endTime")); + reservationService.updateEndTime(reservationId, endTime); + return ResponseResult.success(); + } } diff --git a/src/main/java/github/benjamin/equipreservebackend/service/ReservationService.java b/src/main/java/github/benjamin/equipreservebackend/service/ReservationService.java index 280d3c6..0b00557 100644 --- a/src/main/java/github/benjamin/equipreservebackend/service/ReservationService.java +++ b/src/main/java/github/benjamin/equipreservebackend/service/ReservationService.java @@ -22,4 +22,6 @@ public interface ReservationService { List getReservationStats(LocalDate start, LocalDate end); List getDeviceDetailStats(Long deviceId, LocalDate start, LocalDate end); + + void updateEndTime(Long reservationId, LocalDate endTime); } diff --git a/src/main/java/github/benjamin/equipreservebackend/service/impl/ReservationServiceImpl.java b/src/main/java/github/benjamin/equipreservebackend/service/impl/ReservationServiceImpl.java index b4d0eba..f14bdbf 100644 --- a/src/main/java/github/benjamin/equipreservebackend/service/impl/ReservationServiceImpl.java +++ b/src/main/java/github/benjamin/equipreservebackend/service/impl/ReservationServiceImpl.java @@ -1,6 +1,7 @@ package github.benjamin.equipreservebackend.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import github.benjamin.equipreservebackend.constant.ReservationStatus; import github.benjamin.equipreservebackend.entity.Device; @@ -165,4 +166,11 @@ public class ReservationServiceImpl implements ReservationService { .le(Reservation::getEndTime, end) .orderByAsc(Reservation::getApplicantName, Reservation::getStartTime)).stream().map(DeviceDetailStatsVO::new).toList(); } + + @Override + public void updateEndTime(Long reservationId, LocalDate endTime) { + reservationMapper.update(new LambdaUpdateWrapper() + .eq(Reservation::getId, reservationId) + .set(Reservation::getEndTime, endTime)); + } } diff --git a/src/main/java/github/benjamin/equipreservebackend/vo/LeaderApprovalVO.java b/src/main/java/github/benjamin/equipreservebackend/vo/LeaderApprovalVO.java index 7a21892..9ab34af 100644 --- a/src/main/java/github/benjamin/equipreservebackend/vo/LeaderApprovalVO.java +++ b/src/main/java/github/benjamin/equipreservebackend/vo/LeaderApprovalVO.java @@ -9,6 +9,8 @@ import java.time.LocalDate; @Data public class LeaderApprovalVO { + @JsonSerialize(using = ToStringSerializer.class) + private Long reservationId; @JsonSerialize(using = ToStringSerializer.class) private Long approvalId; private String applicantName; diff --git a/src/main/resources/mapper/ApprovalMapper.xml b/src/main/resources/mapper/ApprovalMapper.xml index a919672..a77cde2 100644 --- a/src/main/resources/mapper/ApprovalMapper.xml +++ b/src/main/resources/mapper/ApprovalMapper.xml @@ -5,7 +5,7 @@