Skip to content

Commit

Permalink
Merge pull request #228 from tukcomCD2024/Backend#225/quiz
Browse files Browse the repository at this point in the history
Backend#225/quiz
  • Loading branch information
Doncham authored May 25, 2024
2 parents 683b741 + fc36595 commit d832488
Show file tree
Hide file tree
Showing 14 changed files with 425 additions and 51 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.Backend.shareNote.domain.Oraganization.DTOs.quizdto;

import lombok.Data;

import java.util.List;

@Data
public class QuizCreateDTO {
private String organizationId;
private String noteId;
private String userId;
private String quizType;
private String problem;
private Integer answer;
private List<String> problems;
private String quizTitle;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.Backend.shareNote.domain.Oraganization.DTOs.quizdto;

import lombok.Data;

@Data
public class QuizDeleteDTO {
private String organizationId;
private String noteId;
private String userId;
private String quizId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.Backend.shareNote.domain.Oraganization.DTOs.quizdto;

import lombok.Data;

@Data
public class QuizDetailReqDTO {
private String organizationId;
private String noteId;
private String userId;
private String quizId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.Backend.shareNote.domain.Oraganization.DTOs.quizdto;

import lombok.Builder;
import lombok.Data;

import java.util.List;

@Data
@Builder
public class QuizDetailResDTO {
private String quizTitle;
private String quizType;
private String noteName; // 노트 이름
private List<String> problems;
private Integer correct;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.Backend.shareNote.domain.Oraganization.DTOs.quizdto;

import lombok.Data;

@Data
public class QuizSearchDTO {
private String quizId;
private String quizTitle;
private Integer correct;
private String nickname;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.Backend.shareNote.domain.Oraganization.DTOs.quizdto;

import lombok.Data;

@Data
public class QuizSolveDTO {
private String organizationId;
private String noteId;
private String userId;
private String quizId;
private Integer answer;
private String nickname;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.Backend.shareNote.domain.Oraganization.controller;

import com.Backend.shareNote.domain.Oraganization.DTOs.quizdto.*;
import com.Backend.shareNote.domain.Oraganization.service.QuizService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api")
public class QuizController {
private final QuizService quizService;
@PostMapping("/quiz")
public ResponseEntity<Object> createQuiz(@RequestBody QuizCreateDTO quizCreateDTO){
return quizService.createQuiz(quizCreateDTO);
}

@PostMapping("/quiz-solutions")
public ResponseEntity<Object> createQuizSolutions(@RequestBody QuizSolveDTO quizCreateDTO){
return quizService.createQuizSolutions(quizCreateDTO);
}

@GetMapping("/quiz/{organizationId}/{noteId}/{userId}")
public ResponseEntity<?> getQuiz(@PathVariable String organizationId, @PathVariable String noteId, @PathVariable String userId){
return quizService.getQuiz(organizationId, noteId, userId);
}

@PostMapping("/quiz/detail")
public ResponseEntity<?> getQuizDetail(@RequestBody QuizDetailReqDTO quizDetailReqDTO){
return quizService.getQuizDetail(quizDetailReqDTO);
}

@DeleteMapping("/quiz")
public ResponseEntity<?> deleteQuiz(@RequestBody QuizDeleteDTO quizDeleteDTO){
return quizService.deleteQuiz(quizDeleteDTO);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public static class Note {
private LocalDateTime createdAt;


private List<Quiz> quiz;

// 생성자, 게터, 세터 등 필요한 메서드들 추가
}
Expand All @@ -79,6 +80,38 @@ public static class Page {
private LocalDateTime createdAt;

}

@Getter
@Builder
@Document(collection = "quizs")
public static class Quiz {
@Id
private String id;
// 생성자
private String userId;
// 객관식 or 주관식
private String quizType;
// 문제 설명
private String problem;
// 답안
private int answer;
// 객관식 보기
private List<String> problems;
@CreatedDate
private LocalDateTime createdAt;

// 정답 맞춘 유저
private List<String> correctUser;
// 정답 틀린 유저
private List<String> wrongUser;

// 닉네임
private String nickname;
private String quizTitle;

}


@Getter
@Slf4j
public static class LikesInfo {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.Backend.shareNote.domain.Oraganization.repository;

import com.Backend.shareNote.domain.Oraganization.entity.Organization;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface QuizRepository extends MongoRepository<Organization.Quiz, String>{
}

Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public ResponseEntity<NoteSearchDTO> createNote(NoteCreateDTO noteCreateDTO) {
.pages(new ArrayList<Organization.Page>())
.noteImageUrl(noteCreateDTO.getNoteImageUrl())
.likesInfo(new Organization.LikesInfo())
.quiz(new ArrayList<Organization.Quiz>())
.build();
noteRepository.save(note);
// organization에 note 추가
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public ResponseEntity<OrganizationSearchDTO> createOrganization(OrganizationCrea
.owner(organizationCreateDTO.getOwner())
.emoji(organizationCreateDTO.getEmoji()) // 이모지 추가
.notes(new ArrayList<Organization.Note>())
.quiz(new ArrayList<String>())
.members(members)
.description("")
.build();
Expand Down
Loading

0 comments on commit d832488

Please sign in to comment.