forked from RAF-SI-2021/Racunovodstvo-Back
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue RAF-SI-2021#28: Ruta za glavnu knjigu (RAF-SI-2021#67)
* odradjena ruta za glavnu knjigu * vraceno ime user tabele na default vrednost * Izbrisan dupli import i ispravljena greska u sonaru * refaktorisan search i prebacen convert u servis * obrisani nepotrebni fajlovi * greske iz sonara i male ispravke * dodat sort i page-ing * vraceno ime user tabele na default * ispravka za sonar
- Loading branch information
Showing
9 changed files
with
198 additions
and
3 deletions.
There are no files selected for viewing
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
46 changes: 46 additions & 0 deletions
46
src/main/java/rs/raf/demo/controllers/GlavnaKnjigaController.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,46 @@ | ||
package rs.raf.demo.controllers; | ||
|
||
import io.swagger.v3.oas.annotations.security.SecurityRequirement; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.jpa.domain.Specification; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
import rs.raf.demo.model.Konto; | ||
import rs.raf.demo.services.impl.KontoService; | ||
import rs.raf.demo.utils.ApiUtil; | ||
import rs.raf.demo.utils.SearchUtil; | ||
|
||
import javax.validation.constraints.Max; | ||
import javax.validation.constraints.Min; | ||
|
||
|
||
@CrossOrigin | ||
@RestController | ||
@SecurityRequirement(name = "bearerAuth") | ||
@RequestMapping("/api/glavna-knjiga") | ||
public class GlavnaKnjigaController { | ||
|
||
private final KontoService kontoService; | ||
private final SearchUtil<Konto> searchUtil; | ||
|
||
public GlavnaKnjigaController(KontoService kontoService) { | ||
this.kontoService = kontoService; | ||
this.searchUtil = new SearchUtil<>(); | ||
} | ||
|
||
@GetMapping(value = "/{kontnaGrupa}", | ||
produces = MediaType.APPLICATION_JSON_VALUE) | ||
public ResponseEntity<?> getPreduzeceById( | ||
@PathVariable("kontnaGrupa") String kontnaGrupa, | ||
@RequestParam(name = "search", required = false, defaultValue = "") String search, | ||
@RequestParam(defaultValue = ApiUtil.DEFAULT_PAGE) @Min(ApiUtil.MIN_PAGE) Integer page, | ||
@RequestParam(defaultValue = ApiUtil.DEFAULT_SIZE) @Min(ApiUtil.MIN_SIZE) @Max(ApiUtil.MAX_SIZE) Integer size, | ||
@RequestParam(defaultValue = "kontoId") String[] sort | ||
) { | ||
Pageable pageSort = ApiUtil.resolveSortingAndPagination(page, size, sort); | ||
if (search.length() > 0) search += ","; | ||
Specification<Konto> spec = this.searchUtil.getSpec(search + "kontnaGrupa:" + kontnaGrupa + ","); | ||
return ResponseEntity.ok(this.kontoService.findAllGlavnaKnjigaResponse(spec, pageSort)); | ||
} | ||
} |
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 rs.raf.demo.converter; | ||
|
||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.PageImpl; | ||
import org.springframework.stereotype.Component; | ||
import rs.raf.demo.model.Konto; | ||
import rs.raf.demo.responses.GlavnaKnjigaResponse; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Component | ||
public class KontoConverter { | ||
|
||
public Page<GlavnaKnjigaResponse> convert(List<Konto> kontoList) { | ||
return new PageImpl<>(kontoList.stream().map( | ||
konto -> new GlavnaKnjigaResponse( | ||
konto.getKnjizenje().getKnjizenjeId(), | ||
konto.getKnjizenje().getDatumKnjizenja(), | ||
konto.getPotrazuje(), | ||
konto.getDuguje(), | ||
konto.getDuguje() - konto.getPotrazuje(), | ||
konto.getKontnaGrupa().getNazivKonta(), | ||
konto.getKontnaGrupa().getBrojKonta()) | ||
).collect(Collectors.toList())); | ||
} | ||
} |
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
11 changes: 11 additions & 0 deletions
11
src/main/java/rs/raf/demo/relations/KontnaGrupaRelations.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,11 @@ | ||
package rs.raf.demo.relations; | ||
|
||
import javax.persistence.criteria.CriteriaBuilder; | ||
import javax.persistence.criteria.Root; | ||
|
||
public class KontnaGrupaRelations<T> extends ForeignKeyRelations<T> { | ||
public KontnaGrupaRelations(Root<T> root, CriteriaBuilder builder, String key, String val) { | ||
super(root, builder, key, val); | ||
idExpression = root.get(key).get("brojKonta").as(Long.class); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/rs/raf/demo/repositories/KontoRepository.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,23 @@ | ||
package rs.raf.demo.repositories; | ||
|
||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.jpa.domain.Specification; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
import rs.raf.demo.model.Konto; | ||
|
||
import java.util.List; | ||
|
||
@Repository | ||
public interface KontoRepository extends JpaRepository<Konto, Long> { | ||
|
||
public List<Konto> findAll(); | ||
|
||
List<Konto> findKontoByKontnaGrupaBrojKonta(String kontnaGrupaId); | ||
|
||
List<Konto> findAll(Specification<Konto> spec); | ||
|
||
Page<Konto> findAll(Specification<Konto> spec, Pageable pageSort); | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/rs/raf/demo/responses/GlavnaKnjigaResponse.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,18 @@ | ||
package rs.raf.demo.responses; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
|
||
import java.util.Date; | ||
|
||
@Data | ||
@AllArgsConstructor | ||
public class GlavnaKnjigaResponse { | ||
Long brojNaloga; | ||
Date datum; | ||
Double potrazuje; | ||
Double duguje; | ||
Double saldo; | ||
String nazivKonta; | ||
String konto; | ||
} |
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