Skip to content

Commit

Permalink
merge: pull request #27 from SOPT-all/feat/#26
Browse files Browse the repository at this point in the history
[FEAT/#26] 장소 검색 API 구현
  • Loading branch information
ckkim817 authored Jan 20, 2025
2 parents 4c5d5ab + 3e7cfab commit c0e3d6d
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.acon.server.spot.api.response.MenuResponse;
import com.acon.server.spot.api.response.MenuListResponse;
import com.acon.server.spot.api.response.SearchSpotListResponse;
import com.acon.server.spot.api.response.SpotDetailResponse;
import com.acon.server.spot.application.service.SpotService;
import jakarta.validation.constraints.Positive;
Expand All @@ -12,6 +13,7 @@
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
Expand Down Expand Up @@ -40,4 +42,13 @@ public ResponseEntity<List<MenuResponse>> getMenus(
spotService.fetchMenus(spotId)
);
}

@GetMapping("/spots/search")
public ResponseEntity<SearchSpotListResponse> searchSpot(
@RequestParam(value = "keyword", required = false) final String keyword
) {
return ResponseEntity.ok(
spotService.searchSpot(keyword)
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.acon.server.spot.api.response;

import java.util.List;

public record SearchSpotListResponse(
List<SearchSpotResponse> spotList
) {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.acon.server.spot.api.response;

import com.acon.server.spot.domain.enums.SpotType;
import lombok.Builder;

@Builder
public record SearchSpotResponse(
Long spotId,
String name,
String address,
SpotType spotType
) {

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
import com.acon.server.global.external.NaverMapsAdapter;
import com.acon.server.member.infra.repository.GuidedSpotRepository;
import com.acon.server.spot.api.response.MenuResponse;
import com.acon.server.spot.api.response.SearchSpotListResponse;
import com.acon.server.spot.api.response.SearchSpotResponse;
import com.acon.server.spot.infra.entity.MenuEntity;
import com.acon.server.spot.infra.entity.SpotEntity;
import com.acon.server.spot.api.response.SpotDetailResponse;
import com.acon.server.spot.application.mapper.SpotDtoMapper;
import com.acon.server.spot.application.mapper.SpotMapper;
Expand Down Expand Up @@ -160,4 +164,19 @@ public List<MenuResponse> fetchMenus(final Long spotId) {
.build())
.toList();
}

public SearchSpotListResponse searchSpot(final String keyword) {
List<SpotEntity> spotEntityList = spotRepository.findTop10ByNameContainsIgnoreCase(keyword);
List<SearchSpotResponse> spotList = spotEntityList.stream()
.map(spotEntity -> SearchSpotResponse.builder()
.spotId(spotEntity.getId())
.name(spotEntity.getName())
.address(spotEntity.getAddress())
.spotType(spotEntity.getSpotType())
.build())
.toList();

return new SearchSpotListResponse(spotList);

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

public interface SpotRepository extends JpaRepository<SpotEntity, Long> {

List<SpotEntity> findTop10ByNameContainsIgnoreCase(String keyword);

default SpotEntity findByIdOrThrow(Long id) {
return findById(id).orElseThrow(
() -> new BusinessException(ErrorType.NOT_FOUND_SPOT_ERROR)
Expand Down

0 comments on commit c0e3d6d

Please sign in to comment.