-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feat/testimonials'
- Loading branch information
Showing
2 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
src/main/java/ecureuill/milhasapi/controller/RandomTestimonialController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package ecureuill.milhasapi.controller; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import ecureuill.milhasapi.domain.testimonial.TestimonialDetailRecord; | ||
import ecureuill.milhasapi.domain.testimonial.TestimonialRepository; | ||
|
||
@RestController | ||
@RequestMapping("/depoimentos-home") | ||
public class RandomTestimonialController { | ||
|
||
@Autowired | ||
private TestimonialRepository repository; | ||
|
||
@GetMapping | ||
public ResponseEntity<List<TestimonialDetailRecord>> get() { | ||
var testimonials = repository.findThreeTestimonials(); | ||
return ResponseEntity.ok().body(testimonials.stream().map(TestimonialDetailRecord::new).collect(Collectors.toList())); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/ecureuill/milhasapi/domain/testimonial/TestimonialRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,17 @@ | ||
package ecureuill.milhasapi.domain.testimonial; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
|
||
public interface TestimonialRepository extends JpaRepository<Testimonial, Long>{ | ||
|
||
@Query(""" | ||
select t from Testimonial t | ||
order by rand() | ||
limit 3 | ||
""") | ||
List<Testimonial> findThreeTestimonials(); | ||
|
||
} |