Commit 0b7c599 ecureuill
committed
File tree 2 files changed +37
-0
lines changed
src/main/java/ecureuill/milhasapi
2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change
1
+ package ecureuill .milhasapi .controller ;
2
+
3
+ import java .util .List ;
4
+ import java .util .stream .Collectors ;
5
+
6
+ import org .springframework .beans .factory .annotation .Autowired ;
7
+ import org .springframework .http .ResponseEntity ;
8
+ import org .springframework .web .bind .annotation .GetMapping ;
9
+ import org .springframework .web .bind .annotation .RequestMapping ;
10
+ import org .springframework .web .bind .annotation .RestController ;
11
+
12
+ import ecureuill .milhasapi .domain .testimonial .TestimonialDetailRecord ;
13
+ import ecureuill .milhasapi .domain .testimonial .TestimonialRepository ;
14
+
15
+ @ RestController
16
+ @ RequestMapping ("/depoimentos-home" )
17
+ public class RandomTestimonialController {
18
+
19
+ @ Autowired
20
+ private TestimonialRepository repository ;
21
+
22
+ @ GetMapping
23
+ public ResponseEntity <List <TestimonialDetailRecord >> get () {
24
+ var testimonials = repository .findThreeTestimonials ();
25
+ return ResponseEntity .ok ().body (testimonials .stream ().map (TestimonialDetailRecord ::new ).collect (Collectors .toList ()));
26
+ }
27
+ }
Original file line number Diff line number Diff line change 1
1
package ecureuill .milhasapi .domain .testimonial ;
2
2
3
+ import java .util .List ;
4
+
3
5
import org .springframework .data .jpa .repository .JpaRepository ;
6
+ import org .springframework .data .jpa .repository .Query ;
4
7
5
8
public interface TestimonialRepository extends JpaRepository <Testimonial , Long >{
9
+
10
+ @ Query ("""
11
+ select t from Testimonial t
12
+ order by rand()
13
+ limit 3
14
+ """ )
15
+ List <Testimonial > findThreeTestimonials ();
6
16
7
17
}
You can’t perform that action at this time.
0 commit comments