forked from GDSC-snowflowerthon/AL-Go-team05-server
-
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 pull request GDSC-snowflowerthon#39 from ri-naa/feat/message-3
[fix] 지역명, 재해구분명 번역 추가 GDSC-snowflowerthon#3
- Loading branch information
Showing
12 changed files
with
147 additions
and
4 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.ALGo.ALGo_server.entity; | ||
|
||
import jakarta.persistence.*; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@Getter | ||
@NoArgsConstructor | ||
public class Quiz { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long quiz_id; | ||
|
||
@Column(nullable = false) | ||
private String question; | ||
|
||
@Column(nullable = false) | ||
private boolean answer; | ||
|
||
@Column(nullable = false) | ||
private String description; | ||
|
||
} |
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
21 changes: 21 additions & 0 deletions
21
src/main/java/com/ALGo/ALGo_server/quiz/Controller/QuizController.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,21 @@ | ||
package com.ALGo.ALGo_server.quiz.Controller; | ||
|
||
import com.ALGo.ALGo_server.quiz.Dto.QuizResponseDto; | ||
import com.ALGo.ALGo_server.quiz.Service.QuizService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/quiz") | ||
@RequiredArgsConstructor | ||
public class QuizController { | ||
private final QuizService quizService; | ||
|
||
@GetMapping() | ||
public QuizResponseDto getQuiz(){ | ||
return quizService.getQuiz(); | ||
} | ||
} |
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 com.ALGo.ALGo_server.quiz.Dto; | ||
|
||
import com.ALGo.ALGo_server.entity.Quiz; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
public class QuizDto { | ||
private Long id; | ||
|
||
public QuizDto(Quiz quiz){ | ||
this.id = quiz.getQuiz_id(); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/ALGo/ALGo_server/quiz/Dto/QuizResponseDto.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 com.ALGo.ALGo_server.quiz.Dto; | ||
|
||
import lombok.Getter; | ||
|
||
import java.util.List; | ||
|
||
@Getter | ||
public class QuizResponseDto { | ||
List<QuizDto> quizList; | ||
|
||
public QuizResponseDto(List<QuizDto> quizList){ | ||
this.quizList = quizList; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/com/ALGo/ALGo_server/quiz/Service/QuizService.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,34 @@ | ||
package com.ALGo.ALGo_server.quiz.Service; | ||
|
||
|
||
import com.ALGo.ALGo_server.entity.Quiz; | ||
import com.ALGo.ALGo_server.quiz.Dto.QuizDto; | ||
import com.ALGo.ALGo_server.quiz.Dto.QuizResponseDto; | ||
import com.ALGo.ALGo_server.repository.QuizRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.*; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class QuizService { | ||
private final QuizRepository quizRepository; | ||
|
||
@Transactional(readOnly = true) | ||
public QuizResponseDto getQuiz(){ | ||
Random random = new Random(); | ||
|
||
Set<QuizDto> quizDtoList = new HashSet<>(); | ||
while (quizDtoList.size() < 4){ | ||
Long randomNum = Long.valueOf(random.nextInt(16) + 1); | ||
Quiz q = quizRepository.findById(randomNum).get(); | ||
QuizDto quizDto = new QuizDto(q); | ||
quizDtoList.add(quizDto); | ||
} | ||
QuizResponseDto responseDto = new QuizResponseDto(quizDtoList.stream().toList()); | ||
|
||
return responseDto; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/ALGo/ALGo_server/repository/QuizRepository.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,8 @@ | ||
package com.ALGo.ALGo_server.repository; | ||
|
||
import com.ALGo.ALGo_server.entity.Quiz; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
public interface QuizRepository extends JpaRepository<Quiz, Long> { | ||
} |