-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProvinceController.java
executable file
·38 lines (29 loc) · 1.2 KB
/
ProvinceController.java
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
package com.cpe.backend.Members.controller;
import com.cpe.backend.Members.entity.Province;
import com.cpe.backend.Members.repository.ProvinceRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import java.util.Collection;
import java.util.Optional;
import java.util.stream.Collectors;
import org.springframework.web.bind.annotation.CrossOrigin;
@CrossOrigin(origins = "http://localhost:8080")
@RestController
public class ProvinceController {
@Autowired
private final ProvinceRepository provinceRepository;
public ProvinceController(ProvinceRepository provinceRepository) {
this.provinceRepository = provinceRepository;
}
@GetMapping("/province")
public Collection<Province> Province() {
return provinceRepository.findAll().stream().collect(Collectors.toList());
}
@GetMapping("/province/{id}")
public Optional<Province> Province(@PathVariable Long id) {
Optional<Province> province = provinceRepository.findById(id);
return province;
}
}