-
Notifications
You must be signed in to change notification settings - Fork 2
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
13c32d5
commit 4bdd766
Showing
8 changed files
with
272 additions
and
17 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
backend/src/main/java/ca/bc/gov/app/dto/client/ContactTypeCodeDto.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,10 @@ | ||
package ca.bc.gov.app.dto.client; | ||
|
||
import java.time.LocalDate; | ||
|
||
public record ContactTypeCodeDto( | ||
String code, | ||
String description, | ||
LocalDate effectiveDate, | ||
LocalDate expiryDate) { | ||
} |
50 changes: 50 additions & 0 deletions
50
backend/src/main/java/ca/bc/gov/app/entity/client/ContactTypeCodeEntity.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,50 @@ | ||
package ca.bc.gov.app.entity.client; | ||
|
||
import ca.bc.gov.app.ApplicationConstant; | ||
import jakarta.validation.constraints.NotNull; | ||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import lombok.With; | ||
import org.springframework.data.annotation.Id; | ||
import org.springframework.data.relational.core.mapping.Column; | ||
import org.springframework.data.relational.core.mapping.Table; | ||
|
||
@Table(name = "contact_type_code", schema = ApplicationConstant.POSTGRES_ATTRIBUTE_SCHEMA) | ||
@Data | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@With | ||
public class ContactTypeCodeEntity { | ||
@Id | ||
@Column("contact_type_code") | ||
private String contactTypeCode; | ||
|
||
@NotNull | ||
@Column("description") | ||
private String description; | ||
|
||
@NotNull | ||
@Column("effective_date") | ||
private LocalDate effectiveAt; | ||
|
||
@NotNull | ||
@Column("expiry_date") | ||
private LocalDate expiredAt; | ||
|
||
@Column("create_timestamp") | ||
private LocalDateTime createdAt; | ||
|
||
@Column("update_timestamp") | ||
private LocalDateTime updatedAt; | ||
|
||
@Column("create_user") | ||
private String createdBy; | ||
|
||
@Column("update_user") | ||
private String updatedBy; | ||
} |
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
105 changes: 105 additions & 0 deletions
105
backend/src/main/java/ca/bc/gov/app/handlers/client/ContactTypeCodeHandler.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,105 @@ | ||
package ca.bc.gov.app.handlers.client; | ||
|
||
import static org.springdoc.core.fn.builders.apiresponse.Builder.responseBuilder; | ||
import static org.springdoc.core.fn.builders.arrayschema.Builder.arraySchemaBuilder; | ||
import static org.springdoc.core.fn.builders.content.Builder.contentBuilder; | ||
import static org.springdoc.core.fn.builders.parameter.Builder.parameterBuilder; | ||
import static org.springdoc.core.fn.builders.requestbody.Builder.requestBodyBuilder; | ||
import static org.springdoc.core.fn.builders.schema.Builder.schemaBuilder; | ||
|
||
import ca.bc.gov.app.dto.client.ContactTypeCodeDto; | ||
import ca.bc.gov.app.handlers.BaseHandler; | ||
import ca.bc.gov.app.service.client.ClientService; | ||
import ca.bc.gov.app.util.HandlerUtil; | ||
import io.swagger.v3.oas.annotations.enums.ParameterIn; | ||
import java.util.function.Consumer; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springdoc.core.fn.builders.operation.Builder; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.reactive.function.server.ServerRequest; | ||
import org.springframework.web.reactive.function.server.ServerResponse; | ||
import org.springframework.web.server.ResponseStatusException; | ||
import reactor.core.publisher.Mono; | ||
|
||
@Component | ||
@Slf4j | ||
@RequiredArgsConstructor | ||
public class ContactTypeCodeHandler implements BaseHandler { | ||
|
||
private final ClientService clientService; | ||
|
||
|
||
@Override | ||
public Mono<ServerResponse> handle(ServerRequest serverRequest) { | ||
return | ||
ServerResponse | ||
.ok() | ||
.body( | ||
clientService | ||
.listClientContactTypeCodes( | ||
serverRequest | ||
.queryParam("page") | ||
.map(Integer::parseInt) | ||
.orElse(0), | ||
serverRequest | ||
.queryParam("size") | ||
.map(Integer::parseInt) | ||
.orElse(5) | ||
), | ||
ContactTypeCodeHandler.class | ||
) | ||
.doOnError(ResponseStatusException.class, HandlerUtil.handleStatusResponse()) | ||
.doOnError(HandlerUtil.handleError()); | ||
} | ||
|
||
@Override | ||
public Consumer<Builder> documentation(String tag) { | ||
return ops -> ops | ||
.tag(tag) | ||
.description("List contact type codes") | ||
.beanClass(ContactTypeCodeHandler.class) | ||
.beanMethod("handle") | ||
.operationId("handle") | ||
.requestBody(requestBodyBuilder()) | ||
.parameter( | ||
parameterBuilder() | ||
.in(ParameterIn.QUERY) | ||
.name("page") | ||
.description(""" | ||
0 index page number, for example: | ||
0 for the first page, 4 for the fifth page. | ||
Defaults to 0 (first page)""") | ||
.allowEmptyValue(true) | ||
.schema(schemaBuilder().implementation(String.class)) | ||
.example("4") | ||
) | ||
.parameter( | ||
parameterBuilder() | ||
.in(ParameterIn.QUERY) | ||
.name("size") | ||
.description("Amount of entries per page,default to 5") | ||
.allowEmptyValue(true) | ||
.schema(schemaBuilder().implementation(String.class)) | ||
.example("5") | ||
) | ||
.response( | ||
responseBuilder() | ||
.responseCode("200") | ||
.description("OK - List a page of contact type codes") | ||
.content( | ||
contentBuilder() | ||
.array( | ||
arraySchemaBuilder() | ||
.schema( | ||
schemaBuilder() | ||
.name("ContactTypeCode") | ||
.implementation(ContactTypeCodeDto.class) | ||
) | ||
) | ||
.mediaType(MediaType.APPLICATION_JSON_VALUE) | ||
) | ||
); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
backend/src/main/java/ca/bc/gov/app/repository/client/ContactTypeCodeRepository.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,16 @@ | ||
package ca.bc.gov.app.repository.client; | ||
|
||
import ca.bc.gov.app.entity.client.ContactTypeCodeEntity; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.repository.reactive.ReactiveCrudRepository; | ||
import org.springframework.data.repository.reactive.ReactiveSortingRepository; | ||
import org.springframework.stereotype.Repository; | ||
import reactor.core.publisher.Flux; | ||
|
||
@Repository | ||
public interface ContactTypeCodeRepository | ||
extends ReactiveCrudRepository<ContactTypeCodeEntity, String>, | ||
ReactiveSortingRepository<ContactTypeCodeEntity, String> { | ||
|
||
Flux<ContactTypeCodeEntity> findBy(Pageable pageable); | ||
} |
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