Skip to content

Commit

Permalink
feat : 장소 키워드 검색 API 개발 (#34)
Browse files Browse the repository at this point in the history
* fix:소셜 로그인 수정

* fix:소셜 로그인 로직

* fix:소셜로그인 jwt filter수정

* fix:transaction 짜잘짜잘

* feat:검색 API개발

* fix:코멘트 맞춰 수정
  • Loading branch information
JjungminLee authored Aug 27, 2023
1 parent fcc2554 commit a5f4741
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

import java.util.List;

import com.onna.onnaback.domain.place.adapter.in.web.response.PlaceSearchDto;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import com.onna.onnaback.domain.place.adapter.in.web.response.PlaceReloadDto;
import com.onna.onnaback.domain.place.application.port.in.PlaceUseCase;
Expand Down Expand Up @@ -43,4 +41,10 @@ public ResponseEntity<List<PlaceReloadDto>> reload(
southwestLatitude, northeastLatitude)
);
}

@Operation(description = "장소 키워드 검색 API")
@GetMapping("/search/{value}")
public ResponseEntity<List<PlaceSearchDto>> searchPlace(@PathVariable("value")String value){
return ResponseEntity.ok().body(this.placeUseCase.searchPlace(value));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.onna.onnaback.domain.place.adapter.in.web.response;

import com.onna.onnaback.domain.place.domain.PlaceType;
import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
public class PlaceSearchDto {

private Long placeId;

private String name;

private String detailAddress;

private PlaceType placeType;

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

import javax.persistence.criteria.Join;
import javax.persistence.criteria.Predicate;

import com.onna.onnaback.domain.place.adapter.in.web.response.PlaceSearchDto;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Repository;

Expand Down Expand Up @@ -77,6 +79,18 @@ public Optional<Place> getById(Long placeId) {
return placeRepository.findById(placeId);
}

@Override
public List<PlaceSearchDto> searchPlaceList(String value) {
return placeRepository.findByNameContaining(value).stream().map(
place -> PlaceSearchDto.builder()
.name(place.getName())
.detailAddress(place.getDetailAddress())
.placeId(place.getPlaceId())
.placeType(place.getPlaceType())
.build()
).collect(Collectors.toList());
}

private Specification<Place> hasSparkType(SparkType sparkType) {
return (root, query, criteriaBuilder) -> {
List<Predicate> predicates = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.onna.onnaback.domain.place.adapter.out.persistence;

import java.util.List;
import java.util.Optional;

import org.springframework.data.jpa.repository.JpaRepository;
Expand All @@ -14,4 +15,7 @@ public interface PlaceRepository extends JpaRepository<Place, Long>, JpaSpecific

@Query("select p from Place p where placeId = :placeId")
Place findByPlaceId(@Param("placeId") Long placeId);

List<Place> findByNameContaining(String name);

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.List;

import com.onna.onnaback.domain.place.adapter.in.web.response.PlaceReloadDto;
import com.onna.onnaback.domain.place.adapter.in.web.response.PlaceSearchDto;
import com.onna.onnaback.domain.place.domain.Place;
import com.onna.onnaback.domain.place.domain.PlaceType;
import com.onna.onnaback.domain.spark.domain.DurationHour;
Expand All @@ -16,4 +17,7 @@ List<PlaceReloadDto> reload(
);

Place getById(Long placeId);

List<PlaceSearchDto> searchPlace(String value);

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.Optional;

import com.onna.onnaback.domain.place.adapter.in.web.response.PlaceReloadDto;
import com.onna.onnaback.domain.place.adapter.in.web.response.PlaceSearchDto;
import com.onna.onnaback.domain.place.domain.Place;
import com.onna.onnaback.domain.place.domain.PlaceType;
import com.onna.onnaback.domain.spark.domain.DurationHour;
Expand All @@ -18,4 +19,7 @@ List<PlaceReloadDto> getMarkers(
);

Optional<Place> getById(Long placeId);

List<PlaceSearchDto> searchPlaceList(String value);

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.List;

import com.onna.onnaback.domain.place.adapter.in.web.response.PlaceSearchDto;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand Down Expand Up @@ -40,4 +41,10 @@ public List<PlaceReloadDto> reload(
public Place getById(Long placeId) {
return loadPlacePort.getById(placeId).orElseThrow();
}

@Override
public List<PlaceSearchDto> searchPlace(String value) {
return loadPlacePort.searchPlaceList(value);
}

}

0 comments on commit a5f4741

Please sign in to comment.