Skip to content

Commit

Permalink
Merge pull request #200 from FS-FAST-TRACK/production/v_1
Browse files Browse the repository at this point in the history
Production/v 1
  • Loading branch information
jaymar921 authored Mar 20, 2024
2 parents d7ccc89 + a41a89b commit 3087900
Show file tree
Hide file tree
Showing 33 changed files with 378 additions and 107 deletions.
6 changes: 0 additions & 6 deletions MobileApp/README.md

This file was deleted.

Empty file.
Empty file.
5 changes: 5 additions & 0 deletions WebApp/.env
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ OVERRIDE_QUESTION_TIMER_TYPEANSWER=25
OVERRIDE_QUESTION_TIMER_MULTIPLECHOICE=20
OVERRIDE_QUESTION_TIMER_TRUEORFALSE=15
BUFFER_TIME=3
OVERRIDE_POINT_EASY_ROUND=1
OVERRIDE_POINT_AVERAGE_ROUND=3
OVERRIDE_POINT_DIFFICULT_ROUND=5
OVERRIDE_POINT_CLINCHER_ROUND=5
OVERRIDE_POINT_GENERAL=1


# QUIZMASTER-ADMIN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public class QuizSettings
public int BufferTime { get; set; } = 0;

public OverrideQuestionTimer OverrideQuestionTimer { get; set;} = new();
public OverridePointSystem OverridePointSystem { get; set; } = new();
}

public class OverrideQuestionTimer
Expand All @@ -15,4 +16,14 @@ public class OverrideQuestionTimer
public int MultipleChoice { get; set; } = 0;
public int TrueOrFalse { get; set; } = 0;
}


public class OverridePointSystem
{
public int Easy { get; set; } = 1;
public int Average { get; set; } = 3;
public int Difficult { get; set; } = 5;
public int Clincher { get; set; } = 5;
public int GeneralPoints { get; set; } = 1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public class ParticipantAnswerReport
public string ParticipantName { get; set; } = string.Empty; // can be username
public string Answer { get; set; } = string.Empty;
public int QuestionId { get; set; }
public int Points { get; set; } = 0;
public int Score { get; set; } = 0;
public string ScreenshotLink { get; set; } = string.Empty;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public async Task StartQuiz(SessionHub hub, SessionHandler handler, QuizRoomServ
bool ForcedToExit = false;
foreach (var Qset in quizSets)
{
ForcedToExit = handler.IsRoomForcedToExit(roomId);
if (ForcedToExit) break;
// Get the Sets
var setRequest = new SetRequest() { Id = Qset.QSetId };
Expand Down Expand Up @@ -132,6 +133,7 @@ public async Task StartQuiz(SessionHub hub, SessionHandler handler, QuizRoomServ
* - CurrentQuestionName
* - TotalNumberOfQuestions
* - bufferTime
* - points
* - ParticipantsInRoom
*/
await hub.Clients.Group(roomPin).SendAsync("metadata", new {
Expand All @@ -142,6 +144,8 @@ public async Task StartQuiz(SessionHub hub, SessionHandler handler, QuizRoomServ
currentQuestionName = details.question.QStatement,
totalNumberOfQuestions = Setquestions.Count,
bufferTime = quizSettings.BufferTime,
points = quizSettings.OverridePointSystem,
currentDifficulty = details.question.QDifficulty.QDifficultyDesc.ToLower(),
participantsInRoom = handler.GetParticipantLinkedConnectionsInAGroup(roomPin).Count(),
});

Expand Down Expand Up @@ -178,6 +182,9 @@ public async Task StartQuiz(SessionHub hub, SessionHandler handler, QuizRoomServ
int limit = quizSettings.ForceNextRoundTimeout; // DEFAULT (300s) of 5mins, if not clicked `proceed` then continue
while (handler.GetPausedRoom(roomId) && limit > 0)
{
ForcedToExit = handler.IsRoomForcedToExit(roomId);
// force break loop if triggered 'end game'
if (ForcedToExit) break;
// Adding delay so it doesn't kill the backend when looping infinitely
await Task.Delay(1000);
// Notify the admin while the game is paused
Expand Down
29 changes: 26 additions & 3 deletions WebApp/backend/QuizMaster.API.Gatewway/Services/SessionHandler.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.Options;
using Microsoft.Extensions.Primitives;
using Newtonsoft.Json;
using QuizMaster.API.Authentication.Models;
using QuizMaster.API.Authentication.Proto;
using QuizMaster.API.Gateway.Configuration;
using QuizMaster.API.Gateway.Hubs;
using QuizMaster.API.Gateway.Models.Report;
using QuizMaster.API.Gateway.Services.ReportService;
using QuizMaster.API.QuizSession.Models;
using QuizMaster.API.QuizSession.Protos;
using QuizMaster.Library.Common.Entities.Questionnaire;
using QuizMaster.Library.Common.Entities.Rooms;
using QuizMaster.Library.Common.Models.QuizSession;
using System.IdentityModel.Tokens.Jwt;
using System.Net.Http;
using System.Runtime.Intrinsics.X86;

namespace QuizMaster.API.Gateway.Services
{
Expand All @@ -32,8 +36,9 @@ public class SessionHandler
private readonly ReportServiceHandler ReportHandler;
private Dictionary<int, bool> RoomNextSetPaused;
private List<int> RoomForceExitIds;
private QuizSettings QuizSettings;

public SessionHandler(ReportServiceHandler reportServiceHandler)
public SessionHandler(ReportServiceHandler reportServiceHandler, IOptions<QuizSettings> options)
{
connectionGroupPair = new();
participantLinkedConnectionId = new();
Expand All @@ -48,6 +53,7 @@ public SessionHandler(ReportServiceHandler reportServiceHandler)
RoomNextSetPaused = new();
ReportHandler = reportServiceHandler;
RoomForceExitIds = new();
QuizSettings = options.Value;
}

public string GenerateSessionId(string roomPin)
Expand Down Expand Up @@ -374,6 +380,21 @@ public async Task<string> SubmitAnswer(QuizRoomService.QuizRoomServiceClient grp
}
}

// Get the question difficulty description
int Point = QuizSettings.OverridePointSystem.GeneralPoints;
QuestionDifficulty diff = questionData.question.QDifficulty;
if(diff != null || diff != default)
{
if (diff.QDifficultyDesc.ToLower().Contains("easy"))
Point = QuizSettings.OverridePointSystem.Easy;
else if (diff.QDifficultyDesc.ToLower().Contains("average"))
Point = QuizSettings.OverridePointSystem.Average;
else if (diff.QDifficultyDesc.ToLower().Contains("difficult"))
Point = QuizSettings.OverridePointSystem.Difficult;
else if (diff.QDifficultyDesc.ToLower().Contains("clincher"))
Point = QuizSettings.OverridePointSystem.Clincher;
}

QuizParticipant? participantData;
// get the participant data
participantData = GetLinkedParticipantInConnectionId(connectionId);
Expand All @@ -382,7 +403,7 @@ public async Task<string> SubmitAnswer(QuizRoomService.QuizRoomServiceClient grp
if (correct)
{
// increment score by 1
participantData.Score += 1;
participantData.Score += Point;
}
// Hold Submission of Answer
HoldClientAnswerSubmission(connectionId);
Expand All @@ -393,7 +414,9 @@ public async Task<string> SubmitAnswer(QuizRoomService.QuizRoomServiceClient grp
ParticipantName = participantData.QParticipantDesc,
Answer = answer,
QuestionId = questionData.question.Id,
ScreenshotLink = ""
ScreenshotLink = "",
Points = Point,
Score = correct ? Point:0
});
#endregion
return "Answer submitted";
Expand Down
9 changes: 8 additions & 1 deletion WebApp/backend/QuizMaster.API.Gatewway/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,18 @@
"QuizSettings": {
"ShowAnswerAfterQuestionDelay": 10,
"ForceNextRoundTimeout": 120,
"BufferTime": 3,
"BufferTime": 3,
"OverrideQuestionTimer": {
"TypeAnswer": 0,
"MultipleChoice": 0,
"TrueOrFalse": 0
},
"OverridePointSystem": {
"Easy": 1,
"Average": 3,
"Difficult": 5,
"Clincher": 5,
"GeneralPoints": 1
}
}

Expand Down
3 changes: 2 additions & 1 deletion WebApp/backend/QuizMaster.API.Quiz/Models/QuestionDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ public class QuestionDto
public int QTime { get; set; }

public int QDifficultyId { get; set; }
public QuestionDifficulty QDifficulty { get; set; } = default!;

public int QCategoryId { get; set; }
public int QCategoryId { get; set; }

public int QTypeId { get; set; }
public IEnumerable<QuestionDetailDto> Details { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,10 @@ public async Task<PagedList<Question>> GetAllQuestionsAsync(QuestionResourcePara
qDetail.DetailTypes = _context.QuestionDetailTypes.Where(qDetailType => qDetailType.QuestionDetailId == qDetail.Id).Select((qDetailType) =>
qDetailType.DetailType).ToList();
});
}

var diff = _context.Difficulties.Where(d => d.Id == question.QDifficultyId).FirstOrDefault();
if(null != diff) question.QDifficulty = diff;
}

return question;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ public override async Task<RoomResponse> GetQuestion(SetRequest request, ServerC
var reply = new RoomResponse();
var id = request.Id;

var question = _context.Questions.FirstOrDefault(x => x.Id == id);
var question = _context.Questions.Include(q => q.QDifficulty).FirstOrDefault(x => x.Id == id);
//_ = _context.DetailTypes.ToList();
//var details = _context.QuestionDetails.Where(x => x.QuestionId == question.Id).Include(qD => qD.DetailTypes).ToList();
var details = _context.QuestionDetails.Where(x => x.QuestionId == question.Id).Include(qD => qD.DetailTypes).ToList();
Expand All @@ -418,6 +418,9 @@ public override async Task<RoomResponse> GetQuestion(SetRequest request, ServerC
return await Task.FromResult(reply);
}

// include the qDifficulty
question.QDifficulty = _context.Difficulties.Where(d => d.Id == question.QDifficultyId).First();

reply.Code = 200;
reply.Data = JsonConvert.SerializeObject(new QuestionsDTO { question=question, details=details});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ public override async Task<QuizSetMessage> AddQuizSet(QuizSetRequest request, Se
}
catch (Exception ex)
{
reply.Code = 500;
reply.Message = ex.Message;
return await Task.FromResult(reply);
//reply.Code = 500;
//reply.Message = ex.Message;
//return await Task.FromResult(reply);
}

reply.Code = 200;
Expand Down Expand Up @@ -249,9 +249,9 @@ public override async Task<QuizSetMessage> DeleteQuizSet(GetQuizSetRequest reque
}
catch (Exception ex)
{
reply.Code = 500;
reply.Message = ex.Message;
return await Task.FromResult(reply);
//reply.Code = 500;
//reply.Message = ex.Message;
//return await Task.FromResult(reply);
}

reply.Code = 200;
Expand Down Expand Up @@ -367,9 +367,9 @@ public override async Task<QuizSetMessage> UpdateQuizSet(QuizSetRequest request,
}
catch (Exception ex)
{
reply.Code = 500;
reply.Message = ex.Message;
return await Task.FromResult(reply);
//reply.Code = 500;
//reply.Message = ex.Message;
//return await Task.FromResult(reply);
}

reply.Code = 200;
Expand Down
7 changes: 5 additions & 2 deletions WebApp/docker-compose-no-frontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,17 @@ services:
- GrpcServerConfiguration:Session_Service=https://backend_api_quizsession:6006
- Kestrel:EndpointDefaults:Protocols=Http1AndHttp2
- Kestrel:Endpoints:Https:Url=https://*:443
# - Kestrel:Certificates:Default:Path=/app/localhost_cert.pfx
# - Kestrel:Certificates:Default:Password=123456
- AppSettings:CORS_ORIGINS=${GATEWAY_CORS}
- QuizSettings:ShowAnswerAfterQuestionDelay=${SHOW_ANSWER_AFTER_QUESTION_DELAY}
- QuizSettings:ForceNextRoundTimeout=${FORCE_NEXT_ROUND_TIMEOUT}
- QuizSettings:OverrideQuestionTimer:TypeAnswer=${OVERRIDE_QUESTION_TIMER_TYPEANSWER}
- QuizSettings:OverrideQuestionTimer:MultipleChoice=${OVERRIDE_QUESTION_TIMER_MULTIPLECHOICE}
- QuizSettings:OverrideQuestionTimer:TrueOrFalse=${OVERRIDE_QUESTION_TIMER_TRUEORFALSE}
- QuizSettings:OverridePointSystem:Easy=${OVERRIDE_POINT_EASY_ROUND}
- QuizSettings:OverridePointSystem:Average=${OVERRIDE_POINT_AVERAGE_ROUND}
- QuizSettings:OverridePointSystem:Difficult=${OVERRIDE_POINT_DIFFICULT_ROUND}
- QuizSettings:OverridePointSystem:Clincher=${OVERRIDE_POINT_CLINCHER_ROUND}
- QuizSettings:OverridePointSystem:GeneralPoints=${OVERRIDE_POINT_GENERAL}
networks:
- gateway

Expand Down
7 changes: 5 additions & 2 deletions WebApp/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,18 @@ services:
- GrpcServerConfiguration:Session_Service=https://backend_api_quizsession:6006
- Kestrel:EndpointDefaults:Protocols=Http1AndHttp2
- Kestrel:Endpoints:Https:Url=https://*:443
# - Kestrel:Certificates:Default:Path=/app/localhost_cert.pfx
# - Kestrel:Certificates:Default:Password=123456
- AppSettings:CORS_ORIGINS=${GATEWAY_CORS}
- QuizSettings:ShowAnswerAfterQuestionDelay=${SHOW_ANSWER_AFTER_QUESTION_DELAY}
- QuizSettings:ForceNextRoundTimeout=${FORCE_NEXT_ROUND_TIMEOUT}
- QuizSettings:BufferTime=${BUFFER_TIME}
- QuizSettings:OverrideQuestionTimer:TypeAnswer=${OVERRIDE_QUESTION_TIMER_TYPEANSWER}
- QuizSettings:OverrideQuestionTimer:MultipleChoice=${OVERRIDE_QUESTION_TIMER_MULTIPLECHOICE}
- QuizSettings:OverrideQuestionTimer:TrueOrFalse=${OVERRIDE_QUESTION_TIMER_TRUEORFALSE}
- QuizSettings:OverridePointSystem:Easy=${OVERRIDE_POINT_EASY_ROUND}
- QuizSettings:OverridePointSystem:Average=${OVERRIDE_POINT_AVERAGE_ROUND}
- QuizSettings:OverridePointSystem:Difficult=${OVERRIDE_POINT_DIFFICULT_ROUND}
- QuizSettings:OverridePointSystem:Clincher=${OVERRIDE_POINT_CLINCHER_ROUND}
- QuizSettings:OverridePointSystem:GeneralPoints=${OVERRIDE_POINT_GENERAL}
networks:
- gateway

Expand Down
14 changes: 12 additions & 2 deletions WebApp/frontend/quiz-master/app/dashboard/game.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
import { useSession } from "next-auth/react";
import CryptoJS from "crypto-js";
import { QUIZMASTER_SESSION_WEBSITE } from "@/api/api-routes";
import jwtDecode from "jwt-decode";

export default function Game() {
const { data: session } = useSession();
const user = session?.user;
let user = session?.user;
let username;

function encodeUTF8(input: string) {
return encodeURIComponent(input);
Expand All @@ -14,6 +16,14 @@ export default function Game() {
// Get the data to be encrypted (e.g., from localStorage)
const token = localStorage.getItem("token") || "";

// Get username from token
if (token) {
const data: any = jwtDecode(token);
const userData = JSON.parse(data.token);
console.log(userData);
username = userData["UserData"]["UserName"];
}

// Encode the data as UTF-8
const utf8EncodedToken = encodeUTF8(token);

Expand All @@ -25,6 +35,6 @@ export default function Game() {
).toString();

const encodedEncryptedToken = encodeURIComponent(encryptedToken);
const linkVar = `${QUIZMASTER_SESSION_WEBSITE}?name=${user?.username}&token=${encodedEncryptedToken}`;
const linkVar = `${QUIZMASTER_SESSION_WEBSITE}?name=${username}&token=${encodedEncryptedToken}`;
return linkVar;
}
2 changes: 1 addition & 1 deletion WebApp/frontend/quiz-master/lib/correctAnswerUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ export function isCorrectAnswer(
return false;
}
}
}
}
1 change: 1 addition & 0 deletions WebApp/frontend/quiz_session/.env
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
NEXT_PUBLIC_QUIZMASTER_ADMIN=http://localhost:3000
NEXT_PUBLIC_QUIZMASTER_GATEWAY=https://localhost:7081
NEXT_PUBLIC_QUIZMASTER_TRIGGER_SFX_SECONDS=5
Loading

0 comments on commit 3087900

Please sign in to comment.