Skip to content

Commit

Permalink
Student Lesson API and Registration API | SIS-112 (#61)
Browse files Browse the repository at this point in the history
* longListToString and longArrayToLongList Methods Have Been Added to SisUtil Class

* StudentLessonMapping Class Have Been Created

* Student Lesson Entity Classes Have Been Created

* StudentLessonException Class Have Been Created

* Student Lesson Response Classes Have Been Created

* Student Lesson Request Classes Have Been Created

* Student Lesson Converter Class Has Been Created

* StudentOutService Classes Have Been Created

* Student Lesson Repository Classes Have Been Created

* Student Lesson Service Classes Have Been Created

* Student Lesson Controller Classes Have Been Created

* StudentLessonRegistrationMapping Class Has Been Created

* StudentLessonRegistrationException Class Has Been Created

* StudentLessonRegistrationStatus Enum Class Has Been Created

* StudentLessonRegistrationEntity Class Has Been Created

* Student Lesson Registration Request Classes Have Been Created

* Student Lesson Registration Response Classes Have Been Created

* StudentLessonRegistrationInfoConverter Class Has Been Created

* Student Lesson Registration Repository Classes Have Been Created

* Student Lesson Registration Service Classes Have Been Created

* Student Lesson Registration Controller Classes Have Been Created

* STUDENT_LESSON_API_TAG and STUDENT_LESSON_REGISTRATION_API_TAG Have Been Added to SisSwaggerConfiguration Class

* STUDENT_LESSON and STUDENT_LESSON_REGISTRATION Endpoints Have Been Added to SisControllerEndpoint Class
  • Loading branch information
agitrubard authored Feb 25, 2022
1 parent 13baa03 commit 417d151
Show file tree
Hide file tree
Showing 44 changed files with 1,749 additions and 20 deletions.
47 changes: 27 additions & 20 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<commons.validator.version>1.7</commons.validator.version>
<javax.mail.version>1.6.2</javax.mail.version>
<spring-security-crypto.version>5.6.0</spring-security-crypto.version>
<gson.version>2.9.0</gson.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -129,26 +130,32 @@
</dependency>

<dependency>
<groupId>commons-validator</groupId>
<artifactId>commons-validator</artifactId>
<version>${commons.validator.version}</version>
</dependency>

<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
<version>${javax.mail.version}</version>
</dependency>

<!--Those Dependencies are for Hikari slf4j Error!-->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.32</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<groupId>commons-validator</groupId>
<artifactId>commons-validator</artifactId>
<version>${commons.validator.version}</version>
</dependency>

<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
<version>${javax.mail.version}</version>
</dependency>

<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>${gson.version}</version>
</dependency>

<!--Those Dependencies are for Hikari slf4j Error!-->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.32</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.2.7</version>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public class SisSwaggerConfiguration {
public static final String EXAM_SCHEDULE_FILE_API_TAG = "Exam Schedule File Controller";
public static final String LESSON_SCHEDULE_FILE_API_TAG = "Lesson Schedule File Controller";
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 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 @@ -44,6 +46,8 @@ public Docket api() {
new Tag(EXAM_SCHEDULE_FILE_API_TAG, "UNIV_EXAM_SCHEDULE_FILE"),
new Tag(LESSON_SCHEDULE_FILE_API_TAG, "UNIV_LESSON_SCHEDULE_FILE"),
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(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
@@ -1,7 +1,10 @@
package com.graduationproject.studentinformationsystem.common.util;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import org.apache.commons.lang3.BooleanUtils;

import java.lang.reflect.Type;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
Expand Down Expand Up @@ -104,4 +107,14 @@ public static boolean integerToBoolean(final Integer integer) {
public static Integer booleanToInteger(final Boolean bool) {
return BooleanUtils.toIntegerObject(bool);
}

public static String longListToString(final List<Long> values) {
return new Gson().toJson(values);
}

public static List<Long> longArrayToLongList(final String values) {
Type type = new TypeToken<List<Long>>() {
}.getType();
return new Gson().fromJson(values, type);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@ public static class Path {
private Path() {
}

private static final String REGISTRATION = "/registration";

public static final String FACULTY = "/faculty";
public static final String DEPARTMENT = "/department";
public static final String LESSON = "/lesson";
public static final String EXAM_SCHEDULE_FILE = "/exam-schedule-file";
public static final String LESSON_SCHEDULE_FILE = "/lesson-schedule-file";
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 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
@@ -0,0 +1,48 @@
package com.graduationproject.studentinformationsystem.university.lesson.student.common.controller;

import com.graduationproject.studentinformationsystem.common.util.controller.response.SisApiResponse;
import com.graduationproject.studentinformationsystem.common.util.controller.response.SisBaseApiResponse;
import com.graduationproject.studentinformationsystem.common.util.exception.SisAlreadyException;
import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException;
import com.graduationproject.studentinformationsystem.common.util.validation.id.StudentID;
import com.graduationproject.studentinformationsystem.university.lesson.student.common.controller.endpoint.StudentLessonControllerEndpoint;
import com.graduationproject.studentinformationsystem.university.lesson.student.common.model.dto.response.StudentLessonsResponse;
import com.graduationproject.studentinformationsystem.university.lesson.student.common.service.StudentLessonService;
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 static com.graduationproject.studentinformationsystem.common.config.SisSwaggerConfiguration.STUDENT_LESSON_API_TAG;
import static com.graduationproject.studentinformationsystem.common.util.controller.endpoint.SisControllerEndpoint.Path.STUDENT_LESSON;
import static com.graduationproject.studentinformationsystem.common.util.controller.response.SisResponseUtil.successResponse;

@RestController
@RequestMapping(STUDENT_LESSON)
@Api(tags = STUDENT_LESSON_API_TAG)
@RequiredArgsConstructor
public class StudentLessonController {

private final StudentLessonService lessonService;

@GetMapping(StudentLessonControllerEndpoint.GET_BY_STUDENT_ID)
@ApiOperation(value = "Get Student All Lessons By Student ID")
public ResponseEntity<SisBaseApiResponse<StudentLessonsResponse>> getStudentLessonsById(
@PathVariable @StudentID final Long studentId)
throws SisNotExistException {

final StudentLessonsResponse lessonsResponse = lessonService.getStudentLessonsById(studentId);
return successResponse(lessonsResponse);
}

@DeleteMapping(StudentLessonControllerEndpoint.DELETE_BY_STUDENT_ID)
@ApiOperation(value = "Delete Student All Lessons By Student ID")
public ResponseEntity<SisApiResponse> deleteStudentLessons(
@PathVariable @StudentID final Long studentId)
throws SisAlreadyException, SisNotExistException {

lessonService.deleteStudentLessons(studentId);
return successResponse();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.graduationproject.studentinformationsystem.university.lesson.student.common.controller.endpoint;

public class StudentLessonControllerEndpoint {

private StudentLessonControllerEndpoint() {
}

private static final String STUDENT_ID = "/{studentId}";
public static final String GET_BY_STUDENT_ID = "/get" + STUDENT_ID;
public static final String DELETE_BY_STUDENT_ID = "/delete" + STUDENT_ID;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package com.graduationproject.studentinformationsystem.university.lesson.student.common.model.dto.converter;

import com.graduationproject.studentinformationsystem.common.util.SisUtil;
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.model.dto.response.StudentLessonResponse;
import com.graduationproject.studentinformationsystem.university.lesson.student.common.model.dto.response.StudentLessonsResponse;
import com.graduationproject.studentinformationsystem.university.lesson.student.common.model.entity.StudentLessonEntity;
import com.graduationproject.studentinformationsystem.university.lesson.student.common.model.entity.StudentLessonSaveEntity;
import com.graduationproject.studentinformationsystem.university.student.model.dto.response.StudentInfoResponse;
import com.graduationproject.studentinformationsystem.university.student.service.StudentOutService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Component
@RequiredArgsConstructor
public class StudentLessonInfoConverter {

private final StudentOutService studentOutService;
private final LessonOutService lessonOutService;

public StudentLessonSaveEntity generateSaveEntity(final Long studentId,
final Long lessonId,
final Long operationUserId) {

return StudentLessonSaveEntity.builder()
.studentId(studentId)
.lessonId(lessonId)
.createdUserId(operationUserId)
.createdDate(new Date()).build();
}

public StudentLessonResponse entityToResponse(final StudentLessonEntity studentLessonEntity) {

final StudentInfoResponse studentInfoResponse = getStudentInfoResponse(studentLessonEntity.getStudentId());
final LessonResponse lessonResponse = getLessonResponse(studentLessonEntity.getLessonId());

return StudentLessonResponse.builder()
.createdUserId(studentLessonEntity.getCreatedUserId())
.createdDate(SisUtil.getFormattedDateTime(studentLessonEntity.getCreatedDate()))
.studentInfoResponse(studentInfoResponse)
.lessonResponse(lessonResponse).build();
}

public StudentLessonsResponse entitiesToResponse(final List<StudentLessonEntity> studentLessonEntities) {
if (studentLessonEntities.isEmpty()) {
return null;
}

final StudentInfoResponse studentInfoResponse = getStudentInfoResponse(studentLessonEntities.get(0).getStudentId());
final List<LessonResponse> lessonResponses = new ArrayList<>();

studentLessonEntities.forEach(studentLessonEntity -> {
final LessonResponse lessonResponse = getLessonResponse(studentLessonEntity.getLessonId());
lessonResponses.add(lessonResponse);
});

return StudentLessonsResponse.builder()
.createdUserId(studentLessonEntities.get(0).getCreatedUserId())
.createdDate(SisUtil.getFormattedDateTime(studentLessonEntities.get(0).getCreatedDate()))
.lessonsResponses(lessonResponses)
.studentInfoResponse(studentInfoResponse).build();
}

private StudentInfoResponse getStudentInfoResponse(Long studentId) {
return studentOutService.getStudentInfoResponse(studentId);
}

private LessonResponse getLessonResponse(Long lessonId) {
return lessonOutService.getLessonResponse(lessonId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.graduationproject.studentinformationsystem.university.lesson.student.common.model.dto.request;

import lombok.Getter;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.io.Serial;
import java.io.Serializable;

@Getter
public class StudentLessonDeleteRequest implements Serializable {

@Serial
private static final long serialVersionUID = 8186474487495643349L;

@Valid
@NotNull
private StudentLessonInfoRequest studentLessonInfoRequest;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.graduationproject.studentinformationsystem.university.lesson.student.common.model.dto.request;

import com.graduationproject.studentinformationsystem.common.util.validation.id.LessonID;
import com.graduationproject.studentinformationsystem.common.util.validation.id.StudentID;
import lombok.Getter;

import javax.validation.constraints.NotNull;
import java.io.Serial;
import java.io.Serializable;

@Getter
public class StudentLessonInfoRequest implements Serializable {

@Serial
private static final long serialVersionUID = -3737062791585675014L;

@NotNull
@StudentID
private Long studentId;

@NotNull
@LessonID
private Long lessonId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.graduationproject.studentinformationsystem.university.lesson.student.common.model.dto.request;

import com.graduationproject.studentinformationsystem.common.model.dto.request.SisOperationInfoRequest;
import lombok.Getter;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.io.Serial;
import java.io.Serializable;

@Getter
public class StudentLessonSaveRequest implements Serializable {

@Serial
private static final long serialVersionUID = -7325837862878819492L;

@Valid
@NotNull
private StudentLessonInfoRequest studentLessonInfoRequest;

@Valid
@NotNull
private SisOperationInfoRequest operationInfoRequest;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.graduationproject.studentinformationsystem.university.lesson.student.common.model.dto.response;

import com.graduationproject.studentinformationsystem.university.lesson.common.model.dto.response.LessonResponse;
import com.graduationproject.studentinformationsystem.university.student.model.dto.response.StudentInfoResponse;
import lombok.Getter;
import lombok.experimental.SuperBuilder;

@Getter
@SuperBuilder
public class StudentLessonResponse {

private Long createdUserId;
private String createdDate;

private StudentInfoResponse studentInfoResponse;
private LessonResponse lessonResponse;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.graduationproject.studentinformationsystem.university.lesson.student.common.model.dto.response;

import com.graduationproject.studentinformationsystem.university.lesson.common.model.dto.response.LessonResponse;
import com.graduationproject.studentinformationsystem.university.student.model.dto.response.StudentInfoResponse;
import lombok.Getter;
import lombok.experimental.SuperBuilder;

import java.util.List;

@Getter
@SuperBuilder
public class StudentLessonsResponse {

private Long createdUserId;
private String createdDate;

private StudentInfoResponse studentInfoResponse;
private List<LessonResponse> lessonsResponses;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.graduationproject.studentinformationsystem.university.lesson.student.common.model.entity;

import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
public class StudentLessonDeleteEntity {

private Long studentId;
private Long lessonId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.graduationproject.studentinformationsystem.university.lesson.student.common.model.entity;

import lombok.Builder;
import lombok.Getter;

import java.util.Date;

@Getter
@Builder
public class StudentLessonEntity {

private Long studentId;
private Long lessonId;
private Long createdUserId;
private Date createdDate;
}
Loading

0 comments on commit 417d151

Please sign in to comment.