File tree Expand file tree Collapse file tree 4 files changed +53
-2
lines changed
src/main/java/com/getourguide/interview Expand file tree Collapse file tree 4 files changed +53
-2
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 []>> supplierStats () {
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 11package com .getourguide .interview .service ;
22
3- import com .getourguide .interview .controller .SupplierController ;
43import com .getourguide .interview .dto .ActivityDto ;
54import com .getourguide .interview .entity .Activity ;
65import com .getourguide .interview .repository .ActivityRepository ;
1413@ AllArgsConstructor
1514public class ActivityService {
1615 private final ActivityRepository activityRepository ;
17- private final SupplierController supplierController ;
16+
1817 public List <ActivityDto > getActivities () {
1918 List <Activity > activities = activityRepository .findAll ();
2019 List <ActivityDto > result = new ArrayList <>();
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