generated from Arquisoft/wiq_0
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/develop' into chore/actions-fixing
- Loading branch information
Showing
51 changed files
with
969 additions
and
210 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
api/src/main/java/lab/en2b/quizapi/auth/dtos/JwtResponseDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 2 additions & 4 deletions
6
api/src/main/java/lab/en2b/quizapi/auth/dtos/RefreshTokenResponseDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
api/src/main/java/lab/en2b/quizapi/commons/exceptions/InvalidAuthenticationException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package lab.en2b.quizapi.commons.exceptions; | ||
|
||
public class InvalidAuthenticationException extends RuntimeException{ | ||
public InvalidAuthenticationException(String message) { | ||
super(message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
api/src/main/java/lab/en2b/quizapi/commons/utils/TestUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package lab.en2b.quizapi.commons.utils; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
public class TestUtils { | ||
public static String asJsonString(final Object obj) { | ||
try { | ||
return new ObjectMapper().writeValueAsString(obj); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
api/src/main/java/lab/en2b/quizapi/questions/answer/Answer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package lab.en2b.quizapi.questions.answer; | ||
|
||
import jakarta.persistence.*; | ||
import lab.en2b.quizapi.questions.question.Question; | ||
import lombok.*; | ||
|
||
import java.util.List; | ||
|
||
@Entity | ||
@Table(name = "answers") | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Getter | ||
@Setter | ||
public class Answer { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Setter(AccessLevel.NONE) | ||
private Long id; | ||
private String text; | ||
private AnswerCategory category; | ||
@OneToMany(mappedBy = "correctAnswer", fetch = FetchType.EAGER) | ||
private List<Question> questions; | ||
|
||
@ManyToMany(mappedBy = "answers", fetch = FetchType.EAGER) | ||
private List<Question> questionsWithThisAnswer; | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
api/src/main/java/lab/en2b/quizapi/questions/answer/AnswerCategory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package lab.en2b.quizapi.questions.answer; | ||
|
||
public enum AnswerCategory { | ||
CITY, COUNTRY, PERSON, EVENT, DATE, OTHER | ||
} |
14 changes: 14 additions & 0 deletions
14
api/src/main/java/lab/en2b/quizapi/questions/answer/dtos/AnswerDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package lab.en2b.quizapi.questions.answer.dtos; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class AnswerDto { | ||
@JsonProperty("answer_id") | ||
private Long answerId; | ||
} |
15 changes: 15 additions & 0 deletions
15
api/src/main/java/lab/en2b/quizapi/questions/answer/dtos/AnswerResponseDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package lab.en2b.quizapi.questions.answer.dtos; | ||
|
||
import lab.en2b.quizapi.questions.answer.AnswerCategory; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Getter | ||
public class AnswerResponseDto { | ||
private Long id; | ||
private String text; | ||
private AnswerCategory category; | ||
} |
15 changes: 15 additions & 0 deletions
15
api/src/main/java/lab/en2b/quizapi/questions/answer/mappers/AnswerResponseDtoMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package lab.en2b.quizapi.questions.answer.mappers; | ||
|
||
import lab.en2b.quizapi.questions.answer.Answer; | ||
import lab.en2b.quizapi.questions.answer.dtos.AnswerResponseDto; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.function.Function; | ||
|
||
@Service | ||
public class AnswerResponseDtoMapper implements Function<Answer, AnswerResponseDto> { | ||
@Override | ||
public AnswerResponseDto apply(Answer answer) { | ||
return null; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
api/src/main/java/lab/en2b/quizapi/questions/question/Question.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package lab.en2b.quizapi.questions.question; | ||
|
||
import jakarta.persistence.*; | ||
import jakarta.validation.constraints.NotNull; | ||
import lab.en2b.quizapi.questions.answer.Answer; | ||
import lab.en2b.quizapi.questions.answer.AnswerCategory; | ||
import lombok.*; | ||
|
||
import java.util.List; | ||
|
||
@Entity | ||
@Table(name = "questions") | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Getter | ||
@Setter | ||
public class Question { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Setter(AccessLevel.NONE) | ||
private Long id; | ||
private String content; | ||
@NotNull | ||
@ManyToMany(fetch = FetchType.EAGER) | ||
@JoinTable(name="questions_answers", | ||
joinColumns= | ||
@JoinColumn(name="question_id", referencedColumnName="id"), | ||
inverseJoinColumns= | ||
@JoinColumn(name="answer_id", referencedColumnName="id") | ||
) | ||
private List<Answer> answers; | ||
@ManyToOne | ||
@JoinColumn(name = "correct_answer_id") | ||
private Answer correctAnswer; | ||
private QuestionCategory questionCategory; | ||
private AnswerCategory answerCategory; | ||
private String language; | ||
private QuestionType type; | ||
|
||
|
||
} |
5 changes: 5 additions & 0 deletions
5
api/src/main/java/lab/en2b/quizapi/questions/question/QuestionCategory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package lab.en2b.quizapi.questions.question; | ||
|
||
public enum QuestionCategory { | ||
HISTORY, GEOGRAPHY, SCIENCE, MATH, LITERATURE, ART, SPORTS, MUSIC, MOVIES, TV, POLITICS, OTHER | ||
} |
36 changes: 30 additions & 6 deletions
36
api/src/main/java/lab/en2b/quizapi/questions/question/QuestionController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,38 @@ | ||
package lab.en2b.quizapi.questions.question; | ||
|
||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import lab.en2b.quizapi.questions.answer.dtos.AnswerDto; | ||
import lab.en2b.quizapi.questions.question.dtos.AnswerCheckResponseDto; | ||
import lab.en2b.quizapi.questions.question.dtos.QuestionResponseDto; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequestMapping("/questions") | ||
@RequiredArgsConstructor | ||
public class QuestionController { | ||
@GetMapping("/dummy") | ||
private String getDummyQuestion(){ | ||
return "Who the hell is Steve Jobs?"; | ||
private final QuestionService questionService; | ||
|
||
// TODO: REMOVE WHEN NOT USED FOR TESTING | ||
@GetMapping | ||
private ResponseEntity<List<QuestionResponseDto>> getQuestions() { | ||
return ResponseEntity.ok(questionService.getQuestions()); | ||
} | ||
|
||
@PostMapping("/{questionId}/answer") | ||
private ResponseEntity<AnswerCheckResponseDto> answerQuestion(@PathVariable Long questionId, @RequestBody AnswerDto answerDto){ | ||
return ResponseEntity.ok(questionService.answerQuestion(questionId,answerDto)); | ||
} | ||
|
||
@GetMapping("/new") | ||
private ResponseEntity<QuestionResponseDto> generateQuestion(){ | ||
return ResponseEntity.ok(questionService.getQuestion()); | ||
} | ||
|
||
@GetMapping("/{id}") | ||
private ResponseEntity<QuestionResponseDto> getQuestionById(@PathVariable Long id){ | ||
return ResponseEntity.ok(questionService.getQuestionById(id)); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
api/src/main/java/lab/en2b/quizapi/questions/question/QuestionRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package lab.en2b.quizapi.questions.question; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
|
||
public interface QuestionRepository extends JpaRepository<Question,Long> { | ||
@Query(value = "SELECT * FROM questions ORDER BY RAND() LIMIT 1", nativeQuery = true) | ||
Question findRandomQuestion(); | ||
} |
Oops, something went wrong.