Skip to content

Commit

Permalink
Merge pull request #30 from SOPT-SOPHY/feat/#29-get-place-filter-city
Browse files Browse the repository at this point in the history
feat: 지역으로 공간리스트 조회 구현
  • Loading branch information
onpyeong committed Jul 10, 2023
2 parents b8577f8 + 19fbf3d commit 3022ce1
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 5 deletions.
19 changes: 16 additions & 3 deletions src/main/java/org/sophy/sophy/InitDb.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package org.sophy.sophy;

import lombok.RequiredArgsConstructor;
import org.sophy.sophy.domain.Author;
import org.sophy.sophy.domain.Authority;
import org.sophy.sophy.domain.Member;
import org.sophy.sophy.domain.*;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
Expand Down Expand Up @@ -65,6 +63,21 @@ public void dbInit() {
author.setBookTalkCount(3);
author.setBookCount(3);
em.persist(author);

Place place = Place.builder()
.name("장소")
.city(City.UIJEONGBU_SI)
.address("의정부시 무슨동 뭐시기")
.maximum(30)
.build();
Place place2 = Place.builder()
.name("장소")
.city(City.GANEUNG_DONG)
.address("의정부시 가능동")
.maximum(10)
.build();
em.persist(place);
em.persist(place2);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package org.sophy.sophy.common.advice;

import com.fasterxml.jackson.databind.exc.InvalidFormatException;
import io.jsonwebtoken.ExpiredJwtException;
import io.lettuce.core.RedisCommandExecutionException;
import org.sophy.sophy.common.dto.ApiResponseDto;
import org.sophy.sophy.exception.ErrorStatus;
import org.sophy.sophy.exception.model.SophyException;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.sophy.sophy.exception.model.SophyException;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
Expand All @@ -35,6 +36,12 @@ protected ApiResponseDto handleExpiredRefreshTokenException(final ExpiredJwtExce
return ApiResponseDto.error(ErrorStatus.REFRESH_TOKEN_TIME_EXPIRED_EXCEPTION);
}

@ResponseStatus(HttpStatus.NOT_FOUND)
@ExceptionHandler(InvalidFormatException.class)
protected ApiResponseDto handleInvalidFormatException(final InvalidFormatException e) {
return ApiResponseDto.error(ErrorStatus.NOT_FOUND_CITY_EXCEPTION);
}

/**
* Sopt custom error
*/
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/org/sophy/sophy/controller/PlaceController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.sophy.sophy.controller;

import lombok.RequiredArgsConstructor;
import org.sophy.sophy.common.dto.ApiResponseDto;
import org.sophy.sophy.controller.dto.request.PlaceRequestDto;
import org.sophy.sophy.controller.dto.response.PlaceResponseDto;
import org.sophy.sophy.exception.SuccessStatus;
import org.sophy.sophy.service.PlaceService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/place")
public class PlaceController {
private final PlaceService placeService;

@GetMapping
public ApiResponseDto<List<PlaceResponseDto>> getPlacesByCity(@RequestBody PlaceRequestDto placeRequestDto) {
return ApiResponseDto.success(SuccessStatus.GET_PLACES_BY_CITY_SUCCESS, placeService.getPlacesByCity(placeRequestDto));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.sophy.sophy.controller.dto.request;

import lombok.Getter;
import org.sophy.sophy.domain.City;

@Getter
public class PlaceRequestDto {
private City city;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.sophy.sophy.controller.dto.response;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.sophy.sophy.domain.Place;

@Getter
@AllArgsConstructor
public class PlaceResponseDto {
private Long placeId;
private String placeImage;
private String name;
private String address;
private Integer maximum;

public static PlaceResponseDto of(Place place) {
return new PlaceResponseDto(
place.getId(),
place.getPlaceImage(),
place.getName(),
place.getAddress(),
place.getMaximum());
}
}
1 change: 1 addition & 0 deletions src/main/java/org/sophy/sophy/exception/ErrorStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public enum ErrorStatus {
NOT_FOUND_USER_EXCEPTION(HttpStatus.NOT_FOUND, "존재하지 않는 유저입니다"),
NOT_FOUND_SAVE_IMAGE_EXCEPTION(HttpStatus.NOT_FOUND, "이미지 저장에 실패했습니다"),
NOT_FOUND_IMAGE_EXCEPTION(HttpStatus.NOT_FOUND, "이미지 이름을 찾을 수 없습니다"),
NOT_FOUND_CITY_EXCEPTION(HttpStatus.NOT_FOUND, "존재하지 않는 지역입니다"),

/**
* 409 CONFLICT
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/sophy/sophy/exception/SuccessStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public enum SuccessStatus {
GET_MYINFO_SUCCESS(HttpStatus.OK, "내 정보를 성공적으로 불러왔습니다."),
PATCH_MYINFO_SUCCESS(HttpStatus.OK, "내 정보를 성공적으로 수정했습니다."),
POST_ADDITIONALINFO_SUCCESS(HttpStatus.OK, "내 정보를 성공적으로 추가했습니다."),
GET_PLACES_BY_CITY_SUCCESS(HttpStatus.OK, "지역으로 공간 리스트를 성공적으로 불러왔습니다"),
TEST_SUCCESS(HttpStatus.OK, "Test :: OK"),
/*
* 201 created
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/org/sophy/sophy/infrastructure/PlaceRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.sophy.sophy.infrastructure;

import org.sophy.sophy.domain.City;
import org.sophy.sophy.domain.Place;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface PlaceRepository extends JpaRepository<Place, Long> {
List<Place> findAllByCity(City city);

List<Place> findAll();
}
30 changes: 30 additions & 0 deletions src/main/java/org/sophy/sophy/service/PlaceService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.sophy.sophy.service;

import lombok.RequiredArgsConstructor;
import org.sophy.sophy.controller.dto.request.PlaceRequestDto;
import org.sophy.sophy.controller.dto.response.PlaceResponseDto;
import org.sophy.sophy.domain.City;
import org.sophy.sophy.infrastructure.PlaceRepository;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
public class PlaceService {
private final PlaceRepository placeRepository;

public List<PlaceResponseDto> getPlacesByCity(PlaceRequestDto placeRequestDto) {
City city = placeRequestDto.getCity();
//의정부 시이면 전체 조회
if (city == City.UIJEONGBU_SI) {
return placeRepository.findAll().stream()
.map(PlaceResponseDto::of)
.collect(Collectors.toList());
}
return placeRepository.findAllByCity(city).stream()
.map(PlaceResponseDto::of)
.collect(Collectors.toList());
}
}

0 comments on commit 3022ce1

Please sign in to comment.