Skip to content

Commit

Permalink
Student Absenteeism API Fixes and Updates | SIS-199 (#111)
Browse files Browse the repository at this point in the history
* StudentLessonAbsenteeismResponse Has Been Renamed to StudentsLessonAbsenteeismResponse

* StudentLessonAbsenteeismHoursState Enum Class Has Been Created

* THEORETICAL_HOURS_STATE and PRACTICE_HOURS_STATE Fields Have Been Added to StudentLessonAbsenteeismMapping

* THEORETICAL_HOURS_STATE and PRACTICE_HOURS_STATE Fields Have Been Added to SQLs & Method Return Entities Have Been Updated

* SStudentLessonAbsenteeismEntity Has Been Renamed to StudentsLessonAbsenteeismEntity

* StudentLessonsAbsenteeismEntity Class Has Been Created

* theoreticalHoursState and practiceHoursState Variables Have Been Added to StudentLessonAbsenteeismSaveEntity and StudentLessonAbsenteeismUpdateEntity Classes

* StudentLessonsAbsenteeismResponse Class Has Been Created

* theoreticalHoursState and practiceHoursState Have Been Added to StudentsLessonAbsenteeismResponse Class

* theoreticalHoursState and practiceHoursState Fields Have Been Added to Converter Methods

* getAllStudentLessonsAbsenteeismByStudentId Method Has Been Updated and Return Objects Have Been Updated

* getAllStudentsLessonsAbsenteeismByLessonId Method Has Been Renamed to getAllStudentsLessonAbsenteeismByLessonId

* getAllStudentLessonsAbsenteeismByStudentId Method Return Object Has Been Updated

* StudentLessonAbsenteeismHoursState/NOT_EXIST Message Has Been Fixed

* Generate StudentLessonsAbsenteeismResponse Method Has Been Fixed

* theoreticalHoursState, practiceHoursState and status Responses Have Been Fixed

* status Variable Has Been Removed for Student Absenteeism Response

* if Conditions Have Been Fixed for hours Checks
  • Loading branch information
agitrubard authored May 20, 2022
1 parent 255624f commit 3ccdc50
Show file tree
Hide file tree
Showing 15 changed files with 315 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import com.graduationproject.studentinformationsystem.common.util.exception.SisProcessException;
import com.graduationproject.studentinformationsystem.university.absenteeism.controller.endpoint.StudentLessonAbsenteeismControllerEndpoint;
import com.graduationproject.studentinformationsystem.university.absenteeism.model.dto.request.StudentsLessonAbsenteeismUpdateRequest;
import com.graduationproject.studentinformationsystem.university.absenteeism.model.dto.response.StudentLessonAbsenteeismResponse;
import com.graduationproject.studentinformationsystem.university.absenteeism.model.dto.response.StudentLessonsAbsenteeismResponse;
import com.graduationproject.studentinformationsystem.university.absenteeism.model.dto.response.StudentsLessonAbsenteeismResponse;
import com.graduationproject.studentinformationsystem.university.absenteeism.service.StudentLessonAbsenteeismService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
Expand All @@ -31,13 +32,12 @@ public class StudentLessonAbsenteeismController {

@GetMapping(StudentLessonAbsenteeismControllerEndpoint.BY_STUDENT_ID)
@ApiOperation(value = "Get All Student Lessons Absenteeism By Student ID")
public ResponseEntity<SisBaseApiResponse<List<StudentLessonAbsenteeismResponse>>> getAllStudentLessonsAbsenteeismByStudentId(
@PathVariable final Long studentId,
@RequestParam final Integer week)
public ResponseEntity<SisBaseApiResponse<List<StudentLessonsAbsenteeismResponse>>> getAllStudentLessonsAbsenteeismByStudentId(
@PathVariable final Long studentId)
throws SisNotExistException {

final List<StudentLessonAbsenteeismResponse> absenteeismResponses = studentLessonAbsenteeismService
.getAllStudentLessonsAbsenteeismByStudentId(studentId, week);
final List<StudentLessonsAbsenteeismResponse> absenteeismResponses = studentLessonAbsenteeismService
.getAllStudentLessonsAbsenteeismByStudentId(studentId);

if (absenteeismResponses.isEmpty()) {
return failResponse(absenteeismResponses);
Expand All @@ -47,14 +47,14 @@ public ResponseEntity<SisBaseApiResponse<List<StudentLessonAbsenteeismResponse>>
}

@GetMapping(StudentLessonAbsenteeismControllerEndpoint.BY_LESSON_ID)
@ApiOperation(value = "Get All Students Lessons Absenteeism By Lesson ID")
public ResponseEntity<SisBaseApiResponse<List<StudentLessonAbsenteeismResponse>>> getAllStudentsLessonsAbsenteeismByLessonId(
@ApiOperation(value = "Get All Students Lesson Absenteeism By Lesson ID")
public ResponseEntity<SisBaseApiResponse<List<StudentsLessonAbsenteeismResponse>>> getAllStudentsLessonAbsenteeismByLessonId(
@PathVariable final Long lessonId,
@RequestParam final Integer week)
throws SisNotExistException {

final List<StudentLessonAbsenteeismResponse> absenteeismResponses = studentLessonAbsenteeismService
.getAllStudentsLessonsAbsenteeismByLessonId(lessonId, week);
final List<StudentsLessonAbsenteeismResponse> absenteeismResponses = studentLessonAbsenteeismService
.getAllStudentsLessonAbsenteeismByLessonId(lessonId, week);

if (absenteeismResponses.isEmpty()) {
return failResponse(absenteeismResponses);
Expand All @@ -65,11 +65,11 @@ public ResponseEntity<SisBaseApiResponse<List<StudentLessonAbsenteeismResponse>>

@PutMapping(StudentLessonAbsenteeismControllerEndpoint.BASE)
@ApiOperation(value = "Update Students Lesson Absenteeism")
public ResponseEntity<SisBaseApiResponse<List<StudentLessonAbsenteeismResponse>>> updateStudentLessonAbsenteeism(
public ResponseEntity<SisBaseApiResponse<List<StudentsLessonAbsenteeismResponse>>> updateStudentLessonAbsenteeism(
@RequestBody @Valid final StudentsLessonAbsenteeismUpdateRequest updateRequest)
throws SisNotExistException, SisProcessException {

final List<StudentLessonAbsenteeismResponse> absenteeismResponses = studentLessonAbsenteeismService
final List<StudentsLessonAbsenteeismResponse> absenteeismResponses = studentLessonAbsenteeismService
.updateStudentLessonAbsenteeism(updateRequest);

return successResponse(absenteeismResponses);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
import com.graduationproject.studentinformationsystem.common.model.dto.request.SisOperationInfoRequest;
import com.graduationproject.studentinformationsystem.common.util.SisUtil;
import com.graduationproject.studentinformationsystem.university.absenteeism.model.dto.request.StudentLessonAbsenteeismSaveRequest;
import com.graduationproject.studentinformationsystem.university.absenteeism.model.dto.response.StudentLessonAbsenteeismResponse;
import com.graduationproject.studentinformationsystem.university.absenteeism.model.entity.StudentLessonAbsenteeismEntity;
import com.graduationproject.studentinformationsystem.university.absenteeism.model.dto.response.StudentLessonsAbsenteeismResponse;
import com.graduationproject.studentinformationsystem.university.absenteeism.model.dto.response.StudentsLessonAbsenteeismResponse;
import com.graduationproject.studentinformationsystem.university.absenteeism.model.entity.StudentLessonAbsenteeismSaveEntity;
import com.graduationproject.studentinformationsystem.university.absenteeism.model.entity.StudentLessonAbsenteeismUpdateEntity;
import com.graduationproject.studentinformationsystem.university.absenteeism.model.entity.StudentLessonsAbsenteeismEntity;
import com.graduationproject.studentinformationsystem.university.absenteeism.model.entity.StudentsLessonAbsenteeismEntity;
import com.graduationproject.studentinformationsystem.university.absenteeism.model.enums.StudentLessonAbsenteeismHoursState;
import com.graduationproject.studentinformationsystem.university.absenteeism.model.enums.StudentLessonAbsenteeismStatus;
import com.graduationproject.studentinformationsystem.university.lesson.common.model.dto.response.LessonResponse;
import com.graduationproject.studentinformationsystem.university.lesson.common.service.LessonOutService;
Expand All @@ -33,13 +36,29 @@ public StudentLessonAbsenteeismSaveEntity generateSaveEntity(final StudentLesson

final SisOperationInfoRequest operationInfoRequest = saveRequest.getOperationInfoRequest();

final StudentLessonAbsenteeismHoursState theoreticalHoursState;
if (saveRequest.getMaxTheoreticalHours() == 0) {
theoreticalHoursState = StudentLessonAbsenteeismHoursState.NOT_EXIST;
} else {
theoreticalHoursState = StudentLessonAbsenteeismHoursState.NOT_ENTERED;
}

final StudentLessonAbsenteeismHoursState practiceHoursState;
if (saveRequest.getMaxPracticeHours() == 0) {
practiceHoursState = StudentLessonAbsenteeismHoursState.NOT_EXIST;
} else {
practiceHoursState = StudentLessonAbsenteeismHoursState.NOT_ENTERED;
}

return StudentLessonAbsenteeismSaveEntity.builder()
.id(SisUtil.generateRandomUUID())
.teacherId(saveRequest.getTeacherId())
.studentId(saveRequest.getStudentId())
.lessonId(saveRequest.getLessonId())
.week(saveRequest.getWeek())
.theoreticalHoursState(theoreticalHoursState)
.maxTheoreticalHours(saveRequest.getMaxTheoreticalHours())
.practiceHoursState(practiceHoursState)
.maxPracticeHours(saveRequest.getMaxPracticeHours())
.status(StudentLessonAbsenteeismStatus.NOT_ENTERED)
.createdUserId(operationInfoRequest.getUserId())
Expand All @@ -52,17 +71,75 @@ public StudentLessonAbsenteeismUpdateEntity generateUpdateEntity(final String ab
final Integer practiceHours,
final SisOperationInfoRequest operationInfoRequest) {

StudentLessonAbsenteeismHoursState theoreticalHoursState = StudentLessonAbsenteeismHoursState.NOT_ENTERED;
if (theoreticalHours != null) {
theoreticalHoursState = StudentLessonAbsenteeismHoursState.ENTERED;
}

StudentLessonAbsenteeismHoursState practiceHoursState = StudentLessonAbsenteeismHoursState.NOT_ENTERED;
if (practiceHours != null) {
practiceHoursState = StudentLessonAbsenteeismHoursState.ENTERED;
}

return StudentLessonAbsenteeismUpdateEntity.builder()
.id(absenteeismId)
.theoreticalHoursState(theoreticalHoursState)
.theoreticalHours(theoreticalHours)
.practiceHoursState(practiceHoursState)
.practiceHours(practiceHours)
.status(StudentLessonAbsenteeismStatus.ENTERED)
.modifiedUserId(operationInfoRequest.getUserId())
.modifiedDate(new Date())
.build();
}

public StudentLessonAbsenteeismResponse entityToResponse(final StudentLessonAbsenteeismEntity absenteeismEntity) {
public StudentLessonsAbsenteeismResponse entityToResponse(final Integer currentTheoreticalHours,
final Integer currentPracticeHours,
final Integer balanceTheoreticalHours,
final Integer balancePracticeHours,
final StudentLessonsAbsenteeismEntity absenteeismEntity) {

final Long teacherId = absenteeismEntity.getTeacherId();
final TeacherInfoResponse teacherResponse = teacherOutService.getTeacherInfoResponse(teacherId);

final Long studentId = absenteeismEntity.getStudentId();
final StudentInfoResponse studentResponse = studentOutService.getStudentInfoResponse(studentId);

final Long lessonId = absenteeismEntity.getLessonId();
final LessonResponse lessonResponse = lessonOutService.getLessonResponse(lessonId);

StudentLessonAbsenteeismHoursState theoreticalHoursState = StudentLessonAbsenteeismHoursState.NOT_ENTERED;
if (currentTheoreticalHours != 0 && balanceTheoreticalHours != 0) {
theoreticalHoursState = StudentLessonAbsenteeismHoursState.ENTERED;
} else if (currentTheoreticalHours == 0 && balanceTheoreticalHours == 0) {
theoreticalHoursState = StudentLessonAbsenteeismHoursState.NOT_EXIST;
}

StudentLessonAbsenteeismHoursState practiceHoursState = StudentLessonAbsenteeismHoursState.NOT_ENTERED;
if (currentPracticeHours != 0 && balancePracticeHours != 0) {
practiceHoursState = StudentLessonAbsenteeismHoursState.ENTERED;
} else if (currentPracticeHours == 0 && balancePracticeHours == 0) {
practiceHoursState = StudentLessonAbsenteeismHoursState.NOT_EXIST;
}

return StudentLessonsAbsenteeismResponse.builder()
.id(absenteeismEntity.getId())
.theoreticalHoursState(theoreticalHoursState)
.currentTheoreticalHours(currentTheoreticalHours)
.balanceTheoreticalHours(balanceTheoreticalHours)
.practiceHoursState(practiceHoursState)
.currentPracticeHours(currentPracticeHours)
.balancePracticeHours(balancePracticeHours)
.createdDate(SisUtil.getFormattedDateTime(absenteeismEntity.getCreatedDate()))
.createdUserId(absenteeismEntity.getCreatedUserId())
.modifiedDate(SisUtil.getFormattedDateTime(absenteeismEntity.getModifiedDate()))
.modifiedUserId(absenteeismEntity.getModifiedUserId())
.teacherResponse(teacherResponse)
.studentResponse(studentResponse)
.lessonResponse(lessonResponse).build();
}

public StudentsLessonAbsenteeismResponse entityToResponse(final StudentsLessonAbsenteeismEntity absenteeismEntity) {

final Long teacherId = absenteeismEntity.getTeacherId();
final TeacherInfoResponse teacherResponse = teacherOutService.getTeacherInfoResponse(teacherId);
Expand All @@ -73,10 +150,12 @@ public StudentLessonAbsenteeismResponse entityToResponse(final StudentLessonAbse
final Long lessonId = absenteeismEntity.getLessonId();
final LessonResponse lessonResponse = lessonOutService.getLessonResponse(lessonId);

return StudentLessonAbsenteeismResponse.builder()
return StudentsLessonAbsenteeismResponse.builder()
.id(absenteeismEntity.getId())
.week(absenteeismEntity.getWeek())
.theoreticalHoursState(absenteeismEntity.getTheoreticalHoursState())
.theoreticalHours(absenteeismEntity.getTheoreticalHours())
.practiceHoursState(absenteeismEntity.getPracticeHoursState())
.practiceHours(absenteeismEntity.getPracticeHours())
.status(absenteeismEntity.getStatus())
.createdDate(SisUtil.getFormattedDateTime(absenteeismEntity.getCreatedDate()))
Expand All @@ -88,8 +167,8 @@ public StudentLessonAbsenteeismResponse entityToResponse(final StudentLessonAbse
.lessonResponse(lessonResponse).build();
}

public List<StudentLessonAbsenteeismResponse> entitiesToResponses(final List<StudentLessonAbsenteeismEntity> absenteeismEntities) {
List<StudentLessonAbsenteeismResponse> absenteeismResponses = new ArrayList<>();
public List<StudentsLessonAbsenteeismResponse> entitiesToResponses(final List<StudentsLessonAbsenteeismEntity> absenteeismEntities) {
List<StudentsLessonAbsenteeismResponse> absenteeismResponses = new ArrayList<>();
absenteeismEntities.forEach(absenteeismEntity -> absenteeismResponses.add(entityToResponse(absenteeismEntity)));
return absenteeismResponses;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.graduationproject.studentinformationsystem.university.absenteeism.model.dto.response;

import com.graduationproject.studentinformationsystem.common.model.dto.response.SisBaseResponse;
import com.graduationproject.studentinformationsystem.university.absenteeism.model.enums.StudentLessonAbsenteeismHoursState;
import com.graduationproject.studentinformationsystem.university.lesson.common.model.dto.response.LessonResponse;
import com.graduationproject.studentinformationsystem.university.student.model.dto.response.StudentInfoResponse;
import com.graduationproject.studentinformationsystem.university.teacher.model.dto.response.TeacherInfoResponse;
import lombok.Getter;
import lombok.experimental.SuperBuilder;

@Getter
@SuperBuilder
public class StudentLessonsAbsenteeismResponse extends SisBaseResponse {

private String id;
private StudentLessonAbsenteeismHoursState theoreticalHoursState;
private Integer currentTheoreticalHours;
private Integer balanceTheoreticalHours;
private StudentLessonAbsenteeismHoursState practiceHoursState;
private Integer currentPracticeHours;
private Integer balancePracticeHours;

private TeacherInfoResponse teacherResponse;
private StudentInfoResponse studentResponse;
private LessonResponse lessonResponse;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.graduationproject.studentinformationsystem.university.absenteeism.model.dto.response;

import com.graduationproject.studentinformationsystem.common.model.dto.response.SisBaseResponse;
import com.graduationproject.studentinformationsystem.university.absenteeism.model.enums.StudentLessonAbsenteeismHoursState;
import com.graduationproject.studentinformationsystem.university.absenteeism.model.enums.StudentLessonAbsenteeismStatus;
import com.graduationproject.studentinformationsystem.university.lesson.common.model.dto.response.LessonResponse;
import com.graduationproject.studentinformationsystem.university.student.model.dto.response.StudentInfoResponse;
Expand All @@ -10,11 +11,13 @@

@Getter
@SuperBuilder
public class StudentLessonAbsenteeismResponse extends SisBaseResponse {
public class StudentsLessonAbsenteeismResponse extends SisBaseResponse {

private String id;
private Integer week;
private StudentLessonAbsenteeismHoursState theoreticalHoursState;
private Integer theoreticalHours;
private StudentLessonAbsenteeismHoursState practiceHoursState;
private Integer practiceHours;
private StudentLessonAbsenteeismStatus status;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.graduationproject.studentinformationsystem.university.absenteeism.model.entity;

import com.graduationproject.studentinformationsystem.university.absenteeism.model.enums.StudentLessonAbsenteeismHoursState;
import com.graduationproject.studentinformationsystem.university.absenteeism.model.enums.StudentLessonAbsenteeismStatus;
import lombok.Getter;
import lombok.experimental.SuperBuilder;
Expand All @@ -15,7 +16,9 @@ public class StudentLessonAbsenteeismSaveEntity {
private Long studentId;
private Long lessonId;
private Integer week;
private StudentLessonAbsenteeismHoursState theoreticalHoursState;
private Integer maxTheoreticalHours;
private StudentLessonAbsenteeismHoursState practiceHoursState;
private Integer maxPracticeHours;
private StudentLessonAbsenteeismStatus status;
private Long createdUserId;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.graduationproject.studentinformationsystem.university.absenteeism.model.entity;

import com.graduationproject.studentinformationsystem.university.absenteeism.model.enums.StudentLessonAbsenteeismHoursState;
import com.graduationproject.studentinformationsystem.university.absenteeism.model.enums.StudentLessonAbsenteeismStatus;
import lombok.Getter;
import lombok.experimental.SuperBuilder;
Expand All @@ -11,7 +12,9 @@
public class StudentLessonAbsenteeismUpdateEntity {

private String id;
private StudentLessonAbsenteeismHoursState theoreticalHoursState;
private Integer theoreticalHours;
private StudentLessonAbsenteeismHoursState practiceHoursState;
private Integer practiceHours;
private StudentLessonAbsenteeismStatus status;
private Long modifiedUserId;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.graduationproject.studentinformationsystem.university.absenteeism.model.entity;

import com.graduationproject.studentinformationsystem.common.model.entity.SisBaseEntity;
import com.graduationproject.studentinformationsystem.university.absenteeism.model.enums.StudentLessonAbsenteeismHoursState;
import com.graduationproject.studentinformationsystem.university.absenteeism.model.enums.StudentLessonAbsenteeismStatus;
import lombok.Getter;
import lombok.experimental.SuperBuilder;

@Getter
@SuperBuilder
public class StudentLessonsAbsenteeismEntity extends SisBaseEntity {

private String id;
private Long teacherId;
private Long studentId;
private Long lessonId;
private Integer week;
private StudentLessonAbsenteeismHoursState theoreticalHoursState;
private Integer theoreticalHours;
private Integer maxTheoreticalHours;
private StudentLessonAbsenteeismHoursState practiceHoursState;
private Integer practiceHours;
private Integer maxPracticeHours;
private StudentLessonAbsenteeismStatus status;
}
Loading

0 comments on commit 3ccdc50

Please sign in to comment.