-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
VKT(Backend&Frontend): Load all examiner details for OPH clerk
- Loading branch information
Showing
14 changed files
with
183 additions
and
27 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
backend/vkt/src/main/java/fi/oph/vkt/api/clerk/ClerkExaminerController.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,27 @@ | ||
package fi.oph.vkt.api.clerk; | ||
|
||
import fi.oph.vkt.api.dto.examiner.ExaminerDetailsDTO; | ||
import fi.oph.vkt.service.ClerkExaminerService; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import jakarta.annotation.Resource; | ||
import java.util.List; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping(value = "/api/v1/clerk/examiner", produces = MediaType.APPLICATION_JSON_VALUE) | ||
public class ClerkExaminerController { | ||
|
||
private static final String TAG_CLERK_EXAMINER = "Examiner API for OPH clerk users"; | ||
|
||
@Resource | ||
private ClerkExaminerService clerkExaminerService; | ||
|
||
@GetMapping | ||
@Operation(tags = TAG_CLERK_EXAMINER, summary = "List examiner details") | ||
public List<ExaminerDetailsDTO> listExaminers() { | ||
return clerkExaminerService.listExaminers(); | ||
} | ||
} |
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
29 changes: 29 additions & 0 deletions
29
backend/vkt/src/main/java/fi/oph/vkt/service/ClerkExaminerService.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,29 @@ | ||
package fi.oph.vkt.service; | ||
|
||
import fi.oph.vkt.api.dto.examiner.ExaminerDetailsDTO; | ||
import fi.oph.vkt.audit.AuditService; | ||
import fi.oph.vkt.repository.ExaminerRepository; | ||
import fi.oph.vkt.util.ExaminerUtil; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class ClerkExaminerService { | ||
|
||
private final ExaminerRepository examinerRepository; | ||
private final AuditService auditService; | ||
|
||
@Transactional(readOnly = true) | ||
public List<ExaminerDetailsDTO> listExaminers() { | ||
// TODO Audit log entry | ||
return examinerRepository | ||
.getAllByDeletedAtIsNull() | ||
.stream() | ||
.map(ExaminerUtil::toExaminerDetailsDTO) | ||
.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
30 changes: 30 additions & 0 deletions
30
backend/vkt/src/main/java/fi/oph/vkt/util/ExaminerUtil.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,30 @@ | ||
package fi.oph.vkt.util; | ||
|
||
import fi.oph.vkt.api.dto.MunicipalityDTO; | ||
import fi.oph.vkt.api.dto.examiner.ExaminerDetailsDTO; | ||
import fi.oph.vkt.model.Examiner; | ||
import fi.oph.vkt.model.Municipality; | ||
|
||
public class ExaminerUtil { | ||
|
||
public static MunicipalityDTO toMunicipalityDTO(final Municipality municipality) { | ||
return MunicipalityDTO.builder().code(municipality.getCode()).build(); | ||
} | ||
|
||
public static ExaminerDetailsDTO toExaminerDetailsDTO(final Examiner examiner) { | ||
return ExaminerDetailsDTO | ||
.builder() | ||
.id(examiner.getId()) | ||
.version(examiner.getVersion()) | ||
.oid(examiner.getOid()) | ||
.lastName(examiner.getLastName()) | ||
.firstName(examiner.getFirstName()) | ||
.email(examiner.getEmail()) | ||
.phoneNumber(examiner.getPhoneNumber()) | ||
.municipalities(examiner.getMunicipalities().stream().map(ExaminerUtil::toMunicipalityDTO).toList()) | ||
.isPublic(examiner.isPublic()) | ||
.examLanguageFinnish(examiner.isExamLanguageFinnish()) | ||
.examLanguageSwedish(examiner.isExamLanguageSwedish()) | ||
.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
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,8 @@ | ||
import { APIResponseStatus } from 'shared/enums'; | ||
|
||
import { ExaminerDetails } from 'interfaces/examinerDetails'; | ||
|
||
export interface ClerkListExaminerState { | ||
status: APIResponseStatus; | ||
examiners: Array<ExaminerDetails>; | ||
} |
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
31 changes: 31 additions & 0 deletions
31
frontend/packages/vkt/src/redux/reducers/clerkListExaminer.ts
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,31 @@ | ||
import { createSlice, PayloadAction } from '@reduxjs/toolkit'; | ||
import { APIResponseStatus } from 'shared/enums'; | ||
|
||
import { ClerkListExaminerState } from 'interfaces/clerkListExaminer'; | ||
import { ExaminerDetails } from 'interfaces/examinerDetails'; | ||
|
||
const initialState: ClerkListExaminerState = { | ||
status: APIResponseStatus.NotStarted, | ||
examiners: [], | ||
}; | ||
|
||
const clerkListExaminerSlice = createSlice({ | ||
name: 'clerkListExaminer', | ||
initialState, | ||
reducers: { | ||
acceptExaminers(state, action: PayloadAction<Array<ExaminerDetails>>) { | ||
state.status = APIResponseStatus.Success; | ||
state.examiners = action.payload; | ||
}, | ||
loadExaminers(state) { | ||
state.status = APIResponseStatus.InProgress; | ||
}, | ||
rejectExaminers(state) { | ||
state.status = APIResponseStatus.Error; | ||
}, | ||
}, | ||
}); | ||
|
||
export const { acceptExaminers, loadExaminers, rejectExaminers } = | ||
clerkListExaminerSlice.actions; | ||
export const clerkListExaminerReducer = clerkListExaminerSlice.reducer; |
31 changes: 31 additions & 0 deletions
31
frontend/packages/vkt/src/redux/sagas/clerkListExaminer.ts
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,31 @@ | ||
import { AxiosError, AxiosResponse } from 'axios'; | ||
import { call, put, takeLatest } from 'redux-saga/effects'; | ||
|
||
import axiosInstance from 'configs/axios'; | ||
import { APIEndpoints } from 'enums/api'; | ||
import { ExaminerDetails } from 'interfaces/examinerDetails'; | ||
import { setAPIError } from 'redux/reducers/APIError'; | ||
import { | ||
acceptExaminers, | ||
loadExaminers, | ||
rejectExaminers, | ||
} from 'redux/reducers/clerkListExaminer'; | ||
import { NotifierUtils } from 'utils/notifier'; | ||
|
||
function* loadExaminersSaga() { | ||
try { | ||
const response: AxiosResponse<Array<ExaminerDetails>> = yield call( | ||
axiosInstance.get, | ||
APIEndpoints.ClerkExaminer, | ||
); | ||
yield put(acceptExaminers(response.data)); | ||
} catch (error) { | ||
const errorMessage = NotifierUtils.getAPIErrorMessage(error as AxiosError); | ||
yield put(setAPIError(errorMessage)); | ||
yield put(rejectExaminers()); | ||
} | ||
} | ||
|
||
export function* watchListExaminers() { | ||
yield takeLatest(loadExaminers.type, loadExaminersSaga); | ||
} |
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
6 changes: 6 additions & 0 deletions
6
frontend/packages/vkt/src/redux/selectors/clerkListExaminer.ts
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 @@ | ||
import { RootState } from 'configs/redux'; | ||
import { ClerkListExaminerState } from 'interfaces/clerkListExaminer'; | ||
|
||
export const clerkListExaminerSelector = ( | ||
state: RootState, | ||
): ClerkListExaminerState => state.clerkListExaminer; |
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