-
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.
Merge pull request #234 from bcgov/feature/schoolFunding
Added school funding codes
- Loading branch information
Showing
28 changed files
with
1,588 additions
and
26 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
113 changes: 113 additions & 0 deletions
113
...a/ca/bc/gov/educ/api/institute/controller/v1/IndependentSchoolFundingGroupController.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,113 @@ | ||
package ca.bc.gov.educ.api.institute.controller.v1; | ||
|
||
import ca.bc.gov.educ.api.institute.endpoint.v1.IndependentSchoolFundingGroupEndpoint; | ||
import ca.bc.gov.educ.api.institute.exception.EntityNotFoundException; | ||
import ca.bc.gov.educ.api.institute.exception.InvalidPayloadException; | ||
import ca.bc.gov.educ.api.institute.exception.errors.ApiError; | ||
import ca.bc.gov.educ.api.institute.mapper.v1.IndependentSchoolFundingGroupMapper; | ||
import ca.bc.gov.educ.api.institute.model.v1.IndependentSchoolFundingGroupEntity; | ||
import ca.bc.gov.educ.api.institute.model.v1.IndependentSchoolFundingGroupHistoryEntity; | ||
import ca.bc.gov.educ.api.institute.service.v1.IndependentSchoolFundingGroupService; | ||
import ca.bc.gov.educ.api.institute.struct.v1.IndependentSchoolFundingGroup; | ||
import ca.bc.gov.educ.api.institute.struct.v1.IndependentSchoolFundingGroupHistory; | ||
import ca.bc.gov.educ.api.institute.util.RequestUtil; | ||
import ca.bc.gov.educ.api.institute.util.ValidationUtil; | ||
import ca.bc.gov.educ.api.institute.validator.IndependentSchoolFundingGroupPayloadValidator; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import lombok.extern.slf4j.Slf4j; | ||
import lombok.val; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import org.springframework.validation.FieldError; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
import java.util.function.Supplier; | ||
|
||
import static org.springframework.http.HttpStatus.BAD_REQUEST; | ||
|
||
@RestController | ||
@Slf4j | ||
public class IndependentSchoolFundingGroupController implements IndependentSchoolFundingGroupEndpoint { | ||
|
||
private static final IndependentSchoolFundingGroupMapper independentSchoolFundingGroupMapper = IndependentSchoolFundingGroupMapper.mapper; | ||
private final IndependentSchoolFundingGroupPayloadValidator independentSchoolFundingGroupPayloadValidator; | ||
private final IndependentSchoolFundingGroupService independentSchoolFundingGroupService; | ||
|
||
@Autowired | ||
public IndependentSchoolFundingGroupController(IndependentSchoolFundingGroupPayloadValidator independentSchoolFundingGroupPayloadValidator, IndependentSchoolFundingGroupService independentSchoolFundingGroupService) { | ||
this.independentSchoolFundingGroupPayloadValidator = independentSchoolFundingGroupPayloadValidator; | ||
this.independentSchoolFundingGroupService = independentSchoolFundingGroupService; | ||
} | ||
|
||
private void validatePayload(Supplier<List<FieldError>> validator) { | ||
val validationResult = validator.get(); | ||
if (!validationResult.isEmpty()) { | ||
ApiError error = ApiError.builder().timestamp(LocalDateTime.now()).message("Payload contains invalid data.").status(BAD_REQUEST).build(); | ||
error.addValidationErrors(validationResult); | ||
throw new InvalidPayloadException(error); | ||
} | ||
} | ||
|
||
@Override | ||
public IndependentSchoolFundingGroup getIndependentSchoolFundingGroup(UUID schoolFundingGroupID) { | ||
Optional<IndependentSchoolFundingGroupEntity> independentSchoolFundingGroup = this.independentSchoolFundingGroupService.getIndependentSchoolFundingGroup(schoolFundingGroupID); | ||
|
||
if (independentSchoolFundingGroup.isPresent()) { | ||
return independentSchoolFundingGroupMapper.toStructure(independentSchoolFundingGroup.get()); | ||
} else { | ||
throw new EntityNotFoundException(); | ||
} | ||
} | ||
|
||
@Override | ||
public List<IndependentSchoolFundingGroup> getIndependentSchoolFundingGroups(UUID schoolID) { | ||
List<IndependentSchoolFundingGroupEntity> independentSchoolFundingGroups = this.independentSchoolFundingGroupService.getIndependentSchoolFundingGroups(schoolID); | ||
|
||
List<IndependentSchoolFundingGroup> independentSchoolFundingGroupList = new ArrayList<>(); | ||
for(IndependentSchoolFundingGroupEntity entity: independentSchoolFundingGroups){ | ||
independentSchoolFundingGroupList.add(independentSchoolFundingGroupMapper.toStructure(entity)); | ||
} | ||
|
||
return independentSchoolFundingGroupList; | ||
} | ||
|
||
@Override | ||
public List<IndependentSchoolFundingGroupHistory> getIndependentSchoolFundingGroupHistory(UUID schoolID) { | ||
List<IndependentSchoolFundingGroupHistoryEntity> independentSchoolFundingGroups = this.independentSchoolFundingGroupService.getIndependentSchoolFundingGroupHistory(schoolID); | ||
|
||
List<IndependentSchoolFundingGroupHistory> independentSchoolFundingGroupList = new ArrayList<>(); | ||
for(IndependentSchoolFundingGroupHistoryEntity entity: independentSchoolFundingGroups){ | ||
independentSchoolFundingGroupList.add(independentSchoolFundingGroupMapper.toStructure(entity)); | ||
} | ||
|
||
return independentSchoolFundingGroupList; | ||
} | ||
|
||
@Override | ||
public IndependentSchoolFundingGroup createIndependentSchoolFundingGroup(IndependentSchoolFundingGroup fundingGroup) throws JsonProcessingException { | ||
validatePayload(() -> this.independentSchoolFundingGroupPayloadValidator.validateCreatePayload(fundingGroup)); | ||
RequestUtil.setAuditColumnsForCreate(fundingGroup); | ||
|
||
return independentSchoolFundingGroupMapper.toStructure(independentSchoolFundingGroupService.createIndependentSchoolFundingGroup(fundingGroup)); | ||
} | ||
|
||
@Override | ||
public IndependentSchoolFundingGroup updateIndependentSchoolFundingGroup(UUID schoolFundingGroupID, IndependentSchoolFundingGroup independentSchoolFundingGroup) { | ||
ValidationUtil.validatePayload(() -> this.independentSchoolFundingGroupPayloadValidator.validatePayload(independentSchoolFundingGroup, false)); | ||
RequestUtil.setAuditColumnsForUpdate(independentSchoolFundingGroup); | ||
return independentSchoolFundingGroupMapper.toStructure(independentSchoolFundingGroupService.updateIndependentSchoolFundingGroup(independentSchoolFundingGroup)); | ||
} | ||
|
||
@Override | ||
@Transactional | ||
public ResponseEntity<Void> deleteIndependentSchoolFundingGroup(UUID schoolFundingGroupID) { | ||
this.independentSchoolFundingGroupService.deleteIndependentSchoolFundingGroup(schoolFundingGroupID); | ||
return ResponseEntity.noContent().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
73 changes: 73 additions & 0 deletions
73
.../java/ca/bc/gov/educ/api/institute/endpoint/v1/IndependentSchoolFundingGroupEndpoint.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,73 @@ | ||
package ca.bc.gov.educ.api.institute.endpoint.v1; | ||
|
||
import ca.bc.gov.educ.api.institute.constants.v1.URL; | ||
import ca.bc.gov.educ.api.institute.struct.v1.IndependentSchoolFundingGroup; | ||
import ca.bc.gov.educ.api.institute.struct.v1.IndependentSchoolFundingGroupHistory; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.security.access.prepost.PreAuthorize; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import org.springframework.validation.annotation.Validated; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
import static org.springframework.http.HttpStatus.CREATED; | ||
import static org.springframework.http.HttpStatus.NO_CONTENT; | ||
|
||
@RequestMapping(URL.BASE_URL_SCHOOL_FUNDING) | ||
public interface IndependentSchoolFundingGroupEndpoint { | ||
|
||
@GetMapping("/{schoolFundingGroupID}") | ||
@PreAuthorize("hasAuthority('SCOPE_READ_SCHOOL_FUNDING_GROUP')") | ||
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "404", description = "NOT FOUND")}) | ||
@Transactional(readOnly = true) | ||
@Tag(name = "IndependentSchoolFundingGroup Entity", description = "Endpoints for independent school group funding entity.") | ||
@Schema(name = "IndependentSchoolFundingGroup", implementation = IndependentSchoolFundingGroup.class) | ||
IndependentSchoolFundingGroup getIndependentSchoolFundingGroup(@PathVariable("schoolFundingGroupID") UUID schoolFundingGroupID); | ||
|
||
@GetMapping("/search/{schoolID}") | ||
@PreAuthorize("hasAuthority('SCOPE_READ_SCHOOL_FUNDING_GROUP')") | ||
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "404", description = "NOT FOUND")}) | ||
@Transactional(readOnly = true) | ||
@Tag(name = "IndependentSchoolFundingGroup Entity", description = "Endpoints for independent school group funding entity.") | ||
@Schema(name = "IndependentSchoolFundingGroup", implementation = IndependentSchoolFundingGroup.class) | ||
List<IndependentSchoolFundingGroup> getIndependentSchoolFundingGroups(@PathVariable("schoolID") UUID schoolID); | ||
|
||
@GetMapping("/search/{schoolID}/history") | ||
@PreAuthorize("hasAuthority('SCOPE_READ_SCHOOL_FUNDING_GROUP')") | ||
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "404", description = "NOT FOUND")}) | ||
@Transactional(readOnly = true) | ||
@Tag(name = "IndependentSchoolFundingGroupHistory Entity", description = "Endpoints for independent school group funding history entities.") | ||
@Schema(name = "IndependentSchoolFundingGroupHistory", implementation = IndependentSchoolFundingGroupHistory.class) | ||
List<IndependentSchoolFundingGroupHistory> getIndependentSchoolFundingGroupHistory(@PathVariable("schoolID") UUID schoolID); | ||
|
||
@PostMapping() | ||
@PreAuthorize("hasAuthority('SCOPE_WRITE_SCHOOL_FUNDING_GROUP')") | ||
@ApiResponses(value = {@ApiResponse(responseCode = "201", description = "CREATED"), @ApiResponse(responseCode = "400", description = "BAD REQUEST")}) | ||
@Tag(name = "IndependentSchoolFundingGroup Entity", description = "Endpoints for independent school group funding entity.") | ||
@Schema(name = "IndependentSchoolFundingGroup", implementation = IndependentSchoolFundingGroup.class) | ||
@ResponseStatus(CREATED) | ||
IndependentSchoolFundingGroup createIndependentSchoolFundingGroup(@Validated @RequestBody IndependentSchoolFundingGroup fundingGroup) throws JsonProcessingException; | ||
|
||
@PutMapping("/{schoolFundingGroupID}") | ||
@PreAuthorize("hasAuthority('SCOPE_WRITE_SCHOOL_FUNDING_GROUP')") | ||
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "400", description = "BAD REQUEST"), @ApiResponse(responseCode = "404", description = "NOT FOUND")}) | ||
@Transactional | ||
@Tag(name = "IndependentSchoolFundingGroup Entity", description = "Endpoints for independent school group funding entity.") | ||
@Schema(name = "IndependentSchoolFundingGroup", implementation = IndependentSchoolFundingGroup.class) | ||
IndependentSchoolFundingGroup updateIndependentSchoolFundingGroup(@PathVariable("schoolFundingGroupID") UUID schoolFundingGroupID, @Validated @RequestBody IndependentSchoolFundingGroup independentSchoolFundingGroup); | ||
|
||
@DeleteMapping("/{schoolFundingGroupID}") | ||
@PreAuthorize("hasAuthority('SCOPE_DELETE_SCHOOL_FUNDING_GROUP')") | ||
@ApiResponses(value = {@ApiResponse(responseCode = "204", description = "NO CONTENT"), @ApiResponse(responseCode = "404", description = "NOT FOUND")}) | ||
@Tag(name = "IndependentSchoolFundingGroup Entity", description = "Endpoints for independent school group funding entity.") | ||
@Schema(name = "IndependentSchoolFundingGroup", implementation = IndependentSchoolFundingGroup.class) | ||
@ResponseStatus(NO_CONTENT) | ||
ResponseEntity<Void> deleteIndependentSchoolFundingGroup(@PathVariable UUID schoolFundingGroupID); | ||
} |
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
24 changes: 24 additions & 0 deletions
24
...main/java/ca/bc/gov/educ/api/institute/mapper/v1/IndependentSchoolFundingGroupMapper.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,24 @@ | ||
package ca.bc.gov.educ.api.institute.mapper.v1; | ||
|
||
import ca.bc.gov.educ.api.institute.mapper.LocalDateTimeMapper; | ||
import ca.bc.gov.educ.api.institute.mapper.UUIDMapper; | ||
import ca.bc.gov.educ.api.institute.model.v1.IndependentSchoolFundingGroupEntity; | ||
import ca.bc.gov.educ.api.institute.model.v1.IndependentSchoolFundingGroupHistoryEntity; | ||
import ca.bc.gov.educ.api.institute.struct.v1.IndependentSchoolFundingGroup; | ||
import ca.bc.gov.educ.api.institute.struct.v1.IndependentSchoolFundingGroupHistory; | ||
import org.mapstruct.Mapper; | ||
import org.mapstruct.factory.Mappers; | ||
|
||
@Mapper(uses = {UUIDMapper.class, LocalDateTimeMapper.class}) | ||
@SuppressWarnings("squid:S1214") | ||
public interface IndependentSchoolFundingGroupMapper { | ||
|
||
IndependentSchoolFundingGroupMapper mapper = Mappers.getMapper(IndependentSchoolFundingGroupMapper.class); | ||
|
||
IndependentSchoolFundingGroupEntity toModel(IndependentSchoolFundingGroup structure); | ||
|
||
IndependentSchoolFundingGroup toStructure(IndependentSchoolFundingGroupEntity entity); | ||
IndependentSchoolFundingGroupHistoryEntity toModel(IndependentSchoolFundingGroupHistory structure); | ||
|
||
IndependentSchoolFundingGroupHistory toStructure(IndependentSchoolFundingGroupHistoryEntity entity); | ||
} |
61 changes: 61 additions & 0 deletions
61
.../main/java/ca/bc/gov/educ/api/institute/model/v1/IndependentSchoolFundingGroupEntity.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,61 @@ | ||
package ca.bc.gov.educ.api.institute.model.v1; | ||
|
||
import ca.bc.gov.educ.api.institute.util.UpperCase; | ||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import jakarta.persistence.*; | ||
import jakarta.validation.constraints.PastOrPresent; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import org.hibernate.annotations.DynamicUpdate; | ||
import org.hibernate.annotations.GenericGenerator; | ||
import org.hibernate.annotations.Parameter; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.UUID; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@DynamicUpdate | ||
@Entity | ||
@Builder | ||
@Table(name = "INDEPENDENT_SCHOOL_FUNDING_GROUP") | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public class IndependentSchoolFundingGroupEntity { | ||
|
||
@Id | ||
@GeneratedValue(generator = "UUID") | ||
@GenericGenerator(name = "UUID", strategy = "org.hibernate.id.UUIDGenerator", parameters = { | ||
@Parameter(name = "uuid_gen_strategy_class", value = "org.hibernate.id.uuid.CustomVersionOneStrategy")}) | ||
@Column(name = "SCHOOL_FUNDING_GROUP_ID", unique = true, updatable = false, columnDefinition = "BINARY(16)") | ||
private UUID schoolFundingGroupID; | ||
|
||
@Basic | ||
@Column(name = "SCHOOL_ID", columnDefinition = "BINARY(16)") | ||
private UUID schoolID; | ||
|
||
@Column(name = "SCHOOL_GRADE_CODE", nullable = false, length = 10) | ||
@UpperCase | ||
private String schoolGradeCode; | ||
|
||
@Column(name = "SCHOOL_FUNDING_GROUP_CODE", nullable = false, length = 10) | ||
@UpperCase | ||
private String schoolFundingGroupCode; | ||
|
||
@Column(name = "CREATE_USER", updatable = false , length = 32) | ||
private String createUser; | ||
|
||
@PastOrPresent | ||
@Column(name = "CREATE_DATE", updatable = false) | ||
private LocalDateTime createDate; | ||
|
||
@Column(name = "UPDATE_USER", length = 32) | ||
private String updateUser; | ||
|
||
@PastOrPresent | ||
@Column(name = "UPDATE_DATE") | ||
private LocalDateTime updateDate; | ||
|
||
} |
Oops, something went wrong.