Merge pull request #17 from TeamBNBN/be/Lecture

feat: lecture
This commit is contained in:
Jungmin 2024-07-16 13:28:19 +09:00 committed by GitHub
commit ef75e672f1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 181 additions and 3 deletions

View File

@ -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<Lecture> lectures = lectureService.findAllLecture();
return new ResponseEntity<>(lectures, HttpStatus.OK);
}
@GetMapping("/teacherId/{teacherId}")
public ResponseEntity<?> findByTeacherId (@PathVariable String teacherId) {
List<Lecture> 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);
}
}

View File

@ -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;
}

View File

@ -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, Long> {
Lecture findByTitle(@Param("title") String title);
List<Lecture> findByTeacherId(@Param("teacherId") String teacherId);
}

View File

@ -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<Lecture> findLectureByTeacherId(String teacherId);
List<Lecture> findAllLecture();
}

View File

@ -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<Lecture> findLectureByTeacherId(String teacherId) {
return lectureRepository.findByTeacherId(teacherId);
}
@Override
public List<Lecture> findAllLecture() {
return lectureRepository.findAll();
}
}

View File

@ -16,4 +16,3 @@ spring.mvc.pathmatch.matching-strategy=ant_path_matcher
spring.jpa.database=mysql spring.jpa.database=mysql
spring.jpa.hibernate.ddl-auto=create spring.jpa.hibernate.ddl-auto=create
spring.jpa.show-sql=true spring.jpa.show-sql=true