Skip to content

Commit

Permalink
package refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
chosoobin37 committed Jul 2, 2024
1 parent 6133137 commit 05a679b
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
@Getter
@Setter
@ToString
@Data
public class Member {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
@Getter
@Setter
@ToString
@Data
public class MemberDTO {
private int memberId;
private String memberPhone;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ public class ReservationController {
private final StudyRoomService studyRoomService;

@Autowired
public ReservationController(ReservationService reservationService,
StudyRoomService studyRoomService) {
public ReservationController(ReservationService reservationService, StudyRoomService studyRoomService) {
this.reservationService = reservationService;
this.studyRoomService = studyRoomService;
}
Expand All @@ -46,8 +45,7 @@ public ResponseEntity<List<ReservationDTO>> findAllOccupiedSeat() {
public ResponseEntity<MemberDTO> findMemberByPhone(@PathVariable("phone") String phone) {
Optional<Member> member = reservationService.findMemberByPhone(phone);

return member.map(value -> ResponseEntity.ok(new MemberDTO(value))).orElseGet(()
-> ResponseEntity.status(HttpStatus.NOT_FOUND).body(null));
return member.map(value -> ResponseEntity.ok(new MemberDTO(value))).orElseGet(() -> ResponseEntity.status(HttpStatus.NOT_FOUND).body(null));
}

@PostMapping("/member")
Expand All @@ -61,13 +59,11 @@ public ResponseEntity<MemberDTO> addMember(@RequestBody MemberDTO memberDTO) {
public ResponseEntity<ReservationDTO> findReservationByPhone(@PathVariable("phone") String phone) {
Optional<Reservation> reservation = reservationService.findReservationByPhone(phone);

return reservation.map(value -> ResponseEntity.ok(new ReservationDTO(value))).orElseGet(()
-> ResponseEntity.status(HttpStatus.NOT_FOUND).body(null));
return reservation.map(value -> ResponseEntity.ok(new ReservationDTO(value))).orElseGet(() -> ResponseEntity.status(HttpStatus.NOT_FOUND).body(null));
}

@GetMapping("/reservation/{phone}/{roomId}")
public ResponseEntity<ReservationDTO> findReservation(@PathVariable("phone") String phone,
@PathVariable("roomId") int roomId) {
public ResponseEntity<ReservationDTO> findReservation(@PathVariable("phone") String phone, @PathVariable("roomId") int roomId) {
ReservationDTO reservation = reservationService.findReservationByPhoneAndSeat(phone, roomId);

return ResponseEntity.ok(reservation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@

import com.team4chamchi.tunastudycicd.reservation.aggregate.Reservation;

import lombok.*;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.time.LocalDateTime;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Data
public class ReservationDTO {

private int reservationId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import com.team4chamchi.tunastudycicd.reservation.aggregate.Reservation;
import com.team4chamchi.tunastudycicd.reservation.dto.ReservationDTO;
import com.team4chamchi.tunastudycicd.reservation.repository.ReservationRepository;
import com.team4chamchi.tunastudycicd.studyroom.aggregate.StudyRoom;
import com.team4chamchi.tunastudycicd.studyroom.respository.StudyRoomRepository;
import com.team4chamchi.tunastudy.studyroom.aggregate.StudyRoom;
import com.team4chamchi.tunastudy.studyroom.respository.StudyRoomRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -65,15 +65,12 @@ public Member addMember(MemberDTO memberDTO) {

@Transactional
public ReservationDTO findReservationByPhoneAndSeat(String memberPhone, int roomId) {
Member member = findMemberByPhone(memberPhone).orElseThrow(()
-> new RuntimeException("존재하지 않는 회원입니다."));
Member member = findMemberByPhone(memberPhone).orElseThrow(() -> new RuntimeException("존재하지 않는 회원입니다."));

StudyRoom room = studyRoomRepository.findById(roomId).orElseThrow(()
-> new RuntimeException("유효하지 않은 좌석입니다."));
StudyRoom room = studyRoomRepository.findById(roomId).orElseThrow(() -> new RuntimeException("유효하지 않은 좌석입니다."));

//전화번호랑 좌석으로 예약 조회
Optional<Reservation> reservation
= reservationRepository.findByMember_MemberPhoneAndRoom_RoomId(memberPhone, roomId);
Optional<Reservation> reservation = reservationRepository.findByMember_MemberPhoneAndRoom_RoomId(memberPhone, roomId);

//조회된 예약이 없는 경우 -> 예약
if (reservation.isEmpty()) {
Expand All @@ -95,8 +92,7 @@ public ReservationDTO createReservation(int reservationId) {

foundReservation.setOccupied(true);
foundReservation.setStartDate(LocalDateTime.now().withSecond(0).withNano(0));
foundReservation.setEndDate
(foundReservation.getStartDate().plusHours(2).withSecond(0).withNano(0));
foundReservation.setEndDate(foundReservation.getStartDate().plusHours(2).withSecond(0).withNano(0));

String phone = "+82" + foundReservation.getMember().getMemberPhone();
String roomName = foundReservation.getRoom().getRoomName();
Expand Down Expand Up @@ -139,8 +135,7 @@ public void tenMinutesNotification() {
System.out.println("실행");

for (Reservation reservation : reservationList) {
notificationService.sendMessage("+82" + reservation.getMember().getMemberPhone(),
reservation.getRoom().getRoomName()+ "번 좌석 퇴실 10분 전입니다.");
notificationService.sendMessage("+82" + reservation.getMember().getMemberPhone(), reservation.getRoom().getRoomName()+ "번 좌석 퇴실 10분 전입니다.");
// System.out.println(reservation.getMember().getMemberPhone() + " " + reservation.getRoom().getRoomName());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
@Getter
@Setter
@ToString
@Data
public class StudyRoom {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
@Getter
@Setter
@ToString
@Data
public class StudyRoomDTO {
private int roomId;
private String roomName;
Expand Down

0 comments on commit 05a679b

Please sign in to comment.