TestController.java 987 Bytes
package com.esboot.bertsearch.controller;

import com.esboot.bertsearch.dto.Phone;
import com.esboot.bertsearch.repository.PhoneRepository;
import org.elasticsearch.search.aggregations.metrics.InternalHDRPercentiles;
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.RestController;

@RestController
@RequestMapping("/api")
public class TestController {

    private final PhoneRepository phoneRepository;

    public TestController(PhoneRepository phoneRepository) {
        this.phoneRepository = phoneRepository;
    }

    @GetMapping("/phones")
    public Iterable<Phone> findAllPhones() {
        return phoneRepository.findAll();
    }

    @GetMapping("/phones/{model}")
    public Iterable<Phone> findByModel(@PathVariable String model) {
        return phoneRepository.findByModel(model);
    }
}