Skip to content

Commit

Permalink
Merge pull request #255 from urinaner/feature/233
Browse files Browse the repository at this point in the history
[BE] fix: 예약 로직 변경
  • Loading branch information
2Jin1031 authored Jan 12, 2025
2 parents 064f126 + a8c907b commit 36fa151
Show file tree
Hide file tree
Showing 23 changed files with 86 additions and 583 deletions.
4 changes: 0 additions & 4 deletions backend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ configurations {

repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}

dependencies {
Expand All @@ -41,9 +40,6 @@ dependencies {
implementation 'io.jsonwebtoken:jjwt-impl:0.11.2'
implementation 'io.jsonwebtoken:jjwt-jackson:0.11.2'

// sj-auth
implementation 'com.github.urinaner:sejong-auth:v0.4.4'

// email
implementation 'org.springframework.boot:spring-boot-starter-mail'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import static org.example.backend.admin.exception.AdminExceptionType.ALREADY_EXIST_LOGIN_ID;
import static org.example.backend.admin.exception.AdminExceptionType.INVALID_ACCESS_TOKEN;
import static org.example.backend.user.exception.UserExceptionType.NOT_FOUND_USER;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -11,7 +10,6 @@
import org.example.backend.admin.domain.entity.Admin;
import org.example.backend.admin.exception.AdminException;
import org.example.backend.admin.repository.AdminRepository;
import org.example.backend.user.exception.UserException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand Down

This file was deleted.

This file was deleted.

11 changes: 0 additions & 11 deletions backend/src/main/java/org/example/backend/global/aop/AuthUser.java

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.example.backend.global.config.web;

import org.example.backend.global.aop.AuthUserResolver;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
Expand All @@ -10,18 +9,6 @@

@Configuration
public class WebConfig implements WebMvcConfigurer {

private final AuthUserResolver authUserResolver;

public WebConfig(AuthUserResolver authUserResolver) {
this.authUserResolver = authUserResolver;
}

@Override
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
resolvers.add(authUserResolver);
}

@Override
public void addCorsMappings(CorsRegistry corsRegistry) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.example.backend.reservation.domain.dto.ReservationReqDto;
import org.example.backend.reservation.domain.dto.ReservationCreateDto;
import org.example.backend.reservation.domain.dto.ReservationDeleteRequest;
import org.example.backend.reservation.domain.dto.ReservationResDto;
import org.example.backend.reservation.service.ReservationService;
import org.example.backend.user.domain.entity.User;
import org.example.backend.user.exception.UserException;
import org.example.backend.user.exception.UserExceptionType;
import org.example.backend.user.repository.UserRepository;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -27,15 +24,12 @@
@RequestMapping("/api/room")
public class ReservationController {
private final ReservationService reservationService;
private final UserRepository userRepository;

@PostMapping("/{roomId}/reservation")
public ResponseEntity<List<ReservationResDto>> createReservation(
@PathVariable(value = "roomId") Long roomId,
@RequestBody @Valid ReservationReqDto reqDto) {
User user = userRepository.findById(1L)
.orElseThrow(() -> new UserException(UserExceptionType.NOT_FOUND_USER));
List<ReservationResDto> resDtos = reservationService.createReservation(roomId, reqDto, user);
@RequestBody @Valid ReservationCreateDto reqDto) {
List<ReservationResDto> resDtos = reservationService.createReservation(roomId, reqDto);
log.debug("Reservation created successfully: {}", resDtos);
return ResponseEntity.ok(resDtos);
}
Expand All @@ -44,7 +38,7 @@ public ResponseEntity<List<ReservationResDto>> createReservation(
@GetMapping("/{roomId}/reservation")
public ResponseEntity<List<ReservationResDto>> getReservationsByRoomAndDate(
@PathVariable(name = "roomId") Long roomId,
@RequestParam(value = "date") String date
@RequestParam(value = "date", required = false) String date
) {
List<ReservationResDto> reservations = reservationService.getReservationsByRoomAndDate(roomId, date);
return ResponseEntity.ok(reservations);
Expand Down Expand Up @@ -75,8 +69,10 @@ public ResponseEntity<ReservationResDto> getReservation(
@DeleteMapping("/{roomId}/reservation/{reservationId}")
public ResponseEntity<Void> deleteReservation(
@PathVariable(value = "roomId") Long roomId,
@PathVariable(value = "reservationId") Long reservationId) {
reservationService.deleteReservation(reservationId);
@PathVariable(value = "reservationId") Long reservationId,
@RequestBody ReservationDeleteRequest request) {
reservationService.deleteReservation(reservationId, request.getPassword());
return ResponseEntity.ok().build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.example.backend.common.domain.BaseEntity;
import org.example.backend.common.utils.TimeParsingUtils;
import org.example.backend.reservation.domain.dto.ReservationReqDto;
import org.example.backend.reservation.domain.dto.ReservationCreateDto;
import org.example.backend.room.domain.Room;
import org.example.backend.user.domain.entity.User;

@Entity
@Getter
Expand Down Expand Up @@ -49,29 +47,37 @@ public class Reservation extends BaseEntity {
@JoinColumn(name = "room_id")
private Room room;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
private User user;
@Column(name = "user_name")
private String username;

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

public boolean isPasswordMatch(String inputPassword) {
return this.password.equals(inputPassword);
}

@Builder
private Reservation(LocalDateTime startTime, LocalDateTime endTime, ReservationPurpose purpose,
String etc, Room room, User user) {
String etc, Room room, String username, String password) {
this.startTime = startTime;
this.endTime = endTime;
this.purpose = purpose;
this.etc = etc;
this.room = room;
this.user = user;
this.username = username;
this.password = password;
}

public static Reservation of(ReservationReqDto dto, Room room, User user) {
public static Reservation of(ReservationCreateDto dto, Room room) {
return Reservation.builder()
.startTime(TimeParsingUtils.formatterLocalDateTime(String.valueOf(dto.getStartTime())))
.endTime(TimeParsingUtils.formatterLocalDateTime(String.valueOf(dto.getEndTime())))
.startTime(dto.getStartTime())
.endTime(dto.getEndTime())
.purpose(ReservationPurpose.valueOf(dto.getPurpose()))
.etc(dto.getEtc())
.room(room)
.user(user)
.username(dto.getUserName())
.password(dto.getPassword())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,23 @@
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import java.time.LocalDateTime;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class ReservationReqDto {
public class ReservationCreateDto {

@JsonFormat(pattern = "yyyy-MM-dd HH:mm")
@NotNull(message = "시작 시간은 필수 입력값입니다.")
private String startTime;

@JsonFormat(pattern = "yyyy-MM-dd HH:mm")
private LocalDateTime startTime;

@NotNull(message = "종료 시간은 필수 입력값입니다.")
private String endTime;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm")
private LocalDateTime endTime;

@NotBlank(message = "목적은 필수 입력값입니다.")
@Size(max = 100, message = "목적은 최대 100자까지 입력 가능합니다.")
Expand All @@ -27,18 +28,22 @@ public class ReservationReqDto {
@Size(max = 200, message = "기타 내용은 최대 200자까지 입력 가능합니다.")
private String etc;

private String userName;

private String password;

@Builder
private ReservationReqDto(String startTime, String endTime,
String purpose, String etc) {
private ReservationCreateDto(LocalDateTime startTime, LocalDateTime endTime,
String purpose, String etc) {
this.startTime = startTime;
this.endTime = endTime;
this.purpose = purpose;
this.etc = etc;
}

public static ReservationReqDto of(String startTime, String endTime,
String purpose, String etc) {
return ReservationReqDto.builder()
public static ReservationCreateDto of(LocalDateTime startTime, LocalDateTime endTime,
String purpose, String etc) {
return ReservationCreateDto.builder()
.startTime(startTime)
.endTime(endTime)
.purpose(purpose)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.example.backend.reservation.domain.dto;

import lombok.Data;

@Data
public class ReservationDeleteRequest {
private String password;
}
Loading

0 comments on commit 36fa151

Please sign in to comment.