-
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.
- Loading branch information
1 parent
bdd3a6d
commit d1a2613
Showing
8 changed files
with
79 additions
and
2 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
src/main/java/br/com/carteira/controller/RelatoriosController.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,25 @@ | ||
package br.com.carteira.controller; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import br.com.carteira.dto.ItemCarteiraDTO; | ||
import br.com.carteira.service.RelatorioService; | ||
|
||
@RestController | ||
@RequestMapping("/relatorios") | ||
public class RelatoriosController { | ||
|
||
@Autowired | ||
private RelatorioService service; | ||
|
||
@GetMapping("/carteira") | ||
public List<ItemCarteiraDTO> relatorioCarteiraDeInvestimentos() | ||
{ | ||
return service.relatorioCarteiraDeInvestimentos(); | ||
} | ||
} |
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,13 @@ | ||
package br.com.carteira.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public class ItemCarteiraDTO { | ||
|
||
private String ticker; | ||
private Long quantidade; | ||
private Double percentual; | ||
} |
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
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
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
12 changes: 12 additions & 0 deletions
12
src/main/java/br/com/carteira/repository/TransacaoRepository.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,9 +1,21 @@ | ||
package br.com.carteira.repository; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
|
||
import br.com.carteira.dto.ItemCarteiraDTO; | ||
import br.com.carteira.model.Transacao; | ||
|
||
public interface TransacaoRepository extends JpaRepository<Transacao, Integer> { | ||
|
||
@Query("SELECT new br.com.carteira.dto.ItemCarteiraDTO(" | ||
+ "t.ticker, " | ||
+ "sum(t.quantidade), " | ||
+ "sum(t.quantidade) * 1.0 / (SELECT sum(t2.quantidade) FROM Transacao t2) *1.0) " | ||
+ "from Transacao t " | ||
+ "GROUP BY t.ticker") | ||
List<ItemCarteiraDTO> relatorioCarteiraDeInvestimentos(); | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/br/com/carteira/service/RelatorioService.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,22 @@ | ||
package br.com.carteira.service; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
import br.com.carteira.dto.ItemCarteiraDTO; | ||
import br.com.carteira.repository.TransacaoRepository; | ||
|
||
@Service | ||
public class RelatorioService { | ||
|
||
@Autowired | ||
private TransacaoRepository repository; | ||
|
||
public List<ItemCarteiraDTO> relatorioCarteiraDeInvestimentos() | ||
{ | ||
return repository.relatorioCarteiraDeInvestimentos(); | ||
} | ||
|
||
} |
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