Skip to content

Commit

Permalink
VKT(Frontend & Backend): Examiner contact request listing
Browse files Browse the repository at this point in the history
  • Loading branch information
jrkkp committed Nov 11, 2024
1 parent c4418df commit 30306a4
Show file tree
Hide file tree
Showing 13 changed files with 158 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package fi.oph.vkt.api.dto.examiner;

import jakarta.validation.constraints.NotEmpty;
import java.util.List;
import lombok.Builder;
import lombok.NonNull;

@Builder
public record ExaminerContactRequestDTO(
@NonNull Long id,
@NonNull String lastName,
@NonNull String firstName
) {}
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ public record ExaminerDetailsDTO(
@NonNull Boolean examLanguageSwedish,
@NonNull Boolean isPublic,
@NonNull @NotEmpty List<MunicipalityDTO> municipalities,
@NonNull List<ExaminerExamEventDTO> examEvents
@NonNull List<ExaminerExamEventDTO> examEvents,
@NonNull List<ExaminerContactRequestDTO> contactRequests
) {}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
import fi.oph.vkt.api.dto.examiner.ExaminerExamEventDTO;
import fi.oph.vkt.service.ExaminerExamEventService;
import io.swagger.v3.oas.annotations.Operation;
import java.util.List;

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.PathVariable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import fi.oph.vkt.model.Enrollment;
import fi.oph.vkt.model.EnrollmentAppointment;
import fi.oph.vkt.model.ExamEvent;
import fi.oph.vkt.model.Examiner;
import fi.oph.vkt.model.Person;
import fi.oph.vkt.model.type.EnrollmentAppointmentStatus;
import fi.oph.vkt.model.type.EnrollmentStatus;
import java.util.List;
import java.util.Optional;
Expand All @@ -14,4 +16,8 @@
@Repository
public interface EnrollmentAppointmentRepository extends BaseRepository<EnrollmentAppointment> {
Optional<EnrollmentAppointment> findByIdAndAuthHash(final long id, final String paymentLinkHash);
List<EnrollmentAppointment> findByExaminerAndStatus(
final Examiner examiner,
final EnrollmentAppointmentStatus status
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@
import org.springframework.stereotype.Repository;

@Repository
public interface ExaminerExamEventRepository extends BaseRepository<ExaminerExamEvent> {
}
public interface ExaminerExamEventRepository extends BaseRepository<ExaminerExamEvent> {}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public List<ExaminerDetailsDTO> listExaminers() {
return examinerRepository
.getAllByDeletedAtIsNull()
.stream()
.map(e -> ExaminerUtil.toExaminerDetailsDTO(e, baseUrlAPI))
.map(e -> ExaminerUtil.toExaminerDetailsDTO(e, List.of(), baseUrlAPI))
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
import fi.oph.vkt.api.dto.examiner.ExaminerDetailsInitDTO;
import fi.oph.vkt.api.dto.examiner.ExaminerDetailsUpsertDTO;
import fi.oph.vkt.audit.AuditService;
import fi.oph.vkt.model.EnrollmentAppointment;
import fi.oph.vkt.model.Examiner;
import fi.oph.vkt.model.type.EnrollmentAppointmentStatus;
import fi.oph.vkt.repository.EnrollmentAppointmentRepository;
import fi.oph.vkt.repository.ExaminerRepository;
import fi.oph.vkt.service.onr.OnrService;
import fi.oph.vkt.service.onr.PersonalData;
Expand All @@ -25,6 +28,7 @@
public class ExaminerDetailsService {

private final ExaminerRepository examinerRepository;
private final EnrollmentAppointmentRepository enrollmentAppointmentRepository;
private final MunicipalityService municipalityService;
private final OnrService onrService;
private final AuditService auditService;
Expand Down Expand Up @@ -86,19 +90,23 @@ public ExaminerDetailsDTO upsertExaminer(final String oid, ExaminerDetailsUpsert
examinerRepository.saveAndFlush(examiner);
final String baseUrlAPI = environment.getRequiredProperty("app.base-url.api");

return ExaminerUtil.toExaminerDetailsDTO(examiner, baseUrlAPI);
return ExaminerUtil.toExaminerDetailsDTO(examiner, List.of(), baseUrlAPI);
}

@Transactional(readOnly = true)
public ExaminerDetailsDTO getExaminer(final String oid) {
// TODO Audit log entry
Examiner examiner = examinerRepository.getByOid(oid);
final Examiner examiner = examinerRepository.getByOid(oid);
if (examiner == null) {
throw new APIException(APIExceptionType.EXAMINER_NOT_FOUND);
}
final String baseUrlAPI = environment.getRequiredProperty("app.base-url.api");
final List<EnrollmentAppointment> enrollmentAppointments = enrollmentAppointmentRepository.findByExaminerAndStatus(
examiner,
EnrollmentAppointmentStatus.CONTACT_CREATED
);

return ExaminerUtil.toExaminerDetailsDTO(examiner, baseUrlAPI);
return ExaminerUtil.toExaminerDetailsDTO(examiner, enrollmentAppointments, baseUrlAPI);
}

@Transactional
Expand Down
19 changes: 18 additions & 1 deletion backend/vkt/src/main/java/fi/oph/vkt/util/ExaminerUtil.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
package fi.oph.vkt.util;

import fi.oph.vkt.api.dto.MunicipalityDTO;
import fi.oph.vkt.api.dto.examiner.ExaminerContactRequestDTO;
import fi.oph.vkt.api.dto.examiner.ExaminerDetailsDTO;
import fi.oph.vkt.api.dto.examiner.ExaminerExamEventDTO;
import fi.oph.vkt.model.EnrollmentAppointment;
import fi.oph.vkt.model.Examiner;
import fi.oph.vkt.model.ExaminerExamEvent;
import fi.oph.vkt.model.Municipality;
import java.util.List;

public class ExaminerUtil {

public static MunicipalityDTO toMunicipalityDTO(final Municipality municipality) {
return MunicipalityDTO.builder().code(municipality.getCode()).build();
}

public static ExaminerContactRequestDTO toContactRequestDTO(final EnrollmentAppointment enrollmentAppointment) {
return ExaminerContactRequestDTO
.builder()
.id(enrollmentAppointment.getId())
.firstName(enrollmentAppointment.getFirstName())
.lastName(enrollmentAppointment.getLastName())
.build();
}

public static ExaminerExamEventDTO toExaminerExamEventDTO(
final ExaminerExamEvent examinerExamEvent,
final String baseUrlAPI
Expand All @@ -38,7 +50,11 @@ public static ExaminerExamEventDTO toExaminerExamEventDTO(
.build();
}

public static ExaminerDetailsDTO toExaminerDetailsDTO(final Examiner examiner, final String baseUrlAPI) {
public static ExaminerDetailsDTO toExaminerDetailsDTO(
final Examiner examiner,
final List<EnrollmentAppointment> enrollmentAppointments,
final String baseUrlAPI
) {
return ExaminerDetailsDTO
.builder()
.id(examiner.getId())
Expand All @@ -53,6 +69,7 @@ public static ExaminerDetailsDTO toExaminerDetailsDTO(final Examiner examiner, f
.examLanguageFinnish(examiner.isExamLanguageFinnish())
.examLanguageSwedish(examiner.isExamLanguageSwedish())
.examEvents(examiner.getExamEvents().stream().map(e -> toExaminerExamEventDTO(e, baseUrlAPI)).toList())
.contactRequests(enrollmentAppointments.stream().map(ExaminerUtil::toContactRequestDTO).toList())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@
}
}

.margin-bottom-xxl {
&#{&} {
margin-bottom: map.get($spacing, 'xxl');
}
}

.margin-top-lg {
&#{&} {
margin-top: map.get($spacing, 'lg');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import ChevronRightIcon from '@mui/icons-material/ChevronRight';
import { TableCell, TableHead, TableRow } from '@mui/material';
import { CustomButtonLink, CustomTable, Text } from 'shared/components';
import { Color, Variant } from 'shared/enums';

import { useAppSelector } from 'configs/redux';
import { AppRoutes } from 'enums/app';
import { ContactRequest } from 'interfaces/examinerDetails';
import { examinerDetailsSelector } from 'redux/selectors/examinerDetails';

const ExaminerExamEventListingHeader = () => {
return (
<TableHead className="heading-text">
<TableRow>
<TableCell>Etunimi</TableCell>
<TableCell>Sukunimi</TableCell>
<TableCell>Toiminnot</TableCell>
</TableRow>
</TableHead>
);
};

const ExaminerContactRequestListingRow = ({
contactRequest,
}: {
contactRequest: ContactRequest;
}) => {
return (
<TableRow>
<TableCell>
<Text>{contactRequest.firstName}</Text>
</TableCell>
<TableCell>
<Text>{contactRequest.lastName}</Text>
</TableCell>
<TableCell>
<CustomButtonLink
sx={{ padding: 0 }}
variant={Variant.Text}
color={Color.Secondary}
endIcon={<ChevronRightIcon />}
to={AppRoutes.ClerkEnrollmentContactRequestPage.replace(
/:enrollmentContactRequestId/,
contactRequest.id.toString(),
)}
>
Katso tiedot
</CustomButtonLink>
</TableCell>
</TableRow>
);
};

const getRowDetails = (contactRequest: ContactRequest) => {
return <ExaminerContactRequestListingRow contactRequest={contactRequest} />;
};

const ExaminerContactRequestsTable = ({
contactRequests,
}: {
contactRequests: Array<ContactRequest>;
}) => {
return (
<CustomTable
className="table-layout-auto"
data={contactRequests}
getRowDetails={getRowDetails}
header={<ExaminerExamEventListingHeader />}
/>
);
};

export const ExaminerContactRequestListing = () => {
const { examiner } = useAppSelector(examinerDetailsSelector);

return (
examiner?.contactRequests &&
examiner?.contactRequests?.length > 0 && (
<ExaminerContactRequestsTable
contactRequests={examiner.contactRequests}
/>
)
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export const ExaminerExamEventListing = () => {
};

return (
<div className="examiner-homepage__exam-events rows gapped-xl">
<div className="examiner-homepage__exam-events rows gapped-xl margin-top-xxl">
<div className="columns">
<H2 className="grow">{t('heading')}</H2>
<div className="flex-end">
Expand Down
7 changes: 7 additions & 0 deletions frontend/packages/vkt/src/interfaces/examinerDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ export interface ExaminerDetailsState {
};
}

export interface ContactRequest extends WithId {
id: number;
firstName: string;
lastName: string;
}

export interface ExaminerDetails extends WithId {
oid: string;
lastName: string;
Expand All @@ -30,6 +36,7 @@ export interface ExaminerDetails extends WithId {
municipalities: Array<MunicipalityCode>;
isPublic: boolean;
examEvents: Array<ExaminerExamEvent>;
contactRequests: Array<ContactRequest>;
}

export interface ExaminerDetailsResponse
Expand Down
11 changes: 7 additions & 4 deletions frontend/packages/vkt/src/pages/examiner/ExaminerHomePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { CustomButtonLink, H1, H2, Text } from 'shared/components';
import { APIResponseStatus, Color, Variant } from 'shared/enums';
import { DateUtils } from 'shared/utils';

import { ExaminerContactRequestListing } from 'components/examinerExamEvent/listing/ExaminerContactRequestListing';
import { ExaminerExamEventListing } from 'components/examinerExamEvent/listing/ExaminerExamEventListing';
import {
useCommonTranslation,
Expand Down Expand Up @@ -32,7 +33,7 @@ const PublicInformation = () => {
const { examEvents } = examiner;

return (
<div className="examiner-homepage__public-information rows gapped-xl">
<div className="examiner-homepage__public-information rows gapped-xl margin-bottom-xxl">
<div className="columns gapped">
<H2 className="grow">{t('heading')}</H2>
<CustomButtonLink
Expand Down Expand Up @@ -98,14 +99,16 @@ const ContactRequests = () => {
keyPrefix: 'vkt.component.examinerOverview.contactRequests',
});
// TODO Get contact requests from redux state & render them
const contactRequests = [];
const { examiner } = useAppSelector(examinerDetailsSelector);

return (
<div className="examiner-homepage__contact-requests rows gapped-xl">
<div className="examiner-homepage__contact-requests rows gapped-xl margin-top-xxl margin-bottom-xxl">
<H2>{t('heading')}</H2>
<Divider />
{contactRequests.length === 0 && (
{examiner?.contactRequests?.length === 0 ? (
<Text className="empty-results">{t('labels.noContactRequests')}</Text>
) : (
<ExaminerContactRequestListing />
)}
</div>
);
Expand Down

0 comments on commit 30306a4

Please sign in to comment.