parent
f2f306eba7
commit
4dc120bce8
@ -0,0 +1,20 @@
|
|||||||
|
package space.kklochko.spring_rest_example.config;
|
||||||
|
|
||||||
|
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
|
||||||
|
|
||||||
|
public class SpringWebInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
|
||||||
|
@Override
|
||||||
|
protected Class[] getServletConfigClasses() {
|
||||||
|
return new Class[] { WebConfig.class };
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String[] getServletMappings() {
|
||||||
|
return new String[] { "/" };
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Class[] getRootConfigClasses() {
|
||||||
|
return new Class[] {};
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
package space.kklochko.spring_rest_example.config;
|
||||||
|
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.http.converter.HttpMessageConverter;
|
||||||
|
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||||
|
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||||
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||||
|
import space.kklochko.spring_rest_example.models.Indicator;
|
||||||
|
|
||||||
|
@EnableWebMvc
|
||||||
|
@Configuration
|
||||||
|
@ComponentScan("space.kklochko")
|
||||||
|
public class WebConfig implements WebMvcConfigurer {
|
||||||
|
@Override
|
||||||
|
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
|
||||||
|
converters.add(new MappingJackson2HttpMessageConverter());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean("indicator")
|
||||||
|
public Indicator getIndicator() {
|
||||||
|
UUID id = UUID.fromString("becbafac-702c-11ee-9113-c0e4349366ab");
|
||||||
|
Timestamp timestamp = Timestamp.valueOf("2023-10-18 14:30:00");
|
||||||
|
Indicator indicator = new Indicator(id, "Blood2", "Fine2", timestamp);
|
||||||
|
return indicator;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,34 @@
|
|||||||
|
package space.kklochko.spring_rest_example.controllers;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import space.kklochko.spring_rest_example.models.Indicator;
|
||||||
|
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/v1/indicators")
|
||||||
|
public class IndicatorController {
|
||||||
|
@Autowired
|
||||||
|
Indicator indicator;
|
||||||
|
@GetMapping("/{indicatorId}")
|
||||||
|
@ResponseBody
|
||||||
|
public Indicator getIndicator(@PathVariable UUID indicatorId) {
|
||||||
|
return indicator;
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping
|
||||||
|
@ResponseBody
|
||||||
|
public List<Indicator> getIndicators() {
|
||||||
|
UUID id = UUID.fromString("becbafac-702c-11ee-9113-c0e4349366ab");
|
||||||
|
Timestamp timestamp = Timestamp.valueOf("2023-10-18 14:30:00");
|
||||||
|
Indicator indicator = new Indicator(id, "Blood2", "Fine2", timestamp);
|
||||||
|
|
||||||
|
List<Indicator> indicators = new ArrayList<>();
|
||||||
|
indicators.add(indicator);
|
||||||
|
return indicators;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1 @@
|
|||||||
|
|
Loading…
Reference in new issue