Skip to content

Commit

Permalink
Merge branch 'dev' into feature/#63-RefactoringClub
Browse files Browse the repository at this point in the history
  • Loading branch information
c0smosaur authored Jun 8, 2024
2 parents 8546824 + 9472f5e commit fbf0695
Show file tree
Hide file tree
Showing 19 changed files with 339 additions and 112 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class ClubNotice extends BaseEntity { // board -> notice
private Long memberId;
private String title;
private String content;

@Enumerated(EnumType.STRING)
private NotificationType type; //게시판 or 공지
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public Page<ClubNoticeResponse> findAllNotice(Long clubId, Pageable pageable) {

List<ClubNotice> clubNoticeList = queryFactory.selectFrom(clubNotice)
.where(clubNotice.clubId.eq(clubId)
.and(clubNotice.type.eq(NotificationType.valueOf("NOTICE"))))
.and(clubNotice.type.eq(NotificationType.NOTICE)))
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.fetch();
Expand All @@ -54,7 +54,7 @@ public ClubNoticeResponse findNotice(Long clubId, Long noticeId) {
ClubNotice notice = queryFactory.selectFrom(clubNotice)
.where(clubNotice.clubId.eq(clubId)
.and(clubNotice.id.eq(noticeId))
.and(clubNotice.type.eq(NotificationType.valueOf("notice"))))
.and(clubNotice.type.eq(NotificationType.NOTICE)))
.fetchOne();

if (notice == null) {
Expand All @@ -70,14 +70,14 @@ public Page<ClubNotice> findAllBoard(Long clubId, Pageable pageable) {

List<ClubNotice> clubNoticeList = queryFactory.selectFrom(clubNotice)
.where(clubNotice.clubId.eq(clubId)
.and(clubNotice.type.eq(NotificationType.valueOf("BOARD"))))
.and(clubNotice.type.eq(NotificationType.BOARD)))
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.fetch();

long total = queryFactory.selectFrom(clubNotice)
.where(clubNotice.clubId.eq(clubId)
.and(clubNotice.type.eq(NotificationType.valueOf("BOARD"))))
.and(clubNotice.type.eq(NotificationType.BOARD)))
.fetchCount();

return new PageImpl<>(clubNoticeList, pageable, total);
Expand All @@ -90,7 +90,7 @@ public Optional<ClubNotice> findBoard(Long clubId, Long noticeId) {
ClubNotice notice = queryFactory.selectFrom(clubNotice)
.where(clubNotice.clubId.eq(clubId)
.and(clubNotice.id.eq(noticeId))
.and(clubNotice.type.eq(NotificationType.valueOf("BOARD"))))
.and(clubNotice.type.eq(NotificationType.BOARD)))
.fetchOne();

return Optional.ofNullable(notice);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
// 카테고리 조회
"/api/v1/category/*",

//소모임
"/api/v1/club/**").permitAll()
//소모임 - 비로그인 범위
"/api/v1/club/search").permitAll()

.anyRequest().authenticated())
.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.core.linkup.common.response.BaseResponse;
import com.core.linkup.common.response.BaseResponseStatus;
import jakarta.persistence.OptimisticLockException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
Expand All @@ -22,6 +23,17 @@ public ResponseEntity<BaseResponse<T>> exception(BaseException exception) {
.body(BaseResponse.response(exception.getStatus()));
}

@ExceptionHandler(value = OptimisticLockException.class)
public ResponseEntity<BaseResponse<T>> optimisticLockException(OptimisticLockException exception) {
log.warn("Optimistic Lock: {}\nClass: {}\nCause: {}", exception.getMessage(),
exception.getEntity().getClass().getName(),
exception.getCause().getMessage());

return ResponseEntity
.badRequest()
.body(BaseResponse.response(BaseResponseStatus.CONCURRENCY_CONFLICT));
}

// 커스텀으로 처리되지 않은 예외 처리
@ExceptionHandler(value = Exception.class)
public ResponseEntity<BaseResponse<T>> exception(Exception exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,23 @@ public enum BaseResponseStatus {

EMAIL_ERROR(false, OK.value(), "메일이 도착하지 않았다면 다시 시도해주세요."),


// TODO: 개발 진행에 따라 추가될 에정

EXPIRED_TOKEN(false, UNAUTHORIZED.value(), "만료된 토큰입니다."),
INVALID_TOKEN(false, UNAUTHORIZED.value(), "잘못된 토큰입니다."),
TOKEN_NOT_FOUND(false, UNAUTHORIZED.value(), "토큰이 존재하지 않습니다."),

INVALID_MEMBER(false, UNAUTHORIZED.value(), "로그인된 사용자와 일치하지 않습니다."),

REQUIRES_CONSENT(false, BAD_REQUEST.value(), "개인정보 수집에 동의해주세요."),
DUPLICATE_EMAIL(false, BAD_REQUEST.value(), "이미 가입된 이메일입니다."),
UNVERIFIED_EMAIL(false, BAD_REQUEST.value(), "인증되지 않은 이메일입니다."),
DUPLICATE_USERNAME(false, BAD_REQUEST.value(), "이미 사용중인 닉네임입니다."),
INVALID_PASSWORD(false, BAD_REQUEST.value(), "아이디나 비밀번호가 일치하지 않습니다."),
INVALID_AUTHCODE(false, BAD_REQUEST.value(), "인증에 실패했습니다."),
AUTHCODE_ISSUE_ERROR(false, INTERNAL_SERVER_ERROR.value(), "인증코드 발급에 실패했습니다."),
INVALID_RESERVATION_DATE(false, BAD_REQUEST.value(), "예약 날짜가 옳지 않습니다."),

CONCURRENCY_CONFLICT(false, BAD_REQUEST.value(), "예약 정보가 수정되었습니다. 새로고침 후 다시 시도해주세요."),

INVALID_REQUEST(false, BAD_REQUEST.value(), "잘못된 요청입니다."),

UNREGISTERD_MEMBER(false, NOT_FOUND.value(), "존재하지 않는 사용자입니다."),
DOES_NOT_EXIST(false, NOT_FOUND.value(), "요청한 데이터가 존재하지 않습니다."),
Expand All @@ -48,8 +51,7 @@ public enum BaseResponseStatus {
INVALID_MEMBERSHIP(false, NOT_FOUND.value(),"멤버십을 먼저 구매 후에 이용해 주세요"),
DUPLICATE_CLUB_LIKE(false, BAD_REQUEST.value(), "이미 좋아요를 눌렀습니다"),

INVALID_REQUEST(false, INTERNAL_SERVER_ERROR.value(), "잘못된 요청입니다."),
INVALID_MEMBER(false, INTERNAL_SERVER_ERROR.value(), "로그인된 사용자와 일치하지 않습니다."),
AUTHCODE_ISSUE_ERROR(false, INTERNAL_SERVER_ERROR.value(), "인증코드 발급에 실패했습니다."),

SERVER_ERROR(false, INTERNAL_SERVER_ERROR.value(), "예상하지 못한 서버 에러가 발생했습니다.");

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.core.linkup.reservation.reservation.controller;

import com.core.linkup.common.response.BaseResponse;
import com.core.linkup.reservation.reservation.response.MainPageReservationResponse;
import com.core.linkup.reservation.reservation.response.MembershipResponse;
import com.core.linkup.reservation.reservation.response.SeatSpaceResponse;
import com.core.linkup.reservation.reservation.service.MembershipReservationService;
Expand All @@ -11,6 +12,7 @@
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

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

@Slf4j
Expand Down Expand Up @@ -43,4 +45,17 @@ public BaseResponse<List<SeatSpaceResponse>> getAvailableSeats(
return BaseResponse.response(
reservationService.getAvailableSeatSpaces(officeId, type, start, startTime, end, endTime));
}

@GetMapping // (뒤에 yyyy-mm-dd)
public BaseResponse<List<MainPageReservationResponse>> getMainPageReservations(
@AuthenticationPrincipal MemberDetails memberDetails,
@RequestParam(name = "date", required = false) LocalDate date) {

if (date == null) {
date = LocalDate.now();
}
return BaseResponse.response(
membershipReservationService.getAllReservationsOnDate(memberDetails.getMember(), date));

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,9 @@ public Reservation toReservationEntity(ReservationRequest request,
BaseMembershipEntity membership,
SeatSpace seatSpace){
ReservationType reservationType = ReservationType.fromKor(request.getType());

LocalDate startDate = LocalDate.parse(request.getStartDate());
LocalDate endDate = LocalDate.parse(request.getEndDate());
List<LocalDateTime> dates = getLocalDateTime(request);

if (membership.getClass().equals(IndividualMembership.class)) {
List<LocalDateTime> dates = getLocalDateTime(request);

return Reservation.builder()
.type(reservationType)
.startDate(dates.get(0))
Expand All @@ -53,7 +49,6 @@ public Reservation toReservationEntity(ReservationRequest request,
.seatId(seatSpace.getId())
.build();
} else {
List<LocalDateTime> dates = getLocalDateTime(request);
return Reservation.builder()
.type(reservationType)
.startDate(dates.get(0))
Expand Down Expand Up @@ -118,46 +113,51 @@ public ReservationResponse toReservationResponse(
.build();
}

// 좌석 응답
public SeatSpaceResponse toSeatSpaceResponse(SeatSpace seatSpace, boolean isReserved){
return SeatSpaceResponse.builder()
.id(seatSpace.getId())
.type(seatSpace.getType().getTypeName())
.code(seatSpace.getCode())
.isAvailable(isReserved)
.build();
}

// 예약 수정
public Reservation updateOriginalDesignatedReservation(ReservationRequest request, Reservation originalReservation){
return originalReservation.toBuilder()
.endDate(LocalDate.parse(request.getStartDate()).atStartOfDay())
.build();
}

// 에약 수정
public Reservation updateReservation(ReservationRequest request, Reservation originalReservation){
// 자율 좌석 변경
if (request.getType().equals(ReservationType.TEMPORARY_SEAT.getName())) {
return originalReservation.toBuilder()
.seatId(request.getSeatId())
.build();
// 공간 변경
} else {
LocalDateTime startDate = LocalDateTime.of(
LocalDate.parse(request.getStartDate()),
LocalTime.parse(request.getStartTime()));
LocalDateTime endDate = LocalDateTime.of(
LocalDate.parse(request.getEndDate()),
LocalTime.parse(request.getEndTime()));
if (request.getType().equals(ReservationType.SPACE.getName())) {
List<LocalDateTime> dates = getLocalDateTime(request);
LocalDateTime startDate = dates.get(0);
LocalDateTime endDate = dates.get(1);
return originalReservation.toBuilder()
.startDate(startDate)
.endDate(endDate)
.seatId(request.getSeatId())
.price(request.getPrice())
.build();
} else {
// 자율 좌석 변경
return originalReservation.toBuilder()
.seatId(request.getSeatId())
.build();
}
}

public MainPageReservationResponse toMainPageReservationResponse(
BaseMembershipEntity membership, Reservation reservation, SeatSpace seatSpace){
return MainPageReservationResponse.builder()
.membershipType(membership.getType().getName())
.officeId(membership.getId())
.location(membership.getLocation())
.reservationId(reservation.getId())
.reservationType(reservation.getType().getName())
.startDate(reservation.getStartDate().toLocalDate())
.startTime(reservation.getStartDate().toLocalTime())
.endDate(reservation.getEndDate().toLocalDate())
.endTime(reservation.getEndDate().toLocalTime())
.seatType(seatSpace.getType().getTypeName())
.seatCode(seatSpace.getCode())
.build();
}

public ReservationResponse emptyReservationResponse(){
return ReservationResponse.builder().build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,7 @@ public class Reservation extends BaseEntity {
private Long companyMembershipId;
private Long individualMembershipId;
private Long seatId;

@Version
private int version;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
@Getter
public enum ReservationType {

COMPANY_DESIGNATED_SEAT("기업 지정석"),
DESIGNATED_SEAT("지정석"),
TEMPORARY_SEAT("자율 좌석"),
SPACE("공간");
Expand All @@ -20,4 +21,4 @@ public static ReservationType fromKor(String name) {
}
throw new IllegalArgumentException("No matching occupation type for: " + name);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@


import com.core.linkup.office.entity.SeatSpace;
import com.core.linkup.office.entity.enums.SeatSpaceType;
import com.core.linkup.reservation.reservation.entity.Reservation;
import com.querydsl.core.Tuple;

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

Expand All @@ -12,8 +15,10 @@ public interface ReservationRepositoryCustom {
// 사용자의 전체 개인 멤버십/예약/좌석 조회
List<Tuple> findAllIndividualMembershipAndReservationsAndSeatByMemberId(Long memberId);

// 사용자의 해당 지점 전체 개인 멤버십/예약/좌석 조회
List<Tuple> findAllReservationsAndSeatAndIndividualMembershipByMemberIdAndOfficeId(Long memberId, Long officeId);
// 사용자의 개인 멤버십 특정 날짜 예약 조회
List<Tuple> findAllReservationsAndSeatForIndividualMembershipByMemberIdAndDate(Long memberId, LocalDate date);

List<Tuple> findAllReservationsAndSeatForCompanyMembershipByMemberIdAndDate(Long memberId, LocalDate date);

// 특정 개인 멤버십의 전체 예약/좌석
List<Tuple> findAllReservationAndSeatByIndividualMembershipId(Long membershipId, Long memberId);
Expand All @@ -29,4 +34,8 @@ public interface ReservationRepositoryCustom {

// 잔여 좌석 조회
List<SeatSpace> findAllSeatSpacesByOfficeIdAndType(Long officeId, String type, LocalDateTime start, LocalDateTime end);

// 잔여 공간 조회
List<Reservation> findAllReservationsBySeatIdAndDateAndType(Long seatId, LocalDateTime startDate, SeatSpaceType type);

}
Loading

0 comments on commit fbf0695

Please sign in to comment.