Generate question bank domain model from JDL

This commit is contained in:
jieun committed 2026-10-20 18:46:29 +09:00
1 parent 1d97cc4e31
commit 1d74d8f04b
160 files changed
+26900 -2

No files matched your search

@@ -0,0 +1,162 @@
package com.example.questionbank.domain;
import com.example.questionbank.domain.enumeration.OptionKey;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import jakarta.persistence.*;
import jakarta.validation.constraints.*;
import java.io.Serial;
import java.io.Serializable;
/**
* A Choice.
*/
@Entity
@Table(name = "choice")
@SuppressWarnings("common-java:DuplicatedBlocks")
public class Choice implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
@SequenceGenerator(name = "sequenceGenerator")
@Column(name = "id")
private Long id;
@NotNull
@Enumerated(EnumType.STRING)
@Column(name = "option_key", nullable = false)
private OptionKey optionKey;
@NotNull
@Size(max = 500)
@Column(name = "content", length = 500, nullable = false)
private String content;
@NotNull
@Min(value = 1)
@Max(value = 4)
@Column(name = "display_order", nullable = false)
private Integer displayOrder;
@NotNull
@Column(name = "correct", nullable = false)
private Boolean correct;
@ManyToOne(optional = false)
@NotNull
@JsonIgnoreProperties(value = { "choices", "subject" }, allowSetters = true)
private Question question;
// jhipster-needle-entity-add-field - JHipster will add fields here
public Long getId() {
return this.id;
}
public Choice id(Long id) {
this.setId(id);
return this;
}
public void setId(Long id) {
this.id = id;
}
public OptionKey getOptionKey() {
return this.optionKey;
}
public Choice optionKey(OptionKey optionKey) {
this.setOptionKey(optionKey);
return this;
}
public void setOptionKey(OptionKey optionKey) {
this.optionKey = optionKey;
}
public String getContent() {
return this.content;
}
public Choice content(String content) {
this.setContent(content);
return this;
}
public void setContent(String content) {
this.content = content;
}
public Integer getDisplayOrder() {
return this.displayOrder;
}
public Choice displayOrder(Integer displayOrder) {
this.setDisplayOrder(displayOrder);
return this;
}
public void setDisplayOrder(Integer displayOrder) {
this.displayOrder = displayOrder;
}
public Boolean getCorrect() {
return this.correct;
}
public Choice correct(Boolean correct) {
this.setCorrect(correct);
return this;
}
public void setCorrect(Boolean correct) {
this.correct = correct;
}
public Question getQuestion() {
return this.question;
}
public void setQuestion(Question question) {
this.question = question;
}
public Choice question(Question question) {
this.setQuestion(question);
return this;
}
// jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters here
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof Choice)) {
return false;
}
return getId() != null && getId().equals(((Choice) o).getId());
}
@Override
public int hashCode() {
// see https://vladmihalcea.com/how-to-implement-equals-and-hashcode-using-the-jpa-entity-identifier/
return getClass().hashCode();
}
// prettier-ignore
@Override
public String toString() {
return "Choice{" +
"id=" + getId() +
", optionKey='" + getOptionKey() + "'" +
", content='" + getContent() + "'" +
", displayOrder=" + getDisplayOrder() +
", correct='" + getCorrect() + "'" +
"}";
}
}
@@ -0,0 +1,212 @@
package com.example.questionbank.domain;
import com.example.questionbank.domain.enumeration.OptionKey;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import jakarta.persistence.*;
import jakarta.validation.constraints.*;
import java.io.Serial;
import java.io.Serializable;
/**
* A ExamAnswer.
*/
@Entity
@Table(name = "exam_answer")
@SuppressWarnings("common-java:DuplicatedBlocks")
public class ExamAnswer implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
@SequenceGenerator(name = "sequenceGenerator")
@Column(name = "id")
private Long id;
@NotNull
@Size(max = 2000)
@Column(name = "question_text_snapshot", length = 2000, nullable = false)
private String questionTextSnapshot;
@Size(max = 2000)
@Column(name = "explanation_snapshot", length = 2000)
private String explanationSnapshot;
@Enumerated(EnumType.STRING)
@Column(name = "selected_option")
private OptionKey selectedOption;
@Size(max = 500)
@Column(name = "selected_content_snapshot", length = 500)
private String selectedContentSnapshot;
@Column(name = "correct")
private Boolean correct;
@Min(value = 0)
@Column(name = "awarded_points")
private Integer awardedPoints;
@ManyToOne(optional = false)
@NotNull
@JsonIgnoreProperties(value = { "choices", "subject" }, allowSetters = true)
private Question question;
@ManyToOne(optional = false)
@NotNull
@JsonIgnoreProperties(value = { "answers", "subject", "user" }, allowSetters = true)
private ExamAttempt attempt;
// jhipster-needle-entity-add-field - JHipster will add fields here
public Long getId() {
return this.id;
}
public ExamAnswer id(Long id) {
this.setId(id);
return this;
}
public void setId(Long id) {
this.id = id;
}
public String getQuestionTextSnapshot() {
return this.questionTextSnapshot;
}
public ExamAnswer questionTextSnapshot(String questionTextSnapshot) {
this.setQuestionTextSnapshot(questionTextSnapshot);
return this;
}
public void setQuestionTextSnapshot(String questionTextSnapshot) {
this.questionTextSnapshot = questionTextSnapshot;
}
public String getExplanationSnapshot() {
return this.explanationSnapshot;
}
public ExamAnswer explanationSnapshot(String explanationSnapshot) {
this.setExplanationSnapshot(explanationSnapshot);
return this;
}
public void setExplanationSnapshot(String explanationSnapshot) {
this.explanationSnapshot = explanationSnapshot;
}
public OptionKey getSelectedOption() {
return this.selectedOption;
}
public ExamAnswer selectedOption(OptionKey selectedOption) {
this.setSelectedOption(selectedOption);
return this;
}
public void setSelectedOption(OptionKey selectedOption) {
this.selectedOption = selectedOption;
}
public String getSelectedContentSnapshot() {
return this.selectedContentSnapshot;
}
public ExamAnswer selectedContentSnapshot(String selectedContentSnapshot) {
this.setSelectedContentSnapshot(selectedContentSnapshot);
return this;
}
public void setSelectedContentSnapshot(String selectedContentSnapshot) {
this.selectedContentSnapshot = selectedContentSnapshot;
}
public Boolean getCorrect() {
return this.correct;
}
public ExamAnswer correct(Boolean correct) {
this.setCorrect(correct);
return this;
}
public void setCorrect(Boolean correct) {
this.correct = correct;
}
public Integer getAwardedPoints() {
return this.awardedPoints;
}
public ExamAnswer awardedPoints(Integer awardedPoints) {
this.setAwardedPoints(awardedPoints);
return this;
}
public void setAwardedPoints(Integer awardedPoints) {
this.awardedPoints = awardedPoints;
}
public Question getQuestion() {
return this.question;
}
public void setQuestion(Question question) {
this.question = question;
}
public ExamAnswer question(Question question) {
this.setQuestion(question);
return this;
}
public ExamAttempt getAttempt() {
return this.attempt;
}
public void setAttempt(ExamAttempt examAttempt) {
this.attempt = examAttempt;
}
public ExamAnswer attempt(ExamAttempt examAttempt) {
this.setAttempt(examAttempt);
return this;
}
// jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters here
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof ExamAnswer)) {
return false;
}
return getId() != null && getId().equals(((ExamAnswer) o).getId());
}
@Override
public int hashCode() {
// see https://vladmihalcea.com/how-to-implement-equals-and-hashcode-using-the-jpa-entity-identifier/
return getClass().hashCode();
}
// prettier-ignore
@Override
public String toString() {
return "ExamAnswer{" +
"id=" + getId() +
", questionTextSnapshot='" + getQuestionTextSnapshot() + "'" +
", explanationSnapshot='" + getExplanationSnapshot() + "'" +
", selectedOption='" + getSelectedOption() + "'" +
", selectedContentSnapshot='" + getSelectedContentSnapshot() + "'" +
", correct='" + getCorrect() + "'" +
", awardedPoints=" + getAwardedPoints() +
"}";
}
}
@@ -0,0 +1,212 @@
package com.example.questionbank.domain;
import com.example.questionbank.domain.enumeration.AttemptStatus;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import jakarta.persistence.*;
import jakarta.validation.constraints.*;
import java.io.Serial;
import java.io.Serializable;
import java.time.Instant;
import java.util.HashSet;
import java.util.Set;
/**
* A ExamAttempt.
*/
@Entity
@Table(name = "exam_attempt")
@SuppressWarnings("common-java:DuplicatedBlocks")
public class ExamAttempt implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
@SequenceGenerator(name = "sequenceGenerator")
@Column(name = "id")
private Long id;
@NotNull
@Column(name = "started_at", nullable = false)
private Instant startedAt;
@Column(name = "submitted_at")
private Instant submittedAt;
@NotNull
@Enumerated(EnumType.STRING)
@Column(name = "status", nullable = false)
private AttemptStatus status;
@Min(value = 0)
@Column(name = "score")
private Integer score;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "attempt")
@JsonIgnoreProperties(value = { "question", "attempt" }, allowSetters = true)
private Set<ExamAnswer> answers = new HashSet<>();
@ManyToOne(optional = false)
@NotNull
private Subject subject;
@ManyToOne(optional = false)
@NotNull
private User user;
// jhipster-needle-entity-add-field - JHipster will add fields here
public Long getId() {
return this.id;
}
public ExamAttempt id(Long id) {
this.setId(id);
return this;
}
public void setId(Long id) {
this.id = id;
}
public Instant getStartedAt() {
return this.startedAt;
}
public ExamAttempt startedAt(Instant startedAt) {
this.setStartedAt(startedAt);
return this;
}
public void setStartedAt(Instant startedAt) {
this.startedAt = startedAt;
}
public Instant getSubmittedAt() {
return this.submittedAt;
}
public ExamAttempt submittedAt(Instant submittedAt) {
this.setSubmittedAt(submittedAt);
return this;
}
public void setSubmittedAt(Instant submittedAt) {
this.submittedAt = submittedAt;
}
public AttemptStatus getStatus() {
return this.status;
}
public ExamAttempt status(AttemptStatus status) {
this.setStatus(status);
return this;
}
public void setStatus(AttemptStatus status) {
this.status = status;
}
public Integer getScore() {
return this.score;
}
public ExamAttempt score(Integer score) {
this.setScore(score);
return this;
}
public void setScore(Integer score) {
this.score = score;
}
public Set<ExamAnswer> getAnswers() {
return this.answers;
}
public void setAnswers(Set<ExamAnswer> examAnswers) {
if (this.answers != null) {
this.answers.forEach(i -> i.setAttempt(null));
}
if (examAnswers != null) {
examAnswers.forEach(i -> i.setAttempt(this));
}
this.answers = examAnswers;
}
public ExamAttempt answers(Set<ExamAnswer> examAnswers) {
this.setAnswers(examAnswers);
return this;
}
public ExamAttempt addAnswer(ExamAnswer examAnswer) {
this.answers.add(examAnswer);
examAnswer.setAttempt(this);
return this;
}
public ExamAttempt removeAnswer(ExamAnswer examAnswer) {
this.answers.remove(examAnswer);
examAnswer.setAttempt(null);
return this;
}
public Subject getSubject() {
return this.subject;
}
public void setSubject(Subject subject) {
this.subject = subject;
}
public ExamAttempt subject(Subject subject) {
this.setSubject(subject);
return this;
}
public User getUser() {
return this.user;
}
public void setUser(User user) {
this.user = user;
}
public ExamAttempt user(User user) {
this.setUser(user);
return this;
}
// jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters here
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof ExamAttempt)) {
return false;
}
return getId() != null && getId().equals(((ExamAttempt) o).getId());
}
@Override
public int hashCode() {
// see https://vladmihalcea.com/how-to-implement-equals-and-hashcode-using-the-jpa-entity-identifier/
return getClass().hashCode();
}
// prettier-ignore
@Override
public String toString() {
return "ExamAttempt{" +
"id=" + getId() +
", startedAt='" + getStartedAt() + "'" +
", submittedAt='" + getSubmittedAt() + "'" +
", status='" + getStatus() + "'" +
", score=" + getScore() +
"}";
}
}
@@ -0,0 +1,176 @@
package com.example.questionbank.domain;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import jakarta.persistence.*;
import jakarta.validation.constraints.*;
import java.io.Serial;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
/**
* A Question.
*/
@Entity
@Table(name = "question")
@SuppressWarnings("common-java:DuplicatedBlocks")
public class Question implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
@SequenceGenerator(name = "sequenceGenerator")
@Column(name = "id")
private Long id;
@NotNull
@Size(min = 5, max = 2000)
@Column(name = "prompt", length = 2000, nullable = false)
private String prompt;
@Size(max = 2000)
@Column(name = "explanation", length = 2000)
private String explanation;
@NotNull
@Column(name = "active", nullable = false)
private Boolean active;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "question")
@JsonIgnoreProperties(value = { "question" }, allowSetters = true)
private Set<Choice> choices = new HashSet<>();
@ManyToOne(optional = false)
@NotNull
private Subject subject;
// jhipster-needle-entity-add-field - JHipster will add fields here
public Long getId() {
return this.id;
}
public Question id(Long id) {
this.setId(id);
return this;
}
public void setId(Long id) {
this.id = id;
}
public String getPrompt() {
return this.prompt;
}
public Question prompt(String prompt) {
this.setPrompt(prompt);
return this;
}
public void setPrompt(String prompt) {
this.prompt = prompt;
}
public String getExplanation() {
return this.explanation;
}
public Question explanation(String explanation) {
this.setExplanation(explanation);
return this;
}
public void setExplanation(String explanation) {
this.explanation = explanation;
}
public Boolean getActive() {
return this.active;
}
public Question active(Boolean active) {
this.setActive(active);
return this;
}
public void setActive(Boolean active) {
this.active = active;
}
public Set<Choice> getChoices() {
return this.choices;
}
public void setChoices(Set<Choice> choices) {
if (this.choices != null) {
this.choices.forEach(i -> i.setQuestion(null));
}
if (choices != null) {
choices.forEach(i -> i.setQuestion(this));
}
this.choices = choices;
}
public Question choices(Set<Choice> choices) {
this.setChoices(choices);
return this;
}
public Question addChoice(Choice choice) {
this.choices.add(choice);
choice.setQuestion(this);
return this;
}
public Question removeChoice(Choice choice) {
this.choices.remove(choice);
choice.setQuestion(null);
return this;
}
public Subject getSubject() {
return this.subject;
}
public void setSubject(Subject subject) {
this.subject = subject;
}
public Question subject(Subject subject) {
this.setSubject(subject);
return this;
}
// jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters here
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof Question)) {
return false;
}
return getId() != null && getId().equals(((Question) o).getId());
}
@Override
public int hashCode() {
// see https://vladmihalcea.com/how-to-implement-equals-and-hashcode-using-the-jpa-entity-identifier/
return getClass().hashCode();
}
// prettier-ignore
@Override
public String toString() {
return "Question{" +
"id=" + getId() +
", prompt='" + getPrompt() + "'" +
", explanation='" + getExplanation() + "'" +
", active='" + getActive() + "'" +
"}";
}
}
@@ -0,0 +1,121 @@
package com.example.questionbank.domain;
import jakarta.persistence.*;
import jakarta.validation.constraints.*;
import java.io.Serial;
import java.io.Serializable;
/**
* A Subject.
*/
@Entity
@Table(name = "subject")
@SuppressWarnings("common-java:DuplicatedBlocks")
public class Subject implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
@SequenceGenerator(name = "sequenceGenerator")
@Column(name = "id")
private Long id;
@NotNull
@Size(min = 2, max = 100)
@Column(name = "name", length = 100, nullable = false)
private String name;
@Size(max = 1000)
@Column(name = "description", length = 1000)
private String description;
@NotNull
@Column(name = "active", nullable = false)
private Boolean active;
// jhipster-needle-entity-add-field - JHipster will add fields here
public Long getId() {
return this.id;
}
public Subject id(Long id) {
this.setId(id);
return this;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return this.name;
}
public Subject name(String name) {
this.setName(name);
return this;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return this.description;
}
public Subject description(String description) {
this.setDescription(description);
return this;
}
public void setDescription(String description) {
this.description = description;
}
public Boolean getActive() {
return this.active;
}
public Subject active(Boolean active) {
this.setActive(active);
return this;
}
public void setActive(Boolean active) {
this.active = active;
}
// jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters here
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof Subject)) {
return false;
}
return getId() != null && getId().equals(((Subject) o).getId());
}
@Override
public int hashCode() {
// see https://vladmihalcea.com/how-to-implement-equals-and-hashcode-using-the-jpa-entity-identifier/
return getClass().hashCode();
}
// prettier-ignore
@Override
public String toString() {
return "Subject{" +
"id=" + getId() +
", name='" + getName() + "'" +
", description='" + getDescription() + "'" +
", active='" + getActive() + "'" +
"}";
}
}
@@ -0,0 +1,9 @@
package com.example.questionbank.domain.enumeration;
/**
* The AttemptStatus enumeration.
*/
public enum AttemptStatus {
IN_PROGRESS,
SUBMITTED,
}
@@ -0,0 +1,11 @@
package com.example.questionbank.domain.enumeration;
/**
* The OptionKey enumeration.
*/
public enum OptionKey {
A,
B,
C,
D,
}
@@ -0,0 +1,4 @@
/**
* This package file was generated by JHipster
*/
package com.example.questionbank.domain.enumeration;
@@ -0,0 +1,12 @@
package com.example.questionbank.repository;
import com.example.questionbank.domain.Choice;
import org.springframework.data.jpa.repository.*;
import org.springframework.stereotype.Repository;
/**
* Spring Data JPA repository for the Choice entity.
*/
@SuppressWarnings("unused")
@Repository
public interface ChoiceRepository extends JpaRepository<Choice, Long> {}
@@ -0,0 +1,12 @@
package com.example.questionbank.repository;
import com.example.questionbank.domain.ExamAnswer;
import org.springframework.data.jpa.repository.*;
import org.springframework.stereotype.Repository;
/**
* Spring Data JPA repository for the ExamAnswer entity.
*/
@SuppressWarnings("unused")
@Repository
public interface ExamAnswerRepository extends JpaRepository<ExamAnswer, Long> {}
@@ -0,0 +1,45 @@
package com.example.questionbank.repository;
import com.example.questionbank.domain.ExamAttempt;
import java.util.List;
import java.util.Optional;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.*;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
/**
* Spring Data JPA repository for the ExamAttempt entity.
*/
@Repository
public interface ExamAttemptRepository extends JpaRepository<ExamAttempt, Long> {
@Query("select examAttempt from ExamAttempt examAttempt where examAttempt.user.login = ?#{authentication.name}")
List<ExamAttempt> findByUserIsCurrentUser();
default Optional<ExamAttempt> findOneWithEagerRelationships(Long id) {
return this.findOneWithToOneRelationships(id);
}
default List<ExamAttempt> findAllWithEagerRelationships() {
return this.findAllWithToOneRelationships();
}
default Page<ExamAttempt> findAllWithEagerRelationships(Pageable pageable) {
return this.findAllWithToOneRelationships(pageable);
}
@Query(
value = "select examAttempt from ExamAttempt examAttempt left join fetch examAttempt.subject left join fetch examAttempt.user",
countQuery = "select count(examAttempt) from ExamAttempt examAttempt"
)
Page<ExamAttempt> findAllWithToOneRelationships(Pageable pageable);
@Query("select examAttempt from ExamAttempt examAttempt left join fetch examAttempt.subject left join fetch examAttempt.user")
List<ExamAttempt> findAllWithToOneRelationships();
@Query(
"select examAttempt from ExamAttempt examAttempt left join fetch examAttempt.subject left join fetch examAttempt.user where examAttempt.id =:id"
)
Optional<ExamAttempt> findOneWithToOneRelationships(@Param("id") Long id);
}
@@ -0,0 +1,40 @@
package com.example.questionbank.repository;
import com.example.questionbank.domain.Question;
import java.util.List;
import java.util.Optional;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.*;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
/**
* Spring Data JPA repository for the Question entity.
*/
@Repository
public interface QuestionRepository extends JpaRepository<Question, Long> {
default Optional<Question> findOneWithEagerRelationships(Long id) {
return this.findOneWithToOneRelationships(id);
}
default List<Question> findAllWithEagerRelationships() {
return this.findAllWithToOneRelationships();
}
default Page<Question> findAllWithEagerRelationships(Pageable pageable) {
return this.findAllWithToOneRelationships(pageable);
}
@Query(
value = "select question from Question question left join fetch question.subject",
countQuery = "select count(question) from Question question"
)
Page<Question> findAllWithToOneRelationships(Pageable pageable);
@Query("select question from Question question left join fetch question.subject")
List<Question> findAllWithToOneRelationships();
@Query("select question from Question question left join fetch question.subject where question.id =:id")
Optional<Question> findOneWithToOneRelationships(@Param("id") Long id);
}
@@ -0,0 +1,12 @@
package com.example.questionbank.repository;
import com.example.questionbank.domain.Subject;
import org.springframework.data.jpa.repository.*;
import org.springframework.stereotype.Repository;
/**
* Spring Data JPA repository for the Subject entity.
*/
@SuppressWarnings("unused")
@Repository
public interface SubjectRepository extends JpaRepository<Subject, Long> {}
@@ -0,0 +1,112 @@
package com.example.questionbank.service;
import com.example.questionbank.domain.Choice;
import com.example.questionbank.repository.ChoiceRepository;
import com.example.questionbank.service.dto.ChoiceDTO;
import com.example.questionbank.service.mapper.ChoiceMapper;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
/**
* Service Implementation for managing {@link com.example.questionbank.domain.Choice}.
*/
@Service
@Transactional
public class ChoiceService {
private static final Logger LOG = LoggerFactory.getLogger(ChoiceService.class);
private final ChoiceRepository choiceRepository;
private final ChoiceMapper choiceMapper;
public ChoiceService(ChoiceRepository choiceRepository, ChoiceMapper choiceMapper) {
this.choiceRepository = choiceRepository;
this.choiceMapper = choiceMapper;
}
/**
* Save a choice.
*
* @param choiceDTO the entity to save.
* @return the persisted entity.
*/
public ChoiceDTO save(ChoiceDTO choiceDTO) {
LOG.debug("Request to save Choice : {}", choiceDTO);
Choice choice = choiceMapper.toEntity(choiceDTO);
choice = choiceRepository.save(choice);
return choiceMapper.toDto(choice);
}
/**
* Update a choice.
*
* @param choiceDTO the entity to save.
* @return the persisted entity.
*/
public ChoiceDTO update(ChoiceDTO choiceDTO) {
LOG.debug("Request to update Choice : {}", choiceDTO);
Choice choice = choiceMapper.toEntity(choiceDTO);
choice = choiceRepository.save(choice);
return choiceMapper.toDto(choice);
}
/**
* Partially update a choice.
*
* @param choiceDTO the entity to update partially.
* @return the persisted entity.
*/
public Optional<ChoiceDTO> partialUpdate(ChoiceDTO choiceDTO) {
LOG.debug("Request to partially update Choice : {}", choiceDTO);
return choiceRepository
.findById(choiceDTO.getId())
.map(existingChoice -> {
choiceMapper.partialUpdate(existingChoice, choiceDTO);
return existingChoice;
})
.map(choiceRepository::save)
.map(choiceMapper::toDto);
}
/**
* Get all the choices.
*
* @return the list of entities.
*/
@Transactional(readOnly = true)
public List<ChoiceDTO> findAll() {
LOG.debug("Request to get all Choices");
return choiceRepository.findAll().stream().map(choiceMapper::toDto).collect(Collectors.toCollection(LinkedList::new));
}
/**
* Get one choice by id.
*
* @param id the id of the entity.
* @return the entity.
*/
@Transactional(readOnly = true)
public Optional<ChoiceDTO> findOne(Long id) {
LOG.debug("Request to get Choice : {}", id);
return choiceRepository.findById(id).map(choiceMapper::toDto);
}
/**
* Delete the choice by id.
*
* @param id the id of the entity.
*/
public void delete(Long id) {
LOG.debug("Request to delete Choice : {}", id);
choiceRepository.deleteById(id);
}
}
@@ -0,0 +1,112 @@
package com.example.questionbank.service;
import com.example.questionbank.domain.ExamAnswer;
import com.example.questionbank.repository.ExamAnswerRepository;
import com.example.questionbank.service.dto.ExamAnswerDTO;
import com.example.questionbank.service.mapper.ExamAnswerMapper;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
/**
* Service Implementation for managing {@link com.example.questionbank.domain.ExamAnswer}.
*/
@Service
@Transactional
public class ExamAnswerService {
private static final Logger LOG = LoggerFactory.getLogger(ExamAnswerService.class);
private final ExamAnswerRepository examAnswerRepository;
private final ExamAnswerMapper examAnswerMapper;
public ExamAnswerService(ExamAnswerRepository examAnswerRepository, ExamAnswerMapper examAnswerMapper) {
this.examAnswerRepository = examAnswerRepository;
this.examAnswerMapper = examAnswerMapper;
}
/**
* Save a examAnswer.
*
* @param examAnswerDTO the entity to save.
* @return the persisted entity.
*/
public ExamAnswerDTO save(ExamAnswerDTO examAnswerDTO) {
LOG.debug("Request to save ExamAnswer : {}", examAnswerDTO);
ExamAnswer examAnswer = examAnswerMapper.toEntity(examAnswerDTO);
examAnswer = examAnswerRepository.save(examAnswer);
return examAnswerMapper.toDto(examAnswer);
}
/**
* Update a examAnswer.
*
* @param examAnswerDTO the entity to save.
* @return the persisted entity.
*/
public ExamAnswerDTO update(ExamAnswerDTO examAnswerDTO) {
LOG.debug("Request to update ExamAnswer : {}", examAnswerDTO);
ExamAnswer examAnswer = examAnswerMapper.toEntity(examAnswerDTO);
examAnswer = examAnswerRepository.save(examAnswer);
return examAnswerMapper.toDto(examAnswer);
}
/**
* Partially update a examAnswer.
*
* @param examAnswerDTO the entity to update partially.
* @return the persisted entity.
*/
public Optional<ExamAnswerDTO> partialUpdate(ExamAnswerDTO examAnswerDTO) {
LOG.debug("Request to partially update ExamAnswer : {}", examAnswerDTO);
return examAnswerRepository
.findById(examAnswerDTO.getId())
.map(existingExamAnswer -> {
examAnswerMapper.partialUpdate(existingExamAnswer, examAnswerDTO);
return existingExamAnswer;
})
.map(examAnswerRepository::save)
.map(examAnswerMapper::toDto);
}
/**
* Get all the examAnswers.
*
* @return the list of entities.
*/
@Transactional(readOnly = true)
public List<ExamAnswerDTO> findAll() {
LOG.debug("Request to get all ExamAnswers");
return examAnswerRepository.findAll().stream().map(examAnswerMapper::toDto).collect(Collectors.toCollection(LinkedList::new));
}
/**
* Get one examAnswer by id.
*
* @param id the id of the entity.
* @return the entity.
*/
@Transactional(readOnly = true)
public Optional<ExamAnswerDTO> findOne(Long id) {
LOG.debug("Request to get ExamAnswer : {}", id);
return examAnswerRepository.findById(id).map(examAnswerMapper::toDto);
}
/**
* Delete the examAnswer by id.
*
* @param id the id of the entity.
*/
public void delete(Long id) {
LOG.debug("Request to delete ExamAnswer : {}", id);
examAnswerRepository.deleteById(id);
}
}
@@ -0,0 +1,121 @@
package com.example.questionbank.service;
import com.example.questionbank.domain.ExamAttempt;
import com.example.questionbank.repository.ExamAttemptRepository;
import com.example.questionbank.service.dto.ExamAttemptDTO;
import com.example.questionbank.service.mapper.ExamAttemptMapper;
import java.util.Optional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
/**
* Service Implementation for managing {@link com.example.questionbank.domain.ExamAttempt}.
*/
@Service
@Transactional
public class ExamAttemptService {
private static final Logger LOG = LoggerFactory.getLogger(ExamAttemptService.class);
private final ExamAttemptRepository examAttemptRepository;
private final ExamAttemptMapper examAttemptMapper;
public ExamAttemptService(ExamAttemptRepository examAttemptRepository, ExamAttemptMapper examAttemptMapper) {
this.examAttemptRepository = examAttemptRepository;
this.examAttemptMapper = examAttemptMapper;
}
/**
* Save a examAttempt.
*
* @param examAttemptDTO the entity to save.
* @return the persisted entity.
*/
public ExamAttemptDTO save(ExamAttemptDTO examAttemptDTO) {
LOG.debug("Request to save ExamAttempt : {}", examAttemptDTO);
ExamAttempt examAttempt = examAttemptMapper.toEntity(examAttemptDTO);
examAttempt = examAttemptRepository.save(examAttempt);
return examAttemptMapper.toDto(examAttempt);
}
/**
* Update a examAttempt.
*
* @param examAttemptDTO the entity to save.
* @return the persisted entity.
*/
public ExamAttemptDTO update(ExamAttemptDTO examAttemptDTO) {
LOG.debug("Request to update ExamAttempt : {}", examAttemptDTO);
ExamAttempt examAttempt = examAttemptMapper.toEntity(examAttemptDTO);
examAttempt = examAttemptRepository.save(examAttempt);
return examAttemptMapper.toDto(examAttempt);
}
/**
* Partially update a examAttempt.
*
* @param examAttemptDTO the entity to update partially.
* @return the persisted entity.
*/
public Optional<ExamAttemptDTO> partialUpdate(ExamAttemptDTO examAttemptDTO) {
LOG.debug("Request to partially update ExamAttempt : {}", examAttemptDTO);
return examAttemptRepository
.findById(examAttemptDTO.getId())
.map(existingExamAttempt -> {
examAttemptMapper.partialUpdate(existingExamAttempt, examAttemptDTO);
return existingExamAttempt;
})
.map(examAttemptRepository::save)
.map(examAttemptMapper::toDto);
}
/**
* Get all the examAttempts.
*
* @param pageable the pagination information.
* @return the list of entities.
*/
@Transactional(readOnly = true)
public Page<ExamAttemptDTO> findAll(Pageable pageable) {
LOG.debug("Request to get all ExamAttempts");
return examAttemptRepository.findAll(pageable).map(examAttemptMapper::toDto);
}
/**
* Get all the examAttempts with eager load of many-to-many relationships.
*
* @return the list of entities.
*/
public Page<ExamAttemptDTO> findAllWithEagerRelationships(Pageable pageable) {
return examAttemptRepository.findAllWithEagerRelationships(pageable).map(examAttemptMapper::toDto);
}
/**
* Get one examAttempt by id.
*
* @param id the id of the entity.
* @return the entity.
*/
@Transactional(readOnly = true)
public Optional<ExamAttemptDTO> findOne(Long id) {
LOG.debug("Request to get ExamAttempt : {}", id);
return examAttemptRepository.findOneWithEagerRelationships(id).map(examAttemptMapper::toDto);
}
/**
* Delete the examAttempt by id.
*
* @param id the id of the entity.
*/
public void delete(Long id) {
LOG.debug("Request to delete ExamAttempt : {}", id);
examAttemptRepository.deleteById(id);
}
}
@@ -0,0 +1,121 @@
package com.example.questionbank.service;
import com.example.questionbank.domain.Question;
import com.example.questionbank.repository.QuestionRepository;
import com.example.questionbank.service.dto.QuestionDTO;
import com.example.questionbank.service.mapper.QuestionMapper;
import java.util.Optional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
/**
* Service Implementation for managing {@link com.example.questionbank.domain.Question}.
*/
@Service
@Transactional
public class QuestionService {
private static final Logger LOG = LoggerFactory.getLogger(QuestionService.class);
private final QuestionRepository questionRepository;
private final QuestionMapper questionMapper;
public QuestionService(QuestionRepository questionRepository, QuestionMapper questionMapper) {
this.questionRepository = questionRepository;
this.questionMapper = questionMapper;
}
/**
* Save a question.
*
* @param questionDTO the entity to save.
* @return the persisted entity.
*/
public QuestionDTO save(QuestionDTO questionDTO) {
LOG.debug("Request to save Question : {}", questionDTO);
Question question = questionMapper.toEntity(questionDTO);
question = questionRepository.save(question);
return questionMapper.toDto(question);
}
/**
* Update a question.
*
* @param questionDTO the entity to save.
* @return the persisted entity.
*/
public QuestionDTO update(QuestionDTO questionDTO) {
LOG.debug("Request to update Question : {}", questionDTO);
Question question = questionMapper.toEntity(questionDTO);
question = questionRepository.save(question);
return questionMapper.toDto(question);
}
/**
* Partially update a question.
*
* @param questionDTO the entity to update partially.
* @return the persisted entity.
*/
public Optional<QuestionDTO> partialUpdate(QuestionDTO questionDTO) {
LOG.debug("Request to partially update Question : {}", questionDTO);
return questionRepository
.findById(questionDTO.getId())
.map(existingQuestion -> {
questionMapper.partialUpdate(existingQuestion, questionDTO);
return existingQuestion;
})
.map(questionRepository::save)
.map(questionMapper::toDto);
}
/**
* Get all the questions.
*
* @param pageable the pagination information.
* @return the list of entities.
*/
@Transactional(readOnly = true)
public Page<QuestionDTO> findAll(Pageable pageable) {
LOG.debug("Request to get all Questions");
return questionRepository.findAll(pageable).map(questionMapper::toDto);
}
/**
* Get all the questions with eager load of many-to-many relationships.
*
* @return the list of entities.
*/
public Page<QuestionDTO> findAllWithEagerRelationships(Pageable pageable) {
return questionRepository.findAllWithEagerRelationships(pageable).map(questionMapper::toDto);
}
/**
* Get one question by id.
*
* @param id the id of the entity.
* @return the entity.
*/
@Transactional(readOnly = true)
public Optional<QuestionDTO> findOne(Long id) {
LOG.debug("Request to get Question : {}", id);
return questionRepository.findOneWithEagerRelationships(id).map(questionMapper::toDto);
}
/**
* Delete the question by id.
*
* @param id the id of the entity.
*/
public void delete(Long id) {
LOG.debug("Request to delete Question : {}", id);
questionRepository.deleteById(id);
}
}
@@ -0,0 +1,112 @@
package com.example.questionbank.service;
import com.example.questionbank.domain.Subject;
import com.example.questionbank.repository.SubjectRepository;
import com.example.questionbank.service.dto.SubjectDTO;
import com.example.questionbank.service.mapper.SubjectMapper;
import java.util.Optional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
/**
* Service Implementation for managing {@link com.example.questionbank.domain.Subject}.
*/
@Service
@Transactional
public class SubjectService {
private static final Logger LOG = LoggerFactory.getLogger(SubjectService.class);
private final SubjectRepository subjectRepository;
private final SubjectMapper subjectMapper;
public SubjectService(SubjectRepository subjectRepository, SubjectMapper subjectMapper) {
this.subjectRepository = subjectRepository;
this.subjectMapper = subjectMapper;
}
/**
* Save a subject.
*
* @param subjectDTO the entity to save.
* @return the persisted entity.
*/
public SubjectDTO save(SubjectDTO subjectDTO) {
LOG.debug("Request to save Subject : {}", subjectDTO);
Subject subject = subjectMapper.toEntity(subjectDTO);
subject = subjectRepository.save(subject);
return subjectMapper.toDto(subject);
}
/**
* Update a subject.
*
* @param subjectDTO the entity to save.
* @return the persisted entity.
*/
public SubjectDTO update(SubjectDTO subjectDTO) {
LOG.debug("Request to update Subject : {}", subjectDTO);
Subject subject = subjectMapper.toEntity(subjectDTO);
subject = subjectRepository.save(subject);
return subjectMapper.toDto(subject);
}
/**
* Partially update a subject.
*
* @param subjectDTO the entity to update partially.
* @return the persisted entity.
*/
public Optional<SubjectDTO> partialUpdate(SubjectDTO subjectDTO) {
LOG.debug("Request to partially update Subject : {}", subjectDTO);
return subjectRepository
.findById(subjectDTO.getId())
.map(existingSubject -> {
subjectMapper.partialUpdate(existingSubject, subjectDTO);
return existingSubject;
})
.map(subjectRepository::save)
.map(subjectMapper::toDto);
}
/**
* Get all the subjects.
*
* @param pageable the pagination information.
* @return the list of entities.
*/
@Transactional(readOnly = true)
public Page<SubjectDTO> findAll(Pageable pageable) {
LOG.debug("Request to get all Subjects");
return subjectRepository.findAll(pageable).map(subjectMapper::toDto);
}
/**
* Get one subject by id.
*
* @param id the id of the entity.
* @return the entity.
*/
@Transactional(readOnly = true)
public Optional<SubjectDTO> findOne(Long id) {
LOG.debug("Request to get Subject : {}", id);
return subjectRepository.findById(id).map(subjectMapper::toDto);
}
/**
* Delete the subject by id.
*
* @param id the id of the entity.
*/
public void delete(Long id) {
LOG.debug("Request to delete Subject : {}", id);
subjectRepository.deleteById(id);
}
}
@@ -0,0 +1,115 @@
package com.example.questionbank.service.dto;
import com.example.questionbank.domain.enumeration.OptionKey;
import jakarta.validation.constraints.*;
import java.io.Serializable;
import java.util.Objects;
/**
* A DTO for the {@link com.example.questionbank.domain.Choice} entity.
*/
@SuppressWarnings("common-java:DuplicatedBlocks")
public class ChoiceDTO implements Serializable {
private Long id;
@NotNull
private OptionKey optionKey;
@NotNull
@Size(max = 500)
private String content;
@NotNull
@Min(value = 1)
@Max(value = 4)
private Integer displayOrder;
@NotNull
private Boolean correct;
@NotNull
private QuestionDTO question;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public OptionKey getOptionKey() {
return optionKey;
}
public void setOptionKey(OptionKey optionKey) {
this.optionKey = optionKey;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public Integer getDisplayOrder() {
return displayOrder;
}
public void setDisplayOrder(Integer displayOrder) {
this.displayOrder = displayOrder;
}
public Boolean getCorrect() {
return correct;
}
public void setCorrect(Boolean correct) {
this.correct = correct;
}
public QuestionDTO getQuestion() {
return question;
}
public void setQuestion(QuestionDTO question) {
this.question = question;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof ChoiceDTO)) {
return false;
}
ChoiceDTO choiceDTO = (ChoiceDTO) o;
if (this.id == null) {
return false;
}
return Objects.equals(this.id, choiceDTO.id);
}
@Override
public int hashCode() {
return Objects.hash(this.id);
}
// prettier-ignore
@Override
public String toString() {
return "ChoiceDTO{" +
"id=" + getId() +
", optionKey='" + getOptionKey() + "'" +
", content='" + getContent() + "'" +
", displayOrder=" + getDisplayOrder() +
", correct='" + getCorrect() + "'" +
", question=" + getQuestion() +
"}";
}
}
@@ -0,0 +1,147 @@
package com.example.questionbank.service.dto;
import com.example.questionbank.domain.enumeration.OptionKey;
import jakarta.validation.constraints.*;
import java.io.Serializable;
import java.util.Objects;
/**
* A DTO for the {@link com.example.questionbank.domain.ExamAnswer} entity.
*/
@SuppressWarnings("common-java:DuplicatedBlocks")
public class ExamAnswerDTO implements Serializable {
private Long id;
@NotNull
@Size(max = 2000)
private String questionTextSnapshot;
@Size(max = 2000)
private String explanationSnapshot;
private OptionKey selectedOption;
@Size(max = 500)
private String selectedContentSnapshot;
private Boolean correct;
@Min(value = 0)
private Integer awardedPoints;
@NotNull
private QuestionDTO question;
@NotNull
private ExamAttemptDTO attempt;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getQuestionTextSnapshot() {
return questionTextSnapshot;
}
public void setQuestionTextSnapshot(String questionTextSnapshot) {
this.questionTextSnapshot = questionTextSnapshot;
}
public String getExplanationSnapshot() {
return explanationSnapshot;
}
public void setExplanationSnapshot(String explanationSnapshot) {
this.explanationSnapshot = explanationSnapshot;
}
public OptionKey getSelectedOption() {
return selectedOption;
}
public void setSelectedOption(OptionKey selectedOption) {
this.selectedOption = selectedOption;
}
public String getSelectedContentSnapshot() {
return selectedContentSnapshot;
}
public void setSelectedContentSnapshot(String selectedContentSnapshot) {
this.selectedContentSnapshot = selectedContentSnapshot;
}
public Boolean getCorrect() {
return correct;
}
public void setCorrect(Boolean correct) {
this.correct = correct;
}
public Integer getAwardedPoints() {
return awardedPoints;
}
public void setAwardedPoints(Integer awardedPoints) {
this.awardedPoints = awardedPoints;
}
public QuestionDTO getQuestion() {
return question;
}
public void setQuestion(QuestionDTO question) {
this.question = question;
}
public ExamAttemptDTO getAttempt() {
return attempt;
}
public void setAttempt(ExamAttemptDTO attempt) {
this.attempt = attempt;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof ExamAnswerDTO)) {
return false;
}
ExamAnswerDTO examAnswerDTO = (ExamAnswerDTO) o;
if (this.id == null) {
return false;
}
return Objects.equals(this.id, examAnswerDTO.id);
}
@Override
public int hashCode() {
return Objects.hash(this.id);
}
// prettier-ignore
@Override
public String toString() {
return "ExamAnswerDTO{" +
"id=" + getId() +
", questionTextSnapshot='" + getQuestionTextSnapshot() + "'" +
", explanationSnapshot='" + getExplanationSnapshot() + "'" +
", selectedOption='" + getSelectedOption() + "'" +
", selectedContentSnapshot='" + getSelectedContentSnapshot() + "'" +
", correct='" + getCorrect() + "'" +
", awardedPoints=" + getAwardedPoints() +
", question=" + getQuestion() +
", attempt=" + getAttempt() +
"}";
}
}
@@ -0,0 +1,124 @@
package com.example.questionbank.service.dto;
import com.example.questionbank.domain.enumeration.AttemptStatus;
import jakarta.validation.constraints.*;
import java.io.Serializable;
import java.time.Instant;
import java.util.Objects;
/**
* A DTO for the {@link com.example.questionbank.domain.ExamAttempt} entity.
*/
@SuppressWarnings("common-java:DuplicatedBlocks")
public class ExamAttemptDTO implements Serializable {
private Long id;
@NotNull
private Instant startedAt;
private Instant submittedAt;
@NotNull
private AttemptStatus status;
@Min(value = 0)
private Integer score;
@NotNull
private SubjectDTO subject;
@NotNull
private UserDTO user;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Instant getStartedAt() {
return startedAt;
}
public void setStartedAt(Instant startedAt) {
this.startedAt = startedAt;
}
public Instant getSubmittedAt() {
return submittedAt;
}
public void setSubmittedAt(Instant submittedAt) {
this.submittedAt = submittedAt;
}
public AttemptStatus getStatus() {
return status;
}
public void setStatus(AttemptStatus status) {
this.status = status;
}
public Integer getScore() {
return score;
}
public void setScore(Integer score) {
this.score = score;
}
public SubjectDTO getSubject() {
return subject;
}
public void setSubject(SubjectDTO subject) {
this.subject = subject;
}
public UserDTO getUser() {
return user;
}
public void setUser(UserDTO user) {
this.user = user;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof ExamAttemptDTO)) {
return false;
}
ExamAttemptDTO examAttemptDTO = (ExamAttemptDTO) o;
if (this.id == null) {
return false;
}
return Objects.equals(this.id, examAttemptDTO.id);
}
@Override
public int hashCode() {
return Objects.hash(this.id);
}
// prettier-ignore
@Override
public String toString() {
return "ExamAttemptDTO{" +
"id=" + getId() +
", startedAt='" + getStartedAt() + "'" +
", submittedAt='" + getSubmittedAt() + "'" +
", status='" + getStatus() + "'" +
", score=" + getScore() +
", subject=" + getSubject() +
", user=" + getUser() +
"}";
}
}
@@ -0,0 +1,100 @@
package com.example.questionbank.service.dto;
import jakarta.validation.constraints.*;
import java.io.Serializable;
import java.util.Objects;
/**
* A DTO for the {@link com.example.questionbank.domain.Question} entity.
*/
@SuppressWarnings("common-java:DuplicatedBlocks")
public class QuestionDTO implements Serializable {
private Long id;
@NotNull
@Size(min = 5, max = 2000)
private String prompt;
@Size(max = 2000)
private String explanation;
@NotNull
private Boolean active;
@NotNull
private SubjectDTO subject;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getPrompt() {
return prompt;
}
public void setPrompt(String prompt) {
this.prompt = prompt;
}
public String getExplanation() {
return explanation;
}
public void setExplanation(String explanation) {
this.explanation = explanation;
}
public Boolean getActive() {
return active;
}
public void setActive(Boolean active) {
this.active = active;
}
public SubjectDTO getSubject() {
return subject;
}
public void setSubject(SubjectDTO subject) {
this.subject = subject;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof QuestionDTO)) {
return false;
}
QuestionDTO questionDTO = (QuestionDTO) o;
if (this.id == null) {
return false;
}
return Objects.equals(this.id, questionDTO.id);
}
@Override
public int hashCode() {
return Objects.hash(this.id);
}
// prettier-ignore
@Override
public String toString() {
return "QuestionDTO{" +
"id=" + getId() +
", prompt='" + getPrompt() + "'" +
", explanation='" + getExplanation() + "'" +
", active='" + getActive() + "'" +
", subject=" + getSubject() +
"}";
}
}
@@ -0,0 +1,88 @@
package com.example.questionbank.service.dto;
import jakarta.validation.constraints.*;
import java.io.Serializable;
import java.util.Objects;
/**
* A DTO for the {@link com.example.questionbank.domain.Subject} entity.
*/
@SuppressWarnings("common-java:DuplicatedBlocks")
public class SubjectDTO implements Serializable {
private Long id;
@NotNull
@Size(min = 2, max = 100)
private String name;
@Size(max = 1000)
private String description;
@NotNull
private Boolean active;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Boolean getActive() {
return active;
}
public void setActive(Boolean active) {
this.active = active;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof SubjectDTO)) {
return false;
}
SubjectDTO subjectDTO = (SubjectDTO) o;
if (this.id == null) {
return false;
}
return Objects.equals(this.id, subjectDTO.id);
}
@Override
public int hashCode() {
return Objects.hash(this.id);
}
// prettier-ignore
@Override
public String toString() {
return "SubjectDTO{" +
"id=" + getId() +
", name='" + getName() + "'" +
", description='" + getDescription() + "'" +
", active='" + getActive() + "'" +
"}";
}
}
@@ -0,0 +1,21 @@
package com.example.questionbank.service.mapper;
import com.example.questionbank.domain.Choice;
import com.example.questionbank.domain.Question;
import com.example.questionbank.service.dto.ChoiceDTO;
import com.example.questionbank.service.dto.QuestionDTO;
import org.mapstruct.*;
/**
* Mapper for the entity {@link Choice} and its DTO {@link ChoiceDTO}.
*/
@Mapper(componentModel = "spring")
public interface ChoiceMapper extends EntityMapper<ChoiceDTO, Choice> {
@Mapping(target = "question", source = "question", qualifiedByName = "questionId")
ChoiceDTO toDto(Choice s);
@Named("questionId")
@BeanMapping(ignoreByDefault = true)
@Mapping(target = "id", source = "id")
QuestionDTO toDtoQuestionId(Question question);
}
@@ -0,0 +1,28 @@
package com.example.questionbank.service.mapper;
import java.util.List;
import org.mapstruct.BeanMapping;
import org.mapstruct.MappingTarget;
import org.mapstruct.Named;
import org.mapstruct.NullValuePropertyMappingStrategy;
/**
* 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);
@Named("partialUpdate")
@BeanMapping(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE)
void partialUpdate(@MappingTarget E entity, D dto);
}
@@ -0,0 +1,29 @@
package com.example.questionbank.service.mapper;
import com.example.questionbank.domain.ExamAnswer;
import com.example.questionbank.domain.ExamAttempt;
import com.example.questionbank.domain.Question;
import com.example.questionbank.service.dto.ExamAnswerDTO;
import com.example.questionbank.service.dto.ExamAttemptDTO;
import com.example.questionbank.service.dto.QuestionDTO;
import org.mapstruct.*;
/**
* Mapper for the entity {@link ExamAnswer} and its DTO {@link ExamAnswerDTO}.
*/
@Mapper(componentModel = "spring")
public interface ExamAnswerMapper extends EntityMapper<ExamAnswerDTO, ExamAnswer> {
@Mapping(target = "question", source = "question", qualifiedByName = "questionId")
@Mapping(target = "attempt", source = "attempt", qualifiedByName = "examAttemptId")
ExamAnswerDTO toDto(ExamAnswer s);
@Named("questionId")
@BeanMapping(ignoreByDefault = true)
@Mapping(target = "id", source = "id")
QuestionDTO toDtoQuestionId(Question question);
@Named("examAttemptId")
@BeanMapping(ignoreByDefault = true)
@Mapping(target = "id", source = "id")
ExamAttemptDTO toDtoExamAttemptId(ExamAttempt examAttempt);
}
@@ -0,0 +1,31 @@
package com.example.questionbank.service.mapper;
import com.example.questionbank.domain.ExamAttempt;
import com.example.questionbank.domain.Subject;
import com.example.questionbank.domain.User;
import com.example.questionbank.service.dto.ExamAttemptDTO;
import com.example.questionbank.service.dto.SubjectDTO;
import com.example.questionbank.service.dto.UserDTO;
import org.mapstruct.*;
/**
* Mapper for the entity {@link ExamAttempt} and its DTO {@link ExamAttemptDTO}.
*/
@Mapper(componentModel = "spring")
public interface ExamAttemptMapper extends EntityMapper<ExamAttemptDTO, ExamAttempt> {
@Mapping(target = "subject", source = "subject", qualifiedByName = "subjectName")
@Mapping(target = "user", source = "user", qualifiedByName = "userLogin")
ExamAttemptDTO toDto(ExamAttempt s);
@Named("subjectName")
@BeanMapping(ignoreByDefault = true)
@Mapping(target = "id", source = "id")
@Mapping(target = "name", source = "name")
SubjectDTO toDtoSubjectName(Subject subject);
@Named("userLogin")
@BeanMapping(ignoreByDefault = true)
@Mapping(target = "id", source = "id")
@Mapping(target = "login", source = "login")
UserDTO toDtoUserLogin(User user);
}
@@ -0,0 +1,22 @@
package com.example.questionbank.service.mapper;
import com.example.questionbank.domain.Question;
import com.example.questionbank.domain.Subject;
import com.example.questionbank.service.dto.QuestionDTO;
import com.example.questionbank.service.dto.SubjectDTO;
import org.mapstruct.*;
/**
* Mapper for the entity {@link Question} and its DTO {@link QuestionDTO}.
*/
@Mapper(componentModel = "spring")
public interface QuestionMapper extends EntityMapper<QuestionDTO, Question> {
@Mapping(target = "subject", source = "subject", qualifiedByName = "subjectName")
QuestionDTO toDto(Question s);
@Named("subjectName")
@BeanMapping(ignoreByDefault = true)
@Mapping(target = "id", source = "id")
@Mapping(target = "name", source = "name")
SubjectDTO toDtoSubjectName(Subject subject);
}
@@ -0,0 +1,11 @@
package com.example.questionbank.service.mapper;
import com.example.questionbank.domain.Subject;
import com.example.questionbank.service.dto.SubjectDTO;
import org.mapstruct.*;
/**
* Mapper for the entity {@link Subject} and its DTO {@link SubjectDTO}.
*/
@Mapper(componentModel = "spring")
public interface SubjectMapper extends EntityMapper<SubjectDTO, Subject> {}
@@ -0,0 +1,171 @@
package com.example.questionbank.web.rest;
import com.example.questionbank.repository.ChoiceRepository;
import com.example.questionbank.service.ChoiceService;
import com.example.questionbank.service.dto.ChoiceDTO;
import com.example.questionbank.web.rest.errors.BadRequestAlertException;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import tech.jhipster.web.util.HeaderUtil;
import tech.jhipster.web.util.ResponseUtil;
/**
* REST controller for managing {@link com.example.questionbank.domain.Choice}.
*/
@RestController
@RequestMapping("/api/choices")
public class ChoiceResource {
private static final Logger LOG = LoggerFactory.getLogger(ChoiceResource.class);
private static final String ENTITY_NAME = "choice";
@Value("${jhipster.clientApp.name:questionBank}")
private String applicationName;
private final ChoiceService choiceService;
private final ChoiceRepository choiceRepository;
public ChoiceResource(ChoiceService choiceService, ChoiceRepository choiceRepository) {
this.choiceService = choiceService;
this.choiceRepository = choiceRepository;
}
/**
* {@code POST /choices} : Create a new choice.
*
* @param choiceDTO the choiceDTO to create.
* @return the {@link ResponseEntity} with status {@code 201 (Created)} and with body the new choiceDTO, or with status {@code 400 (Bad Request)} if the choice has already an ID.
* @throws URISyntaxException if the Location URI syntax is incorrect.
*/
@PostMapping("")
public ResponseEntity<ChoiceDTO> createChoice(@Valid @RequestBody ChoiceDTO choiceDTO) throws URISyntaxException {
LOG.debug("REST request to save Choice : {}", choiceDTO);
if (choiceDTO.getId() != null) {
throw new BadRequestAlertException("A new choice cannot already have an ID", ENTITY_NAME, "idexists");
}
choiceDTO = choiceService.save(choiceDTO);
return ResponseEntity.created(new URI("/api/choices/" + choiceDTO.getId()))
.headers(HeaderUtil.createEntityCreationAlert(applicationName, true, ENTITY_NAME, choiceDTO.getId().toString()))
.body(choiceDTO);
}
/**
* {@code PUT /choices/:id} : Updates an existing choice.
*
* @param id the id of the choiceDTO to save.
* @param choiceDTO the choiceDTO to update.
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body the updated choiceDTO,
* or with status {@code 400 (Bad Request)} if the choiceDTO is not valid,
* or with status {@code 500 (Internal Server Error)} if the choiceDTO couldn't be updated.
* @throws URISyntaxException if the Location URI syntax is incorrect.
*/
@PutMapping("/{id}")
public ResponseEntity<ChoiceDTO> updateChoice(
@PathVariable(value = "id", required = false) final Long id,
@Valid @RequestBody ChoiceDTO choiceDTO
) throws URISyntaxException {
LOG.debug("REST request to update Choice : {}, {}", id, choiceDTO);
if (choiceDTO.getId() == null) {
throw new BadRequestAlertException("Invalid id", ENTITY_NAME, "idnull");
}
if (!Objects.equals(id, choiceDTO.getId())) {
throw new BadRequestAlertException("Invalid ID", ENTITY_NAME, "idinvalid");
}
if (!choiceRepository.existsById(id)) {
throw new BadRequestAlertException("Entity not found", ENTITY_NAME, "idnotfound");
}
choiceDTO = choiceService.update(choiceDTO);
return ResponseEntity.ok()
.headers(HeaderUtil.createEntityUpdateAlert(applicationName, true, ENTITY_NAME, choiceDTO.getId().toString()))
.body(choiceDTO);
}
/**
* {@code PATCH /choices/:id} : Partial updates given fields of an existing choice, field will ignore if it is null
*
* @param id the id of the choiceDTO to save.
* @param choiceDTO the choiceDTO to update.
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body the updated choiceDTO,
* or with status {@code 400 (Bad Request)} if the choiceDTO is not valid,
* or with status {@code 404 (Not Found)} if the choiceDTO is not found,
* or with status {@code 500 (Internal Server Error)} if the choiceDTO couldn't be updated.
* @throws URISyntaxException if the Location URI syntax is incorrect.
*/
@PatchMapping(value = "/{id}", consumes = { "application/json", "application/merge-patch+json" })
public ResponseEntity<ChoiceDTO> partialUpdateChoice(
@PathVariable(value = "id", required = false) final Long id,
@NotNull @RequestBody ChoiceDTO choiceDTO
) throws URISyntaxException {
LOG.debug("REST request to partial update Choice partially : {}, {}", id, choiceDTO);
if (choiceDTO.getId() == null) {
throw new BadRequestAlertException("Invalid id", ENTITY_NAME, "idnull");
}
if (!Objects.equals(id, choiceDTO.getId())) {
throw new BadRequestAlertException("Invalid ID", ENTITY_NAME, "idinvalid");
}
if (!choiceRepository.existsById(id)) {
throw new BadRequestAlertException("Entity not found", ENTITY_NAME, "idnotfound");
}
Optional<ChoiceDTO> result = choiceService.partialUpdate(choiceDTO);
return ResponseUtil.wrapOrNotFound(
result,
HeaderUtil.createEntityUpdateAlert(applicationName, true, ENTITY_NAME, choiceDTO.getId().toString())
);
}
/**
* {@code GET /choices} : get all the Choices.
*
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and the list of Choices in body.
*/
@GetMapping("")
public List<ChoiceDTO> getAllChoices() {
LOG.debug("REST request to get all Choices");
return choiceService.findAll();
}
/**
* {@code GET /choices/:id} : get the "id" choice.
*
* @param id the id of the choiceDTO to retrieve.
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body the choiceDTO, or with status {@code 404 (Not Found)}.
*/
@GetMapping("/{id}")
public ResponseEntity<ChoiceDTO> getChoice(@PathVariable("id") Long id) {
LOG.debug("REST request to get Choice : {}", id);
Optional<ChoiceDTO> choiceDTO = choiceService.findOne(id);
return ResponseUtil.wrapOrNotFound(choiceDTO);
}
/**
* {@code DELETE /choices/:id} : delete the "id" choice.
*
* @param id the id of the choiceDTO to delete.
* @return the {@link ResponseEntity} with status {@code 204 (NO_CONTENT)}.
*/
@DeleteMapping("/{id}")
public ResponseEntity<Void> deleteChoice(@PathVariable("id") Long id) {
LOG.debug("REST request to delete Choice : {}", id);
choiceService.delete(id);
return ResponseEntity.noContent()
.headers(HeaderUtil.createEntityDeletionAlert(applicationName, true, ENTITY_NAME, id.toString()))
.build();
}
}
@@ -0,0 +1,171 @@
package com.example.questionbank.web.rest;
import com.example.questionbank.repository.ExamAnswerRepository;
import com.example.questionbank.service.ExamAnswerService;
import com.example.questionbank.service.dto.ExamAnswerDTO;
import com.example.questionbank.web.rest.errors.BadRequestAlertException;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import tech.jhipster.web.util.HeaderUtil;
import tech.jhipster.web.util.ResponseUtil;
/**
* REST controller for managing {@link com.example.questionbank.domain.ExamAnswer}.
*/
@RestController
@RequestMapping("/api/exam-answers")
public class ExamAnswerResource {
private static final Logger LOG = LoggerFactory.getLogger(ExamAnswerResource.class);
private static final String ENTITY_NAME = "examAnswer";
@Value("${jhipster.clientApp.name:questionBank}")
private String applicationName;
private final ExamAnswerService examAnswerService;
private final ExamAnswerRepository examAnswerRepository;
public ExamAnswerResource(ExamAnswerService examAnswerService, ExamAnswerRepository examAnswerRepository) {
this.examAnswerService = examAnswerService;
this.examAnswerRepository = examAnswerRepository;
}
/**
* {@code POST /exam-answers} : Create a new examAnswer.
*
* @param examAnswerDTO the examAnswerDTO to create.
* @return the {@link ResponseEntity} with status {@code 201 (Created)} and with body the new examAnswerDTO, or with status {@code 400 (Bad Request)} if the examAnswer has already an ID.
* @throws URISyntaxException if the Location URI syntax is incorrect.
*/
@PostMapping("")
public ResponseEntity<ExamAnswerDTO> createExamAnswer(@Valid @RequestBody ExamAnswerDTO examAnswerDTO) throws URISyntaxException {
LOG.debug("REST request to save ExamAnswer : {}", examAnswerDTO);
if (examAnswerDTO.getId() != null) {
throw new BadRequestAlertException("A new examAnswer cannot already have an ID", ENTITY_NAME, "idexists");
}
examAnswerDTO = examAnswerService.save(examAnswerDTO);
return ResponseEntity.created(new URI("/api/exam-answers/" + examAnswerDTO.getId()))
.headers(HeaderUtil.createEntityCreationAlert(applicationName, true, ENTITY_NAME, examAnswerDTO.getId().toString()))
.body(examAnswerDTO);
}
/**
* {@code PUT /exam-answers/:id} : Updates an existing examAnswer.
*
* @param id the id of the examAnswerDTO to save.
* @param examAnswerDTO the examAnswerDTO to update.
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body the updated examAnswerDTO,
* or with status {@code 400 (Bad Request)} if the examAnswerDTO is not valid,
* or with status {@code 500 (Internal Server Error)} if the examAnswerDTO couldn't be updated.
* @throws URISyntaxException if the Location URI syntax is incorrect.
*/
@PutMapping("/{id}")
public ResponseEntity<ExamAnswerDTO> updateExamAnswer(
@PathVariable(value = "id", required = false) final Long id,
@Valid @RequestBody ExamAnswerDTO examAnswerDTO
) throws URISyntaxException {
LOG.debug("REST request to update ExamAnswer : {}, {}", id, examAnswerDTO);
if (examAnswerDTO.getId() == null) {
throw new BadRequestAlertException("Invalid id", ENTITY_NAME, "idnull");
}
if (!Objects.equals(id, examAnswerDTO.getId())) {
throw new BadRequestAlertException("Invalid ID", ENTITY_NAME, "idinvalid");
}
if (!examAnswerRepository.existsById(id)) {
throw new BadRequestAlertException("Entity not found", ENTITY_NAME, "idnotfound");
}
examAnswerDTO = examAnswerService.update(examAnswerDTO);
return ResponseEntity.ok()
.headers(HeaderUtil.createEntityUpdateAlert(applicationName, true, ENTITY_NAME, examAnswerDTO.getId().toString()))
.body(examAnswerDTO);
}
/**
* {@code PATCH /exam-answers/:id} : Partial updates given fields of an existing examAnswer, field will ignore if it is null
*
* @param id the id of the examAnswerDTO to save.
* @param examAnswerDTO the examAnswerDTO to update.
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body the updated examAnswerDTO,
* or with status {@code 400 (Bad Request)} if the examAnswerDTO is not valid,
* or with status {@code 404 (Not Found)} if the examAnswerDTO is not found,
* or with status {@code 500 (Internal Server Error)} if the examAnswerDTO couldn't be updated.
* @throws URISyntaxException if the Location URI syntax is incorrect.
*/
@PatchMapping(value = "/{id}", consumes = { "application/json", "application/merge-patch+json" })
public ResponseEntity<ExamAnswerDTO> partialUpdateExamAnswer(
@PathVariable(value = "id", required = false) final Long id,
@NotNull @RequestBody ExamAnswerDTO examAnswerDTO
) throws URISyntaxException {
LOG.debug("REST request to partial update ExamAnswer partially : {}, {}", id, examAnswerDTO);
if (examAnswerDTO.getId() == null) {
throw new BadRequestAlertException("Invalid id", ENTITY_NAME, "idnull");
}
if (!Objects.equals(id, examAnswerDTO.getId())) {
throw new BadRequestAlertException("Invalid ID", ENTITY_NAME, "idinvalid");
}
if (!examAnswerRepository.existsById(id)) {
throw new BadRequestAlertException("Entity not found", ENTITY_NAME, "idnotfound");
}
Optional<ExamAnswerDTO> result = examAnswerService.partialUpdate(examAnswerDTO);
return ResponseUtil.wrapOrNotFound(
result,
HeaderUtil.createEntityUpdateAlert(applicationName, true, ENTITY_NAME, examAnswerDTO.getId().toString())
);
}
/**
* {@code GET /exam-answers} : get all the Exam Answers.
*
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and the list of Exam Answers in body.
*/
@GetMapping("")
public List<ExamAnswerDTO> getAllExamAnswers() {
LOG.debug("REST request to get all ExamAnswers");
return examAnswerService.findAll();
}
/**
* {@code GET /exam-answers/:id} : get the "id" examAnswer.
*
* @param id the id of the examAnswerDTO to retrieve.
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body the examAnswerDTO, or with status {@code 404 (Not Found)}.
*/
@GetMapping("/{id}")
public ResponseEntity<ExamAnswerDTO> getExamAnswer(@PathVariable("id") Long id) {
LOG.debug("REST request to get ExamAnswer : {}", id);
Optional<ExamAnswerDTO> examAnswerDTO = examAnswerService.findOne(id);
return ResponseUtil.wrapOrNotFound(examAnswerDTO);
}
/**
* {@code DELETE /exam-answers/:id} : delete the "id" examAnswer.
*
* @param id the id of the examAnswerDTO to delete.
* @return the {@link ResponseEntity} with status {@code 204 (NO_CONTENT)}.
*/
@DeleteMapping("/{id}")
public ResponseEntity<Void> deleteExamAnswer(@PathVariable("id") Long id) {
LOG.debug("REST request to delete ExamAnswer : {}", id);
examAnswerService.delete(id);
return ResponseEntity.noContent()
.headers(HeaderUtil.createEntityDeletionAlert(applicationName, true, ENTITY_NAME, id.toString()))
.build();
}
}
@@ -0,0 +1,188 @@
package com.example.questionbank.web.rest;
import com.example.questionbank.repository.ExamAttemptRepository;
import com.example.questionbank.service.ExamAttemptService;
import com.example.questionbank.service.dto.ExamAttemptDTO;
import com.example.questionbank.web.rest.errors.BadRequestAlertException;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
import tech.jhipster.web.util.HeaderUtil;
import tech.jhipster.web.util.PaginationUtil;
import tech.jhipster.web.util.ResponseUtil;
/**
* REST controller for managing {@link com.example.questionbank.domain.ExamAttempt}.
*/
@RestController
@RequestMapping("/api/exam-attempts")
public class ExamAttemptResource {
private static final Logger LOG = LoggerFactory.getLogger(ExamAttemptResource.class);
private static final String ENTITY_NAME = "examAttempt";
@Value("${jhipster.clientApp.name:questionBank}")
private String applicationName;
private final ExamAttemptService examAttemptService;
private final ExamAttemptRepository examAttemptRepository;
public ExamAttemptResource(ExamAttemptService examAttemptService, ExamAttemptRepository examAttemptRepository) {
this.examAttemptService = examAttemptService;
this.examAttemptRepository = examAttemptRepository;
}
/**
* {@code POST /exam-attempts} : Create a new examAttempt.
*
* @param examAttemptDTO the examAttemptDTO to create.
* @return the {@link ResponseEntity} with status {@code 201 (Created)} and with body the new examAttemptDTO, or with status {@code 400 (Bad Request)} if the examAttempt has already an ID.
* @throws URISyntaxException if the Location URI syntax is incorrect.
*/
@PostMapping("")
public ResponseEntity<ExamAttemptDTO> createExamAttempt(@Valid @RequestBody ExamAttemptDTO examAttemptDTO) throws URISyntaxException {
LOG.debug("REST request to save ExamAttempt : {}", examAttemptDTO);
if (examAttemptDTO.getId() != null) {
throw new BadRequestAlertException("A new examAttempt cannot already have an ID", ENTITY_NAME, "idexists");
}
examAttemptDTO = examAttemptService.save(examAttemptDTO);
return ResponseEntity.created(new URI("/api/exam-attempts/" + examAttemptDTO.getId()))
.headers(HeaderUtil.createEntityCreationAlert(applicationName, true, ENTITY_NAME, examAttemptDTO.getId().toString()))
.body(examAttemptDTO);
}
/**
* {@code PUT /exam-attempts/:id} : Updates an existing examAttempt.
*
* @param id the id of the examAttemptDTO to save.
* @param examAttemptDTO the examAttemptDTO to update.
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body the updated examAttemptDTO,
* or with status {@code 400 (Bad Request)} if the examAttemptDTO is not valid,
* or with status {@code 500 (Internal Server Error)} if the examAttemptDTO couldn't be updated.
* @throws URISyntaxException if the Location URI syntax is incorrect.
*/
@PutMapping("/{id}")
public ResponseEntity<ExamAttemptDTO> updateExamAttempt(
@PathVariable(value = "id", required = false) final Long id,
@Valid @RequestBody ExamAttemptDTO examAttemptDTO
) throws URISyntaxException {
LOG.debug("REST request to update ExamAttempt : {}, {}", id, examAttemptDTO);
if (examAttemptDTO.getId() == null) {
throw new BadRequestAlertException("Invalid id", ENTITY_NAME, "idnull");
}
if (!Objects.equals(id, examAttemptDTO.getId())) {
throw new BadRequestAlertException("Invalid ID", ENTITY_NAME, "idinvalid");
}
if (!examAttemptRepository.existsById(id)) {
throw new BadRequestAlertException("Entity not found", ENTITY_NAME, "idnotfound");
}
examAttemptDTO = examAttemptService.update(examAttemptDTO);
return ResponseEntity.ok()
.headers(HeaderUtil.createEntityUpdateAlert(applicationName, true, ENTITY_NAME, examAttemptDTO.getId().toString()))
.body(examAttemptDTO);
}
/**
* {@code PATCH /exam-attempts/:id} : Partial updates given fields of an existing examAttempt, field will ignore if it is null
*
* @param id the id of the examAttemptDTO to save.
* @param examAttemptDTO the examAttemptDTO to update.
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body the updated examAttemptDTO,
* or with status {@code 400 (Bad Request)} if the examAttemptDTO is not valid,
* or with status {@code 404 (Not Found)} if the examAttemptDTO is not found,
* or with status {@code 500 (Internal Server Error)} if the examAttemptDTO couldn't be updated.
* @throws URISyntaxException if the Location URI syntax is incorrect.
*/
@PatchMapping(value = "/{id}", consumes = { "application/json", "application/merge-patch+json" })
public ResponseEntity<ExamAttemptDTO> partialUpdateExamAttempt(
@PathVariable(value = "id", required = false) final Long id,
@NotNull @RequestBody ExamAttemptDTO examAttemptDTO
) throws URISyntaxException {
LOG.debug("REST request to partial update ExamAttempt partially : {}, {}", id, examAttemptDTO);
if (examAttemptDTO.getId() == null) {
throw new BadRequestAlertException("Invalid id", ENTITY_NAME, "idnull");
}
if (!Objects.equals(id, examAttemptDTO.getId())) {
throw new BadRequestAlertException("Invalid ID", ENTITY_NAME, "idinvalid");
}
if (!examAttemptRepository.existsById(id)) {
throw new BadRequestAlertException("Entity not found", ENTITY_NAME, "idnotfound");
}
Optional<ExamAttemptDTO> result = examAttemptService.partialUpdate(examAttemptDTO);
return ResponseUtil.wrapOrNotFound(
result,
HeaderUtil.createEntityUpdateAlert(applicationName, true, ENTITY_NAME, examAttemptDTO.getId().toString())
);
}
/**
* {@code GET /exam-attempts} : get all the Exam Attempts.
*
* @param pageable the pagination information.
* @param eagerload flag to eager load entities from relationships (This is applicable for many-to-many).
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and the list of Exam Attempts in body.
*/
@GetMapping("")
public ResponseEntity<List<ExamAttemptDTO>> getAllExamAttempts(
@org.springdoc.core.annotations.ParameterObject Pageable pageable,
@RequestParam(name = "eagerload", required = false, defaultValue = "true") boolean eagerload
) {
LOG.debug("REST request to get a page of ExamAttempts");
Page<ExamAttemptDTO> page;
if (eagerload) {
page = examAttemptService.findAllWithEagerRelationships(pageable);
} else {
page = examAttemptService.findAll(pageable);
}
HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(ServletUriComponentsBuilder.fromCurrentRequest(), page);
return ResponseEntity.ok().headers(headers).body(page.getContent());
}
/**
* {@code GET /exam-attempts/:id} : get the "id" examAttempt.
*
* @param id the id of the examAttemptDTO to retrieve.
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body the examAttemptDTO, or with status {@code 404 (Not Found)}.
*/
@GetMapping("/{id}")
public ResponseEntity<ExamAttemptDTO> getExamAttempt(@PathVariable("id") Long id) {
LOG.debug("REST request to get ExamAttempt : {}", id);
Optional<ExamAttemptDTO> examAttemptDTO = examAttemptService.findOne(id);
return ResponseUtil.wrapOrNotFound(examAttemptDTO);
}
/**
* {@code DELETE /exam-attempts/:id} : delete the "id" examAttempt.
*
* @param id the id of the examAttemptDTO to delete.
* @return the {@link ResponseEntity} with status {@code 204 (NO_CONTENT)}.
*/
@DeleteMapping("/{id}")
public ResponseEntity<Void> deleteExamAttempt(@PathVariable("id") Long id) {
LOG.debug("REST request to delete ExamAttempt : {}", id);
examAttemptService.delete(id);
return ResponseEntity.noContent()
.headers(HeaderUtil.createEntityDeletionAlert(applicationName, true, ENTITY_NAME, id.toString()))
.build();
}
}
@@ -0,0 +1,188 @@
package com.example.questionbank.web.rest;
import com.example.questionbank.repository.QuestionRepository;
import com.example.questionbank.service.QuestionService;
import com.example.questionbank.service.dto.QuestionDTO;
import com.example.questionbank.web.rest.errors.BadRequestAlertException;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
import tech.jhipster.web.util.HeaderUtil;
import tech.jhipster.web.util.PaginationUtil;
import tech.jhipster.web.util.ResponseUtil;
/**
* REST controller for managing {@link com.example.questionbank.domain.Question}.
*/
@RestController
@RequestMapping("/api/questions")
public class QuestionResource {
private static final Logger LOG = LoggerFactory.getLogger(QuestionResource.class);
private static final String ENTITY_NAME = "question";
@Value("${jhipster.clientApp.name:questionBank}")
private String applicationName;
private final QuestionService questionService;
private final QuestionRepository questionRepository;
public QuestionResource(QuestionService questionService, QuestionRepository questionRepository) {
this.questionService = questionService;
this.questionRepository = questionRepository;
}
/**
* {@code POST /questions} : Create a new question.
*
* @param questionDTO the questionDTO to create.
* @return the {@link ResponseEntity} with status {@code 201 (Created)} and with body the new questionDTO, or with status {@code 400 (Bad Request)} if the question has already an ID.
* @throws URISyntaxException if the Location URI syntax is incorrect.
*/
@PostMapping("")
public ResponseEntity<QuestionDTO> createQuestion(@Valid @RequestBody QuestionDTO questionDTO) throws URISyntaxException {
LOG.debug("REST request to save Question : {}", questionDTO);
if (questionDTO.getId() != null) {
throw new BadRequestAlertException("A new question cannot already have an ID", ENTITY_NAME, "idexists");
}
questionDTO = questionService.save(questionDTO);
return ResponseEntity.created(new URI("/api/questions/" + questionDTO.getId()))
.headers(HeaderUtil.createEntityCreationAlert(applicationName, true, ENTITY_NAME, questionDTO.getId().toString()))
.body(questionDTO);
}
/**
* {@code PUT /questions/:id} : Updates an existing question.
*
* @param id the id of the questionDTO to save.
* @param questionDTO the questionDTO to update.
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body the updated questionDTO,
* or with status {@code 400 (Bad Request)} if the questionDTO is not valid,
* or with status {@code 500 (Internal Server Error)} if the questionDTO couldn't be updated.
* @throws URISyntaxException if the Location URI syntax is incorrect.
*/
@PutMapping("/{id}")
public ResponseEntity<QuestionDTO> updateQuestion(
@PathVariable(value = "id", required = false) final Long id,
@Valid @RequestBody QuestionDTO questionDTO
) throws URISyntaxException {
LOG.debug("REST request to update Question : {}, {}", id, questionDTO);
if (questionDTO.getId() == null) {
throw new BadRequestAlertException("Invalid id", ENTITY_NAME, "idnull");
}
if (!Objects.equals(id, questionDTO.getId())) {
throw new BadRequestAlertException("Invalid ID", ENTITY_NAME, "idinvalid");
}
if (!questionRepository.existsById(id)) {
throw new BadRequestAlertException("Entity not found", ENTITY_NAME, "idnotfound");
}
questionDTO = questionService.update(questionDTO);
return ResponseEntity.ok()
.headers(HeaderUtil.createEntityUpdateAlert(applicationName, true, ENTITY_NAME, questionDTO.getId().toString()))
.body(questionDTO);
}
/**
* {@code PATCH /questions/:id} : Partial updates given fields of an existing question, field will ignore if it is null
*
* @param id the id of the questionDTO to save.
* @param questionDTO the questionDTO to update.
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body the updated questionDTO,
* or with status {@code 400 (Bad Request)} if the questionDTO is not valid,
* or with status {@code 404 (Not Found)} if the questionDTO is not found,
* or with status {@code 500 (Internal Server Error)} if the questionDTO couldn't be updated.
* @throws URISyntaxException if the Location URI syntax is incorrect.
*/
@PatchMapping(value = "/{id}", consumes = { "application/json", "application/merge-patch+json" })
public ResponseEntity<QuestionDTO> partialUpdateQuestion(
@PathVariable(value = "id", required = false) final Long id,
@NotNull @RequestBody QuestionDTO questionDTO
) throws URISyntaxException {
LOG.debug("REST request to partial update Question partially : {}, {}", id, questionDTO);
if (questionDTO.getId() == null) {
throw new BadRequestAlertException("Invalid id", ENTITY_NAME, "idnull");
}
if (!Objects.equals(id, questionDTO.getId())) {
throw new BadRequestAlertException("Invalid ID", ENTITY_NAME, "idinvalid");
}
if (!questionRepository.existsById(id)) {
throw new BadRequestAlertException("Entity not found", ENTITY_NAME, "idnotfound");
}
Optional<QuestionDTO> result = questionService.partialUpdate(questionDTO);
return ResponseUtil.wrapOrNotFound(
result,
HeaderUtil.createEntityUpdateAlert(applicationName, true, ENTITY_NAME, questionDTO.getId().toString())
);
}
/**
* {@code GET /questions} : get all the Questions.
*
* @param pageable the pagination information.
* @param eagerload flag to eager load entities from relationships (This is applicable for many-to-many).
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and the list of Questions in body.
*/
@GetMapping("")
public ResponseEntity<List<QuestionDTO>> getAllQuestions(
@org.springdoc.core.annotations.ParameterObject Pageable pageable,
@RequestParam(name = "eagerload", required = false, defaultValue = "true") boolean eagerload
) {
LOG.debug("REST request to get a page of Questions");
Page<QuestionDTO> page;
if (eagerload) {
page = questionService.findAllWithEagerRelationships(pageable);
} else {
page = questionService.findAll(pageable);
}
HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(ServletUriComponentsBuilder.fromCurrentRequest(), page);
return ResponseEntity.ok().headers(headers).body(page.getContent());
}
/**
* {@code GET /questions/:id} : get the "id" question.
*
* @param id the id of the questionDTO to retrieve.
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body the questionDTO, or with status {@code 404 (Not Found)}.
*/
@GetMapping("/{id}")
public ResponseEntity<QuestionDTO> getQuestion(@PathVariable("id") Long id) {
LOG.debug("REST request to get Question : {}", id);
Optional<QuestionDTO> questionDTO = questionService.findOne(id);
return ResponseUtil.wrapOrNotFound(questionDTO);
}
/**
* {@code DELETE /questions/:id} : delete the "id" question.
*
* @param id the id of the questionDTO to delete.
* @return the {@link ResponseEntity} with status {@code 204 (NO_CONTENT)}.
*/
@DeleteMapping("/{id}")
public ResponseEntity<Void> deleteQuestion(@PathVariable("id") Long id) {
LOG.debug("REST request to delete Question : {}", id);
questionService.delete(id);
return ResponseEntity.noContent()
.headers(HeaderUtil.createEntityDeletionAlert(applicationName, true, ENTITY_NAME, id.toString()))
.build();
}
}
@@ -0,0 +1,179 @@
package com.example.questionbank.web.rest;
import com.example.questionbank.repository.SubjectRepository;
import com.example.questionbank.service.SubjectService;
import com.example.questionbank.service.dto.SubjectDTO;
import com.example.questionbank.web.rest.errors.BadRequestAlertException;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
import tech.jhipster.web.util.HeaderUtil;
import tech.jhipster.web.util.PaginationUtil;
import tech.jhipster.web.util.ResponseUtil;
/**
* REST controller for managing {@link com.example.questionbank.domain.Subject}.
*/
@RestController
@RequestMapping("/api/subjects")
public class SubjectResource {
private static final Logger LOG = LoggerFactory.getLogger(SubjectResource.class);
private static final String ENTITY_NAME = "subject";
@Value("${jhipster.clientApp.name:questionBank}")
private String applicationName;
private final SubjectService subjectService;
private final SubjectRepository subjectRepository;
public SubjectResource(SubjectService subjectService, SubjectRepository subjectRepository) {
this.subjectService = subjectService;
this.subjectRepository = subjectRepository;
}
/**
* {@code POST /subjects} : Create a new subject.
*
* @param subjectDTO the subjectDTO to create.
* @return the {@link ResponseEntity} with status {@code 201 (Created)} and with body the new subjectDTO, or with status {@code 400 (Bad Request)} if the subject has already an ID.
* @throws URISyntaxException if the Location URI syntax is incorrect.
*/
@PostMapping("")
public ResponseEntity<SubjectDTO> createSubject(@Valid @RequestBody SubjectDTO subjectDTO) throws URISyntaxException {
LOG.debug("REST request to save Subject : {}", subjectDTO);
if (subjectDTO.getId() != null) {
throw new BadRequestAlertException("A new subject cannot already have an ID", ENTITY_NAME, "idexists");
}
subjectDTO = subjectService.save(subjectDTO);
return ResponseEntity.created(new URI("/api/subjects/" + subjectDTO.getId()))
.headers(HeaderUtil.createEntityCreationAlert(applicationName, true, ENTITY_NAME, subjectDTO.getId().toString()))
.body(subjectDTO);
}
/**
* {@code PUT /subjects/:id} : Updates an existing subject.
*
* @param id the id of the subjectDTO to save.
* @param subjectDTO the subjectDTO to update.
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body the updated subjectDTO,
* or with status {@code 400 (Bad Request)} if the subjectDTO is not valid,
* or with status {@code 500 (Internal Server Error)} if the subjectDTO couldn't be updated.
* @throws URISyntaxException if the Location URI syntax is incorrect.
*/
@PutMapping("/{id}")
public ResponseEntity<SubjectDTO> updateSubject(
@PathVariable(value = "id", required = false) final Long id,
@Valid @RequestBody SubjectDTO subjectDTO
) throws URISyntaxException {
LOG.debug("REST request to update Subject : {}, {}", id, subjectDTO);
if (subjectDTO.getId() == null) {
throw new BadRequestAlertException("Invalid id", ENTITY_NAME, "idnull");
}
if (!Objects.equals(id, subjectDTO.getId())) {
throw new BadRequestAlertException("Invalid ID", ENTITY_NAME, "idinvalid");
}
if (!subjectRepository.existsById(id)) {
throw new BadRequestAlertException("Entity not found", ENTITY_NAME, "idnotfound");
}
subjectDTO = subjectService.update(subjectDTO);
return ResponseEntity.ok()
.headers(HeaderUtil.createEntityUpdateAlert(applicationName, true, ENTITY_NAME, subjectDTO.getId().toString()))
.body(subjectDTO);
}
/**
* {@code PATCH /subjects/:id} : Partial updates given fields of an existing subject, field will ignore if it is null
*
* @param id the id of the subjectDTO to save.
* @param subjectDTO the subjectDTO to update.
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body the updated subjectDTO,
* or with status {@code 400 (Bad Request)} if the subjectDTO is not valid,
* or with status {@code 404 (Not Found)} if the subjectDTO is not found,
* or with status {@code 500 (Internal Server Error)} if the subjectDTO couldn't be updated.
* @throws URISyntaxException if the Location URI syntax is incorrect.
*/
@PatchMapping(value = "/{id}", consumes = { "application/json", "application/merge-patch+json" })
public ResponseEntity<SubjectDTO> partialUpdateSubject(
@PathVariable(value = "id", required = false) final Long id,
@NotNull @RequestBody SubjectDTO subjectDTO
) throws URISyntaxException {
LOG.debug("REST request to partial update Subject partially : {}, {}", id, subjectDTO);
if (subjectDTO.getId() == null) {
throw new BadRequestAlertException("Invalid id", ENTITY_NAME, "idnull");
}
if (!Objects.equals(id, subjectDTO.getId())) {
throw new BadRequestAlertException("Invalid ID", ENTITY_NAME, "idinvalid");
}
if (!subjectRepository.existsById(id)) {
throw new BadRequestAlertException("Entity not found", ENTITY_NAME, "idnotfound");
}
Optional<SubjectDTO> result = subjectService.partialUpdate(subjectDTO);
return ResponseUtil.wrapOrNotFound(
result,
HeaderUtil.createEntityUpdateAlert(applicationName, true, ENTITY_NAME, subjectDTO.getId().toString())
);
}
/**
* {@code GET /subjects} : get all the Subjects.
*
* @param pageable the pagination information.
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and the list of Subjects in body.
*/
@GetMapping("")
public ResponseEntity<List<SubjectDTO>> getAllSubjects(@org.springdoc.core.annotations.ParameterObject Pageable pageable) {
LOG.debug("REST request to get a page of Subjects");
Page<SubjectDTO> page = subjectService.findAll(pageable);
HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(ServletUriComponentsBuilder.fromCurrentRequest(), page);
return ResponseEntity.ok().headers(headers).body(page.getContent());
}
/**
* {@code GET /subjects/:id} : get the "id" subject.
*
* @param id the id of the subjectDTO to retrieve.
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body the subjectDTO, or with status {@code 404 (Not Found)}.
*/
@GetMapping("/{id}")
public ResponseEntity<SubjectDTO> getSubject(@PathVariable("id") Long id) {
LOG.debug("REST request to get Subject : {}", id);
Optional<SubjectDTO> subjectDTO = subjectService.findOne(id);
return ResponseUtil.wrapOrNotFound(subjectDTO);
}
/**
* {@code DELETE /subjects/:id} : delete the "id" subject.
*
* @param id the id of the subjectDTO to delete.
* @return the {@link ResponseEntity} with status {@code 204 (NO_CONTENT)}.
*/
@DeleteMapping("/{id}")
public ResponseEntity<Void> deleteSubject(@PathVariable("id") Long id) {
LOG.debug("REST request to delete Subject : {}", id);
subjectService.delete(id);
return ResponseEntity.noContent()
.headers(HeaderUtil.createEntityDeletionAlert(applicationName, true, ENTITY_NAME, id.toString()))
.build();
}
}