Skip to content

Commit 9eda70d

Browse files
authored
Merge pull request #43 from INU-Software-Design/NEEIS-91-feature/report
[NEEIS-91[ feat: 학생 λ³΄κ³ μ„œ 생성
2 parents cea07c3 + 55936ff commit 9eda70d

27 files changed

Lines changed: 1975 additions & 541 deletions

β€Žbuild.gradleβ€Ž

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,11 @@ dependencies {
6969
// PDF
7070
implementation 'com.openhtmltopdf:openhtmltopdf-slf4j:1.0.10' // 둜그용 (선택)
7171
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
72-
implementation 'com.itextpdf:itext7-core:7.1.2'
73-
implementation 'com.itextpdf:html2pdf:3.0.2'
72+
73+
implementation 'com.itextpdf:layout:7.2.5'
74+
implementation 'com.itextpdf:kernel:7.2.5'
75+
implementation 'com.itextpdf:io:7.2.5'
76+
implementation 'com.itextpdf:font-asian:7.2.5' // ν•œκΈ€ 폰트 지원
7477
}
7578

7679

β€Žsrc/main/java/com/neeis/neeis/domain/behavior/service/BehaviorService.javaβ€Ž

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
import com.neeis.neeis.domain.classroomStudent.ClassroomStudentRepository;
1414
import com.neeis.neeis.domain.classroomStudent.ClassroomStudentService;
1515
import com.neeis.neeis.domain.notification.service.NotificationService;
16+
import com.neeis.neeis.domain.parent.Parent;
17+
import com.neeis.neeis.domain.parent.ParentService;
18+
import com.neeis.neeis.domain.student.Student;
1619
import com.neeis.neeis.domain.teacher.Teacher;
1720
import com.neeis.neeis.domain.teacher.service.TeacherService;
1821
import com.neeis.neeis.domain.user.User;
@@ -27,6 +30,7 @@
2730

2831
import static com.neeis.neeis.domain.user.Role.STUDENT;
2932
import static com.neeis.neeis.domain.user.Role.TEACHER;
33+
import static com.neeis.neeis.global.exception.ErrorCode.CLASSROOM_NOT_FOUND;
3034
import static com.neeis.neeis.global.exception.ErrorCode.HANDLE_ACCESS_DENIED;
3135

3236
@Service
@@ -41,6 +45,7 @@ public class BehaviorService {
4145
private final NotificationService notificationService;
4246
private final UserService userService;
4347
private final ClassroomStudentRepository classroomStudentRepository;
48+
private final ParentService parentService;
4449

4550
// [ꡐ사] 행동 μž‘μ„±
4651
@Transactional //false
@@ -112,13 +117,30 @@ private ClassroomStudent checkValidate(String username, int year, int grade, int
112117
}
113118

114119
case TEACHER -> {
115-
Teacher teacher = teacherService.authenticate(username);
116-
Classroom classroom = classroomService.findClassroom(year, grade, classNum, teacher.getId());
120+
teacherService.authenticate(username);
121+
Classroom classroom = classroomService.findClassroom(year, grade, classNum);
117122

118123
return classroomStudentRepository.findByClassroomAndNumber(classroom, number)
119124
.orElseThrow(() -> new CustomException(HANDLE_ACCESS_DENIED));
120125
}
121126

127+
case PARENT -> {
128+
Parent parent = parentService.getParentByUser(user);
129+
130+
Student student = parent.getStudent();
131+
Classroom classroom = classroomService.findClassroom(year, grade, classNum);
132+
133+
ClassroomStudent classroomStudent = classroomStudentRepository.findByClassroomAndNumber(classroom, number)
134+
.orElseThrow(() -> new CustomException(CLASSROOM_NOT_FOUND));
135+
136+
// μžλ…€κ°€ μ•„λ‹ˆλ©΄ μ ‘κ·Ό λΆˆκ°€ν•¨.
137+
if (!student.getId().equals(classroomStudent.getStudent().getId())) {
138+
throw new CustomException(HANDLE_ACCESS_DENIED);
139+
}
140+
141+
return classroomStudent;
142+
}
143+
122144
default -> throw new CustomException(HANDLE_ACCESS_DENIED);
123145
}
124146
}

β€Žsrc/main/java/com/neeis/neeis/domain/classroomStudent/ClassroomStudentRepository.javaβ€Ž

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,28 @@ public interface ClassroomStudentRepository extends JpaRepository<ClassroomStude
3030
@Query(value = "SELECT cs FROM ClassroomStudent cs " +
3131
"WHERE cs.student.user = :user")
3232
Optional<ClassroomStudent> findByStudentUser(@Param("user") User user);
33-
}
33+
34+
/**
35+
* 학생 User둜 λͺ¨λ“  ClassroomStudent 쑰회 (연도별)
36+
*/
37+
@Query("SELECT cs FROM ClassroomStudent cs WHERE cs.student.user = :user ORDER BY cs.classroom.year DESC")
38+
List<ClassroomStudent> findAllByStudentUserOrderByYear(@Param("user") User user);
39+
40+
/**
41+
* νŠΉμ • 연도, ν•™λ…„, 반의 λͺ¨λ“  학생 쑰회
42+
*/
43+
@Query("SELECT cs FROM ClassroomStudent cs WHERE cs.classroom.year = :year AND cs.classroom.grade = :grade AND cs.classroom.classNum = :classNum ORDER BY cs.number")
44+
List<ClassroomStudent> findByClassroomInfo(@Param("year") int year, @Param("grade") int grade, @Param("classNum") int classNum);
45+
46+
/**
47+
* 학생 ID와 μ—°λ„λ‘œ ClassroomStudent 쑰회
48+
*/
49+
@Query("SELECT cs FROM ClassroomStudent cs WHERE cs.student.id = :studentId AND cs.classroom.year = :year")
50+
Optional<ClassroomStudent> findByStudentIdAndClassroomYear(@Param("studentId") Long studentId, @Param("year") int year);
51+
52+
/**
53+
* 학생 ID둜 ClassroomStudent 쑰회 (연도 λ‚΄λ¦Όμ°¨μˆœ) - 기쑴에 있던 λ©”μ„œλ“œ
54+
*/
55+
@Query("SELECT cs FROM ClassroomStudent cs WHERE cs.student.id = :studentId ORDER BY cs.classroom.year DESC")
56+
List<ClassroomStudent> findByStudentIdOrderByClassroomYearDesc(@Param("studentId") Long studentId);
57+
}

β€Žsrc/main/java/com/neeis/neeis/domain/classroomStudent/ClassroomStudentService.javaβ€Ž

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
import com.neeis.neeis.domain.classroom.Classroom;
44
import com.neeis.neeis.domain.classroom.ClassroomService;
5+
import com.neeis.neeis.domain.user.User;
56
import com.neeis.neeis.global.exception.CustomException;
67
import com.neeis.neeis.global.exception.ErrorCode;
78
import lombok.RequiredArgsConstructor;
89
import org.springframework.stereotype.Service;
910

1011
import java.util.List;
12+
import java.util.Optional;
1113

1214
@Service
1315
@RequiredArgsConstructor
@@ -32,4 +34,30 @@ public ClassroomStudent findByClassroomAndNumber(Classroom classroom, int number
3234
public List<ClassroomStudent> findByClassroom(Classroom classroom) {
3335
return classroomStudentRepository.findByClassroom(classroom);
3436
}
37+
38+
/**
39+
* PDF 생성을 μœ„ν•΄ μΆ”κ°€λœ λ©”μ„œλ“œ
40+
* User 객체둜 ClassroomStudent 쑰회
41+
*/
42+
public Optional<ClassroomStudent> findByStudent(User user) {
43+
return classroomStudentRepository.findByStudentUser(user);
44+
}
45+
46+
/**
47+
* 학생 ID와 μ—°λ„λ‘œ ClassroomStudent 쑰회
48+
*/
49+
public Optional<ClassroomStudent> findByStudentIdAndYear(Long studentId, int year) {
50+
return classroomStudentRepository.findByStudentIdAndClassroomYear(studentId, year);
51+
}
52+
53+
/**
54+
* 학생 ID둜 ν˜„μž¬ ν™œμ„± ClassroomStudent 쑰회 (μ΅œμ‹  연도 κΈ°μ€€)
55+
* @param studentId 학생 ID
56+
* @return ClassroomStudent Optional
57+
*/
58+
public Optional<ClassroomStudent> findByStudentId(Long studentId) {
59+
return classroomStudentRepository.findByStudentIdOrderByClassroomYearDesc(studentId)
60+
.stream()
61+
.findFirst();
62+
}
3563
}

0 commit comments

Comments
Β (0)