Skip to content

Commit 0b7c599

Browse files
author
ecureuill
committed
🔀 ✨ depoimentos-home endpoint
Merge branch 'feat/testimonials'
2 parents 5a2c728 + 0f137ca commit 0b7c599

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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 numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
package ecureuill.milhasapi.domain.testimonial;
22

3+
import java.util.List;
4+
35
import org.springframework.data.jpa.repository.JpaRepository;
6+
import org.springframework.data.jpa.repository.Query;
47

58
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();
616

717
}

0 commit comments

Comments
 (0)