-
Notifications
You must be signed in to change notification settings - Fork 7
feat: adding crud + csv for currency #275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Kammerlo
wants to merge
3
commits into
release/1.1.0
Choose a base branch
from
feat/LOB-1263-CSV-Upload-for-currencies
base: release/1.1.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,2 @@ | ||
Customer Code,Currency ID | ||
CHF,ISO_4217:CHF |
This file contains hidden or 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,2 @@ | ||
Customer Code,Rate,Parent Customer Code,Description,Active | ||
VAT9,0.1,,Vat Code123,True |
This file contains hidden or 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
23 changes: 23 additions & 0 deletions
23
...c/main/java/org/cardanofoundation/lob/app/organisation/domain/request/CurrencyUpdate.java
This file contains hidden or 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,23 @@ | ||
package org.cardanofoundation.lob.app.organisation.domain.request; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
import com.opencsv.bean.CsvBindByName; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
|
||
@Getter | ||
@Setter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class CurrencyUpdate { | ||
|
||
@Schema(example = "CHF") | ||
@CsvBindByName(column = "Customer Code", required = true) | ||
private String customerCode; | ||
@Schema(example = "ISO_4217:CHF") | ||
@CsvBindByName(column = "Currency ID", required = true) | ||
private String currencyId; | ||
} |
31 changes: 31 additions & 0 deletions
31
...on/src/main/java/org/cardanofoundation/lob/app/organisation/domain/view/CurrencyView.java
This file contains hidden or 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,31 @@ | ||
package org.cardanofoundation.lob.app.organisation.domain.view; | ||
|
||
import java.util.Optional; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
import org.zalando.problem.Problem; | ||
|
||
@Getter | ||
@Setter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class CurrencyView { | ||
|
||
private String customerCode; | ||
private String currencyId; | ||
|
||
private Optional<Problem> error; | ||
|
||
public static CurrencyView createFail(Problem error, String customerCode) { | ||
return new CurrencyView(customerCode, null, Optional.of(error)); | ||
} | ||
|
||
public static CurrencyView createSuccess(String customerCode, String currencyId) { | ||
return new CurrencyView(customerCode, currencyId, Optional.empty()); | ||
} | ||
|
||
} |
16 changes: 0 additions & 16 deletions
16
...java/org/cardanofoundation/lob/app/organisation/domain/view/OrganisationCurrencyView.java
This file was deleted.
Oops, something went wrong.
95 changes: 95 additions & 0 deletions
95
...c/main/java/org/cardanofoundation/lob/app/organisation/resource/CostCenterController.java
This file contains hidden or 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,95 @@ | ||
package org.cardanofoundation.lob.app.organisation.resource; | ||
|
||
import static org.springframework.http.HttpStatus.BAD_REQUEST; | ||
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; | ||
import static org.springframework.http.MediaType.MULTIPART_FORM_DATA_VALUE; | ||
|
||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
import jakarta.validation.Valid; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.security.access.prepost.PreAuthorize; | ||
import org.springframework.web.bind.annotation.CrossOrigin; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
import io.swagger.v3.oas.annotations.media.ArraySchema; | ||
import io.swagger.v3.oas.annotations.media.Content; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
|
||
import org.cardanofoundation.lob.app.organisation.domain.csv.CostCenterUpdate; | ||
import org.cardanofoundation.lob.app.organisation.domain.view.OrganisationCostCenterView; | ||
import org.cardanofoundation.lob.app.organisation.service.CostCenterService; | ||
|
||
@RestController | ||
@RequestMapping("/api") | ||
@Tag(name = "Organisation", description = "Organisation API") | ||
@CrossOrigin(origins = "http://localhost:3000") | ||
@RequiredArgsConstructor | ||
@ConditionalOnProperty(value = "lob.organisation.enabled", havingValue = "true", matchIfMissing = true) | ||
public class CostCenterController { | ||
|
||
private final CostCenterService costCenterService; | ||
|
||
@Operation(description = "Organisation cost center", responses = { | ||
@ApiResponse(content = | ||
{@Content(mediaType = "application/json", array = @ArraySchema(schema = @Schema(implementation = OrganisationCostCenterView.class)))} | ||
), | ||
}) | ||
@GetMapping(value = "/organisation/{orgId}/cost-center", produces = "application/json") | ||
public ResponseEntity<Set<OrganisationCostCenterView>> getAllCostCenters(@PathVariable("orgId") @Parameter(example = "75f95560c1d883ee7628993da5adf725a5d97a13929fd4f477be0faf5020ca94") String orgId) { | ||
return ResponseEntity.ok().body( | ||
costCenterService.getAllCostCenter(orgId).stream().map(OrganisationCostCenterView::fromEntity).collect(Collectors.toSet())); | ||
} | ||
|
||
@Operation(description = "Organisation cost center creation", responses = { | ||
@ApiResponse(content = | ||
{@Content(mediaType = "application/json", array = @ArraySchema(schema = @Schema(implementation = OrganisationCostCenterView.class)))} | ||
), | ||
}) | ||
@PostMapping(value = "/organisation/{orgId}/cost-center/insert", produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE) | ||
@PreAuthorize("hasRole(@securityConfig.getManagerRole()) or hasRole(@securityConfig.getAdminRole())") | ||
public ResponseEntity<OrganisationCostCenterView> insertCostCenters(@PathVariable("orgId") @Parameter(example = "75f95560c1d883ee7628993da5adf725a5d97a13929fd4f477be0faf5020ca94") String orgId, @Valid @RequestBody CostCenterUpdate costCenterUpdate) { | ||
return ResponseEntity.ok(costCenterService.insertCostCenter(orgId, costCenterUpdate)); | ||
} | ||
|
||
@Operation(description = "Organisation cost center update", responses = { | ||
@ApiResponse(content = | ||
{@Content(mediaType = "application/json", array = @ArraySchema(schema = @Schema(implementation = OrganisationCostCenterView.class)))} | ||
), | ||
}) | ||
@PostMapping(value = "/organisation/{orgId}/cost-center/update", produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE) | ||
@PreAuthorize("hasRole(@securityConfig.getManagerRole()) or hasRole(@securityConfig.getAdminRole())") | ||
public ResponseEntity<OrganisationCostCenterView> updateCostCenters(@PathVariable("orgId") @Parameter(example = "75f95560c1d883ee7628993da5adf725a5d97a13929fd4f477be0faf5020ca94") String orgId, @Valid @RequestBody CostCenterUpdate costCenterUpdate) { | ||
return ResponseEntity.ok(costCenterService.updateCostCenter(orgId, costCenterUpdate)); | ||
} | ||
|
||
@Operation(description = "Organisation cost center creation csv", responses = { | ||
@ApiResponse(content = | ||
{@Content(mediaType = "application/json", array = @ArraySchema(schema = @Schema(implementation = OrganisationCostCenterView.class)))} | ||
), | ||
}) | ||
@PostMapping(value = "/organisation/{orgId}/cost-center-csv", produces = APPLICATION_JSON_VALUE, consumes = MULTIPART_FORM_DATA_VALUE) | ||
@PreAuthorize("hasRole(@securityConfig.getManagerRole()) or hasRole(@securityConfig.getAdminRole())") | ||
public ResponseEntity<?> insertCostCentersCsv(@PathVariable("orgId") @Parameter(example = "75f95560c1d883ee7628993da5adf725a5d97a13929fd4f477be0faf5020ca94") String orgId, @RequestParam("file") MultipartFile file) { | ||
return costCenterService.createCostCenterFromCsv(orgId, file).fold( | ||
problem -> ResponseEntity.status(BAD_REQUEST).body(problem), | ||
ResponseEntity::ok | ||
); | ||
} | ||
} |
102 changes: 102 additions & 0 deletions
102
...src/main/java/org/cardanofoundation/lob/app/organisation/resource/CurrencyController.java
This file contains hidden or 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,102 @@ | ||
package org.cardanofoundation.lob.app.organisation.resource; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
import jakarta.validation.Valid; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.security.access.prepost.PreAuthorize; | ||
import org.springframework.web.bind.annotation.CrossOrigin; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
import io.swagger.v3.oas.annotations.media.ArraySchema; | ||
import io.swagger.v3.oas.annotations.media.Content; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
|
||
import org.cardanofoundation.lob.app.organisation.domain.request.CurrencyUpdate; | ||
import org.cardanofoundation.lob.app.organisation.domain.view.CurrencyView; | ||
import org.cardanofoundation.lob.app.organisation.service.CurrencyService; | ||
|
||
@RestController | ||
@RequestMapping("/api/organisation") | ||
@Tag(name = "Organisation", description = "Organisation API") | ||
@CrossOrigin(origins = "http://localhost:3000") | ||
@RequiredArgsConstructor | ||
@ConditionalOnProperty(value = "lob.organisation.enabled", havingValue = "true", matchIfMissing = true) | ||
public class CurrencyController { | ||
|
||
private final CurrencyService currencyService; | ||
|
||
@Operation(description = "Get all currencies", responses = { | ||
@ApiResponse(content = | ||
{@Content(mediaType = "application/json", array = @ArraySchema(schema = @Schema(implementation = CurrencyView.class)))} | ||
), | ||
}) | ||
@GetMapping(value = "/{orgId}/currencies", produces = "application/json") | ||
public ResponseEntity<List<CurrencyView>> getAllCurrencies(@PathVariable("orgId") @Parameter(example = "75f95560c1d883ee7628993da5adf725a5d97a13929fd4f477be0faf5020ca94") String orgId) { | ||
return ResponseEntity.ok().body(currencyService.getAllCurrencies(orgId)); | ||
} | ||
|
||
@Operation(description = "Get currency", responses = { | ||
@ApiResponse(content = | ||
{@Content(mediaType = "application/json", array = @ArraySchema(schema = @Schema(implementation = CurrencyView.class)))} | ||
), | ||
}) | ||
@GetMapping(value = "/{orgId}/currencies/{customerCode}", produces = "application/json") | ||
public ResponseEntity<CurrencyView> getCurrency(@PathVariable("orgId") @Parameter(example = "75f95560c1d883ee7628993da5adf725a5d97a13929fd4f477be0faf5020ca94") String orgId, @PathVariable("customerCode") @Parameter(example = "CHF") String customerCode) { | ||
return currencyService.getCurrency(orgId, customerCode) | ||
.map(ResponseEntity::ok) | ||
.orElseGet(() -> ResponseEntity.notFound().build()); | ||
} | ||
|
||
@Operation(description = "Currency Insert", responses = { | ||
@ApiResponse(content = | ||
{@Content(mediaType = "application/json", array = @ArraySchema(schema = @Schema(implementation = CurrencyView.class)))} | ||
), | ||
}) | ||
@PostMapping(value = "/{orgId}/currencies/insert", produces = "application/json") | ||
@PreAuthorize("hasRole(@securityConfig.getManagerRole()) or hasRole(@securityConfig.getAccountantRole()) or hasRole(@securityConfig.getAdminRole())") | ||
public ResponseEntity<CurrencyView> insertCurrency(@PathVariable("orgId") @Parameter(example = "75f95560c1d883ee7628993da5adf725a5d97a13929fd4f477be0faf5020ca94") String orgId, @Valid @RequestBody CurrencyUpdate currencyUpdate) { | ||
return ResponseEntity.ok().body(currencyService.insertCurrency(orgId, currencyUpdate)); | ||
} | ||
|
||
@Operation(description = "Currency Update", responses = { | ||
@ApiResponse(content = | ||
{@Content(mediaType = "application/json", array = @ArraySchema(schema = @Schema(implementation = CurrencyView.class)))} | ||
), | ||
}) | ||
@PostMapping(value = "/{orgId}/currencies/update", produces = "application/json") | ||
@PreAuthorize("hasRole(@securityConfig.getManagerRole()) or hasRole(@securityConfig.getAccountantRole()) or hasRole(@securityConfig.getAdminRole())") | ||
public ResponseEntity<CurrencyView> updateCurrency(@PathVariable("orgId") @Parameter(example = "75f95560c1d883ee7628993da5adf725a5d97a13929fd4f477be0faf5020ca94") String orgId, @Valid @RequestBody CurrencyUpdate currencyUpdate) { | ||
return ResponseEntity.ok().body(currencyService.updateCurrency(orgId, currencyUpdate)); | ||
} | ||
|
||
@Operation(description = "Currency Upload", responses = { | ||
@ApiResponse(content = | ||
{@Content(mediaType = "application/json", array = @ArraySchema(schema = @Schema(implementation = CurrencyView.class)))} | ||
), | ||
}) | ||
@PostMapping(value = "/{orgId}/currencies/upload", produces = "application/json") | ||
@PreAuthorize("hasRole(@securityConfig.getManagerRole()) or hasRole(@securityConfig.getAccountantRole()) or hasRole(@securityConfig.getAdminRole())") | ||
public ResponseEntity<?> insertCurrenciesCsv(@PathVariable("orgId") @Parameter(example = "75f95560c1d883ee7628993da5adf725a5d97a13929fd4f477be0faf5020ca94") String orgId, @RequestParam(value = "file") MultipartFile file) { | ||
return currencyService.insertViaCsv(orgId, file).fold( | ||
problem -> ResponseEntity.status(Objects.requireNonNull(problem.getStatus()).getStatusCode()).body(problem), | ||
ResponseEntity::ok | ||
); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename the endpoint as
currencies/insert-csv
to use consistente names on endpoints.