From ed966e985ebad8cb8a13848c62129e3a6a8fa16c Mon Sep 17 00:00:00 2001 From: kgc9007 Date: Tue, 16 Jul 2024 13:20:16 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20lecture=20lecture=20entity,=20repositor?= =?UTF-8?q?y,=20service,=20controller=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/build.gradle | 6 +- .../lecture/controller/LectureController.java | 56 +++++++++++++++++++ .../edufocus/lecture/entity/Lecture.java | 40 +++++++++++++ .../lecture/repository/LectureRepository.java | 15 +++++ .../lecture/service/LectureService.java | 23 ++++++++ .../lecture/service/LectureServiceImpl.java | 45 +++++++++++++++ .../src/main/resources/application.properties | 9 +-- 7 files changed, 189 insertions(+), 5 deletions(-) create mode 100644 backend/src/main/java/com/edufocus/edufocus/lecture/controller/LectureController.java create mode 100644 backend/src/main/java/com/edufocus/edufocus/lecture/entity/Lecture.java create mode 100644 backend/src/main/java/com/edufocus/edufocus/lecture/repository/LectureRepository.java create mode 100644 backend/src/main/java/com/edufocus/edufocus/lecture/service/LectureService.java create mode 100644 backend/src/main/java/com/edufocus/edufocus/lecture/service/LectureServiceImpl.java diff --git a/backend/build.gradle b/backend/build.gradle index 6c0680f..68902bf 100644 --- a/backend/build.gradle +++ b/backend/build.gradle @@ -23,9 +23,13 @@ dependencies { implementation 'mysql:mysql-connector-java:8.0.33' testImplementation 'org.springframework.boot:spring-boot-starter-test' implementation group: 'io.livekit', name: 'livekit-server', version: '0.6.1' + implementation 'org.projectlombok:lombok' + annotationProcessor 'org.projectlombok:lombok' + implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.2.0' + } test { useJUnitPlatform() -} +} \ No newline at end of file diff --git a/backend/src/main/java/com/edufocus/edufocus/lecture/controller/LectureController.java b/backend/src/main/java/com/edufocus/edufocus/lecture/controller/LectureController.java new file mode 100644 index 0000000..ca8e1ff --- /dev/null +++ b/backend/src/main/java/com/edufocus/edufocus/lecture/controller/LectureController.java @@ -0,0 +1,56 @@ +package com.edufocus.edufocus.lecture.controller; + +import com.edufocus.edufocus.lecture.entity.Lecture; +import com.edufocus.edufocus.lecture.service.LectureService; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@RestController +@RequestMapping("/lecture") +@Slf4j +@RequiredArgsConstructor +public class LectureController { + + private final LectureService lectureService; + + @PostMapping + public ResponseEntity createLecture (@RequestBody Lecture lecture) { + lectureService.createLecture(lecture); + return new ResponseEntity<>(HttpStatus.CREATED); + } + + @DeleteMapping("/{lectureId}") + public ResponseEntity deleteLecture (@PathVariable long lectureId) { + lectureService.deleteLecture(lectureId); + return new ResponseEntity<>(HttpStatus.NO_CONTENT); + } + + @GetMapping + public ResponseEntity findAllLecture () { + List lectures = lectureService.findAllLecture(); + return new ResponseEntity<>(lectures, HttpStatus.OK); + } + + @GetMapping("/teacherId/{teacherId}") + public ResponseEntity findByTeacherId (@PathVariable String teacherId) { + List lectures = lectureService.findLectureByTeacherId(teacherId); + return new ResponseEntity<>(lectures, HttpStatus.OK); + } + + @GetMapping("/title/{title}") + public ResponseEntity findByTitle (@PathVariable String title) { + Lecture lecture = lectureService.findLectureByTitle(title); + + if (lecture == null) { + return new ResponseEntity<>(HttpStatus.NO_CONTENT); + } + + return new ResponseEntity<>(lecture, HttpStatus.OK); + } + +} diff --git a/backend/src/main/java/com/edufocus/edufocus/lecture/entity/Lecture.java b/backend/src/main/java/com/edufocus/edufocus/lecture/entity/Lecture.java new file mode 100644 index 0000000..c006240 --- /dev/null +++ b/backend/src/main/java/com/edufocus/edufocus/lecture/entity/Lecture.java @@ -0,0 +1,40 @@ +package com.edufocus.edufocus.lecture.entity; + +import jakarta.persistence.*; +import lombok.Getter; +import lombok.Setter; + +import java.util.Date; + +@Entity +@Getter +@Setter +public class Lecture { + + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column + private Long id; + + @Column(name = "teacher_id") + private String teacherId; + + @Column + private String title; + + @Lob + private String description; + + @Column(name = "start_date") + @Temporal(TemporalType.DATE) + private Date startDate; + + @Column(name = "end_date") + @Temporal(TemporalType.DATE) + private Date endDate; + + @Lob + private String plan; + + + +} diff --git a/backend/src/main/java/com/edufocus/edufocus/lecture/repository/LectureRepository.java b/backend/src/main/java/com/edufocus/edufocus/lecture/repository/LectureRepository.java new file mode 100644 index 0000000..032085b --- /dev/null +++ b/backend/src/main/java/com/edufocus/edufocus/lecture/repository/LectureRepository.java @@ -0,0 +1,15 @@ +package com.edufocus.edufocus.lecture.repository; + +import com.edufocus.edufocus.lecture.entity.Lecture; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.repository.query.Param; +import org.springframework.stereotype.Repository; + +import java.util.List; + +@Repository +public interface LectureRepository extends JpaRepository { + Lecture findByTitle(@Param("title") String title); + + List findByTeacherId(@Param("teacherId") String teacherId); +} diff --git a/backend/src/main/java/com/edufocus/edufocus/lecture/service/LectureService.java b/backend/src/main/java/com/edufocus/edufocus/lecture/service/LectureService.java new file mode 100644 index 0000000..777fd58 --- /dev/null +++ b/backend/src/main/java/com/edufocus/edufocus/lecture/service/LectureService.java @@ -0,0 +1,23 @@ +package com.edufocus.edufocus.lecture.service; + +import com.edufocus.edufocus.lecture.entity.Lecture; +import jakarta.transaction.Transactional; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import java.util.List; + + +@Service +public interface LectureService { + + void createLecture(Lecture lecture); + + void deleteLecture(long lectureId); + + Lecture findLectureByTitle(String title); + + List findLectureByTeacherId(String teacherId); + + List findAllLecture(); +} diff --git a/backend/src/main/java/com/edufocus/edufocus/lecture/service/LectureServiceImpl.java b/backend/src/main/java/com/edufocus/edufocus/lecture/service/LectureServiceImpl.java new file mode 100644 index 0000000..0431045 --- /dev/null +++ b/backend/src/main/java/com/edufocus/edufocus/lecture/service/LectureServiceImpl.java @@ -0,0 +1,45 @@ +package com.edufocus.edufocus.lecture.service; + +import com.edufocus.edufocus.lecture.entity.Lecture; +import com.edufocus.edufocus.lecture.repository.LectureRepository; +import jakarta.transaction.Transactional; +import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.Optional; + +@Service +@Transactional +@RequiredArgsConstructor +public class LectureServiceImpl implements LectureService { + + @Autowired + private final LectureRepository lectureRepository; + + @Override + public void createLecture(Lecture lecture) { + lectureRepository.save(lecture); + } + + @Override + public void deleteLecture(long lectureId) { + lectureRepository.deleteById(lectureId); + } + + @Override + public Lecture findLectureByTitle(String title) { + return lectureRepository.findByTitle(title); + } + + @Override + public List findLectureByTeacherId(String teacherId) { + return lectureRepository.findByTeacherId(teacherId); + } + + @Override + public List findAllLecture() { + return lectureRepository.findAll(); + } +} diff --git a/backend/src/main/resources/application.properties b/backend/src/main/resources/application.properties index 172132c..b1eeab4 100644 --- a/backend/src/main/resources/application.properties +++ b/backend/src/main/resources/application.properties @@ -1,6 +1,6 @@ spring.application.name=edufocus +server.port=8080 -server.port=${SERVER_PORT:6080} server.ssl.enabled=false # LiveKit configuration @@ -8,10 +8,11 @@ livekit.api.key=${LIVEKIT_API_KEY:devkey} livekit.api.secret=${LIVEKIT_API_SECRET:secret} spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver -spring.datasource.url=jdbc:mysql://localhost:3306/edufocus?serverTimezone=Asia/Seoul +spring.datasource.url=jdbc:mysql://localhost:3306/edufocus?useSSL=false spring.datasource.username=root spring.datasource.password=root +spring.mvc.pathmatch.matching-strategy=ant_path_matcher spring.jpa.database=mysql -spring.jpa.hibernate.ddl-auto=update -spring.jpa.show-sql=true +spring.jpa.hibernate.ddl-auto=create +spring.jpa.show-sql=true \ No newline at end of file