File tree Expand file tree Collapse file tree 3 files changed +52
-0
lines changed
src/main/java/dev/urner/volodb Expand file tree Collapse file tree 3 files changed +52
-0
lines changed Original file line number Diff line number Diff line change 1
1
package dev .urner .volodb .dao ;
2
2
3
+ import java .util .List ;
4
+
3
5
import org .springframework .data .repository .ListCrudRepository ;
4
6
import org .springframework .stereotype .Repository ;
5
7
8
10
@ Repository
9
11
public interface CountryDAO extends ListCrudRepository <Country , Integer > {
10
12
13
+ public List <Country > findAll ();
14
+
11
15
public Country findByLocalName (String localName );
12
16
13
17
public Country findByName (String name );
Original file line number Diff line number Diff line change
1
+ package dev .urner .volodb .rest ;
2
+
3
+ import java .util .List ;
4
+
5
+ import org .springframework .web .bind .annotation .RestController ;
6
+
7
+ import dev .urner .volodb .entity .Country ;
8
+ import dev .urner .volodb .exception .CountryNotFoundException ;
9
+ import dev .urner .volodb .service .CountryService ;
10
+ import lombok .RequiredArgsConstructor ;
11
+
12
+ import org .springframework .http .HttpStatus ;
13
+ import org .springframework .http .ResponseEntity ;
14
+ import org .springframework .web .bind .annotation .ExceptionHandler ;
15
+ import org .springframework .web .bind .annotation .GetMapping ;
16
+ import org .springframework .web .bind .annotation .RequestMapping ;
17
+
18
+ @ RestController
19
+ @ RequestMapping ("/countrys" )
20
+ @ RequiredArgsConstructor
21
+ public class CountryRestController {
22
+
23
+ private final CountryService countryService ;
24
+
25
+ @ GetMapping ()
26
+ public List <Country > getCountrys () {
27
+ return countryService .findAll ();
28
+ }
29
+
30
+ @ ExceptionHandler
31
+ public ResponseEntity <VolodbErrorResponse > handleException (CountryNotFoundException exc ) {
32
+ HttpStatus httpStatus = HttpStatus .NOT_FOUND ;
33
+
34
+ VolodbErrorResponse error = new VolodbErrorResponse (
35
+ httpStatus .value (),
36
+ exc .getMessage (),
37
+ System .currentTimeMillis ());
38
+
39
+ return new ResponseEntity <>(error , httpStatus );
40
+ }
41
+
42
+ }
Original file line number Diff line number Diff line change 1
1
package dev .urner .volodb .service ;
2
2
3
+ import java .util .List ;
4
+
3
5
import org .springframework .stereotype .Service ;
4
6
5
7
import dev .urner .volodb .dao .CountryDAO ;
@@ -13,6 +15,10 @@ public class CountryService {
13
15
14
16
private final CountryDAO countryDao ;
15
17
18
+ public List <Country > findAll () {
19
+ return countryDao .findAll ();
20
+ }
21
+
16
22
public Country findByName (String countryName ) {
17
23
return countryDao .findByLocalName (countryName );
18
24
}
You can’t perform that action at this time.
0 commit comments