date issue update
This commit is contained in:
@ -9,10 +9,9 @@ import net.shyshkin.study.fullstack.supportportal.backend.domain.ProfessorCatego
|
|||||||
import net.shyshkin.study.fullstack.supportportal.backend.domain.dto.SkillDto;
|
import net.shyshkin.study.fullstack.supportportal.backend.domain.dto.SkillDto;
|
||||||
import net.shyshkin.study.fullstack.supportportal.backend.domain.dto.AwardDto;
|
import net.shyshkin.study.fullstack.supportportal.backend.domain.dto.AwardDto;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.ZonedDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.validation.constraints.Email;
|
import javax.validation.constraints.Email;
|
||||||
@ -35,8 +34,7 @@ public class ProfessorDto {
|
|||||||
private WorkingStatus status;
|
private WorkingStatus status;
|
||||||
private ProfessorCategory category;
|
private ProfessorCategory category;
|
||||||
|
|
||||||
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", timezone = "UTC")
|
private ZonedDateTime joinDate;
|
||||||
private LocalDateTime joinDate;
|
|
||||||
|
|
||||||
private MultipartFile profileImage;
|
private MultipartFile profileImage;
|
||||||
|
|
||||||
|
|||||||
@ -10,12 +10,12 @@ import org.mapstruct.Named;
|
|||||||
@Mapper(componentModel = "spring")
|
@Mapper(componentModel = "spring")
|
||||||
public interface ProfessorMapper {
|
public interface ProfessorMapper {
|
||||||
|
|
||||||
// @Mapping(target = "professorId", ignore = true) // Auto-generated
|
@Mapping(target = "joinDate", ignore = true) // Handled in service
|
||||||
@Mapping(target = "joinDate", expression = "java(java.time.LocalDateTime.now())") // Default value
|
|
||||||
@Mapping(target = "status", source = "status", qualifiedByName = "stringToWorkingStatus")
|
@Mapping(target = "status", source = "status", qualifiedByName = "stringToWorkingStatus")
|
||||||
Professor toEntity(ProfessorDto professorDto);
|
Professor toEntity(ProfessorDto professorDto);
|
||||||
|
|
||||||
@Mapping(target = "profileImage", ignore = true) // Ignore profileImage mapping
|
@Mapping(target = "profileImage", ignore = true)
|
||||||
|
@Mapping(target = "joinDate", expression = "java(professor.getJoinDate() != null ? professor.getJoinDate().atZone(java.time.ZoneOffset.UTC) : null)")
|
||||||
@Mapping(target = "status", source = "status", qualifiedByName = "workingStatusToString")
|
@Mapping(target = "status", source = "status", qualifiedByName = "workingStatusToString")
|
||||||
ProfessorDto toDto(Professor professor);
|
ProfessorDto toDto(Professor professor);
|
||||||
|
|
||||||
@ -28,6 +28,4 @@ public interface ProfessorMapper {
|
|||||||
default String workingStatusToString(WorkingStatus status) {
|
default String workingStatusToString(WorkingStatus status) {
|
||||||
return status == null ? null : status.name();
|
return status == null ? null : status.name();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@ -156,21 +156,18 @@ public class ProfessorServiceImpl implements ProfessorService {
|
|||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public Professor addNewProfessor(ProfessorDto professorDto) {
|
public Professor addNewProfessor(ProfessorDto professorDto) {
|
||||||
// ✅ FIX: Removed validateNewEmail() - duplicate emails are now allowed
|
|
||||||
|
|
||||||
Professor professor = professorMapper.toEntity(professorDto);
|
Professor professor = professorMapper.toEntity(professorDto);
|
||||||
|
|
||||||
// Set a unique identifier for the professor
|
|
||||||
professor.setProfessorId(generateUuid());
|
professor.setProfessorId(generateUuid());
|
||||||
professor.setJoinDate(
|
professor.setJoinDate(
|
||||||
professorDto.getJoinDate() != null ? professorDto.getJoinDate() : LocalDateTime.now()
|
professorDto.getJoinDate() != null
|
||||||
|
? professorDto.getJoinDate().toLocalDateTime()
|
||||||
|
: LocalDateTime.now()
|
||||||
);
|
);
|
||||||
professor.setProfileImageUrl(generateDefaultProfileImageUrl(professor.getProfessorId()));
|
professor.setProfileImageUrl(generateDefaultProfileImageUrl(professor.getProfessorId()));
|
||||||
|
|
||||||
// Save the professor first to get the ID
|
|
||||||
Professor savedProfessor = professorRepository.save(professor);
|
Professor savedProfessor = professorRepository.save(professor);
|
||||||
|
|
||||||
// ✅ Handle skills if provided
|
|
||||||
if (professorDto.getSkills() != null && !professorDto.getSkills().isEmpty()) {
|
if (professorDto.getSkills() != null && !professorDto.getSkills().isEmpty()) {
|
||||||
Set<ProfessorSkill> skills = professorDto.getSkills().stream()
|
Set<ProfessorSkill> skills = professorDto.getSkills().stream()
|
||||||
.filter(skillDto -> skillDto.getName() != null && !skillDto.getName().trim().isEmpty())
|
.filter(skillDto -> skillDto.getName() != null && !skillDto.getName().trim().isEmpty())
|
||||||
@ -183,7 +180,6 @@ public class ProfessorServiceImpl implements ProfessorService {
|
|||||||
savedProfessor.setSkills(skills);
|
savedProfessor.setSkills(skills);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ✅ Handle awards if provided
|
|
||||||
if (professorDto.getAwards() != null && !professorDto.getAwards().isEmpty()) {
|
if (professorDto.getAwards() != null && !professorDto.getAwards().isEmpty()) {
|
||||||
Set<ProfessorAward> awards = professorDto.getAwards().stream()
|
Set<ProfessorAward> awards = professorDto.getAwards().stream()
|
||||||
.filter(awardDto -> awardDto.getTitle() != null && !awardDto.getTitle().trim().isEmpty())
|
.filter(awardDto -> awardDto.getTitle() != null && !awardDto.getTitle().trim().isEmpty())
|
||||||
@ -198,10 +194,8 @@ public class ProfessorServiceImpl implements ProfessorService {
|
|||||||
savedProfessor.setAwards(awards);
|
savedProfessor.setAwards(awards);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save again to persist the relationships
|
|
||||||
Professor finalProfessor = professorRepository.save(savedProfessor);
|
Professor finalProfessor = professorRepository.save(savedProfessor);
|
||||||
|
|
||||||
// Handle profile image if provided
|
|
||||||
if (professorDto.getProfileImage() != null) {
|
if (professorDto.getProfileImage() != null) {
|
||||||
saveProfileImage(finalProfessor, professorDto.getProfileImage());
|
saveProfileImage(finalProfessor, professorDto.getProfileImage());
|
||||||
}
|
}
|
||||||
@ -215,9 +209,6 @@ public class ProfessorServiceImpl implements ProfessorService {
|
|||||||
Professor professor = professorRepository.findByProfessorId(professorId)
|
Professor professor = professorRepository.findByProfessorId(professorId)
|
||||||
.orElseThrow(() -> new ProfessorNotFoundException("Professor not found with id: " + professorId));
|
.orElseThrow(() -> new ProfessorNotFoundException("Professor not found with id: " + professorId));
|
||||||
|
|
||||||
// ✅ FIX: Removed validateUpdateEmail() - duplicate emails are now allowed
|
|
||||||
|
|
||||||
// Update basic fields
|
|
||||||
professor.setFirstName(professorDto.getFirstName());
|
professor.setFirstName(professorDto.getFirstName());
|
||||||
professor.setLastName(professorDto.getLastName());
|
professor.setLastName(professorDto.getLastName());
|
||||||
professor.setEmail(professorDto.getEmail());
|
professor.setEmail(professorDto.getEmail());
|
||||||
@ -227,7 +218,6 @@ public class ProfessorServiceImpl implements ProfessorService {
|
|||||||
professor.setStatus(professorDto.getStatus());
|
professor.setStatus(professorDto.getStatus());
|
||||||
professor.setCategory(professorDto.getCategory());
|
professor.setCategory(professorDto.getCategory());
|
||||||
|
|
||||||
// Update extended fields
|
|
||||||
professor.setPhone(professorDto.getPhone());
|
professor.setPhone(professorDto.getPhone());
|
||||||
professor.setSpecialty(professorDto.getSpecialty());
|
professor.setSpecialty(professorDto.getSpecialty());
|
||||||
professor.setCertification(professorDto.getCertification());
|
professor.setCertification(professorDto.getCertification());
|
||||||
@ -237,15 +227,12 @@ public class ProfessorServiceImpl implements ProfessorService {
|
|||||||
professor.setDesignation(professorDto.getDesignation());
|
professor.setDesignation(professorDto.getDesignation());
|
||||||
professor.setWorkDays(professorDto.getWorkDays());
|
professor.setWorkDays(professorDto.getWorkDays());
|
||||||
|
|
||||||
// ✅ Update joinDate if provided
|
|
||||||
if (professorDto.getJoinDate() != null) {
|
if (professorDto.getJoinDate() != null) {
|
||||||
professor.setJoinDate(professorDto.getJoinDate());
|
professor.setJoinDate(professorDto.getJoinDate().toLocalDateTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a final reference for lambda expressions
|
|
||||||
final Professor professorRef = professor;
|
final Professor professorRef = professor;
|
||||||
|
|
||||||
// ✅ Update skills with orphanRemoval=true
|
|
||||||
if (professor.getSkills() == null) {
|
if (professor.getSkills() == null) {
|
||||||
professor.setSkills(new HashSet<>());
|
professor.setSkills(new HashSet<>());
|
||||||
}
|
}
|
||||||
@ -263,7 +250,6 @@ public class ProfessorServiceImpl implements ProfessorService {
|
|||||||
professor.getSkills().addAll(newSkills);
|
professor.getSkills().addAll(newSkills);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ✅ Update awards with orphanRemoval=true
|
|
||||||
if (professor.getAwards() == null) {
|
if (professor.getAwards() == null) {
|
||||||
professor.setAwards(new HashSet<>());
|
professor.setAwards(new HashSet<>());
|
||||||
}
|
}
|
||||||
@ -285,7 +271,6 @@ public class ProfessorServiceImpl implements ProfessorService {
|
|||||||
|
|
||||||
Professor savedProfessor = professorRepository.save(professor);
|
Professor savedProfessor = professorRepository.save(professor);
|
||||||
|
|
||||||
// Handle profile image if provided
|
|
||||||
if (professorDto.getProfileImage() != null) {
|
if (professorDto.getProfileImage() != null) {
|
||||||
saveProfileImage(savedProfessor, professorDto.getProfileImage());
|
saveProfileImage(savedProfessor, professorDto.getProfileImage());
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
spring:
|
spring:
|
||||||
datasource:
|
datasource:
|
||||||
url: jdbc:mysql://localhost:3306/support_portal?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC
|
url: jdbc:mysql://127.0.0.1:3306/support_portal?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC
|
||||||
username: root
|
username: root
|
||||||
password: root
|
password: root
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user