diff --git a/src/main/java/com/example/demo/controller/HelloController.java b/src/main/java/com/example/demo/controller/HelloController.java new file mode 100644 index 0000000..54f430c --- /dev/null +++ b/src/main/java/com/example/demo/controller/HelloController.java @@ -0,0 +1,29 @@ +package com.example.demo.controller; + +import com.example.demo.service.HelloService; +import org.springframework.http.ResponseEntity; +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/hello") +public class HelloController { + + private final HelloService helloService; + + public HelloController(HelloService helloService) { + this.helloService = helloService; + } + + @GetMapping + public ResponseEntity greet() { + return ResponseEntity.ok(helloService.getGreeting()); + } + + @GetMapping("/{name}") + public ResponseEntity greetWithName(@PathVariable String name) { + return ResponseEntity.ok(helloService.getGreetingFor(name)); + } +}