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/#26] 장소 검색 API 구현 #27

Merged
merged 4 commits into from
Jan 20, 2025
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 @@ -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
Loading