Skip to content

Commit

Permalink
Merge pull request #49 from mju-facilty-organization/dev
Browse files Browse the repository at this point in the history
학생, 시설, 대여 api 문서화를 위한 test code 작성, 리팩토링
  • Loading branch information
0702Yoon authored Feb 4, 2025
2 parents 8f42822 + 7daf4b8 commit 5b6ead4
Show file tree
Hide file tree
Showing 36 changed files with 1,896 additions and 214 deletions.
13 changes: 13 additions & 0 deletions src/docs/asciidoc/facility.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
= 시설 API

=== 시설 생성 성공

operation::facility/시설등록[snippets="http-request,http-response"]

=== 시설 전체 조회

operation::facility/시설 전체 조회[snippets="http-request,http-response"]

=== 시설 상세 조회

operation::facility/시설 상세 조회[snippets="http-request,http-response"]
2 changes: 2 additions & 0 deletions src/docs/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@

include::members.adoc[]
include::email.adoc[]
include::facility.adoc[]
include::rental.adoc[]
9 changes: 9 additions & 0 deletions src/docs/asciidoc/rental.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
= 대여 API

=== 시설 대여 요청

operation::rental/대여 신청[snippets="http-request,http-response"]

=== 대여 내역 전체 조회

operation::rental/대여 내역 전체 조회[snippets="http-request,http-response"]
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.example.rentalSystem.domain.facility.convert;

import com.example.rentalSystem.domain.facility.entity.RentalStatus;
import com.example.rentalSystem.domain.facility.entity.timeTable.TimeStatus;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
Expand All @@ -9,7 +9,7 @@
import java.util.LinkedHashMap;

public class TimeSlotConverter implements
AttributeConverter<LinkedHashMap<LocalTime, RentalStatus>, String> {
AttributeConverter<LinkedHashMap<LocalTime, TimeStatus>, String> {

private final ObjectMapper mapper;

Expand All @@ -19,7 +19,7 @@ public TimeSlotConverter() {
}

@Override
public String convertToDatabaseColumn(LinkedHashMap<LocalTime, RentalStatus> timeSlot) {
public String convertToDatabaseColumn(LinkedHashMap<LocalTime, TimeStatus> timeSlot) {
try {
return mapper.writeValueAsString(timeSlot);
} catch (JsonProcessingException e) {
Expand All @@ -28,11 +28,11 @@ public String convertToDatabaseColumn(LinkedHashMap<LocalTime, RentalStatus> tim
}

@Override
public LinkedHashMap<LocalTime, RentalStatus> convertToEntityAttribute(String data) {
public LinkedHashMap<LocalTime, TimeStatus> convertToEntityAttribute(String data) {
try {
return mapper.readValue(data,
mapper.getTypeFactory()
.constructMapType(LinkedHashMap.class, LocalTime.class, RentalStatus.class));
.constructMapType(LinkedHashMap.class, LocalTime.class, TimeStatus.class));
} catch (JsonProcessingException e) {
throw new RuntimeException("Error deserializing TimeSlot", e);
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.example.rentalSystem.domain.facility.dto.request;

import com.example.rentalSystem.domain.facility.entity.Facility;
import com.example.rentalSystem.domain.facility.entity.FacilityType;
import com.example.rentalSystem.global.exception.custom.CustomException;
import com.example.rentalSystem.global.response.ErrorType;
import java.time.LocalTime;
import java.util.List;

Expand All @@ -21,20 +18,18 @@ public record CreateFacilityRequestDto(
) {

public Facility toFacility(List<String> imageUrlList) {
if (FacilityType.existsByValue(facilityType)) {
return Facility.builder()
.facilityType(facilityType)
.facilityNumber(facilityNumber)
.images(imageUrlList)
.capacity(capacity)
.allowedBoundary(allowedBoundary)
.supportFacilities(supportFacilities)
.pic(pic)
.startTime(startTime)
.endTime(endTime)
.isAvailable(isAvailable)
.build();
}
throw new CustomException(ErrorType.INVALID_REQUEST);
return Facility.builder()
.facilityType(facilityType)
.facilityNumber(facilityNumber)
.images(imageUrlList)
.capacity(capacity)
.allowedBoundary(allowedBoundary)
.supportFacilities(supportFacilities)
.pic(pic)
.startTime(startTime)
.endTime(endTime)
.isAvailable(isAvailable)
.build();
}
}

Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.example.rentalSystem.domain.facility.dto.request;

import com.example.rentalSystem.domain.facility.entity.Facility;
import com.example.rentalSystem.domain.facility.entity.FacilityType;
import com.example.rentalSystem.global.exception.custom.CustomException;
import com.example.rentalSystem.global.response.ErrorType;
import java.time.LocalTime;
import java.util.List;

Expand All @@ -21,15 +18,12 @@ public record UpdateFacilityRequestDto(
) {

public Facility toFacility() {
if (FacilityType.existsByValue(facilityType)) {
return Facility.builder()
.facilityType((facilityType))
.capacity(capacity)
.facilityNumber(facilityNumber)
.supportFacilities(supportFacilities)
.isAvailable(isAvailable)
.build();
}
throw new CustomException(ErrorType.INVALID_REQUEST);
return Facility.builder()
.facilityType((facilityType))
.capacity(capacity)
.facilityNumber(facilityNumber)
.supportFacilities(supportFacilities)
.isAvailable(isAvailable)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.example.rentalSystem.domain.facility.dto.response;

import com.example.rentalSystem.domain.facility.entity.Facility;
import com.example.rentalSystem.domain.facility.entity.RentalStatus;
import com.example.rentalSystem.domain.facility.entity.TimeTable;
import com.example.rentalSystem.domain.facility.entity.timeTable.TimeStatus;
import com.example.rentalSystem.domain.facility.entity.timeTable.TimeTable;
import java.time.LocalTime;
import java.util.LinkedHashMap;
import java.util.List;
Expand All @@ -20,7 +20,7 @@ public record FacilityDetailResponse(
List<String> supportFacilities,
String pic,
String date,
LinkedHashMap<LocalTime, RentalStatus> timeSlot
LinkedHashMap<LocalTime, TimeStatus> timeSlot

) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ public Facility(
LocalTime startTime,
LocalTime endTime,
boolean isAvailable) {

this.facilityType = facilityType;
this.facilityType = FacilityType.existsByValue(facilityType);
this.facilityNumber = facilityNumber;
this.images = images;
this.capacity = capacity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,19 @@ public enum FacilityType {

private final String value;

// @JsonCreator
// @JsonCreator
// public static FacilityType fromKoreanName(String value) {
// return Arrays.stream(values())
// .filter(type -> type.value.equals(value))
// .findAny()
// .orElseThrow(() -> new CustomException(ErrorType.INVALID_REQUEST));
// }

public static boolean existsByValue(String value) {
public static String existsByValue(String value) {
return Arrays.stream(values())
.anyMatch(type -> type.value.equals(value));
.filter(type -> type.value.equals(value))
.map(type -> type.value) // 존재하면 value 반환
.findFirst()
.orElseThrow(() -> new CustomException(ErrorType.INVALID_FACILITY_TYPE)); // 없으면 예외 발생
}

}
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
package com.example.rentalSystem.domain.facility.entity;
package com.example.rentalSystem.domain.facility.entity.timeTable;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.Getter;
import lombok.RequiredArgsConstructor;


@Getter
@RequiredArgsConstructor
public enum RentalStatus {
public enum TimeStatus {
AVAILABLE("예약가능"), UNAVAILABLE("이용불가"), RESERVED("예약완료"), WAITING("예약대기"), CURRENT("현재예약");
final String description;

@JsonValue
public String getDescription() {
return description;
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.example.rentalSystem.domain.facility.entity;
package com.example.rentalSystem.domain.facility.entity.timeTable;


import com.example.rentalSystem.domain.facility.convert.TimeSlotConverter;
import com.example.rentalSystem.domain.facility.entity.Facility;
import jakarta.persistence.Column;
import jakarta.persistence.Convert;
import jakarta.persistence.Entity;
Expand Down Expand Up @@ -32,13 +33,13 @@ public class TimeTable {
private LocalDate date;

@Convert(converter = TimeSlotConverter.class)
private LinkedHashMap<LocalTime, RentalStatus> timeSlot;
private LinkedHashMap<LocalTime, TimeStatus> timeSlot;

@Builder
public TimeTable(
Facility facility,
LocalDate date,
LinkedHashMap<LocalTime, RentalStatus> timeSlot
LinkedHashMap<LocalTime, TimeStatus> timeSlot
) {
this.facility = facility;
this.date = date;
Expand All @@ -58,11 +59,11 @@ public static TimeTable toEntity(
.build();
}

private static LinkedHashMap<LocalTime, RentalStatus> createTimeSlot(LocalTime startTime,
private static LinkedHashMap<LocalTime, TimeStatus> createTimeSlot(LocalTime startTime,
LocalTime endTime) {
LinkedHashMap<LocalTime, RentalStatus> timeSlot = new LinkedHashMap<>();
LinkedHashMap<LocalTime, TimeStatus> timeSlot = new LinkedHashMap<>();
while (startTime.isBefore(endTime)) {
timeSlot.put(startTime, RentalStatus.AVAILABLE);
timeSlot.put(startTime, TimeStatus.AVAILABLE);
startTime = startTime.plusMinutes(30);
}
return timeSlot;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
@RequiredArgsConstructor
public class FacilityReader {

private final FacilityJpaRepository facilityJpaRepository;
private final FacilityJpaRepository facilityJpaRepository;

public List<Facility> getAll() {
return facilityJpaRepository.findAll();
}
public List<Facility> getAll() {
return facilityJpaRepository.findAll();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
@RequiredArgsConstructor
public class FacilityRemover {

private final FacilityJpaRepository facilityJpaRepository;
private final FacilityJpaRepository facilityJpaRepository;

public void delete(Facility facility) {
facilityJpaRepository.delete(facility);
}
public void delete(Facility facility) {
facilityJpaRepository.delete(facility);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
@Component
public class FacilitySaver {

private final FacilityJpaRepository facilityJpaRepository;
private final FacilityJpaRepository facilityJpaRepository;

public Facility save(Facility facility) {
return facilityJpaRepository.save(facility);
}
public Facility save(Facility facility) {
return facilityJpaRepository.save(facility);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.example.rentalSystem.domain.facility.reposiotry;

import com.example.rentalSystem.domain.facility.entity.Facility;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;

public interface FacilityJpaRepository extends JpaRepository<Facility, Long> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.example.rentalSystem.domain.facility.reposiotry;

import com.example.rentalSystem.domain.facility.entity.Facility;
import com.example.rentalSystem.domain.facility.entity.TimeTable;
import com.example.rentalSystem.domain.facility.entity.timeTable.TimeTable;
import java.time.LocalDate;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.example.rentalSystem.domain.facility.dto.response.FacilityResponse;
import com.example.rentalSystem.domain.facility.dto.response.PresignUrlListResponse;
import com.example.rentalSystem.domain.facility.entity.Facility;
import com.example.rentalSystem.domain.facility.entity.TimeTable;
import com.example.rentalSystem.domain.facility.entity.timeTable.TimeTable;
import com.example.rentalSystem.domain.facility.implement.FacilityFinder;
import com.example.rentalSystem.domain.facility.implement.FacilityRemover;
import com.example.rentalSystem.domain.facility.implement.FacilitySaver;
Expand Down Expand Up @@ -35,6 +35,7 @@ public class FacilityService {

@Transactional
public PresignUrlListResponse create(CreateFacilityRequestDto createFacilityRequestDto) {

// 이미지 이름을 s3 url로 변환
List<String> imageUrlList =
createFacilityRequestDto
Expand All @@ -47,13 +48,11 @@ public PresignUrlListResponse create(CreateFacilityRequestDto createFacilityRequ
facilitySaver.save(facility);

// 시작시간과 끝시간을 이용한 타임 테이블 생성

TimeTable timeTable = TimeTable.toEntity(
facility,
LocalDate.now(),
createFacilityRequestDto.startTime(),
createFacilityRequestDto.endTime());

timeTableRepository.save(timeTable);

// pre signed url을 반환. 업로드용
Expand Down
Loading

0 comments on commit 5b6ead4

Please sign in to comment.