-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestController.java
More file actions
31 lines (26 loc) · 951 Bytes
/
TestController.java
File metadata and controls
31 lines (26 loc) · 951 Bytes
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
package ftn.security.minikms.controller;
import ftn.security.minikms.dto.TestDTO;
import ftn.security.minikms.entity.TestEntity;
import ftn.security.minikms.service.TestService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
@Slf4j
@RestController
@RequestMapping(value = "/api/v1/test")
public class TestController {
@Autowired
private TestService testService;
@GetMapping("/{id}")
public TestEntity getTest(@PathVariable Long id) {
return testService.getById(id);
}
@PostMapping("/add")
public TestEntity addTest(@RequestBody TestDTO testDTO){
TestEntity entity = new TestEntity();
entity.setName(testDTO.getName());
TestEntity savedEntity = testService.addTest(entity);
return ResponseEntity.ok(savedEntity).getBody();
}
}