Skip to content
Snippets Groups Projects
Commit 2d087e5f authored by Martin Gargalovič's avatar Martin Gargalovič
Browse files

Merge branch 'M2' into M2-user

# Conflicts:
#	README.md
#	application/model/src/main/java/org/fuseri/model/dto/course/CourseDto.java
#	application/model/src/main/java/org/fuseri/model/dto/exercise/AnswerCreateDto.java
#	application/model/src/main/java/org/fuseri/model/dto/exercise/AnswersCreateDto.java
#	application/model/src/main/java/org/fuseri/model/dto/exercise/ExerciseCreateDto.java
#	application/model/src/main/java/org/fuseri/model/dto/exercise/ExerciseDto.java
#	application/model/src/main/java/org/fuseri/model/dto/exercise/QuestionCreateDto.java
#	application/model/src/main/java/org/fuseri/model/dto/exercise/QuestionDto.java
#	application/model/src/main/java/org/fuseri/model/dto/exercise/QuestionUpdateDto.java
#	application/model/src/main/java/org/fuseri/model/dto/lecture/LectureCreateDto.java
#	application/model/src/main/java/org/fuseri/model/dto/user/UserDto.java
#	application/module-certificate/src/main/java/org/fuseri/modulecertificate/service/CertificateController.java
#	application/module-certificate/src/test/java/org/fuseri/modulecertificate/CertificateControllerTests.java
#	application/module-exercise/src/main/java/org/fuseri/moduleexercise/answer/Answer.java
#	application/module-exercise/src/main/java/org/fuseri/moduleexercise/answer/AnswerController.java
#	application/module-exercise/src/main/java/org/fuseri/moduleexercise/answer/AnswerFacade.java
#	application/module-exercise/src/main/java/org/fuseri/moduleexercise/answer/AnswerRepository.java
#	application/module-exercise/src/main/java/org/fuseri/moduleexercise/answer/AnswerService.java
#	application/module-exercise/src/main/java/org/fuseri/moduleexercise/common/DomainObject.java
#	application/module-exercise/src/main/java/org/fuseri/moduleexercise/common/DomainService.java
#	application/module-exercise/src/main/java/org/fuseri/moduleexercise/exercise/Exercise.java
#	application/module-exercise/src/main/java/org/fuseri/moduleexercise/exercise/ExerciseController.java
#	application/module-exercise/src/main/java/org/fuseri/moduleexercise/exercise/ExerciseRepository.java
#	application/module-exercise/src/main/java/org/fuseri/moduleexercise/exercise/ExerciseService.java
#	application/module-exercise/src/main/java/org/fuseri/moduleexercise/question/Question.java
#	application/module-exercise/src/main/java/org/fuseri/moduleexercise/question/QuestionController.java
#	application/module-exercise/src/main/java/org/fuseri/moduleexercise/question/QuestionFacade.java
#	application/module-exercise/src/main/java/org/fuseri/moduleexercise/question/QuestionRepository.java
#	application/module-exercise/src/main/java/org/fuseri/moduleexercise/question/QuestionService.java
#	application/module-exercise/src/main/resources/application.properties
#	application/module-exercise/src/test/java/org/fuseri/moduleexercise/answer/AnswerTest.java
#	application/module-exercise/src/test/java/org/fuseri/moduleexercise/exercise/ExerciseTest.java
#	application/module-exercise/src/test/java/org/fuseri/moduleexercise/question/QuestionTest.java
#	application/module-language-school/pom.xml
#	application/module-language-school/src/main/java/org/fuseri/modulelanguageschool/common/DomainObject.java
#	application/module-language-school/src/main/java/org/fuseri/modulelanguageschool/course/Course.java
#	application/module-language-school/src/main/java/org/fuseri/modulelanguageschool/course/CourseController.java
#	application/module-language-school/src/main/java/org/fuseri/modulelanguageschool/lecture/Lecture.java
#	application/module-language-school/src/main/java/org/fuseri/modulelanguageschool/lecture/LectureController.java
#	application/module-language-school/src/main/java/org/fuseri/modulelanguageschool/user/UserController.java
#	application/module-language-school/src/main/resources/application.properties
#	application/module-language-school/src/test/java/org/fuseri/modulelanguageschool/course/CourseTest.java
#	application/module-language-school/src/test/java/org/fuseri/modulelanguageschool/lecture/LectureTest.java
#	application/module-language-school/src/test/java/org/fuseri/modulelanguageschool/user/UserControllerTest.java
parents af6e9dbc 0a159c09
No related branches found
No related tags found
3 merge requests!31M2,!28M2 user,!27Draft: M2 user
Showing
with 164 additions and 106 deletions
...@@ -11,14 +11,37 @@ ...@@ -11,14 +11,37 @@
- Martin Gargalovič *@xgargal* - Martin Gargalovič *@xgargal*
- Jan Pokorný *@xpokorn8* - Jan Pokorný *@xpokorn8*
- Ester Vilímková - _Project Leader_ *@xvilimk* - Ester Vilímková - _Project Leader_ *@xvilimk*
- **Assigment**: - **Assigment**:
- Create a system for language school lecture management. Each lecture can occur on a given day and time and is related to some course. The course is defined by its (unique) name, language and proficiency level. However, each lecture will be independent. That means that each lecture can have a different topic. Different lecturers can give it, and an arbitrary number of students can enrol. Each lecturer will have a name, surname, and record of taught languages. In addition, the lecturer will indicate that they are a native speaker. Exercises can be prepared for each course to allow the students to learn the language. Each student can pick the exercises depending on the levels of difficulty. - Create a system for language school lecture management. Each lecture can occur on a given day and time and is related to some course. The course is defined by its (unique) name, language and proficiency level. However, each lecture will be independent. That means that each lecture can have a different topic. Different lecturers can give it, and an arbitrary number of students can enrol. Each lecturer will have a name, surname, and record of taught languages. In addition, the lecturer will indicate that they are a native speaker. Exercises can be prepared for each course to allow the students to learn the language. Each student can pick the exercises depending on the levels of difficulty.
- **Running the modules**:
- ```cd ./application``` - **Running the modules using docker-compose**:
- ```mvn clean install```
- ```cd ./module-*``` ```console
- ```mvn spring-boot:run``` cd ./application
mvn clean install
docker-compose build --parallel
docker-compose up
```
- **Running the modules using podman-compose**:
~~~console
cd ./application
mvn clean install
podman-compose build --parallel
podman-compose up
~~~
- **Running the modules using docker**:
~~~console
sudo docker run -d -p 5001:5001 xpokorn8/sprachschulsystem:certificate &&
sudo docker run -d -p 5002:5002 xpokorn8/sprachschulsystem:exercise &&
sudo docker run -d -p 5000:5000 xpokorn8/sprachschulsystem:language-school &&
sudo docker run -d -p 5003:5003 xpokorn8/sprachschulsystem:mail
~~~
# Project Description # Project Description
......
version: '3'
services:
certificate:
build: ./module-certificate
container_name: certificate
image: xpokorn8/sprachschulsystem:certificate
ports:
- "5001:5001"
exercise:
build: ./module-exercise
container_name: exercise
image: xpokorn8/sprachschulsystem:exercise
ports:
- "5002:5002"
language-school:
build: ./module-language-school
container_name: language-school
image: xpokorn8/sprachschulsystem:language-school
ports:
- "5000:5000"
mail:
build: ./module-mail
container_name: mail
image: xpokorn8/sprachschulsystem:mail
ports:
- "5003:5003"
\ No newline at end of file
...@@ -28,10 +28,10 @@ public class CourseCreateDto { ...@@ -28,10 +28,10 @@ public class CourseCreateDto {
@NotNull(message = "Language type is required") @NotNull(message = "Language type is required")
@Valid @Valid
private LanguageTypeDto languageTypeDto; private LanguageTypeDto language;
@NotNull(message = "Proficiency level is required") @NotNull(message = "Proficiency level is required")
@Valid @Valid
private ProficiencyLevelDto proficiencyLevelDto; private ProficiencyLevelDto proficiency;
} }
...@@ -20,7 +20,7 @@ import java.util.List; ...@@ -20,7 +20,7 @@ import java.util.List;
*/ */
@Getter @Getter
@Setter @Setter
@EqualsAndHashCode @EqualsAndHashCode(callSuper = true)
public class CourseDto extends DomainObjectDto { public class CourseDto extends DomainObjectDto {
@NotBlank(message = "Course name is required") @NotBlank(message = "Course name is required")
...@@ -33,22 +33,22 @@ public class CourseDto extends DomainObjectDto { ...@@ -33,22 +33,22 @@ public class CourseDto extends DomainObjectDto {
@NotNull(message = "Language type is required") @NotNull(message = "Language type is required")
@Valid @Valid
private LanguageTypeDto languageTypeDto; private LanguageTypeDto language;
@NotNull(message = "Proficiency level is required") @NotNull(message = "Proficiency level is required")
@Valid @Valid
private ProficiencyLevelDto proficiencyLevelDto; private ProficiencyLevelDto proficiency;
@NotNull(message = "Student's list is required") @NotNull(message = "Student's list is required")
@Valid @Valid
private List<Long> studentIds; private List<Long> studentIds;
public CourseDto(String name, Integer capacity, LanguageTypeDto languageTypeDto, ProficiencyLevelDto proficiencyLevelDto) { public CourseDto(Long id, String name, Integer capacity, LanguageTypeDto languageTypeDto, ProficiencyLevelDto proficiencyLevelDto) {
setId(0L); this.setId(id);
this.name = name; this.name = name;
this.capacity = capacity; this.capacity = capacity;
this.languageTypeDto = languageTypeDto; this.language = languageTypeDto;
this.proficiencyLevelDto = proficiencyLevelDto; this.proficiency = proficiencyLevelDto;
this.studentIds = new ArrayList<>(); this.studentIds = new ArrayList<>();
} }
} }
package org.fuseri.model.dto.course; package org.fuseri.model.dto.course;
import lombok.AllArgsConstructor;
@AllArgsConstructor
public enum LanguageTypeDto { public enum LanguageTypeDto {
ENGLISH, ENGLISH,
GERMAN, GERMAN,
......
...@@ -15,6 +15,6 @@ public class AnswerCreateDto { ...@@ -15,6 +15,6 @@ public class AnswerCreateDto {
@NotNull @NotNull
private boolean correct; private boolean correct;
@NotNull @NotBlank
private long questionId; private String questionId;
} }
package org.fuseri.model.dto.exercise; package org.fuseri.model.dto.exercise;
import jakarta.validation.Valid; import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.NotBlank;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
...@@ -11,8 +11,8 @@ import java.util.List; ...@@ -11,8 +11,8 @@ import java.util.List;
@Getter @Getter
public class AnswersCreateDto { public class AnswersCreateDto {
@NotNull @NotBlank
private long questionId; private String questionId;
@Valid @Valid
private List<AnswerInQuestionCreateDto> answers; private List<AnswerInQuestionCreateDto> answers;
......
...@@ -20,6 +20,6 @@ public class ExerciseCreateDto { ...@@ -20,6 +20,6 @@ public class ExerciseCreateDto {
@PositiveOrZero @PositiveOrZero
private int difficulty; private int difficulty;
@NotNull @NotBlank
private long courseId; private String courseId;
} }
...@@ -23,18 +23,28 @@ public class ExerciseDto extends DomainObjectDto { ...@@ -23,18 +23,28 @@ public class ExerciseDto extends DomainObjectDto {
@PositiveOrZero @PositiveOrZero
private int difficulty; private int difficulty;
@NotNull @NotBlank
private long courseId; private String courseId;
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) return true;
if (!(o instanceof ExerciseDto that)) return false; if (o == null || getClass() != o.getClass()) return false;
return getDifficulty() == that.getDifficulty() && getCourseId() == that.getCourseId() && Objects.equals(getName(), that.getName()) && Objects.equals(getDescription(), that.getDescription());
ExerciseDto that = (ExerciseDto) o;
if (difficulty != that.difficulty) return false;
if (!Objects.equals(name, that.name)) return false;
if (!Objects.equals(description, that.description)) return false;
return Objects.equals(courseId, that.courseId);
} }
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(getName(), getDescription(), getDifficulty(), getCourseId()); int result = name != null ? name.hashCode() : 0;
result = 31 * result + (description != null ? description.hashCode() : 0);
result = 31 * result + difficulty;
result = 31 * result + (courseId != null ? courseId.hashCode() : 0);
return result;
} }
} }
...@@ -2,7 +2,6 @@ package org.fuseri.model.dto.exercise; ...@@ -2,7 +2,6 @@ package org.fuseri.model.dto.exercise;
import jakarta.validation.Valid; import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
...@@ -15,8 +14,8 @@ public class QuestionCreateDto { ...@@ -15,8 +14,8 @@ public class QuestionCreateDto {
@NotBlank @NotBlank
private String text; private String text;
@NotNull @NotBlank
private long exerciseId; private String exerciseId;
@Valid @Valid
private List<AnswerInQuestionCreateDto> answers; private List<AnswerInQuestionCreateDto> answers;
......
...@@ -2,7 +2,6 @@ package org.fuseri.model.dto.exercise; ...@@ -2,7 +2,6 @@ package org.fuseri.model.dto.exercise;
import jakarta.validation.Valid; import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import org.fuseri.model.dto.common.DomainObjectDto; import org.fuseri.model.dto.common.DomainObjectDto;
...@@ -17,8 +16,8 @@ public class QuestionDto extends DomainObjectDto { ...@@ -17,8 +16,8 @@ public class QuestionDto extends DomainObjectDto {
@NotBlank @NotBlank
private String text; private String text;
@NotNull @NotBlank
private long exerciseId; private String exerciseId;
@Valid @Valid
private List<AnswerDto> answers; private List<AnswerDto> answers;
...@@ -26,12 +25,20 @@ public class QuestionDto extends DomainObjectDto { ...@@ -26,12 +25,20 @@ public class QuestionDto extends DomainObjectDto {
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) return true;
if (!(o instanceof QuestionDto that)) return false; if (o == null || getClass() != o.getClass()) return false;
return getExerciseId() == that.getExerciseId() && Objects.equals(getText(), that.getText()) && Objects.equals(getAnswers(), that.getAnswers());
QuestionDto that = (QuestionDto) o;
if (!Objects.equals(text, that.text)) return false;
if (!Objects.equals(exerciseId, that.exerciseId)) return false;
return Objects.equals(answers, that.answers);
} }
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(getText(), getExerciseId(), getAnswers()); int result = text != null ? text.hashCode() : 0;
result = 31 * result + (exerciseId != null ? exerciseId.hashCode() : 0);
result = 31 * result + (answers != null ? answers.hashCode() : 0);
return result;
} }
} }
package org.fuseri.model.dto.exercise; package org.fuseri.model.dto.exercise;
import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Builder; import lombok.Builder;
import lombok.Getter; import lombok.Getter;
...@@ -12,6 +11,6 @@ public class QuestionUpdateDto { ...@@ -12,6 +11,6 @@ public class QuestionUpdateDto {
@NotBlank @NotBlank
private String text; private String text;
@NotNull @NotBlank
private long exerciseId; private String exerciseId;
} }
...@@ -3,7 +3,6 @@ package org.fuseri.model.dto.lecture; ...@@ -3,7 +3,6 @@ package org.fuseri.model.dto.lecture;
import jakarta.validation.constraints.*; import jakarta.validation.constraints.*;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import org.fuseri.model.dto.course.CourseDto;
import java.time.LocalDateTime; import java.time.LocalDateTime;
...@@ -27,10 +26,10 @@ public class LectureCreateDto { ...@@ -27,10 +26,10 @@ public class LectureCreateDto {
@Min(value = 1, message = "Lecture capacity must be at least 1") @Min(value = 1, message = "Lecture capacity must be at least 1")
private Integer capacity; private Integer capacity;
@NotBlank(message = "Lecture course cannot be blank") @NotNull(message = "Lecture course cannot be null")
private String courseId; private Long courseId;
public LectureCreateDto(LocalDateTime from, LocalDateTime to, String topic, Integer capacity, String courseId) { public LectureCreateDto(LocalDateTime from, LocalDateTime to, String topic, Integer capacity, Long courseId) {
this.from = from; this.from = from;
this.to = to; this.to = to;
this.topic = topic; this.topic = topic;
......
...@@ -29,16 +29,16 @@ public class LectureDto extends DomainObjectDto { ...@@ -29,16 +29,16 @@ public class LectureDto extends DomainObjectDto {
@Min(value = 1, message = "Lecture capacity must be at least 1") @Min(value = 1, message = "Lecture capacity must be at least 1")
private Integer capacity; private Integer capacity;
@NotNull(message = "Lecture capacity cannot be null") @NotNull(message = "Lecture lecturer cannot be null")
private String lecturerId; private Long lecturerId;
@NotBlank(message = "Lecture courseId cannot be blank") @NotNull(message = "Lecture courseId cannot be null")
private String courseId; private Long courseId;
@NotNull(message = "Student IDs list cannot be null") @NotNull(message = "Student IDs list cannot be null")
private List<Long> studentIds; private List<Long> studentIds;
public LectureDto(LocalDateTime from, LocalDateTime to, String topic, Integer capacity, String lecturerId, String courseId) { public LectureDto(LocalDateTime from, LocalDateTime to, String topic, Integer capacity, Long lecturerId, Long courseId) {
this.from = from; this.from = from;
this.to = to; this.to = to;
this.topic = topic; this.topic = topic;
......
FROM docker.io/library/eclipse-temurin:17-jre-focal
COPY ./target/module-certificate-0.0.1-SNAPSHOT.jar /app.jar
ENTRYPOINT ["java", "-jar", "/app.jar"]
...@@ -2,7 +2,9 @@ package org.fuseri.modulecertificate.service; ...@@ -2,7 +2,9 @@ package org.fuseri.modulecertificate.service;
import jakarta.validation.Valid; import jakarta.validation.Valid;
import org.fuseri.model.dto.certificate.CertificateCreateDto; import org.fuseri.model.dto.certificate.CertificateCreateDto;
import org.fuseri.model.dto.certificate.CertificateDto;
import org.fuseri.model.dto.certificate.CertificateSimpleDto; import org.fuseri.model.dto.certificate.CertificateSimpleDto;
import org.fuseri.model.dto.common.Result;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
......
...@@ -9,12 +9,16 @@ import org.fuseri.model.dto.course.ProficiencyLevelDto; ...@@ -9,12 +9,16 @@ import org.fuseri.model.dto.course.ProficiencyLevelDto;
import org.fuseri.model.dto.user.AddressDto; import org.fuseri.model.dto.user.AddressDto;
import org.fuseri.model.dto.user.UserDto; import org.fuseri.model.dto.user.UserDto;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springdoc.core.converters.models.Pageable;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MockMvc;
import java.util.List;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
...@@ -99,14 +103,14 @@ class CertificateControllerTests { ...@@ -99,14 +103,14 @@ class CertificateControllerTests {
.andExpect(status().is4xxClientError()); .andExpect(status().is4xxClientError());
} }
// @Test @Test
// void findCertificateIdForUserAndCourse() throws Exception { void findCertificateIdForUserAndCourse() throws Exception {
// mockMvc.perform(get("/certificates/findForUserAndCourse") mockMvc.perform(get("/certificates/findForUserAndCourse")
// .param("userId", "0") .param("userId", "0")
// .param("courseId", "0")) .param("courseId", "0"))
// .andExpect(status().isOk()) .andExpect(status().isOk())
// .andExpect(content().string("[]")); .andExpect(content().string("[]"));
// } }
@Test @Test
void findCertificateIdWithoutUserId() throws Exception { void findCertificateIdWithoutUserId() throws Exception {
...@@ -149,10 +153,10 @@ class CertificateControllerTests { ...@@ -149,10 +153,10 @@ class CertificateControllerTests {
.contentType(MediaType.APPLICATION_JSON)) .contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk()); .andExpect(status().isOk());
// mockMvc.perform(get("/certificates/findAll") mockMvc.perform(get("/certificates/findAll")
// .content("{ \"page\": 0, \"size\": 1, \"sort\": []}") .content("{ \"page\": 0, \"size\": 1, \"sort\": []}")
// .contentType(MediaType.APPLICATION_JSON)) .contentType(MediaType.APPLICATION_JSON))
// .andExpect(status().isOk()); .andExpect(status().isOk());
} }
@Test @Test
......
FROM docker.io/library/eclipse-temurin:17-jre-focal
COPY ./target/module-exercise-0.0.1-SNAPSHOT.jar /app.jar
ENTRYPOINT ["java", "-jar", "/app.jar"]
package org.fuseri.moduleexercise.answer; package org.fuseri.moduleexercise.answer;
import jakarta.persistence.*;
import lombok.*; import lombok.*;
import org.fuseri.moduleexercise.common.DomainObject; import org.fuseri.moduleexercise.common.DomainObject;
import org.fuseri.moduleexercise.question.Question;
/** /**
* Represent Answer entity * Represent Answer entity
...@@ -14,16 +12,10 @@ import org.fuseri.moduleexercise.question.Question; ...@@ -14,16 +12,10 @@ import org.fuseri.moduleexercise.question.Question;
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@Builder @Builder
@Entity
@Table(name = "answer")
public class Answer extends DomainObject { public class Answer extends DomainObject {
private String text; private String text;
@Column(name = "is_correct")
private boolean correct; private boolean correct;
@ManyToOne private String questionId;
@JoinColumn(name="question_id")
private Question question;
} }
package org.fuseri.moduleexercise.answer; package org.fuseri.moduleexercise.answer;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import jakarta.persistence.EntityNotFoundException; import jakarta.persistence.EntityNotFoundException;
import jakarta.validation.Valid; import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.NotBlank;
import org.fuseri.model.dto.exercise.AnswerCreateDto; import org.fuseri.model.dto.exercise.AnswerCreateDto;
import org.fuseri.model.dto.exercise.AnswerDto; import org.fuseri.model.dto.exercise.AnswerDto;
import org.fuseri.model.dto.exercise.AnswersCreateDto; import org.fuseri.model.dto.exercise.AnswersCreateDto;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.server.ResponseStatusException; import org.springframework.web.server.ResponseStatusException;
...@@ -32,24 +28,30 @@ public class AnswerController { ...@@ -32,24 +28,30 @@ public class AnswerController {
this.facade = facade; this.facade = facade;
} }
/**
* Retrieve a list of AnswerDto objects which belong to question with questionId
*
* @param questionId the ID of the question for which to retrieve answers
* @return a List of AnswerDto objects
*/
@GetMapping("/{question-id}")
public List<AnswerDto> findAllByQuestionId(@NotBlank @PathVariable("question-id") String questionId) {
return facade.findAllByQuestionId(questionId);
}
/** /**
* Create a new answer for the given question ID * Create a new answer for the given question ID
* *
* @param dto the AnswerCreateDto object containing information about the answer to create * @param dto the AnswerCreateDto object containing information about the answer to create
* @return a ResponseEntity containing an AnswerDto object representing the newly created answer, or a 404 Not Found response * @return an AnswerDto object representing the newly created answer
* if the question with the specified ID in dto was not found * @throws ResponseStatusException if the question ID specified in the dto does not exist
*/ */
@Operation(summary = "Create new answers for question", description = "Creates new answers for question.")
@ApiResponses(value = {
@ApiResponse(responseCode = "201", description = "Answers created successfully."),
@ApiResponse(responseCode = "400", description = "Invalid input.")
})
@PostMapping @PostMapping
public ResponseEntity<List<AnswerDto>> createMultiple(@Valid @RequestBody AnswersCreateDto dto) { public List<AnswerDto> createMultiple(@Valid @RequestBody AnswersCreateDto dto) {
try { try {
return ResponseEntity.status(HttpStatus.CREATED).body(facade.createMultiple(dto)); return facade.createMultiple(dto);
} catch (EntityNotFoundException e) { } catch (EntityNotFoundException e) {
return ResponseEntity.notFound().build(); throw new ResponseStatusException(HttpStatus.NOT_FOUND, e.getMessage());
} }
} }
...@@ -58,42 +60,30 @@ public class AnswerController { ...@@ -58,42 +60,30 @@ public class AnswerController {
* *
* @param id of answer to update * @param id of answer to update
* @param dto dto with updated answer information * @param dto dto with updated answer information
* @return A ResponseEntity with an AnswerDto object representing the updated answer on an HTTP status code of 200 if the update was successful. * @throws ResponseStatusException if the question id specified in the AnswerCreateDto dto does not exist
* or a NOT_FOUND response if the answer ID is invalid
*/ */
@Operation(summary = "Update an answer", description = "Updates an answer with the specified ID.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Answer with the specified ID updated successfully."),
@ApiResponse(responseCode = "400", description = "Invalid input."),
@ApiResponse(responseCode = "404", description = "Answer with the specified ID was not found.")
})
@PutMapping("/{id}") @PutMapping("/{id}")
public ResponseEntity<AnswerDto> update(@NotNull @PathVariable long id, @Valid @RequestBody AnswerCreateDto dto) { public AnswerDto update(@NotBlank @PathVariable String id, @Valid @RequestBody AnswerCreateDto dto) {
try { try {
return ResponseEntity.ok(facade.update(id, dto)); return facade.update(id, dto);
} catch (EntityNotFoundException e) { } catch (EntityNotFoundException e) {
return ResponseEntity.notFound().build(); throw new ResponseStatusException(HttpStatus.NOT_FOUND,
e.getMessage());
} }
} }
/** /**
* Delete answer with the specified ID * Delete answer with the given id
* *
* @param id of answer to delete * @param id of answer to delete
* @throws ResponseStatusException if answer with specified id does not exist * @throws ResponseStatusException if answer with specified id does not exist
*/ */
@Operation(summary = "Delete an answer with specified ID", description = "Deletes an answer with the specified ID.")
@ApiResponses(value = {
@ApiResponse(responseCode = "204", description = "Answer with the specified ID deleted successfully."),
@ApiResponse(responseCode = "404", description = "Answer with the specified ID was not found.")
})
@DeleteMapping("/{id}") @DeleteMapping("/{id}")
public ResponseEntity<Void> delete(@NotNull @PathVariable long id) { public void delete(@NotBlank @PathVariable String id) {
try { try {
facade.delete(id); facade.delete(id);
return ResponseEntity.noContent().build();
} catch (EntityNotFoundException e) { } catch (EntityNotFoundException e) {
return ResponseEntity.notFound().build(); throw new ResponseStatusException(HttpStatus.NOT_FOUND, e.getMessage());
} }
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment