TDMS/server/src/main/java/ru/tubryansk/tdms/service/StudentService.java
2025-02-09 10:59:44 +03:00

33 lines
936 B
Java

package ru.tubryansk.tdms.service;
import jakarta.transaction.Transactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import ru.tubryansk.tdms.controller.payload.StudentDTO;
import ru.tubryansk.tdms.entity.Student;
import ru.tubryansk.tdms.entity.repository.StudentRepository;
import java.util.Optional;
@Service
@Transactional
public class StudentService {
@Autowired
private StudentRepository studentRepository;
@Autowired
private CallerService callerService;
public Optional<Student> getCallerStudent() {
return studentRepository.findByUser(callerService.getCallerUser().orElse(null));
}
public StudentDTO getCallerStudentDTO() {
Student callerStudent = getCallerStudent().orElse(null);
if (callerStudent == null) {
return null;
}
return StudentDTO.from(callerStudent);
}
}