Skip to content

Commit

Permalink
fix: feature/174 병합 충돌 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
2Jin1031 committed Nov 25, 2024
2 parents b2f5927 + f3a1779 commit 8db0a25
Show file tree
Hide file tree
Showing 21 changed files with 686 additions and 18 deletions.
2 changes: 1 addition & 1 deletion backend/backup.sql
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ CREATE TABLE IF NOT EXISTS `board` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

-- User 테이블 생성
CREATE TABLE IF NOT EXISTS `user` (
CREATE TABLE IF NOT EXISTS `users` (
`user_id` bigint NOT NULL AUTO_INCREMENT,
`student_id` varchar(255) DEFAULT NULL,
`name` varchar(255) DEFAULT NULL,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.example.backend.board.domain.entity;

import jakarta.persistence.*;
import java.time.LocalDateTime;
import java.util.List;
import lombok.AccessLevel;
import lombok.Builder;
Expand Down Expand Up @@ -36,6 +37,9 @@ public class Board extends BaseEntity {
@Column(name = "file_list", length = 1000)
private List<String> fileList;

@Column(name = "created_date_time")
private LocalDateTime createdDateTime;

@Enumerated(EnumType.STRING)
@Column(name = "category")
private Category category;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
public abstract class BaseEntity {

@CreatedDate
private LocalDateTime createdDateTime;
private LocalDateTime createdAt;

@LastModifiedDate
private LocalDateTime modifiedDateTime;
private LocalDateTime updatedAt;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.example.backend.reservation.controller;

import lombok.RequiredArgsConstructor;
import org.example.backend.reservation.domain.ReservationStatus;
import org.example.backend.reservation.domain.dto.ReservationReqDto;
import org.example.backend.reservation.domain.dto.ReservationResDto;
import org.example.backend.reservation.service.ReservationService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/reservations")
public class ReservationController {
private final ReservationService reservationService;

@PostMapping
public ResponseEntity<ReservationResDto> createReservation(@RequestBody ReservationReqDto reqDto) {
ReservationResDto resDto = reservationService.createReservation(reqDto);
return ResponseEntity.ok(resDto);
}

@GetMapping
public ResponseEntity<List<ReservationResDto>> getAllReservations() {
List<ReservationResDto> reservations = reservationService.getAllReservations();
return ResponseEntity.ok(reservations);
}

@GetMapping("/{reservationId}")
public ResponseEntity<ReservationResDto> getReservation(@PathVariable(value = "reservationId") Long id) {
ReservationResDto resDto = reservationService.getReservation(id);
return ResponseEntity.ok(resDto);
}

@PatchMapping("/{reservationId}/status")
public ResponseEntity<ReservationResDto> updateReservationStatus(
@PathVariable(value = "reservationId") Long id,
@RequestParam(value = "status") ReservationStatus status) {
ReservationResDto resDto = reservationService.updateReservationStatus(id, status);
return ResponseEntity.ok(resDto);
}

@DeleteMapping("/{reservationId}")
public ResponseEntity<Void> deleteReservation(@PathVariable(value = "reservationId") Long id) {
reservationService.deleteReservation(id);
return ResponseEntity.ok().build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,91 @@

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import java.util.Date;
import java.time.LocalDateTime;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.example.backend.global.config.BaseEntity;
import org.example.backend.reservation.domain.dto.ReservationReqDto;
import org.example.backend.seminarRoom.domain.SeminarRoom;
import org.example.backend.user.domain.entity.User;

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Table(name = "reservation")
public class Reservation {

public class Reservation extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "reservation_id")
private Long id;

@Column(name = "start_date")
private Date startDate;
@Column(name = "start_time")
private LocalDateTime startTime;

@Column(name = "end_date")
private Date endDate;
@Column(name = "end_time")
private LocalDateTime endTime;

@Enumerated(EnumType.STRING)
@Column(name = "purpose")
private ReservationPurpose purpose;

@Column(name = "etc")
private String etc;

@Enumerated(EnumType.STRING)
@Column(name = "status")
private ReservationStatus status;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id", nullable = false)
private User user;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "seminar_room", nullable = false)
@JoinColumn(name = "seminar_room_id")
private SeminarRoom seminarRoom;
}

@Column(name = "user_id")
private Long userId;

@Builder
private Reservation(LocalDateTime startTime, LocalDateTime endTime, ReservationPurpose purpose,
String etc, ReservationStatus status, SeminarRoom seminarRoom, Long userId) {
this.startTime = startTime;
this.endTime = endTime;
this.purpose = purpose;
this.etc = etc;
this.status = status;
this.seminarRoom = seminarRoom;
this.userId = userId;
}

public static Reservation of(ReservationReqDto dto, SeminarRoom seminarRoom) {
return Reservation.builder()
.startTime(dto.getStartTime())
.endTime(dto.getEndTime())
.purpose(dto.getPurpose())
.etc(dto.getEtc())
.status(ReservationStatus.APPROVED)
.seminarRoom(seminarRoom)
.userId(dto.getUserId())
.build();
}

public void update(ReservationReqDto dto, SeminarRoom seminarRoom) {
this.startTime = dto.getStartTime();
this.endTime = dto.getEndTime();
this.purpose = dto.getPurpose();
this.etc = dto.getEtc();
this.seminarRoom = seminarRoom;
}

public void updateStatus(ReservationStatus status) {
this.status = status;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
package org.example.backend.reservation.domain;

public enum ReservationPurpose {
SEMINAR("세미나"),
MEETING("회의"),
STUDY("스터디"),
CLASS("수업"),
OTHER("기타");

private final String description;

ReservationPurpose(String description) {
this.description = description;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
package org.example.backend.reservation.domain;

public enum ReservationStatus {
PENDING("대기중"),
APPROVED("승인됨"),
REJECTED("거절됨"),
CANCELLED("취소됨");

private final String description;

ReservationStatus(String description) {
this.description = description;

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.example.backend.reservation.domain.dto;


import java.time.LocalDateTime;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.example.backend.reservation.domain.ReservationPurpose;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class ReservationReqDto {
private LocalDateTime startTime;
private LocalDateTime endTime;
private ReservationPurpose purpose;
private String etc;
private Long seminarRoomId;
private Long userId;

@Builder
private ReservationReqDto(LocalDateTime startTime, LocalDateTime endTime,
ReservationPurpose purpose, String etc, Long seminarRoomId, Long userId) {
this.startTime = startTime;
this.endTime = endTime;
this.purpose = purpose;
this.etc = etc;
this.seminarRoomId = seminarRoomId;
this.userId = userId;
}

public static ReservationReqDto of(LocalDateTime startTime, LocalDateTime endTime,
ReservationPurpose purpose, String etc, Long seminarRoomId, Long userId) {
return ReservationReqDto.builder()
.startTime(startTime)
.endTime(endTime)
.purpose(purpose)
.etc(etc)
.seminarRoomId(seminarRoomId)
.userId(userId)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.example.backend.reservation.domain.dto;

import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.example.backend.reservation.domain.Reservation;
import org.example.backend.reservation.domain.ReservationPurpose;
import org.example.backend.reservation.domain.ReservationStatus;
import java.time.LocalDateTime;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class ReservationResDto {
private Long id;
private LocalDateTime startTime;
private LocalDateTime endTime;
private ReservationPurpose purpose;
private String etc;
private ReservationStatus status;
private String seminarRoomName;
private Long userId;

@Builder
private ReservationResDto(Long id, LocalDateTime startTime, LocalDateTime endTime,
ReservationPurpose purpose, String etc, ReservationStatus status,
String seminarRoomName, Long userId) {
this.id = id;
this.startTime = startTime;
this.endTime = endTime;
this.purpose = purpose;
this.etc = etc;
this.status = status;
this.seminarRoomName = seminarRoomName;
this.userId = userId;
}

public static ReservationResDto of(Reservation reservation) {
return ReservationResDto.builder()
.id(reservation.getId())
.startTime(reservation.getStartTime())
.endTime(reservation.getEndTime())
.purpose(reservation.getPurpose())
.etc(reservation.getEtc())
.status(reservation.getStatus())
.seminarRoomName(reservation.getSeminarRoom().getName())
.userId(reservation.getUserId())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.example.backend.reservation.exception;

import lombok.RequiredArgsConstructor;
import org.example.backend.common.exception.BaseException;
import org.example.backend.common.exception.BaseExceptionType;

@RequiredArgsConstructor
public class ReservationException extends BaseException {
private final ReservationExceptionType exceptionType;

@Override
public BaseExceptionType exceptionType() {
return exceptionType;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.example.backend.reservation.exception;

import static org.springframework.http.HttpStatus.BAD_REQUEST;
import static org.springframework.http.HttpStatus.NOT_FOUND;

import lombok.RequiredArgsConstructor;
import org.example.backend.common.exception.BaseExceptionType;
import org.springframework.http.HttpStatus;

@RequiredArgsConstructor
public enum ReservationExceptionType implements BaseExceptionType {

NOT_FOUND_RESERVATION(NOT_FOUND, "예약을 찾을 수 없습니다"),
EXIST_ALREADY_RESERVATION(BAD_REQUEST, "해당 시간에 이미 승인된 예약이 존재합니다."),
CONFLICT_TIMETABLE(BAD_REQUEST, "해당 시간에 정기 수업이 있어 예약이 불가능합니다."),
INVALID_TIME_ORDER(BAD_REQUEST, "시작 시간은 종료 시간보다 이후일 수 없습니다."), // 새 예외
EXCEEDS_MAX_DURATION(BAD_REQUEST, "예약은 최대 2시간까지만 가능합니다."),
PAST_TIME_RESERVATION(BAD_REQUEST, "과거의 시간으로 예약할 수 없습니다."),
;

private final HttpStatus httpStatus;
private final String errorMessage;

@Override
public HttpStatus httpStatus() {
return httpStatus;
}

@Override
public String errorMessage() {
return errorMessage;
}
}
Loading

0 comments on commit 8db0a25

Please sign in to comment.