Skip to content
This repository has been archived by the owner on Mar 23, 2023. It is now read-only.

Commit

Permalink
Merge pull request #3 from IT-REX-Platform/feature/ITREX-538
Browse files Browse the repository at this point in the history
Feature/itrex 538
  • Loading branch information
acraea-x authored Mar 12, 2021
2 parents d83fa5d + 708db2d commit 42b6f12
Show file tree
Hide file tree
Showing 20 changed files with 616 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package de.uni_stuttgart.it_rex.quiz.domain.enumeration;

/**
* The QUESTIONTYPE enumeration.
*/
public enum QUESTIONTYPE {
SINGLE_CHOICE, MULTIPLE_CHOICE, NUMERIC
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* Enumerations.
*/
package de.uni_stuttgart.it_rex.quiz.domain.enumeration;
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package de.uni_stuttgart.it_rex.quiz.domain.written_entities;

import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;
import org.springframework.data.mongodb.core.mapping.DBRef;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;

/**
* A Quiz.
*/
@Document(collection = "quiz")
public class Quiz implements Serializable {

private static final long serialVersionUID = 1L;

@Id
private UUID id;

@Field("content")
private String content;

// @DBRef
// @Field("b")
// private Set<EntityB> bs = new HashSet<>();

public UUID getId() {
return id;
}

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

public boolean isNew() {
return (getId() == null);
}

public String getContent() {
return content;
}

public void setContent(String content) {
this.content = content;
}

// public Set<EntityB> getBs() {
// return bs;
// }

// public EntityA bs(Set<EntityB> entityBS) {
// this.bs = entityBS;
// return this;
// }

// public EntityA addB(EntityB entityB) {
// this.bs.add(entityB);
// entityB.setA(this);
// return this;
// }

// public EntityA removeB(EntityB entityB) {
// this.bs.remove(entityB);
// entityB.setA(null);
// return this;
// }

// public void setBs(Set<EntityB> entityBS) {
// this.bs = entityBS;
// }

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof Quiz)) {
return false;
}
return id != null && id.equals(((Quiz) o).id);
}

@Override
public int hashCode() {
return 31;
}

// prettier-ignore
@Override
public String toString() {
return "Quiz{" +
"id=" + getId() +
", content='" + getContent() + "'" +
"}";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* JPA domain objects.
*/
package de.uni_stuttgart.it_rex.quiz.domain.written_entities;
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package de.uni_stuttgart.it_rex.quiz.repository.written;

import de.uni_stuttgart.it_rex.quiz.domain.written_entities.Quiz;

import java.util.UUID;

import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;

/**
* Spring Data MongoDB repository for the Quiz entity.
*/
@SuppressWarnings("unused")
@Repository
public interface QuizRepository extends MongoRepository<Quiz, UUID> {
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package de.uni_stuttgart.it_rex.quiz.repository.written;

import java.util.UUID;

import org.springframework.data.mongodb.core.mapping.event.AbstractMongoEventListener;
import org.springframework.data.mongodb.core.mapping.event.BeforeConvertEvent;
import org.springframework.stereotype.Component;

import de.uni_stuttgart.it_rex.quiz.domain.written_entities.Quiz;

@Component
public class QuizUuidListener extends AbstractMongoEventListener<Quiz> {

@Override
public void onBeforeConvert(BeforeConvertEvent<Quiz> event) {
Quiz quiz = event.getSource();
if (quiz.isNew()) {
quiz.setId(UUID.randomUUID());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package de.uni_stuttgart.it_rex.quiz.repository.written;

import java.util.UUID;

import org.springframework.core.convert.converter.Converter;
import org.springframework.data.mongodb.core.mapping.event.AbstractMongoEventListener;
import org.springframework.data.mongodb.core.mapping.event.BeforeConvertEvent;
import org.springframework.stereotype.Component;

import de.uni_stuttgart.it_rex.quiz.domain.written_entities.Quiz;

// @Component
// public class UuidConverter implements Converter<User, DBObject> {
// @Override
// public DBObject convert(User user) {
// DBObject dbObject = new BasicDBObject();
// dbObject.put("name", user.getName());
// dbObject.put("age", user.getAge());
// if (user.getEmailAddress() != null) {
// DBObject emailDbObject = new BasicDBObject();
// emailDbObject.put("value", user.getEmailAddress().getValue());
// dbObject.put("email", emailDbObject);
// }
// dbObject.removeField("_class");
// return dbObject;
// }
// }
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* Spring Data JPA repositories.
*/
package de.uni_stuttgart.it_rex.quiz.repository.written;
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package de.uni_stuttgart.it_rex.quiz.service.dto.written_dtos;


import java.io.Serializable;
import java.time.LocalDate;
import java.util.List;
import java.util.Objects;
import java.util.UUID;



public class AnswerTypeDTO implements Serializable{

public enum ANSWER_TYPE {
SINGLE_CHOICE,
MULTIPLE_CHOICE,
NUMERIC
};

/**
* Identifier.
*/
private UUID id;

private ANSWER_TYPE type;

}

// public class ChoiceAnswer {
// private String content;
// private Boolean correct;
// }

// public class NumericAnswer {
// private Float content;
// private Float epsilon;
// }

// public class ChoiceAnswerTypeDTO extends AnswerTypeDTO {
// private List<ChoiceAnswer> answer;
// }

// public class NumericAnswerTypeDTO extends AnswerTypeDTO {
// private NumericAnswer answer;
// }



Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package de.uni_stuttgart.it_rex.quiz.service.dto.written_dtos;

import java.io.Serializable;
import java.time.LocalDate;
import java.util.List;
import java.util.Objects;
import java.util.UUID;

public class QuestionDTO implements Serializable {
/**
* Identifier.
*/
private UUID id;

/**
* Course id.
*/
private UUID courseId;

private String question;

private AnswerTypeDTO answer;

// for later impls
// for search
// private List<String> tags;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package de.uni_stuttgart.it_rex.quiz.service.dto.written_dtos;

import java.io.Serializable;
import java.time.LocalDate;
import java.util.List;
import java.util.Objects;
import java.util.UUID;

public class QuizDTO implements Serializable {
/**
* Identifier.
*/
private UUID id;

/**
* Title of the chapter.
*/
private String name;

/**
* Course id.
*/
private UUID courseId;

/**
* List of questions
*/
private List<QuestionDTO> questions;

public UUID getId() {
return id;
}

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

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public UUID getCourseId() {
return courseId;
}

public void setCourseId(UUID courseId) {
this.courseId = courseId;
}

public List<QuestionDTO> getQuestions() {
return questions;
}

public void setQuestions(List<QuestionDTO> questions) {
this.questions = questions;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* Data Transfer Objects.
*/
package de.uni_stuttgart.it_rex.quiz.service.dto.written_dtos;

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package de.uni_stuttgart.it_rex.quiz.service.mapper;

import java.util.List;

/**
* Contract for a generic dto to entity mapper.
*
* @param <D> - DTO type parameter.
* @param <E> - Entity type parameter.
*/

public interface EntityMapper <D, E> {

E toEntity(D dto);

D toDto(E entity);

List <E> toEntity(List<D> dtoList);

List <D> toDto(List<E> entityList);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package de.uni_stuttgart.it_rex.quiz.service.mapper.written;


import de.uni_stuttgart.it_rex.quiz.domain.written_entities.Quiz;
import de.uni_stuttgart.it_rex.quiz.service.dto.written_dtos.QuizDTO;
import de.uni_stuttgart.it_rex.quiz.service.mapper.EntityMapper;

import java.util.UUID;

import org.mapstruct.*;

/**
* Mapper for the entity {@link Quiz} and its DTO {@link QuizDTO}.
*/
@Mapper(componentModel = "spring", uses = {})
public interface QuizMapper extends EntityMapper<QuizDTO, Quiz> {

// default UUID idToId(String id) {
// if (id == null) {
// return null;
// }
// return UUID.fromString(id);
// }

// default String idToId(UUID id) {
// if (id == null) {
// return null;
// }
// return id.toString();
// }
}
Loading

0 comments on commit 42b6f12

Please sign in to comment.