Skip to content
GitLab
Explore
Projects
Groups
Topics
Snippets
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Register
Sign in
Toggle navigation
Menu
UPSMF
examsAndAdmissions
Commits
8d1a7c4c
Commit
8d1a7c4c
authored
1 year ago
by
jay pratap singh
Browse files
Options
Download
Patches
Plain Diff
changes for exam cycle
parent
e2a475a8
main
Response_fixes
access_based_check
auxillary_apis
bug_fix_question_paper_upload
development
fee_changes
fee_workflow
github/fork/ruksana2808/filter_bug_examCycle
instituteApis_shishir
uri_access_check
1 merge request
!1
added exam cycle and student enrolment initial code
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
pom.xml
+25
-11
pom.xml
src/main/java/com/tarento/upsmf/examsAndAdmissions/controller/ExamCycleController.java
+57
-8
...mf/examsAndAdmissions/controller/ExamCycleController.java
src/main/java/com/tarento/upsmf/examsAndAdmissions/exception/ServiceException.java
+16
-0
.../upsmf/examsAndAdmissions/exception/ServiceException.java
src/main/java/com/tarento/upsmf/examsAndAdmissions/model/ExamCycle.java
+18
-2
...com/tarento/upsmf/examsAndAdmissions/model/ExamCycle.java
src/main/java/com/tarento/upsmf/examsAndAdmissions/model/dto/ExamCycleDTO.java
+13
-1
...ento/upsmf/examsAndAdmissions/model/dto/ExamCycleDTO.java
src/main/java/com/tarento/upsmf/examsAndAdmissions/service/ExamCycleService.java
+53
-2
...to/upsmf/examsAndAdmissions/service/ExamCycleService.java
with
182 additions
and
24 deletions
+182
-24
pom.xml
+
25
−
11
View file @
8d1a7c4c
...
...
@@ -21,11 +21,32 @@
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-data-jpa
</artifactId>
</dependency>
<!-- Bean Validation API -->
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-webflux
</artifactId>
<groupId>
javax.validation
</groupId>
<artifactId>
validation-api
</artifactId>
</dependency>
<!-- Hibernate Validator (implementation of the Bean Validation API) -->
<dependency>
<groupId>
org.hibernate.validator
</groupId>
<artifactId>
hibernate-validator
</artifactId>
</dependency>
<dependency>
<groupId>
org.modelmapper
</groupId>
<artifactId>
modelmapper
</artifactId>
<version>
3.0.0
</version>
</dependency>
<dependency>
<groupId>
org.postgresql
</groupId>
<artifactId>
postgresql
</artifactId>
<scope>
runtime
</scope>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-web
</artifactId>
</dependency>
<dependency>
<groupId>
org.projectlombok
</groupId>
<artifactId>
lombok
</artifactId>
...
...
@@ -48,15 +69,8 @@
<optional>
true
</optional>
</dependency>
<dependency>
<groupId>
io.r2dbc
</groupId>
<artifactId>
r2dbc-postgresql
</artifactId>
<version>
0.8.11.RELEASE
</version>
<scope>
runtime
</scope>
</dependency>
<dependency>
<groupId>
org.postgresql
</groupId>
<artifactId>
postgresql
</artifactId>
<scope>
runtime
</scope>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-web
</artifactId>
</dependency>
</dependencies>
...
...
This diff is collapsed.
Click to expand it.
src/main/java/com/tarento/upsmf/examsAndAdmissions/controller/ExamCycleController.java
+
57
−
8
View file @
8d1a7c4c
package
com.tarento.upsmf.examsAndAdmissions.controller
;
import
com.tarento.upsmf.examsAndAdmissions.exception.ServiceException
;
import
com.tarento.upsmf.examsAndAdmissions.model.ExamCycle
;
import
com.tarento.upsmf.examsAndAdmissions.model.dto.ExamCycleDTO
;
import
com.tarento.upsmf.examsAndAdmissions.service.ExamCycleService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.List
;
@RestController
@RequestMapping
(
"/exam
-c
ycle
s
"
)
@RequestMapping
(
"/
api/v1/admin/
exam
C
ycle"
)
public
class
ExamCycleController
{
@Autowired
private
ExamCycleService
examCycleService
;
@PostMapping
(
"
admin/enrollment/exam-cycles/institu
te"
)
@PostMapping
(
"
/crea
te"
)
public
ResponseEntity
<
ExamCycle
>
createExamCycle
(
@RequestBody
ExamCycleDTO
examCycleDTO
)
{
return
ResponseEntity
.
ok
(
examCycleService
.
createExamCycle
(
examCycleDTO
));
try
{
ExamCycle
createdExamCycle
=
examCycleService
.
createExamCycle
(
examCycleDTO
);
return
new
ResponseEntity
<>(
createdExamCycle
,
HttpStatus
.
CREATED
);
}
catch
(
Exception
e
)
{
throw
new
ServiceException
(
"Failed to create ExamCycle."
,
HttpStatus
.
INTERNAL_SERVER_ERROR
);
}
}
@GetMapping
@GetMapping
(
"/list"
)
public
ResponseEntity
<
List
<
ExamCycle
>>
getAllExamCycles
()
{
return
ResponseEntity
.
ok
(
examCycleService
.
getAllExamCycles
());
try
{
List
<
ExamCycle
>
examCycles
=
examCycleService
.
getAllExamCycles
();
if
(
examCycles
.
isEmpty
())
{
return
new
ResponseEntity
<>(
HttpStatus
.
NO_CONTENT
);
}
return
new
ResponseEntity
<>(
examCycles
,
HttpStatus
.
OK
);
}
catch
(
Exception
e
)
{
throw
new
ServiceException
(
"Failed to fetch all ExamCycles."
,
HttpStatus
.
INTERNAL_SERVER_ERROR
);
}
}
@GetMapping
(
"/{id}"
)
public
ResponseEntity
<
ExamCycle
>
getExamCycleById
(
@PathVariable
Long
id
)
{
return
ResponseEntity
.
ok
(
examCycleService
.
getExamCycleById
(
id
));
try
{
ExamCycle
examCycle
=
examCycleService
.
getExamCycleById
(
id
);
if
(
examCycle
==
null
)
{
throw
new
ServiceException
(
"ExamCycle not found with ID: "
+
id
,
HttpStatus
.
NOT_FOUND
);
}
return
new
ResponseEntity
<>(
examCycle
,
HttpStatus
.
OK
);
}
catch
(
ServiceException
se
)
{
throw
se
;
}
catch
(
Exception
e
)
{
throw
new
ServiceException
(
"Failed to fetch ExamCycle with ID: "
+
id
,
HttpStatus
.
INTERNAL_SERVER_ERROR
);
}
}
@DeleteMapping
(
"/delete/{id}"
)
public
ResponseEntity
<
Void
>
deleteExamCycle
(
@PathVariable
Long
id
)
{
try
{
examCycleService
.
deleteExamCycleById
(
id
);
return
new
ResponseEntity
<>(
HttpStatus
.
NO_CONTENT
);
}
catch
(
Exception
e
)
{
throw
new
ServiceException
(
"Failed to delete ExamCycle with ID: "
+
id
,
HttpStatus
.
INTERNAL_SERVER_ERROR
);
}
}
}
@PutMapping
(
"/update/{id}"
)
public
ResponseEntity
<
ExamCycle
>
updateExamCycle
(
@PathVariable
Long
id
,
@RequestBody
ExamCycleDTO
examCycleDTO
)
{
try
{
ExamCycle
updatedExamCycle
=
examCycleService
.
updateExamCycle
(
id
,
examCycleDTO
);
if
(
updatedExamCycle
==
null
)
{
throw
new
ServiceException
(
"ExamCycle not found with ID: "
+
id
,
HttpStatus
.
NOT_FOUND
);
}
return
new
ResponseEntity
<>(
updatedExamCycle
,
HttpStatus
.
OK
);
}
catch
(
ServiceException
se
)
{
throw
se
;
}
catch
(
Exception
e
)
{
throw
new
ServiceException
(
"Failed to update ExamCycle with ID: "
+
id
,
HttpStatus
.
INTERNAL_SERVER_ERROR
);
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/main/java/com/tarento/upsmf/examsAndAdmissions/exception/ServiceException.java
0 → 100644
+
16
−
0
View file @
8d1a7c4c
package
com.tarento.upsmf.examsAndAdmissions.exception
;
import
org.springframework.http.HttpStatus
;
public
class
ServiceException
extends
RuntimeException
{
private
HttpStatus
status
;
public
ServiceException
(
String
message
,
HttpStatus
status
)
{
super
(
message
);
this
.
status
=
status
;
}
public
HttpStatus
getStatus
()
{
return
status
;
}
}
This diff is collapsed.
Click to expand it.
src/main/java/com/tarento/upsmf/examsAndAdmissions/model/ExamCycle.java
+
18
−
2
View file @
8d1a7c4c
package
com.tarento.upsmf.examsAndAdmissions.model
;
import
com.tarento.upsmf.examsAndAdmissions.model.Course
;
import
com.tarento.upsmf.examsAndAdmissions.model.CourseDetails
;
import
lombok.*
;
import
javax.persistence.*
;
import
java.time.LocalDate
;
import
java.time.LocalDateTime
;
import
java.util.List
;
@Entity
...
...
@@ -21,9 +23,23 @@ public class ExamCycle {
@GeneratedValue
(
strategy
=
GenerationType
.
IDENTITY
)
private
Long
id
;
private
LocalDate
startDate
;
private
LocalDate
endDate
;
private
String
examCycleName
;
// New field
@ManyToOne
@JoinColumn
(
name
=
"course_id"
)
private
Course
course
;
// Represents the Course-ID
private
LocalDate
startDate
;
// Represents start_date
private
LocalDate
endDate
;
// Represents end_date
private
String
createdBy
;
private
LocalDateTime
createdOn
;
private
String
modifiedBy
;
private
LocalDateTime
modifiedOn
;
private
String
status
;
// Can be "Publish" or "Draft"
private
Boolean
isObsolete
;
// Represents Obselete [0/1]
@OneToMany
(
mappedBy
=
"examCycle"
,
cascade
=
CascadeType
.
ALL
)
private
List
<
CourseDetails
>
courseDetails
;
// ... rest of your code ...
}
This diff is collapsed.
Click to expand it.
src/main/java/com/tarento/upsmf/examsAndAdmissions/model/dto/ExamCycleDTO.java
+
13
−
1
View file @
8d1a7c4c
package
com.tarento.upsmf.examsAndAdmissions.model.dto
;
import
com.tarento.upsmf.examsAndAdmissions.model.dto.CourseDetailDTO
;
import
lombok.*
;
import
java.util.List
;
...
...
@@ -10,8 +11,19 @@ import java.util.List;
@NoArgsConstructor
@Builder
public
class
ExamCycleDTO
{
private
Long
id
;
private
String
examCycleName
;
private
String
startDate
;
private
String
endDate
;
private
String
createdBy
;
private
String
createdOn
;
private
String
modifiedBy
;
private
String
modifiedOn
;
private
String
status
;
private
Boolean
isObsolete
;
private
List
<
CourseDetailDTO
>
courseDetails
;
}
\ No newline at end of file
// getters and setters
}
This diff is collapsed.
Click to expand it.
src/main/java/com/tarento/upsmf/examsAndAdmissions/service/ExamCycleService.java
+
53
−
2
View file @
8d1a7c4c
...
...
@@ -33,16 +33,66 @@ public class ExamCycleService {
ExamCycle
examCycle
=
convertToEntity
(
examCycleDTO
);
return
examCycleRepository
.
save
(
examCycle
);
}
public
ExamCycle
updateExamCycle
(
Long
id
,
ExamCycleDTO
dto
)
{
ExamCycle
existingExamCycle
=
examCycleRepository
.
findById
(
id
)
.
orElseThrow
(()
->
new
EntityNotFoundException
(
"ExamCycle not found with ID: "
+
id
));
// Set updated fields from the DTO to the existingExamCycle
existingExamCycle
.
setStartDate
(
LocalDate
.
parse
(
dto
.
getStartDate
()));
existingExamCycle
.
setEndDate
(
LocalDate
.
parse
(
dto
.
getEndDate
()));
existingExamCycle
.
setExamCycleName
(
dto
.
getExamCycleName
());
existingExamCycle
.
setCreatedBy
(
dto
.
getCreatedBy
());
existingExamCycle
.
setCreatedOn
(
LocalDateTime
.
parse
(
dto
.
getCreatedOn
()));
existingExamCycle
.
setModifiedBy
(
dto
.
getModifiedBy
());
existingExamCycle
.
setModifiedOn
(
LocalDateTime
.
parse
(
dto
.
getModifiedOn
()));
existingExamCycle
.
setStatus
(
dto
.
getStatus
());
existingExamCycle
.
setIsObsolete
(
dto
.
getIsObsolete
());
List
<
CourseDetails
>
courseDetailsList
=
new
ArrayList
<>();
for
(
CourseDetailDTO
cdDto
:
dto
.
getCourseDetails
())
{
CourseDetails
cd
=
new
CourseDetails
();
Optional
<
Course
>
course
=
courseRepository
.
findById
(
cdDto
.
getCourseId
());
if
(!
course
.
isPresent
())
{
throw
new
EntityNotFoundException
(
"Course not found with ID: "
+
cdDto
.
getCourseId
());
}
cd
.
setCourse
(
course
.
get
());
List
<
Exam
>
exams
=
new
ArrayList
<>();
for
(
ExamDTO
eDto
:
cdDto
.
getExams
())
{
Exam
exam
=
new
Exam
();
exam
.
setExamName
(
eDto
.
getExamName
());
exam
.
setExamDate
(
LocalDateTime
.
parse
(
eDto
.
getExamDate
()));
exam
.
setExamDuration
(
Duration
.
parse
(
eDto
.
getExamDuration
()));
exams
.
add
(
exam
);
}
cd
.
setExams
(
exams
);
courseDetailsList
.
add
(
cd
);
}
existingExamCycle
.
setCourseDetails
(
courseDetailsList
);
return
examCycleRepository
.
save
(
existingExamCycle
);
}
public
void
deleteExamCycleById
(
Long
id
)
{
examCycleRepository
.
deleteById
(
id
);
}
private
ExamCycle
convertToEntity
(
ExamCycleDTO
dto
)
{
ExamCycle
examCycle
=
new
ExamCycle
();
examCycle
.
setStartDate
(
LocalDate
.
parse
(
dto
.
getStartDate
()));
examCycle
.
setEndDate
(
LocalDate
.
parse
(
dto
.
getEndDate
()));
examCycle
.
setExamCycleName
(
dto
.
getExamCycleName
());
examCycle
.
setCreatedBy
(
dto
.
getCreatedBy
());
examCycle
.
setCreatedOn
(
LocalDateTime
.
parse
(
dto
.
getCreatedOn
()));
examCycle
.
setModifiedBy
(
dto
.
getModifiedBy
());
examCycle
.
setModifiedOn
(
LocalDateTime
.
parse
(
dto
.
getModifiedOn
()));
examCycle
.
setStatus
(
dto
.
getStatus
());
examCycle
.
setIsObsolete
(
dto
.
getIsObsolete
());
List
<
CourseDetails
>
courseDetailsList
=
new
ArrayList
<>();
for
(
CourseDetailDTO
cdDto
:
dto
.
getCourseDetails
())
{
CourseDetails
cd
=
new
CourseDetails
();
Optional
<
Course
>
course
=
courseRepository
.
findById
(
cdDto
.
getCourseId
());
if
(
course
==
null
)
{
Optional
<
Course
>
course
=
courseRepository
.
findById
(
cdDto
.
getCourseId
());
if
(
!
course
.
isPresent
()
)
{
throw
new
EntityNotFoundException
(
"Course not found with ID: "
+
cdDto
.
getCourseId
());
}
cd
.
setCourse
(
course
.
get
());
...
...
@@ -64,6 +114,7 @@ public class ExamCycleService {
}
public
List
<
ExamCycle
>
getAllExamCycles
()
{
return
examCycleRepository
.
findAll
();
}
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Topics
Snippets