diff --git a/src/main/java/com/app3/server/common/exception/enums/ErrorType.java b/src/main/java/com/app3/server/common/exception/enums/ErrorType.java index e2c3761..a000634 100644 --- a/src/main/java/com/app3/server/common/exception/enums/ErrorType.java +++ b/src/main/java/com/app3/server/common/exception/enums/ErrorType.java @@ -9,7 +9,7 @@ public enum ErrorType { USER_NOT_FOUND_EXCEPTION(HttpStatus.NOT_FOUND, "해당 유저을 찾을 수 없습니다."), REGION_NOT_FOUND_EXCEPTION(HttpStatus.NOT_FOUND, "지역 이미지를 찾을 수 없습니다"), - + DORMITORY_NOT_FOUND_EXCEPTION(HttpStatus.NOT_FOUND, "숙소 정보를 찾을 수 없습니다"), INTERNAL_SERVER_EXCEPTION(HttpStatus.INTERNAL_SERVER_ERROR, "서버 내부 오류입니다."); private final HttpStatus httpStatus; private final String message; diff --git a/src/main/java/com/app3/server/common/exception/enums/SuccessType.java b/src/main/java/com/app3/server/common/exception/enums/SuccessType.java index c3115bf..87f0ee7 100644 --- a/src/main/java/com/app3/server/common/exception/enums/SuccessType.java +++ b/src/main/java/com/app3/server/common/exception/enums/SuccessType.java @@ -9,7 +9,8 @@ public enum SuccessType { USER_SEARCH_SUCCESS(HttpStatus.OK, "유저 닉네임 조회에 성공하였습니다."), - REGION_SEARCH_SUCCESS(HttpStatus.OK, "지역 이미지 조회에 성공하였습니다.") + REGION_SEARCH_SUCCESS(HttpStatus.OK, "지역 이미지 조회에 성공하였습니다."), + DORMITORY_SEARCH_SUCCESS(HttpStatus.OK, "숙소 정보 조회에 성공하였습니다.") ; private final HttpStatus httpStatus; diff --git a/src/main/java/com/app3/server/dormitory/controller/DormitoryController.java b/src/main/java/com/app3/server/dormitory/controller/DormitoryController.java new file mode 100644 index 0000000..d310bd4 --- /dev/null +++ b/src/main/java/com/app3/server/dormitory/controller/DormitoryController.java @@ -0,0 +1,26 @@ +package com.app3.server.dormitory.controller; + +import com.app3.server.common.dto.ApiResponse; +import com.app3.server.common.exception.enums.SuccessType; +import com.app3.server.dormitory.controller.dto.response.DormitoryGetResponse; +import com.app3.server.dormitory.service.DomitoryService; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@RestController +@RequestMapping("/api/dormitory") +@RequiredArgsConstructor +public class DormitoryController { + private final DomitoryService domitoryService; + + @GetMapping + public ApiResponse> getDormitories() { + return ApiResponse.success(SuccessType.DORMITORY_SEARCH_SUCCESS, domitoryService.getDormitories()); + } + +} diff --git a/src/main/java/com/app3/server/dormitory/controller/dto/response/DormitoryGetResponse.java b/src/main/java/com/app3/server/dormitory/controller/dto/response/DormitoryGetResponse.java new file mode 100644 index 0000000..38f5d44 --- /dev/null +++ b/src/main/java/com/app3/server/dormitory/controller/dto/response/DormitoryGetResponse.java @@ -0,0 +1,21 @@ +package com.app3.server.dormitory.controller.dto.response; + +import com.app3.server.dormitory.domain.Dormitory; + +public record DormitoryGetResponse ( + String description, + Integer distance, + String travelDate, + Integer price, + Double scope +) { + public static DormitoryGetResponse of(Dormitory dormitory) { + return new DormitoryGetResponse( + dormitory.getDescription(), + dormitory.getDistance(), + dormitory.getTravelDate(), + dormitory.getPrice(), + dormitory.getScope() + ); + } +} diff --git a/src/main/java/com/app3/server/dormitory/controller/temp b/src/main/java/com/app3/server/dormitory/controller/temp deleted file mode 100644 index e69de29..0000000 diff --git a/src/main/java/com/app3/server/dormitory/domain/Dormitory.java b/src/main/java/com/app3/server/dormitory/domain/Dormitory.java new file mode 100644 index 0000000..ca470b2 --- /dev/null +++ b/src/main/java/com/app3/server/dormitory/domain/Dormitory.java @@ -0,0 +1,36 @@ +package com.app3.server.dormitory.domain; + +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; + +@Entity +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class Dormitory { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + private String imageUrl; + private String description; + private Integer distance; + private String travelDate; + private Integer price; + private Double scope; + @Builder + public Dormitory(String imageUrl, String description, Integer distance, String travelDate, Integer price, Double scope) { + this.imageUrl = imageUrl; + this.description = description; + this.distance = distance; + this.travelDate = travelDate; + this.price = price; + this.scope = scope; + } +} diff --git a/src/main/java/com/app3/server/dormitory/domain/temp b/src/main/java/com/app3/server/dormitory/domain/temp deleted file mode 100644 index e69de29..0000000 diff --git a/src/main/java/com/app3/server/dormitory/repository/DormitoryJpaRepository.java b/src/main/java/com/app3/server/dormitory/repository/DormitoryJpaRepository.java new file mode 100644 index 0000000..6b975aa --- /dev/null +++ b/src/main/java/com/app3/server/dormitory/repository/DormitoryJpaRepository.java @@ -0,0 +1,7 @@ +package com.app3.server.dormitory.repository; + +import com.app3.server.dormitory.domain.Dormitory; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface DormitoryJpaRepository extends JpaRepository { +} diff --git a/src/main/java/com/app3/server/dormitory/repository/temp b/src/main/java/com/app3/server/dormitory/repository/temp deleted file mode 100644 index e69de29..0000000 diff --git a/src/main/java/com/app3/server/dormitory/service/DomitoryService.java b/src/main/java/com/app3/server/dormitory/service/DomitoryService.java new file mode 100644 index 0000000..7147e9d --- /dev/null +++ b/src/main/java/com/app3/server/dormitory/service/DomitoryService.java @@ -0,0 +1,26 @@ +package com.app3.server.dormitory.service; + +import com.app3.server.dormitory.controller.dto.response.DormitoryGetResponse; +import com.app3.server.dormitory.domain.Dormitory; +import com.app3.server.dormitory.repository.DormitoryJpaRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; +import java.util.stream.Collectors; + +@Transactional +@Service +@RequiredArgsConstructor +public class DomitoryService { + private final DormitoryJpaRepository dormitoryJpaRepository; + + public List getDormitories() { + return dormitoryJpaRepository.findAll() + .stream() + .map(DormitoryGetResponse::of) + .collect(Collectors.toList()); + } +} diff --git a/src/main/java/com/app3/server/dormitory/service/temp b/src/main/java/com/app3/server/dormitory/service/temp deleted file mode 100644 index e69de29..0000000