Skip to content

Commit

Permalink
🔀 ✨ depoimentos-home endpoint
Browse files Browse the repository at this point in the history
Merge branch 'feat/testimonials'
  • Loading branch information
ecureuill committed Jul 27, 2023
2 parents 5a2c728 + 0f137ca commit 0b7c599
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
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()));
}
}
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();

}

0 comments on commit 0b7c599

Please sign in to comment.