Skip to content

Commit

Permalink
Merge pull request #16 from Harsh-Srivastav123/update-sessionDetails
Browse files Browse the repository at this point in the history
minor changes
  • Loading branch information
Harsh-Srivastav123 authored Apr 16, 2024
2 parents e3f22c1 + 014e084 commit adf2fc4
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 8 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ Before you begin, make sure you have the following installed:
- Apache Maven
- Vertex AI Configuartion
- Cloudinary API Key and Secret (for profile image management)
- You can also access from deployment server.http://65.2.175.178:8080/
- You can also access from deployment server.http://43.205.68.79:8080/


Expand Down Expand Up @@ -209,7 +209,7 @@ Please check back soon for the completed Postman collection, which will provide
### Swagger API Documentation
QuizApp provides Swagger for easy API documentation and testing. You can access the Swagger UI to interact with the APIs as follows:
http://65.2.175.178:8080/swagger-ui/index.html
http://43.205.68.79:8080/swagger-ui/index.html
```shell
http://localhost:8080/swagger-ui.html
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.Duration;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.temporal.Temporal;
import java.util.*;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -46,6 +50,7 @@ public class SessionService {
@Autowired
ModelMapper modelMapper;

public record sessionMessage(String message, Long timeLeft){}

public SessionDTO createSession(SessionDTO sessionDTO) {
List<QuestionDTO> updatedQuestionList=new ArrayList<>();
Expand Down Expand Up @@ -119,7 +124,7 @@ private Date calculateExpirationTime(int expirationTime) {
return new Date(calendar.getTime().getTime());
}

public SessionDTO getSessionDetails(Integer sessionId) {
public Object getSessionDetails(Integer sessionId) {
log.info(sessionId.toString());
// log.info(sessionId);
// if (sessionId.equals("all")) {
Expand All @@ -129,13 +134,24 @@ public SessionDTO getSessionDetails(Integer sessionId) {
//Collections.singletonList(sessionDAO.findById(Integer.parseInt(sessionId)).get());
if (!sessionDAO.existsById(sessionId)) {
//throw exception
throw new CustomException("Unable to find sessionDetails check the sessionId carefully");
throw new CustomException("Session id not exist check the carefully");
}

Session session=sessionDAO.findById(sessionId).get();

Date currTimeStamp=new Date();
if(currTimeStamp.before(session.getStartTimeStamp())){
// log.info("reach here");
// Duration duration=Duration.between((Temporal) session.getStartTimeStamp(), (Temporal) currTimeStamp);
LocalDateTime dateTime1 = session.getStartTimeStamp().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
LocalDateTime dateTime2 = currTimeStamp.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
return new sessionMessage("Session has not started yet !!",Duration.between(dateTime2,dateTime1).toMinutes() );
}

//rank changes handle here
// return Collections.singletonList(modelMapper.map(sessionDAO.findById(Integer.parseInt(sessionId)).get(), SessionDTO.class));

Session session=sessionDAO.findById(sessionId).get();

List<SessionUser> sessionUserListAttempted=new ArrayList<>();
List<SessionUser> sessionUserListNonAttempted=new ArrayList<>();
for(SessionUser sessionUser:session.getSessionUserList()){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public ResponseEntity<Message> createSession(@RequestBody SessionDTO session){
}

@GetMapping("/session/{sessionId}")
public ResponseEntity<SessionDTO> getSessionDetails(@PathVariable Integer sessionId)
public ResponseEntity<Object> getSessionDetails(@PathVariable Integer sessionId)
{
return new ResponseEntity<>(sessionService.getSessionDetails(sessionId),HttpStatus.OK);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/example/quizapp/QuizApp/entity/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ public class Session {

String dateAndTime ;

@JsonIgnore
// @JsonIgnore
Date startTimeStamp;

@JsonIgnore
// @JsonIgnore
Date expiryTimeStamp;

Integer delayDuration;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.quizapp.QuizApp.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
Expand All @@ -16,6 +17,7 @@ public class QuestionDTO {
String options4;
@JsonProperty( access = JsonProperty.Access.WRITE_ONLY)
String rightAnswer;
@JsonIgnore
Integer rightOption;
String category;
String topic;
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ [email protected]
spring.mail.password=dyxwysgcrtlszoys
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true

0 comments on commit adf2fc4

Please sign in to comment.