Skip to content

Commit

Permalink
change classCode to classId for send invite, remove classCode for cla…
Browse files Browse the repository at this point in the history
…ss table
  • Loading branch information
ernestjx committed Sep 26, 2024
1 parent 11a7bd3 commit c25c3e7
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package com.quemistry.user_ms.model;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;

public record StudentInvitationDto(
@NotBlank String studentEmail,
@NotBlank String studentFullName,
@NotBlank String classCode) {
@NotNull Long classId) {
}

Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,10 @@ public boolean sendInvitation(StudentInvitationDto input, String tutorAccountId)
throw new ResponseStatusException(HttpStatus.NOT_FOUND, message);
// return false;
}
Optional<Class> classOptional = classRepository.findByCode(input.classCode());
Optional<Class> classOptional = classRepository.findById(input.classId());

if (classOptional.isEmpty()) {
message = "class code=%s not found".formatted(input.classCode());
message = "class id=%s not found".formatted(input.classId());
log.error(message);
throw new ResponseStatusException(HttpStatus.NOT_FOUND, message);
// return false;
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ spring:
activate:
on-profile: dev

FLYWAY_LOCATION: classpath:db/migration/dev
FLYWAY_LOCATION: classpath:db/migration, classpath:db/migration/dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE qms_user.class
RENAME COLUMN class_end_ts TO end_date;
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ VALUES(8888, 8888, 'J1', now(), 'mock', now(), 'mock');
-- CLASS
INSERT INTO qms_user."class"
(id, code, description, subject, education_level, created_on, created_by, modified_on, modified_by, status, start_date, end_date)
VALUES(7777, 'classCode', 'classDescription', 'Chemistry', 'J1', now(), 'mock', now(), 'mock', 'active', now(), now());
VALUES(7777, 'classId', 'classDescription', 'Chemistry', 'J1', now(), 'mock', now(), 'mock', 'active', now(), now());

INSERT INTO qms_user.student_class
(student_id, class_id, status, created_on, created_by, modified_on, modified_by)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ void givenStudents_whenSendInvitationToStudent_thenStatus200() throws Exception
{
"studentEmail": "[email protected]",
"studentFullName": "test",
"classCode": "test"
"classId": "1"
}"""))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void testSaveClassSuccess() {
// Given
SaveClassRequest request = new SaveClassRequest();
request.setUserId("testUserId");
request.setCode("classCode");
request.setCode("classId");
request.setDescription("classDescription");
request.setEducationLevel("level");
request.setSubject("subject");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ void givenStudent_whenSendInvitation_thenReturnSuccess() throws Exception {
var inputStudentProfile = new StudentInvitationDto(
"[email protected]",
"full name",
"c001");
1L);


var userEntity = new User(
Expand All @@ -167,7 +167,7 @@ void givenStudent_whenSendInvitation_thenReturnSuccess() throws Exception {
var tutorEntity = new Tutor(2L, "P1", "centre", userEntity, Collections.emptyList());

when(tutorRepository.findTutorByUserEntityAccountId(anyString())).thenReturn(Optional.of(tutorEntity));
when(classRepository.findByCode(any())).thenReturn(Optional.of(clazz));
when(classRepository.findById(any())).thenReturn(Optional.of(clazz));
when(notificationService.sendEmailNotification(anyString(), anyString(), any())).thenReturn(true);
when(cryptoService.encrypt(anyString())).thenReturn("test");

Expand All @@ -193,19 +193,19 @@ void testSendInvitation_TutorNotFound() {
void testSendInvitation_ClassNotFound() {
// Given
String tutorAccountId = "tutor123";
String classCode = "class456";
StudentInvitationDto input = new StudentInvitationDto("John Doe", "[email protected]", classCode);
Long classId = 1L;
StudentInvitationDto input = new StudentInvitationDto("John Doe", "[email protected]", classId);

Tutor tutor = new Tutor();
when(tutorRepository.findTutorByUserEntityAccountId(tutorAccountId)).thenReturn(Optional.of(tutor));
when(classRepository.findByCode(classCode)).thenReturn(Optional.empty());
when(classRepository.findById(classId)).thenReturn(Optional.empty());

// Act & Assert
ResponseStatusException exception = assertThrows(ResponseStatusException.class, () -> {
studentService.sendInvitation(input, tutorAccountId);
});

assertEquals("404 NOT_FOUND \"class code=class456 not found\"", exception.getMessage());
assertEquals("404 NOT_FOUND \"class id=1 not found\"", exception.getMessage());
verify(classInvitationRepository, never()).save(any(ClassInvitation.class));
}

Expand Down

0 comments on commit c25c3e7

Please sign in to comment.