File tree Expand file tree Collapse file tree 3 files changed +52
-0
lines changed
src/main/java/com/getourguide/interview Expand file tree Collapse file tree 3 files changed +52
-0
lines changed Original file line number Diff line number Diff line change
1
+ package com .getourguide .interview .controller ;
2
+
3
+ import com .getourguide .interview .service .StatisticsService ;
4
+ import java .util .List ;
5
+ import lombok .RequiredArgsConstructor ;
6
+ import org .springframework .http .ResponseEntity ;
7
+ import org .springframework .stereotype .Controller ;
8
+ import org .springframework .web .bind .annotation .GetMapping ;
9
+
10
+ @ Controller
11
+ @ RequiredArgsConstructor
12
+ public class StatisticsController {
13
+ private final StatisticsService statisticsService ;
14
+
15
+ @ GetMapping ("/stats/suppliers" )
16
+ public ResponseEntity <List <Object []>> suppliersSearch () {
17
+ return ResponseEntity .ok (statisticsService .getSupplierStats ());
18
+ }
19
+ }
Original file line number Diff line number Diff line change
1
+ package com .getourguide .interview .repository ;
2
+
3
+ import com .getourguide .interview .entity .Supplier ;
4
+ import java .util .List ;
5
+ import org .springframework .data .jpa .repository .JpaRepository ;
6
+ import org .springframework .data .jpa .repository .Query ;
7
+ import org .springframework .stereotype .Repository ;
8
+
9
+ @ Repository
10
+ public interface StatisticsRepository extends JpaRepository <Supplier , Long > {
11
+ String SUPPLIER_STATS_QUERY = """
12
+ SELECT s.* FROM getyourguide.supplier s
13
+ """ ;
14
+
15
+ @ Query (value = SUPPLIER_STATS_QUERY , nativeQuery = true )
16
+ List <Object []> getSupplierStats ();
17
+ }
Original file line number Diff line number Diff line change
1
+ package com .getourguide .interview .service ;
2
+
3
+ import com .getourguide .interview .repository .StatisticsRepository ;
4
+ import java .util .List ;
5
+ import lombok .RequiredArgsConstructor ;
6
+ import org .springframework .stereotype .Service ;
7
+
8
+ @ Service
9
+ @ RequiredArgsConstructor
10
+ public class StatisticsService {
11
+ private final StatisticsRepository statisticsRepository ;
12
+
13
+ public List <Object []> getSupplierStats () {
14
+ return statisticsRepository .getSupplierStats ();
15
+ }
16
+ }
You can’t perform that action at this time.
0 commit comments