Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT] 숙소 정보 조회 기능 구현 #7

Merged
merged 1 commit into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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<List<DormitoryGetResponse>> getDormitories() {
return ApiResponse.success(SuccessType.DORMITORY_SEARCH_SUCCESS, domitoryService.getDormitories());
}

}
Original file line number Diff line number Diff line change
@@ -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()
);
}
}
Empty file.
36 changes: 36 additions & 0 deletions src/main/java/com/app3/server/dormitory/domain/Dormitory.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
Empty file.
Original file line number Diff line number Diff line change
@@ -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<Dormitory, Long> {
}
Empty file.
Original file line number Diff line number Diff line change
@@ -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<DormitoryGetResponse> getDormitories() {
return dormitoryJpaRepository.findAll()
.stream()
.map(DormitoryGetResponse::of)
.collect(Collectors.toList());
}
}
Empty file.