Professor update
This commit is contained in:
@ -6,17 +6,12 @@ import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import net.shyshkin.study.fullstack.supportportal.backend.domain.WorkingStatus;
|
||||
import net.shyshkin.study.fullstack.supportportal.backend.domain.ProfessorCategory;
|
||||
import net.shyshkin.study.fullstack.supportportal.backend.domain.dto.SkillDto;
|
||||
import net.shyshkin.study.fullstack.supportportal.backend.domain.dto.AwardDto;
|
||||
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.List;
|
||||
|
||||
import javax.validation.constraints.Email;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@ -34,11 +29,12 @@ public class ProfessorDto {
|
||||
private WorkingStatus status;
|
||||
private ProfessorCategory category;
|
||||
|
||||
private ZonedDateTime joinDate;
|
||||
// Received as ISO string from multipart form e.g. "2026-04-22T23:17:58.831Z"
|
||||
private String joinDate;
|
||||
|
||||
private MultipartFile profileImage;
|
||||
|
||||
// Additional fields for Next.js integration
|
||||
|
||||
// Additional fields
|
||||
private String phone;
|
||||
private String specialty;
|
||||
private String certification;
|
||||
|
||||
@ -15,7 +15,7 @@ public interface ProfessorMapper {
|
||||
Professor toEntity(ProfessorDto professorDto);
|
||||
|
||||
@Mapping(target = "profileImage", ignore = true)
|
||||
@Mapping(target = "joinDate", expression = "java(professor.getJoinDate() != null ? professor.getJoinDate().atZone(java.time.ZoneOffset.UTC) : null)")
|
||||
@Mapping(target = "joinDate", expression = "java(professor.getJoinDate() != null ? professor.getJoinDate().toString() + 'Z' : null)")
|
||||
@Mapping(target = "status", source = "status", qualifiedByName = "workingStatusToString")
|
||||
ProfessorDto toDto(Professor professor);
|
||||
|
||||
|
||||
@ -28,9 +28,10 @@ import javax.annotation.PostConstruct;
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
@ -62,6 +63,23 @@ public class ProfessorServiceImpl implements ProfessorService {
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses ISO date string from frontend (e.g. "2026-04-22T23:17:58.831Z")
|
||||
* into LocalDateTime. Falls back to now() if null/blank/invalid.
|
||||
*/
|
||||
private LocalDateTime parseJoinDate(String joinDate) {
|
||||
if (joinDate == null || joinDate.isBlank()) {
|
||||
return LocalDateTime.now();
|
||||
}
|
||||
try {
|
||||
return ZonedDateTime.parse(joinDate, DateTimeFormatter.ISO_DATE_TIME)
|
||||
.toLocalDateTime();
|
||||
} catch (Exception e) {
|
||||
log.warn("Could not parse joinDate '{}', defaulting to now()", joinDate);
|
||||
return LocalDateTime.now();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Professor register(String firstName, String lastName, String email, String department, String position) {
|
||||
@ -72,7 +90,6 @@ public class ProfessorServiceImpl implements ProfessorService {
|
||||
.department(department)
|
||||
.position(position)
|
||||
.build();
|
||||
|
||||
return addNewProfessor(professorDto);
|
||||
}
|
||||
|
||||
@ -159,11 +176,7 @@ public class ProfessorServiceImpl implements ProfessorService {
|
||||
Professor professor = professorMapper.toEntity(professorDto);
|
||||
|
||||
professor.setProfessorId(generateUuid());
|
||||
professor.setJoinDate(
|
||||
professorDto.getJoinDate() != null
|
||||
? professorDto.getJoinDate().toLocalDateTime()
|
||||
: LocalDateTime.now()
|
||||
);
|
||||
professor.setJoinDate(parseJoinDate(professorDto.getJoinDate()));
|
||||
professor.setProfileImageUrl(generateDefaultProfileImageUrl(professor.getProfessorId()));
|
||||
|
||||
Professor savedProfessor = professorRepository.save(professor);
|
||||
@ -217,7 +230,6 @@ public class ProfessorServiceImpl implements ProfessorService {
|
||||
professor.setOfficeLocation(professorDto.getOfficeLocation());
|
||||
professor.setStatus(professorDto.getStatus());
|
||||
professor.setCategory(professorDto.getCategory());
|
||||
|
||||
professor.setPhone(professorDto.getPhone());
|
||||
professor.setSpecialty(professorDto.getSpecialty());
|
||||
professor.setCertification(professorDto.getCertification());
|
||||
@ -227,8 +239,9 @@ public class ProfessorServiceImpl implements ProfessorService {
|
||||
professor.setDesignation(professorDto.getDesignation());
|
||||
professor.setWorkDays(professorDto.getWorkDays());
|
||||
|
||||
if (professorDto.getJoinDate() != null) {
|
||||
professor.setJoinDate(professorDto.getJoinDate().toLocalDateTime());
|
||||
// Parse joinDate string safely
|
||||
if (professorDto.getJoinDate() != null && !professorDto.getJoinDate().isBlank()) {
|
||||
professor.setJoinDate(parseJoinDate(professorDto.getJoinDate()));
|
||||
}
|
||||
|
||||
final Professor professorRef = professor;
|
||||
|
||||
Reference in New Issue
Block a user