Skip to content

Commit

Permalink
Student Lesson Note API | SIS-118 (#68)
Browse files Browse the repository at this point in the history
* errorWhenGettingAllByStudentId and errorWhenGettingAllByStudentId Methods Have Been Added to SisErrorLogMessageUtil

* foundAllByLessonId and foundAllByStudentId Methods Have Been Added to SisInfoLogMessageUtil

* notFoundAllByStudentId and notFoundAllByLessonId Methods Have Been Added to SisWarnLogMessageUtil

* getTeacherIdByLessonId Method Has Been Added to TeacherLessonRepository

* StudentLessonNoteMapping Class Has Been Created

* StudentLessonNoteException Class Has Been Created

* StudentLessonNoteUtil Class Has Been Created

* StudentLessonNoteStatus Enum Class Has Been Created

* StudentLesson Note Entity Classes Have Been Created

* StudentLesson Note Request Classes Have Been Created

* StudentLessonNoteResponse Class Has Been Created

* StudentLessonNoteInfoConverter Class Has Been Created

* TeacherLessonOutService Class Has Been Created for getTeacherIdByLessonId Method

* STUDENT_LESSON_NOTE_API_TAG Has Been Added to SisSwaggerConfiguration Class

* STUDENT_LESSON_NOTE Endpoint Has Been Added to SisControllerEndpoint Class

* StudentLessonNote Repository Classes Have Been Created

* StudentLessonNote Service Classes Have Been Created

* StudentLessonNote Out Service Classes Have Been Created

* StudentLessonNoteControllerEndpoint Class Has Been Created

* StudentLessonNoteController Class Has Been Created

* StudentLessonNoteOutService Has Been Integrated to StudentLessonRegistrationService/approveStudentLessonRegistration Method
  • Loading branch information
agitrubard authored Mar 20, 2022
1 parent 9fa3256 commit 139f17f
Show file tree
Hide file tree
Showing 35 changed files with 1,227 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class SisSwaggerConfiguration {
public static final String STUDENT_API_TAG = "Student Controller";
public static final String STUDENT_LESSON_API_TAG = "Student Lesson Controller";
public static final String STUDENT_LESSON_REGISTRATION_API_TAG = "Student Lesson Registration Controller";
public static final String STUDENT_LESSON_NOTE_API_TAG = "Student Lesson Note Controller";
public static final String TEACHER_API_TAG = "Teacher Controller";
public static final String TEACHER_LESSON_API_TAG = "Teacher Lesson Controller";
public static final String OFFICER_API_TAG = "Officer Controller";
Expand All @@ -53,6 +54,7 @@ public Docket api() {
new Tag(STUDENT_API_TAG, "STUDENT_ACADEMIC_INFO & STUDENT_PERSONAL_INFO"),
new Tag(STUDENT_LESSON_API_TAG, "STUDENT_LESSON"),
new Tag(STUDENT_LESSON_REGISTRATION_API_TAG, "STUDENT_LESSON_REGISTRATION"),
new Tag(STUDENT_LESSON_NOTE_API_TAG, "STUDENT_LESSON_NOTE"),
new Tag(TEACHER_API_TAG, "TEACHER_ACADEMIC_INFO & TEACHER_PERSONAL_INFO"),
new Tag(TEACHER_LESSON_API_TAG, "TEACHER_LESSON"),
new Tag(OFFICER_API_TAG, "OFFICER_ACADEMIC_INFO & OFFICER_PERSONAL_INFO"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ private Path() {

private static final String REGISTRATION = "/registration";
private static final String PASSWORD_OPERATION = "/password-operation";
private static final String NOTE = "/note";

public static final String FACULTY = "/faculty";
public static final String DEPARTMENT = "/department";
Expand All @@ -21,6 +22,7 @@ private Path() {
public static final String STUDENT = "/student";
public static final String STUDENT_LESSON = STUDENT + LESSON;
public static final String STUDENT_LESSON_REGISTRATION = STUDENT_LESSON + REGISTRATION;
public static final String STUDENT_LESSON_NOTE = STUDENT + LESSON + NOTE;
public static final String TEACHER = "/teacher";
public static final String TEACHER_LESSON = TEACHER + LESSON;
public static final String OFFICER = "/officer";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ public void errorWhenGettingAllByStatus(final String status) {
log.error("Error When Getting {}s by Status! status:{}", apiName, status);
}

public void errorWhenGettingAllByStudentId(final Long studentId) {
log.error("Error When Getting {}s by Student ID! studentId:{}", apiName, studentId);
}

public void errorWhenGettingAllByLessonId(final Long lessonId) {
log.error("Error When Getting {}s by Lesson ID! lessonId:{}", apiName, lessonId);
}

public void errorWhenGettingAllIdsByDepartmentId(final Long departmentId) {
log.error("Error When Getting {} IDs by Department ID! departmentId:{}", apiName, departmentId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ public void foundAllIds() {
log.info("{} IDs Found!", apiName);
}

public void foundAllByLessonId(final Long lessonId) {
log.info("{}s Found by Lesson ID! lessonId:{}", apiName, lessonId);
}

public void foundAllByStudentId(final Long studentId) {
log.info("{}s Found by Student ID! studentId:{}", apiName, studentId);
}

public void foundAllByStatus(final String status) {
log.info("{}s Found by Status! status:{}", apiName, status);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ public void notFoundByIdAndStatus(final Long id, final String status) {
log.warn("{} Not Found by ID! id:{} status:{}", apiName, id, status);
}

public void notFoundAllByStudentId(final Long lessonId) {
log.warn("{}s Not Found By Student ID! lessonId:{}", apiName, lessonId);
}

public void notFoundAllByLessonId(final Long lessonId) {
log.warn("{}s Not Found By Lesson ID! lessonId:{}", apiName, lessonId);
}

public void notFoundAllIds() {
log.warn("{} IDs Not Found!", apiName);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.graduationproject.studentinformationsystem.university.lesson.student.registration.service.impl;

import com.graduationproject.studentinformationsystem.common.model.dto.request.SisOperationInfoRequest;
import com.graduationproject.studentinformationsystem.common.util.exception.SisAlreadyException;
import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException;
import com.graduationproject.studentinformationsystem.university.lesson.common.model.dto.response.LessonResponse;
import com.graduationproject.studentinformationsystem.university.lesson.common.service.LessonOutService;
import com.graduationproject.studentinformationsystem.university.lesson.student.common.service.StudentLessonOutService;
import com.graduationproject.studentinformationsystem.university.lesson.student.registration.model.dto.converter.StudentLessonRegistrationInfoConverter;
Expand All @@ -15,6 +17,7 @@
import com.graduationproject.studentinformationsystem.university.lesson.student.registration.model.exception.StudentLessonRegistrationException;
import com.graduationproject.studentinformationsystem.university.lesson.student.registration.repository.StudentLessonRegistrationRepository;
import com.graduationproject.studentinformationsystem.university.lesson.student.registration.service.StudentLessonRegistrationService;
import com.graduationproject.studentinformationsystem.university.note.service.StudentLessonNoteOutService;
import com.graduationproject.studentinformationsystem.university.student.service.StudentOutService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
Expand All @@ -28,6 +31,7 @@ public class StudentLessonRegistrationServiceImpl implements StudentLessonRegist
private final StudentOutService studentOutService;
private final LessonOutService lessonOutService;
private final StudentLessonOutService studentLessonOutService;
private final StudentLessonNoteOutService studentLessonNoteOutService;

private final StudentLessonRegistrationRepository studentLessonRegistrationRepository;
private final StudentLessonRegistrationInfoConverter studentLessonRegistrationInfoConverter;
Expand Down Expand Up @@ -87,6 +91,11 @@ public StudentLessonRegistrationDetailResponse approveStudentLessonRegistration(

if (StudentLessonRegistrationStatus.APPROVED.equals(registrationDetailResponse.getStatus())) {
studentLessonOutService.saveStudentLessons(registrationDetailResponse);

final Long studentId = registrationDetailResponse.getStudentInfoResponse().getStudentId();
final List<LessonResponse> lessonResponses = registrationDetailResponse.getLessonResponses();
final SisOperationInfoRequest operationInfoRequest = approveRequest.getOperationInfoRequest();
studentLessonNoteOutService.saveStudentLessonsNotesRegistrations(studentId, lessonResponses, operationInfoRequest);
}

return registrationDetailResponse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ public interface TeacherLessonRepository {
void deleteTeacherLesson(TeacherLessonDeleteEntity deleteLessonEntity);

boolean isTeacherLessonExist(Long teacherId, Long lessonId);

Long getTeacherIdByLessonId(Long lessonId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,18 @@ public boolean isTeacherLessonExist(final Long teacherId, final Long lessonId) {
throw new SisDatabaseException(exception);
}
}

@Override
public Long getTeacherIdByLessonId(Long lessonId) {
try (final Connection connection = sql2o.open(); final Query query = connection.createQuery(GET_TEACHER_ID_BY_LESSON_ID)) {

return query.addParameter(LESSON_ID.getModelName(), lessonId)
.setColumnMappings(COLUMN_MAPPINGS)
.executeScalar(Long.class);

} catch (Exception exception) {
error.errorWhenGetting();
throw new SisDatabaseException(exception);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,11 @@ private TeacherLessonSqlScripts() {
TEACHER_ID.getModelName(),
LESSON_ID.getColumnName(),
LESSON_ID.getModelName());

/**
* SELECT TEACHER_ID FROM TEACHER_LESSON WHERE LESSON_ID=:lessonId;
*/
public static final String GET_TEACHER_ID_BY_LESSON_ID =
sqlBuilder.delete(0, sqlBuilder.length())
.append("SELECT TEACHER_ID FROM TEACHER_LESSON WHERE LESSON_ID=:lessonId").toString();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.graduationproject.studentinformationsystem.university.lesson.teacher.service;

public interface TeacherLessonOutService {

Long getTeacherIdByLessonId(Long lessonId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.graduationproject.studentinformationsystem.university.lesson.teacher.service.impl;

import com.graduationproject.studentinformationsystem.university.lesson.teacher.repository.TeacherLessonRepository;
import com.graduationproject.studentinformationsystem.university.lesson.teacher.service.TeacherLessonOutService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class TeacherLessonOutServiceImpl implements TeacherLessonOutService {

private final TeacherLessonRepository teacherLessonRepository;

@Override
public Long getTeacherIdByLessonId(Long lessonId) {
return teacherLessonRepository.getTeacherIdByLessonId(lessonId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package com.graduationproject.studentinformationsystem.university.note.controller;

import com.graduationproject.studentinformationsystem.common.util.controller.response.SisBaseApiResponse;
import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException;
import com.graduationproject.studentinformationsystem.university.note.controller.endpoint.StudentLessonNoteControllerEndpoint;
import com.graduationproject.studentinformationsystem.university.note.model.dto.request.StudentLessonFinalNoteUpdateRequest;
import com.graduationproject.studentinformationsystem.university.note.model.dto.request.StudentLessonMidtermNoteUpdateRequest;
import com.graduationproject.studentinformationsystem.university.note.model.dto.request.StudentLessonResitNoteUpdateRequest;
import com.graduationproject.studentinformationsystem.university.note.model.dto.response.StudentLessonNoteResponse;
import com.graduationproject.studentinformationsystem.university.note.service.StudentLessonNoteService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

import static com.graduationproject.studentinformationsystem.common.config.SisSwaggerConfiguration.STUDENT_LESSON_NOTE_API_TAG;
import static com.graduationproject.studentinformationsystem.common.util.controller.endpoint.SisControllerEndpoint.Path.STUDENT_LESSON_NOTE;
import static com.graduationproject.studentinformationsystem.common.util.controller.response.SisResponseUtil.successResponse;

@RestController
@RequestMapping(STUDENT_LESSON_NOTE)
@Api(tags = STUDENT_LESSON_NOTE_API_TAG)
@RequiredArgsConstructor
public class StudentLessonNoteController {


private final StudentLessonNoteService studentLessonNoteService;

@GetMapping(StudentLessonNoteControllerEndpoint.GET_ALL_BY_LESSON_ID)
@ApiOperation(value = "Get All Students Lessons Notes By Lesson ID")
public ResponseEntity<SisBaseApiResponse<List<StudentLessonNoteResponse>>> getAllStudentsLessonsNotesByLessonId(
@PathVariable final Long lessonId)
throws SisNotExistException {

final List<StudentLessonNoteResponse> noteResponses = studentLessonNoteService.getAllStudentsLessonsNotesByLessonId(lessonId);
return successResponse(noteResponses);
}

@GetMapping(StudentLessonNoteControllerEndpoint.GET_ALL_BY_STUDENT_ID)
@ApiOperation(value = "Get All Student Lessons Notes By Student ID")
public ResponseEntity<SisBaseApiResponse<List<StudentLessonNoteResponse>>> getAllStudentLessonsNotesByStudentId(
@PathVariable final Long studentId)
throws SisNotExistException {

final List<StudentLessonNoteResponse> noteResponses = studentLessonNoteService.getAllStudentLessonsNotesByStudentId(studentId);
return successResponse(noteResponses);
}

@PutMapping(StudentLessonNoteControllerEndpoint.MIDTERM)
@ApiOperation(value = "Update Student Lesson Midterm Note")
public ResponseEntity<SisBaseApiResponse<StudentLessonNoteResponse>> updateStudentLessonMidtermNote(
@RequestBody @Valid final StudentLessonMidtermNoteUpdateRequest updateRequest)
throws SisNotExistException {

final StudentLessonNoteResponse noteResponse = studentLessonNoteService.updateStudentLessonMidtermNote(updateRequest);
return successResponse(noteResponse);
}

@PutMapping(StudentLessonNoteControllerEndpoint.FINAL)
@ApiOperation(value = "Update Student Lesson Final Note")
public ResponseEntity<SisBaseApiResponse<StudentLessonNoteResponse>> updateStudentLessonFinalNote(
@RequestBody @Valid final StudentLessonFinalNoteUpdateRequest updateRequest)
throws SisNotExistException {

final StudentLessonNoteResponse noteResponse = studentLessonNoteService.updateStudentLessonFinalNote(updateRequest);
return successResponse(noteResponse);
}

@PutMapping(StudentLessonNoteControllerEndpoint.RESIT)
@ApiOperation(value = "Update Student Lesson Resit Note")
public ResponseEntity<SisBaseApiResponse<StudentLessonNoteResponse>> updateStudentLessonResitNote(
@RequestBody final StudentLessonResitNoteUpdateRequest updateRequest)
throws SisNotExistException {

final StudentLessonNoteResponse noteResponse = studentLessonNoteService.updateStudentLessonResitNote(updateRequest);
return successResponse(noteResponse);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.graduationproject.studentinformationsystem.university.note.controller.endpoint;

public class StudentLessonNoteControllerEndpoint {

private StudentLessonNoteControllerEndpoint() {
}

private static final String ID = "/{id}";
private static final String STUDENT_ID = "/{studentId}";
private static final String LESSON_ID = "/{lessonId}";
// public static final String GET_BY_ID = "/get" + ID;
public static final String GET_ALL_BY_STUDENT_ID = "/get/student" + STUDENT_ID;
public static final String GET_ALL_BY_LESSON_ID = "/get/lesson" + LESSON_ID;
public static final String MIDTERM = "/midterm";
public static final String FINAL = "/final";
public static final String RESIT = "/resit";
}
Loading

0 comments on commit 139f17f

Please sign in to comment.