-
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.
feat: [SRTP-81] setup controller and model generation (#20)
- Loading branch information
1 parent
ecf5ed8
commit 9f7cd25
Showing
32 changed files
with
570 additions
and
73 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
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
17 changes: 17 additions & 0 deletions
17
src/main/java/it/gov/pagopa/rtp/activator/configuration/ActivationPropertiesConfig.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,17 @@ | ||
package it.gov.pagopa.rtp.activator.configuration; | ||
|
||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@ConfigurationProperties(prefix = "activation") | ||
@Getter | ||
@Setter | ||
public class ActivationPropertiesConfig{ | ||
private String baseUrl; | ||
|
||
public ActivationPropertiesConfig(String baseUrl){ | ||
this.baseUrl = baseUrl; | ||
} | ||
} |
35 changes: 28 additions & 7 deletions
35
src/main/java/it/gov/pagopa/rtp/activator/controller/ActivationAPIControllerImpl.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,32 +1,53 @@ | ||
package it.gov.pagopa.rtp.activator.controller; | ||
|
||
import it.gov.pagopa.rtp.activator.controller.generated.CreateApi; | ||
import it.gov.pagopa.rtp.activator.model.generated.ActivationReqDto; | ||
import java.util.UUID; | ||
|
||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.security.access.prepost.PreAuthorize; | ||
import org.springframework.validation.annotation.Validated; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.server.ServerWebExchange; | ||
|
||
import it.gov.pagopa.rtp.activator.configuration.ActivationPropertiesConfig; | ||
import it.gov.pagopa.rtp.activator.controller.generated.CreateApi; | ||
import it.gov.pagopa.rtp.activator.domain.errors.PayerAlreadyExists; | ||
import it.gov.pagopa.rtp.activator.model.generated.ActivationReqDto; | ||
import it.gov.pagopa.rtp.activator.service.ActivationPayerService; | ||
import reactor.core.publisher.Mono; | ||
|
||
import org.springframework.security.access.prepost.PreAuthorize; | ||
|
||
import java.net.URI; | ||
import java.util.UUID; | ||
|
||
import static it.gov.pagopa.rtp.activator.utils.Authorizations.verifySubjectRequest; | ||
|
||
@RestController | ||
@Validated | ||
public class ActivationAPIControllerImpl implements CreateApi { | ||
|
||
private final ActivationPayerService activationPayerService; | ||
|
||
private final ActivationPropertiesConfig activationPropertiesConfig; | ||
|
||
public ActivationAPIControllerImpl(ActivationPayerService activationPayerService, | ||
ActivationPropertiesConfig activationPropertiesConfig) { | ||
this.activationPayerService = activationPayerService; | ||
this.activationPropertiesConfig = activationPropertiesConfig; | ||
} | ||
|
||
@Override | ||
@PreAuthorize("hasRole('write_rtp_activations')") | ||
public Mono<ResponseEntity<Void>> activate( | ||
UUID requestId, | ||
String version, | ||
Mono<ActivationReqDto> activationReqDto, | ||
ServerWebExchange exchange | ||
) { | ||
ServerWebExchange exchange) { | ||
|
||
return verifySubjectRequest(activationReqDto, it -> it.getPayer().getRtpSpId()) | ||
.map(request -> ResponseEntity.created(URI.create("http://localhost")).build()); | ||
.flatMap(t -> activationPayerService.activatePayer(t.getPayer().getRtpSpId(), | ||
t.getPayer().getFiscalCode())) | ||
.<ResponseEntity<Void>>map(payer -> ResponseEntity | ||
.created(URI.create(activationPropertiesConfig.getBaseUrl() + payer.payerID().toString())) | ||
.build()) | ||
.onErrorReturn(PayerAlreadyExists.class, ResponseEntity.status(409).build()); | ||
} | ||
} |
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,6 @@ | ||
package it.gov.pagopa.rtp.activator.domain; | ||
|
||
import java.time.Instant; | ||
|
||
public record Payer(PayerID payerID, String rtpSpId, String fiscalCode, Instant effectiveActivationDate) { | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/it/gov/pagopa/rtp/activator/domain/PayerID.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,21 @@ | ||
package it.gov.pagopa.rtp.activator.domain; | ||
|
||
import java.util.UUID; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public class PayerID { | ||
|
||
private final UUID id; | ||
|
||
public PayerID(UUID uuid) { | ||
this.id = uuid; | ||
} | ||
|
||
public static PayerID createNew() { | ||
UUID uuid = UUID.randomUUID(); | ||
return new PayerID(uuid); | ||
} | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/it/gov/pagopa/rtp/activator/domain/PayerRepository.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,13 @@ | ||
package it.gov.pagopa.rtp.activator.domain; | ||
|
||
|
||
import reactor.core.publisher.Mono; | ||
|
||
public interface PayerRepository { | ||
|
||
// Used to check if a specific payer is already registered. | ||
Mono<Payer> findByFiscalCode(String fiscalCode); | ||
|
||
Mono<Payer> save(Payer payer); | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/it/gov/pagopa/rtp/activator/domain/errors/PayerAlreadyExists.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,5 @@ | ||
package it.gov.pagopa.rtp.activator.domain.errors; | ||
|
||
public class PayerAlreadyExists extends Throwable{ | ||
// You can insert here payer info. | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/it/gov/pagopa/rtp/activator/repository/ActivationDB.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,13 @@ | ||
package it.gov.pagopa.rtp.activator.repository; | ||
|
||
|
||
|
||
import org.springframework.data.mongodb.repository.ReactiveMongoRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import reactor.core.publisher.Mono; | ||
|
||
@Repository | ||
public interface ActivationDB extends ReactiveMongoRepository<ActivationEntity, String> { | ||
Mono<ActivationEntity> findByFiscalCode(String fiscalCode); | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/it/gov/pagopa/rtp/activator/repository/ActivationDBRepository.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,33 @@ | ||
package it.gov.pagopa.rtp.activator.repository; | ||
|
||
|
||
import org.springframework.stereotype.Repository; | ||
|
||
import it.gov.pagopa.rtp.activator.domain.Payer; | ||
import it.gov.pagopa.rtp.activator.domain.PayerRepository; | ||
import reactor.core.publisher.Mono; | ||
|
||
@Repository | ||
public class ActivationDBRepository implements PayerRepository { | ||
|
||
private final ActivationDB activationDB; | ||
private final ActivationMapper activationMapper; | ||
|
||
public ActivationDBRepository(ActivationDB activationDB, | ||
ActivationMapper activationMapper) { | ||
this.activationDB = activationDB; | ||
this.activationMapper = activationMapper; | ||
} | ||
|
||
@Override | ||
public Mono<Payer> findByFiscalCode(String fiscalCode) { | ||
return activationDB.findByFiscalCode(fiscalCode) | ||
.map(activationMapper::toDomain); | ||
} | ||
|
||
@Override | ||
public Mono<Payer> save(Payer payer) { | ||
return activationDB.save(activationMapper.toDbEntity(payer)).map(activationMapper::toDomain); | ||
} | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/it/gov/pagopa/rtp/activator/repository/ActivationEntity.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 it.gov.pagopa.rtp.activator.repository; | ||
|
||
import java.time.Instant; | ||
|
||
import org.springframework.data.annotation.Id; | ||
import org.springframework.data.mongodb.core.mapping.Document; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@Builder | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Document("activations") | ||
public class ActivationEntity { | ||
@Id | ||
private String id; | ||
private String rtpSpId; | ||
private Instant effectiveActivationDate; | ||
|
||
private String fiscalCode; | ||
} |
Oops, something went wrong.