Skip to content

Commit

Permalink
Merge pull request #31 from msi-se/form-join-lobby-and-rework-live-fo…
Browse files Browse the repository at this point in the history
…rm-page

Monster Branch
  • Loading branch information
johannesbrandenburger authored Mar 5, 2024
2 parents bc5d364 + f0de5b4 commit 60f70f6
Show file tree
Hide file tree
Showing 53 changed files with 3,745 additions and 1,588 deletions.
6 changes: 6 additions & 0 deletions backend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,9 @@ nb-configuration.xml

# Plugin directory
/.quarkus/cli/plugins/

# Metals
.metals/

# line counts
.VSCodeCounter/
5 changes: 5 additions & 0 deletions backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc</artifactId>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-reactive</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
public enum FormStatus {
STARTED,
FINISHED,
NOT_STARTED
NOT_STARTED,
WAITING,
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public Boolean login() {
public List<MoodleCourse> getCourses() {

// TEMP: mock the special users (Prof, Student, Admin)
if (this.username.equals("Prof") || this.username.equals("Student") || this.username.equals("Admin")) {
if (this.username.startsWith("Prof") || this.username.startsWith("Student") || this.username.startsWith("Admin")) {
return List.of(new MoodleCourse("1"), new MoodleCourse("2"), new MoodleCourse("3"), new MoodleCourse("940"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class Course implements Serializable {
public List<ObjectId> students;
public String key;
public String moodleCourseId;
public Boolean isLinkedToMoodle;

// feedback
public List<FeedbackForm> feedbackForms;
Expand All @@ -55,6 +56,7 @@ public Course(String name, String description) {
this.quizQuestions = new ArrayList<QuizQuestion>();
this.key = "";
this.moodleCourseId = "";
this.isLinkedToMoodle = false;
}

// id
Expand Down Expand Up @@ -338,7 +340,15 @@ public String getKey() {
}

public void setMoodleCourseId(String moodleCourseId) {

if (moodleCourseId == null || moodleCourseId.isEmpty()) {
this.moodleCourseId = "";
this.isLinkedToMoodle = false;
return;
}

this.moodleCourseId = moodleCourseId;
this.isLinkedToMoodle = true;
}

public String getMoodleCourseId() {
Expand Down Expand Up @@ -439,5 +449,30 @@ public boolean equals(Object obj) {
return course.getId().equals(this.getId());
}

public Boolean getIsLinkedToMoodle() {
return this.isLinkedToMoodle;
}

/**
* Clears the content of all forms to not send to much data to the client.
* - clears the questions
* - clears the results
* - clears the participants
* @return Course
*/
public Course clearFormsContent() {
this.feedbackForms.forEach(form -> {
form.questions = new ArrayList<QuestionWrapper>();
form.clearResults();
form.clearParticipants();
});
this.quizForms.forEach(form -> {
form.questions = new ArrayList<QuestionWrapper>();
form.clearResults();
form.clearParticipants();
});
return this;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ public ObjectId getId() {
return this.id;
}

public void setId(ObjectId id) {
this.id = id;
}

public ObjectId getCourseId() {
return this.courseId;
}

public String getName() {
return this.name;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package de.htwg_konstanz.mobilelearning.models;

import org.bson.types.ObjectId;

import de.htwg_konstanz.mobilelearning.enums.FormStatus;

public class FormShell extends Form {

public String type;
public String course;

public FormShell() { }

public FormShell(ObjectId id, ObjectId courseId, String name, String description, FormStatus status, Integer connectCode, String key, String type, String course) {
this.id = id;
this.courseId = courseId;
this.name = name;
this.description = description;
this.status = status;
this.connectCode = connectCode;
this.key = key;
this.type = type;
this.course = course;
}

public String getType() {
return this.type;
}

public void setType(String type) {
this.type = type;
}

public String getCourse() {
return this.course;
}

public void setCourse(String course) {
this.course = course;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,25 @@

import org.bson.types.ObjectId;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonSubTypes;

import de.htwg_konstanz.mobilelearning.models.feedback.FeedbackQuestion;
import de.htwg_konstanz.mobilelearning.models.quiz.QuizQuestion;

import com.fasterxml.jackson.annotation.JsonTypeInfo;

/**
* Contains name & description of a question.
* Options are the possible answers to the question.
*/
public abstract class Question {
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonTypeInfo(use = JsonTypeInfo.Id.DEDUCTION)
@JsonSubTypes({
@JsonSubTypes.Type(QuizQuestion.class),
@JsonSubTypes.Type(FeedbackQuestion.class)
})
public class Question {

public ObjectId id;
public String name;
Expand Down Expand Up @@ -68,6 +82,8 @@ public void setKey(String key) {
this.key = key;
}

public abstract Question copy();
public Question copy() {
return new Question(this.name, this.description, this.options, this.key);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import org.bson.types.ObjectId;

import de.htwg_konstanz.mobilelearning.models.stats.UserStats;

public class User {
public ObjectId id;
public String email;
Expand All @@ -13,6 +15,7 @@ public class User {
public String password;
public List<String> roles;
public List<ObjectId> courses;
public UserStats stats;

public User() {
}
Expand All @@ -34,6 +37,7 @@ public User(String email, String name, String username, String password) {
this.password = password;
this.roles = new ArrayList<String>();
this.courses = new ArrayList<ObjectId>();
this.stats = new UserStats();

// check if email, name and username have ": " in it and if so, only take the part after it
if (this.email.contains(": ")) {
Expand Down Expand Up @@ -187,5 +191,12 @@ public void clearCourses() {
this.courses.clear();
}

public UserStats getStats() {
return this.stats;
}

public void setStats(UserStats stats) {
this.stats = stats;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@
import de.htwg_konstanz.mobilelearning.services.api.models.ApiFeedbackForm.ApiFeedbackQuestion;

public class FeedbackForm extends Form {

public List<FeedbackParticipant> participants;

public FeedbackForm() {
}

public FeedbackForm(ObjectId courseId, String name, String description, List<QuestionWrapper> questions,
FormStatus status) {
super(courseId, name, description, questions, status);
this.participants = new ArrayList<FeedbackParticipant>();
}

public void fillQuestionContents(Course course) {
Expand Down Expand Up @@ -59,6 +63,45 @@ public FeedbackForm copyWithQuestionContents(Course course) {
return copy;
}

public List<FeedbackParticipant> getParticipants() {
return this.participants;
}

public Boolean addParticipant(ObjectId userId) {
if (this.participants == null) {
this.participants = new java.util.ArrayList<FeedbackParticipant>();
}

// if user is already participating, just return true
for (FeedbackParticipant participant : this.participants) {
if (participant.getUserId().toHexString().equals(userId.toHexString())) {
return true;
}
}

// otherwise add a new participant
this.participants.add(new FeedbackParticipant(userId));
return true;
}

public void clearParticipants() {
if (this.participants == null) { this.participants = new ArrayList<FeedbackParticipant>(); }
this.participants.clear();
}

public Boolean isParticipant(String userId) {
if (this.participants == null) {
this.participants = new ArrayList<FeedbackParticipant>();
return false;
}
for (FeedbackParticipant participant : this.participants) {
if (participant.getUserId().toHexString().equals(userId)) {
return true;
}
}
return false;
}

public static FeedbackForm fromApiFeedbackForm(ApiFeedbackForm apiFeedbackForm, Course course)
throws IllegalArgumentException {

Expand Down Expand Up @@ -147,8 +190,7 @@ private static List<QuestionWrapper> questionWrappersFromApiFeedbackFormQuestion
apiFeedbackQuestion.getOptions(),
apiFeedbackQuestion.getKey(),
apiFeedbackQuestion.getRangeLow(),
apiFeedbackQuestion.getRangeHigh()
);
apiFeedbackQuestion.getRangeHigh());

course.addFeedbackQuestion(feedbackQuestion);
feedbackQuestionIds.add(feedbackQuestion.getId());
Expand Down Expand Up @@ -189,4 +231,8 @@ public void updateFromApiFeedbackForm(ApiFeedbackForm apiFeedbackForm, Course co
this.setDescription(apiFeedbackForm.getDescription());

}

public void setParticipants(List<FeedbackParticipant> participants) {
this.participants = participants;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package de.htwg_konstanz.mobilelearning.models.feedback;

import org.bson.types.ObjectId;

public class FeedbackParticipant {

public ObjectId userId;

public FeedbackParticipant() {
}

public FeedbackParticipant(ObjectId userId) {
this.userId = userId;
}

public ObjectId getUserId() {
return this.userId;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,13 @@ public QuizForm copyWithQuestionContents(Course course) {
return copy;
}

public List<QuizParticipant> getParticipants() {
return this.participants;
}

public Boolean addParticipant(ObjectId userId, String userAlias) {
if (this.participants == null) {
this.participants = new java.util.ArrayList<QuizParticipant>();
this.participants = new ArrayList<QuizParticipant>();
}

// if alias is empty or already taken, return false
Expand Down Expand Up @@ -326,4 +330,8 @@ public void updateFromApiQuizForm(ApiQuizForm apiQuizForm, Course course) throws
this.setName(apiQuizForm.getName());
this.setDescription(apiQuizForm.getDescription());
}

public void setParticipants(List<QuizParticipant> participants) {
this.participants = participants;
}
}
Loading

0 comments on commit 60f70f6

Please sign in to comment.