-
Notifications
You must be signed in to change notification settings - Fork 53.6k
Expand file tree
/
Copy pathTravelController.java
More file actions
33 lines (28 loc) · 1.08 KB
/
TravelController.java
File metadata and controls
33 lines (28 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package com.baeldung.springai;
import lombok.RequiredArgsConstructor;
import org.commonmark.parser.Parser;
import org.commonmark.renderer.html.HtmlRenderer;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/api/travel")
@RequiredArgsConstructor
public class TravelController {
private final Parser parser = Parser.builder().build();
private final HtmlRenderer renderer = HtmlRenderer.builder().build();
private final TravelService travelService;
@GetMapping(
value = "/tips",
produces = MediaType.TEXT_HTML_VALUE
)
public String getTips(
@RequestParam(defaultValue = "Paris", name = "destination")
String destination
) {
final var markdown = travelService.getTravelTip(destination);
return renderer.render(parser.parse(markdown));
}
}