Skip to content
Merged

Dev #22

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ name: CI/CD Pipeline

on:
push:
branches: [ main, dev, "feature/**" ]
branches: [ main ]
# branches: [ main, dev, "feature/**" ]
pull_request:
branches: [ main, dev ]
branches: [ main ]
# branches: [ main, dev ]

permissions:
contents: read
Expand Down Expand Up @@ -78,12 +80,12 @@ jobs:
docker-build:
name: Docker Build & Push
runs-on: ubuntu-latest
needs: [build-and-test, qodana]
needs: [ build-and-test, qodana ]
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/dev'

strategy:
matrix:
service: [config-service, eureka-service, api-gateway, user-service, academic-service]
service: [ config-service, eureka-service, api-gateway, user-service, academic-service ]

steps:
- name: Checkout code
Expand Down
7 changes: 1 addition & 6 deletions services/academic-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,6 @@
<artifactId>cloudinary-http44</artifactId>
<version>1.36.0</version>
</dependency>
<!-- Multipart file upload -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<!-- Spring Dotenv -->
<dependency>
Expand Down Expand Up @@ -128,4 +123,4 @@
</plugin>
</plugins>
</build>
</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
@GetMapping("/{id}")
@PreAuthorize("hasAnyRole('SCHOOL_ADMIN', 'TEACHER', 'STUDENT', 'PARENT', 'STAFF')")
public ResponseEntity<AcademicYearResponseDto> findById(@PathVariable("id") String id) {
log.info("GET /api/v1/academic-years/{}", id);

Check notice on line 51 in services/academic-service/src/main/java/com/academicsService/controller/AcademicYearController.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Non-distinguishable logging calls

Similar log messages
return ResponseEntity.ok(academicYearService.findById(id));
}

Expand All @@ -69,7 +69,7 @@
public ResponseEntity<AcademicYearResponseDto> findCurrent(
@RequestHeader("X-User-Id") String currentUserId) {
String schoolId = schoolValidationService.getSchoolIdByUserId(currentUserId);
log.info("GET /api/v1/academic-years/current for school: {}", schoolId);

Check notice on line 72 in services/academic-service/src/main/java/com/academicsService/controller/AcademicYearController.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Non-distinguishable logging calls

Similar log messages
return ResponseEntity.ok(academicYearService.findCurrentBySchool(schoolId));
}

Expand All @@ -83,7 +83,7 @@
}

@DeleteMapping("/{id}")
@PreAuthorize("hasRole('SCHOOL_ADMIN')")
@PreAuthorize("hasAnyRole('SCHOOL_ADMIN', 'STAFF')")
public ResponseEntity<Void> delete(
@PathVariable("id") String id,
@RequestHeader("X-User-Id") String currentUserId) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package com.academicsService.controller;

import com.academicsService.dto.create.AttendanceCreateDto;
import com.academicsService.dto.response.AttendanceResponseDto;
import com.academicsService.dto.update.AttendanceUpdateDto;
import com.academicsService.service.AttendanceService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;

@RestController
@RequestMapping("/api/v1/attendances")
@RequiredArgsConstructor
@Slf4j
public class AttendanceController {

private final AttendanceService attendanceService;

@PostMapping
@PreAuthorize("hasAnyRole('SCHOOL_ADMIN', 'STAFF', 'TEACHER')")
public ResponseEntity<AttendanceResponseDto> create(
@Valid @RequestBody AttendanceCreateDto dto,
@RequestHeader("X-User-Id") String currentUserId) {
log.info("POST /api/v1/attendances by user: {}", currentUserId);
return ResponseEntity.status(HttpStatus.CREATED)
.body(attendanceService.create(dto, currentUserId));
}

@PutMapping("/{id}")
@PreAuthorize("hasAnyRole('SCHOOL_ADMIN', 'STAFF', 'TEACHER')")
public ResponseEntity<AttendanceResponseDto> update(
@PathVariable("id") String id,
@Valid @RequestBody AttendanceUpdateDto dto,
@RequestHeader("X-User-Id") String currentUserId) {
log.info("PUT /api/v1/attendances/{} by user: {}", id, currentUserId);
return ResponseEntity.ok(attendanceService.update(id, dto, currentUserId));
}

@GetMapping("/{id}")
@PreAuthorize("hasAnyRole('SCHOOL_ADMIN', 'STAFF', 'TEACHER', 'STUDENT', 'PARENT')")
public ResponseEntity<AttendanceResponseDto> findById(
@PathVariable("id") String id) {
log.info("GET /api/v1/attendances/{}", id);

Check notice on line 53 in services/academic-service/src/main/java/com/academicsService/controller/AttendanceController.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Non-distinguishable logging calls

Similar log messages
return ResponseEntity.ok(attendanceService.findById(id));
}

@GetMapping
@PreAuthorize("hasAnyRole('SCHOOL_ADMIN', 'STAFF', 'TEACHER')")
public ResponseEntity<Page<AttendanceResponseDto>> findBySchool(
@RequestParam("schoolId") String schoolId,
@RequestParam(value = "classroomId", required = false) String classroomId,
@RequestParam(value = "date", required = false)
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate date,
@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "20") int size) {
log.info("GET /api/v1/attendances?schoolId={}&classroomId={}&date={}", schoolId, classroomId, date);
return ResponseEntity.ok(attendanceService.findBySchool(
schoolId, classroomId, date,
PageRequest.of(page, size, Sort.by("date").descending())
));
}

@GetMapping("/student/{studentId}")
@PreAuthorize("hasAnyRole('SCHOOL_ADMIN', 'STAFF', 'TEACHER', 'STUDENT', 'PARENT')")
public ResponseEntity<Page<AttendanceResponseDto>> findByStudent(
@PathVariable("studentId") String studentId,
@RequestParam("schoolId") String schoolId,
@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "20") int size) {
log.info("GET /api/v1/attendances/student/{}", studentId);

Check notice on line 80 in services/academic-service/src/main/java/com/academicsService/controller/AttendanceController.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Non-distinguishable logging calls

Similar log messages
return ResponseEntity.ok(attendanceService.findByStudent(
studentId, schoolId,
PageRequest.of(page, size)
));
}

@DeleteMapping("/{id}")
@PreAuthorize("hasAnyRole('SCHOOL_ADMIN', 'STAFF')")
public ResponseEntity<Void> delete(
@PathVariable("id") String id,
@RequestHeader("X-User-Id") String currentUserId) {
log.info("DELETE /api/v1/attendances/{} by user: {}", id, currentUserId);
attendanceService.delete(id, currentUserId);
return ResponseEntity.noContent().build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
@PreAuthorize("hasAnyRole('SCHOOL_ADMIN', 'TEACHER', 'STAFF')")
public ResponseEntity<StudentClassroomResponseDto> findById(
@PathVariable("id") String id) {
log.info("GET /api/v1/student-classrooms/{}", id);

Check notice on line 52 in services/academic-service/src/main/java/com/academicsService/controller/StudentClassroomController.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Non-distinguishable logging calls

Similar log messages
return ResponseEntity.ok(studentClassroomService.findById(id));
}

Expand All @@ -59,7 +59,7 @@
@PathVariable("classroomId") String classroomId,
@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "10") int size) {
log.info("GET /api/v1/student-classrooms/classroom/{}", classroomId);

Check notice on line 62 in services/academic-service/src/main/java/com/academicsService/controller/StudentClassroomController.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Non-distinguishable logging calls

Similar log messages
return ResponseEntity.ok(studentClassroomService.findByClassroom(
classroomId,
PageRequest.of(page, size, Sort.by("enrollmentDate").descending())
Expand All @@ -70,7 +70,7 @@
@PreAuthorize("hasAnyRole('SCHOOL_ADMIN', 'TEACHER', 'STAFF', 'PARENT', 'STUDENT')")
public ResponseEntity<List<StudentClassroomResponseDto>> findByStudent(
@PathVariable("studentId") String studentId) {
log.info("GET /api/v1/student-classrooms/student/{}", studentId);

Check notice on line 73 in services/academic-service/src/main/java/com/academicsService/controller/StudentClassroomController.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Non-distinguishable logging calls

Similar log messages
return ResponseEntity.ok(studentClassroomService.findActiveByStudent(studentId));
}

Expand All @@ -78,7 +78,7 @@
@PreAuthorize("hasAnyRole('SCHOOL_ADMIN', 'TEACHER', 'STAFF', 'PARENT', 'STUDENT')")
public ResponseEntity<StudentClassroomResponseDto> findCurrentByStudent(
@PathVariable("studentId") String studentId,
@RequestParam("academicYear") String academicYear) {
@RequestParam(value = "academicYear", required = false) String academicYear) {
log.info("GET /api/v1/student-classrooms/student/{}/current", studentId);
return ResponseEntity.ok(
studentClassroomService.findCurrentByStudent(studentId, academicYear)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
@PreAuthorize("hasAnyRole('SCHOOL_ADMIN', 'TEACHER', 'STAFF')")
public ResponseEntity<TeacherSubjectResponseDto> findById(
@PathVariable("id") String id) {
log.info("GET /api/v1/teacher-subjects/{}", id);

Check notice on line 52 in services/academic-service/src/main/java/com/academicsService/controller/TeacherSubjectController.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Non-distinguishable logging calls

Similar log messages
return ResponseEntity.ok(teacherSubjectService.findById(id));
}

Expand All @@ -57,24 +57,25 @@
@PreAuthorize("hasAnyRole('SCHOOL_ADMIN', 'TEACHER', 'STAFF')")
public ResponseEntity<Page<TeacherSubjectResponseDto>> findByTeacher(
@PathVariable("teacherId") String teacherId,
@RequestParam("academicYear") String academicYear,
@RequestParam(value = "academicYear", required = false) String academicYear,
@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "10") int size) {
log.info("GET /api/v1/teacher-subjects/teacher/{}", teacherId);

Check notice on line 63 in services/academic-service/src/main/java/com/academicsService/controller/TeacherSubjectController.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Non-distinguishable logging calls

Similar log messages
return ResponseEntity.ok(teacherSubjectService.findByTeacherAndYear(
teacherId, academicYear,
PageRequest.of(page, size, Sort.by("academicYear").descending())
));
PageRequest pageable = PageRequest.of(page, size, Sort.by("academicYear").descending());
if (academicYear != null && !academicYear.isBlank()) {
return ResponseEntity.ok(teacherSubjectService.findByTeacherAndYear(teacherId, academicYear, pageable));
}
return ResponseEntity.ok(teacherSubjectService.findByTeacher(teacherId, pageable));
}

@GetMapping("/subject/{subjectId}")
@PreAuthorize("hasAnyRole('SCHOOL_ADMIN', 'STAFF')")
public ResponseEntity<Page<TeacherSubjectResponseDto>> findBySubject(
@PathVariable("subjectId") String subjectId,
@RequestParam("academicYear") String academicYear,
@RequestParam(value = "academicYear", required = false) String academicYear,
@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "10") int size) {
log.info("GET /api/v1/teacher-subjects/subject/{}", subjectId);

Check notice on line 78 in services/academic-service/src/main/java/com/academicsService/controller/TeacherSubjectController.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Non-distinguishable logging calls

Similar log messages
return ResponseEntity.ok(teacherSubjectService.findBySubjectAndYear(
subjectId, academicYear,
PageRequest.of(page, size, Sort.by("academicYear").descending())
Expand All @@ -82,18 +83,19 @@
}

@GetMapping("/school")
@PreAuthorize("hasAnyRole('SCHOOL_ADMIN', 'STAFF')")
@PreAuthorize("hasAnyRole('SCHOOL_ADMIN', 'STAFF', 'TEACHER', 'STUDENT', 'PARENT')")
public ResponseEntity<Page<TeacherSubjectResponseDto>> findBySchool(
@RequestHeader("X-User-Id") String currentUserId,
@RequestParam("academicYear") String academicYear,
@RequestParam(value = "academicYear", required = false) String academicYear,
@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "10") int size) {
String schoolId = schoolValidationService.getSchoolIdByUserId(currentUserId);
log.info("GET /api/v1/teacher-subjects/school schoolId={} academicYear={}", schoolId, academicYear);
return ResponseEntity.ok(teacherSubjectService.findBySchoolAndYear(
schoolId, academicYear,
PageRequest.of(page, size, Sort.by("academicYear").descending())
));
PageRequest pageable = PageRequest.of(page, size, Sort.by("academicYear").descending());
if (academicYear != null && !academicYear.isBlank()) {
return ResponseEntity.ok(teacherSubjectService.findBySchoolAndYear(schoolId, academicYear, pageable));
}
return ResponseEntity.ok(teacherSubjectService.findBySchool(schoolId, pageable));
}

@DeleteMapping("/{id}")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.academicsService.dto.create;

import com.fasterxml.jackson.annotation.JsonProperty;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
Expand All @@ -24,6 +25,7 @@ public class AcademicYearCreateDto {
@NotNull(message = "End date is required")
private LocalDate endDate;

@JsonProperty("isCurrent")
private boolean isCurrent;
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.academicsService.dto.create;

import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.Data;

import java.time.LocalDate;
import java.util.List;

@Data
public class AttendanceCreateDto {

@NotBlank(message = "Classroom ID is required")
private String classroomId;

private String subjectId;

@NotNull(message = "Date is required")
private LocalDate date;

private String notes;

@NotEmpty(message = "At least one record is required")
@Valid
private List<AttendanceRecordCreateDto> records;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.academicsService.dto.create;

import com.academicsService.model.enums.AttendanceStatus;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data;

@Data
public class AttendanceRecordCreateDto {

@NotBlank(message = "Student ID is required")
private String studentId;

@NotNull(message = "Status is required")
private AttendanceStatus status;

private String reason;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.academicsService.dto.response;

import com.fasterxml.jackson.annotation.JsonProperty;

import java.time.LocalDate;

public record AcademicYearResponseDto(
Expand All @@ -8,6 +10,7 @@ public record AcademicYearResponseDto(
String name,
LocalDate startDate,
LocalDate endDate,
@JsonProperty("isCurrent")
boolean isCurrent
) {}

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.academicsService.dto.response;

import com.academicsService.model.enums.AttendanceStatus;

public record AttendanceRecordResponseDto(
String id,
String attendanceId,
String studentId,
AttendanceStatus status,
String reason
) {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.academicsService.dto.response;

import java.time.LocalDate;
import java.util.List;

public record AttendanceResponseDto(
String id,
String schoolId,
String classroomId,
String subjectId,
String teacherId,
LocalDate date,
String notes,
List<AttendanceRecordResponseDto> records,
long presentCount,
long absentCount,
long lateCount,
long excusedCount,
String createdAt,
String updatedAt
) {}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.academicsService.dto.update;

import com.fasterxml.jackson.annotation.JsonProperty;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
Expand All @@ -24,6 +25,7 @@ public class AcademicYearUpdateDto {
@NotNull(message = "End date is required")
private LocalDate endDate;

@JsonProperty("isCurrent")
private boolean isCurrent;
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.academicsService.dto.update;

import com.academicsService.model.enums.AttendanceStatus;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data;

import java.util.Map;

@Data
public class AttendanceUpdateDto {

private String notes;

// Map of studentId -> { status, reason }
private Map<String, RecordUpdate> records;

@Data
public static class RecordUpdate {
@NotNull(message = "Status is required")
private AttendanceStatus status;
private String reason;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.bind.MissingServletRequestParameterException;
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;

import java.time.LocalDateTime;
Expand Down Expand Up @@ -118,6 +119,18 @@ public ResponseEntity<ErrorResponse> handleTypeMismatchException(
);
}

@ExceptionHandler(MissingServletRequestParameterException.class)
public ResponseEntity<ErrorResponse> handleMissingParams(
MissingServletRequestParameterException ex,
HttpServletRequest request) {
log.warn("Missing parameter: {}", ex.getParameterName());
return buildErrorResponse(
HttpStatus.BAD_REQUEST,
"Required parameter '" + ex.getParameterName() + "' is missing",
request.getRequestURI()
);
}

@ExceptionHandler(FileUploadException.class)
public ResponseEntity<ErrorResponse> handleFileUploadException(
FileUploadException ex,
Expand Down
Loading
Loading