-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathPersonalInformationController.java
More file actions
49 lines (40 loc) · 1.64 KB
/
PersonalInformationController.java
File metadata and controls
49 lines (40 loc) · 1.64 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package com.codejam.demo.controller;
import com.codejam.demo.model.PersonalInformation;
import com.codejam.demo.repository.PersonalInformationRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Optional;
@RestController
@RequiredArgsConstructor
@RequestMapping(path = "demo")
public class PersonalInformationController {
@Autowired
private PersonalInformationRepository personalInformationRepository;
@GetMapping("/information/all")
public List<PersonalInformation> getAllInformation() {
return personalInformationRepository.findAll();
}
@GetMapping("/information/{id}")
public Optional<PersonalInformation> getInformation(@PathVariable("id") Integer id) {
return personalInformationRepository.findById(id);
}
@PostMapping("/information/save")
public PersonalInformation savePersonalInformation(@RequestBody PersonalInformation personalInformation) {
return personalInformationRepository.save(personalInformation);
}
@PostMapping("/information/update")
public PersonalInformation updatePersonalInformation(@RequestBody PersonalInformation personalInformation) {
return personalInformationRepository.save(personalInformation);
}
@GetMapping("/information/{id}/delete")
public String deletePersonalInformation(@PathVariable("id") Integer id) {
try {
personalInformationRepository.deleteById(id);
} catch (Exception e) {
return "Failed";
}
return "Successful";
}
}