SearchPlacesController.java

package com.soen390.backend.controller;

import com.soen390.backend.service.PlacesOfInterestService;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class SearchPlacesController {

    private final PlacesOfInterestService placesOfInterestService;

    public SearchPlacesController(PlacesOfInterestService placesOfInterestService) {
        this.placesOfInterestService = placesOfInterestService;
    }

    @GetMapping("/api/places/search")
    public ResponseEntity<String> searchPlaces(
            @RequestParam String query,
            @RequestParam double latitude,
            @RequestParam double longitude
    ) {
        if (query == null || query.trim().isEmpty()) {
            return ResponseEntity.badRequest()
                    .body("{\"error\":\"Query must not be empty\"}");
        }

        String rawJson = placesOfInterestService.searchPlacesByText(
                query, latitude, longitude
        );

        return ResponseEntity.ok()
                .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
                .body(rawJson);
    }
}