-
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 #94 from guma2k2/cart-feature
promotion feature
- Loading branch information
Showing
25 changed files
with
495 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
39 changes: 39 additions & 0 deletions
39
src/main/java/com/backend/elearning/domain/questionLecture/QuestionLecture.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,39 @@ | ||
package com.backend.elearning.domain.questionLecture; | ||
|
||
|
||
import com.backend.elearning.domain.common.AbstractAuditEntity; | ||
import com.backend.elearning.domain.lecture.Lecture; | ||
import com.backend.elearning.domain.quiz.Quiz; | ||
import com.backend.elearning.domain.student.Student; | ||
import jakarta.persistence.*; | ||
import lombok.*; | ||
|
||
|
||
@Entity | ||
@Table(name = "question_lecture") | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Getter | ||
@Setter | ||
@Builder | ||
public class QuestionLecture extends AbstractAuditEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
private String title; | ||
|
||
|
||
private String description; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "lecture_id") | ||
private Lecture lecture; | ||
|
||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "student_id") | ||
private Student student; | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/com/backend/elearning/domain/questionLecture/QuestionLectureController.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,40 @@ | ||
package com.backend.elearning.domain.questionLecture; | ||
|
||
import com.backend.elearning.domain.lecture.LectureVm; | ||
import com.backend.elearning.domain.note.NotePostVM; | ||
import com.backend.elearning.domain.note.NoteVM; | ||
import io.swagger.v3.oas.annotations.media.Content; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/api/v1") | ||
public class QuestionLectureController { | ||
|
||
private final QuestionLectureService questionLectureService; | ||
|
||
|
||
public QuestionLectureController(QuestionLectureService questionLectureService) { | ||
this.questionLectureService = questionLectureService; | ||
} | ||
@PostMapping("/question-lecture") | ||
@ApiResponses(value = { | ||
@ApiResponse(responseCode = "200", description = "Created", content = | ||
@Content(schema = @Schema(implementation = LectureVm.class))) | ||
}) | ||
public ResponseEntity<QuestionLectureVM> create ( | ||
@RequestBody QuestionLecturePostVM questionLecturePostVM | ||
) { | ||
QuestionLectureVM questionLectureVM = questionLectureService.create(questionLecturePostVM); | ||
return ResponseEntity.status(HttpStatus.OK).body(questionLectureVM); | ||
} | ||
|
||
|
||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/backend/elearning/domain/questionLecture/QuestionLecturePostVM.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.backend.elearning.domain.questionLecture; | ||
|
||
public record QuestionLecturePostVM ( | ||
String title, | ||
String description, | ||
Long lectureId | ||
) { | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/backend/elearning/domain/questionLecture/QuestionLectureRepo.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.backend.elearning.domain.questionLecture; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface QuestionLectureRepo extends JpaRepository<QuestionLecture, Long> { | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/backend/elearning/domain/questionLecture/QuestionLectureService.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 com.backend.elearning.domain.questionLecture; | ||
|
||
public interface QuestionLectureService { | ||
|
||
QuestionLectureVM create(QuestionLecturePostVM questionLecturePostVM); | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
src/main/java/com/backend/elearning/domain/questionLecture/QuestionLectureServiceImpl.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,43 @@ | ||
package com.backend.elearning.domain.questionLecture; | ||
|
||
import com.backend.elearning.domain.lecture.Lecture; | ||
import com.backend.elearning.domain.lecture.LectureRepository; | ||
import com.backend.elearning.domain.student.Student; | ||
import com.backend.elearning.domain.student.StudentRepository; | ||
import org.springframework.security.core.context.SecurityContextHolder; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Service | ||
public class QuestionLectureServiceImpl implements QuestionLectureService { | ||
|
||
private final QuestionLectureRepo questionLectureRepo; | ||
private final StudentRepository studentRepository; | ||
private final LectureRepository lectureRepository; | ||
|
||
public QuestionLectureServiceImpl(QuestionLectureRepo questionLectureRepo, StudentRepository studentRepository, LectureRepository lectureRepository) { | ||
this.questionLectureRepo = questionLectureRepo; | ||
this.studentRepository = studentRepository; | ||
this.lectureRepository = lectureRepository; | ||
} | ||
|
||
@Override | ||
public QuestionLectureVM create(QuestionLecturePostVM questionLecturePostVM) { | ||
String email = SecurityContextHolder.getContext().getAuthentication().getName(); | ||
Lecture lecture = lectureRepository.findById(questionLecturePostVM.lectureId()).orElseThrow(); | ||
Student student = studentRepository.findByEmail(email).orElseThrow(); | ||
QuestionLecture questionLecture = QuestionLecture | ||
.builder() | ||
.title(questionLecturePostVM.title()) | ||
.description(questionLecturePostVM.description()) | ||
.lecture(lecture) | ||
.student(student) | ||
.build(); | ||
questionLecture.setCreatedAt(LocalDateTime.now()); | ||
questionLecture.setUpdatedAt(LocalDateTime.now()); | ||
|
||
QuestionLecture savedQuestionLecture = questionLectureRepo.saveAndFlush(questionLecture); | ||
return QuestionLectureVM.fromModel(savedQuestionLecture); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/com/backend/elearning/domain/questionLecture/QuestionLectureVM.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,26 @@ | ||
package com.backend.elearning.domain.questionLecture; | ||
|
||
import com.backend.elearning.domain.student.Student; | ||
import com.backend.elearning.domain.user.UserGetVM; | ||
|
||
public record QuestionLectureVM ( | ||
Long id, | ||
String title, | ||
String description, | ||
|
||
UserGetVM student, | ||
String createdAt, | ||
String updatedAt | ||
) { | ||
|
||
public static final QuestionLectureVM fromModel (QuestionLecture questionLecture) { | ||
Student student = questionLecture.getStudent(); | ||
UserGetVM userGetVM = UserGetVM.fromModelStudent(student); | ||
return new QuestionLectureVM(questionLecture.getId(), | ||
questionLecture.getTitle(), | ||
questionLecture.getDescription(), | ||
userGetVM, | ||
questionLecture.getCreatedAt().toString(), | ||
questionLecture.getUpdatedAt().toString()); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/com/backend/elearning/domain/questionLecture/studentAnswer/StudentAnswer.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,33 @@ | ||
package com.backend.elearning.domain.questionLecture.studentAnswer; | ||
|
||
import com.backend.elearning.domain.common.AbstractAuditEntity; | ||
import com.backend.elearning.domain.lecture.Lecture; | ||
import com.backend.elearning.domain.questionLecture.QuestionLecture; | ||
import com.backend.elearning.domain.student.Student; | ||
import jakarta.persistence.*; | ||
import lombok.*; | ||
|
||
@Entity | ||
@Table(name = "student_answer") | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Getter | ||
@Setter | ||
@Builder | ||
public class StudentAnswer extends AbstractAuditEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
private String content; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "question_lecture_id") | ||
private QuestionLecture questionLecture; | ||
|
||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "student_id") | ||
private Student student; | ||
} |
39 changes: 39 additions & 0 deletions
39
...a/com/backend/elearning/domain/questionLecture/studentAnswer/StudentAnswerController.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,39 @@ | ||
package com.backend.elearning.domain.questionLecture.studentAnswer; | ||
|
||
import com.backend.elearning.domain.lecture.LectureVm; | ||
import com.backend.elearning.domain.questionLecture.QuestionLecturePostVM; | ||
import com.backend.elearning.domain.questionLecture.QuestionLectureVM; | ||
import io.swagger.v3.oas.annotations.media.Content; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/api/v1") | ||
public class StudentAnswerController { | ||
|
||
private final StudentAnswerService studentAnswerService; | ||
|
||
public StudentAnswerController(StudentAnswerService studentAnswerService) { | ||
this.studentAnswerService = studentAnswerService; | ||
} | ||
|
||
|
||
@PostMapping("/student-answer") | ||
@ApiResponses(value = { | ||
@ApiResponse(responseCode = "200", description = "Created", content = | ||
@Content(schema = @Schema(implementation = StudentAnswerVM.class))) | ||
}) | ||
public ResponseEntity<StudentAnswerVM> create ( | ||
@RequestBody StudentAnswerPostVM studentAnswerPostVM | ||
) { | ||
StudentAnswerVM studentAnswerVM = studentAnswerService.create(studentAnswerPostVM); | ||
return ResponseEntity.status(HttpStatus.OK).body(studentAnswerVM); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
.../java/com/backend/elearning/domain/questionLecture/studentAnswer/StudentAnswerPostVM.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 com.backend.elearning.domain.questionLecture.studentAnswer; | ||
|
||
public record StudentAnswerPostVM( | ||
String content, | ||
Long questionLectureId | ||
) { | ||
} |
8 changes: 8 additions & 0 deletions
8
...in/java/com/backend/elearning/domain/questionLecture/studentAnswer/StudentAnswerRepo.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.backend.elearning.domain.questionLecture.studentAnswer; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface StudentAnswerRepo extends JpaRepository<StudentAnswer, Long> { | ||
} |
5 changes: 5 additions & 0 deletions
5
...java/com/backend/elearning/domain/questionLecture/studentAnswer/StudentAnswerService.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 com.backend.elearning.domain.questionLecture.studentAnswer; | ||
|
||
public interface StudentAnswerService { | ||
StudentAnswerVM create(StudentAnswerPostVM studentAnswerPostVM); | ||
} |
45 changes: 45 additions & 0 deletions
45
.../com/backend/elearning/domain/questionLecture/studentAnswer/StudentAnswerServiceImpl.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,45 @@ | ||
package com.backend.elearning.domain.questionLecture.studentAnswer; | ||
|
||
|
||
import com.backend.elearning.domain.questionLecture.QuestionLecture; | ||
import com.backend.elearning.domain.questionLecture.QuestionLectureRepo; | ||
import com.backend.elearning.domain.questionLecture.QuestionLectureVM; | ||
import com.backend.elearning.domain.student.Student; | ||
import com.backend.elearning.domain.student.StudentRepository; | ||
import org.springframework.security.core.context.SecurityContextHolder; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Service | ||
public class StudentAnswerServiceImpl implements StudentAnswerService { | ||
|
||
private final StudentAnswerRepo studentAnswerRepo; | ||
|
||
private final StudentRepository studentRepository; | ||
private final QuestionLectureRepo questionLectureRepo; | ||
|
||
public StudentAnswerServiceImpl(StudentAnswerRepo studentAnswerRepo, StudentRepository studentRepository, QuestionLectureRepo questionLectureRepo) { | ||
this.studentAnswerRepo = studentAnswerRepo; | ||
this.studentRepository = studentRepository; | ||
this.questionLectureRepo = questionLectureRepo; | ||
} | ||
|
||
@Override | ||
public StudentAnswerVM create(StudentAnswerPostVM studentAnswerPostVM) { | ||
String email = SecurityContextHolder.getContext().getAuthentication().getName(); | ||
QuestionLecture questionLecture = questionLectureRepo.findById(studentAnswerPostVM.questionLectureId()).orElseThrow(); | ||
Student student = studentRepository.findByEmail(email).orElseThrow(); | ||
StudentAnswer studentAnswer = StudentAnswer | ||
.builder() | ||
.content(studentAnswerPostVM.content()) | ||
.student(student) | ||
.questionLecture(questionLecture) | ||
.build(); | ||
studentAnswer.setCreatedAt(LocalDateTime.now()); | ||
studentAnswer.setUpdatedAt(LocalDateTime.now()); | ||
|
||
StudentAnswer savedStudentAnswer = studentAnswerRepo.saveAndFlush(studentAnswer); | ||
return StudentAnswerVM.fromModel(savedStudentAnswer); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...main/java/com/backend/elearning/domain/questionLecture/studentAnswer/StudentAnswerVM.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,19 @@ | ||
package com.backend.elearning.domain.questionLecture.studentAnswer; | ||
|
||
import com.backend.elearning.domain.student.Student; | ||
import com.backend.elearning.domain.user.UserGetVM; | ||
|
||
public record StudentAnswerVM( | ||
Long id, | ||
String content, | ||
String createdAt, | ||
String updatedAt, | ||
UserGetVM student | ||
) { | ||
public static final StudentAnswerVM fromModel(StudentAnswer studentAnswer) { | ||
Student student = studentAnswer.getStudent(); | ||
UserGetVM userGetVM = UserGetVM.fromModelStudent(student); | ||
return new StudentAnswerVM(studentAnswer.getId(), studentAnswer.getContent(), studentAnswer.getCreatedAt().toString(), | ||
studentAnswer.getUpdatedAt().toString(), userGetVM); | ||
} | ||
} |
Oops, something went wrong.