/
dmuruz
/
Course_Service
Обзор
Документация
Войти
/
dmuruz
/
Course_Service
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
dev
src/main/java/org/example/controller/LessonController.java
64 строки
2 KB
Danil Muruz
MVP
24 апр 2025, 09:39
24 апр 2025, 09:39
16b1c45
Код
Авторство
О чём код?
package org.example.controller; import org.example.dto.LessonDTO; import org.example.dto.LessonProgressDTO; import org.example.manager.LessonManager; import org.example.manager.UserProgressManager; import org.example.model.Lesson; import org.example.model.User; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.*; import java.util.List; @RestController @RequestMapping("/lessons") public class LessonController { @Autowired private LessonManager lessonManager; @Autowired private UserProgressManager userProgressManager; @PostMapping public ResponseEntity<Lesson> createLesson(@RequestBody LessonDTO lessonDTO) { Lesson lesson = lessonManager.createLesson(lessonDTO); return ResponseEntity.ok(lesson); } @GetMapping public ResponseEntity<List<LessonProgressDTO>> getAllLessons( @AuthenticationPrincipal User user) { Long userId = user.getId(); List<LessonProgressDTO> list = userProgressManager.getAllLessonsWithStatus(userId); return ResponseEntity.ok(list); } @GetMapping("/{id}") public ResponseEntity<Lesson> getLessonById(@PathVariable Long id) { return lessonManager.getLessonById(id) .map(ResponseEntity::ok) .orElse(ResponseEntity.notFound().build()); } @PutMapping("/{id}") public ResponseEntity<Lesson> updateLesson(@PathVariable Long id, @RequestBody LessonDTO lessonDTO) { Lesson updated = lessonManager.updateLesson(id, lessonDTO); return ResponseEntity.ok(updated); } @DeleteMapping("/{id}") public ResponseEntity<Void> deleteLesson(@PathVariable Long id) { lessonManager.deleteLesson(id); return ResponseEntity.ok().build(); } @GetMapping("/first/{courseId}") public ResponseEntity<Lesson> getFirstLesson(@PathVariable Long courseId) { Lesson lesson = lessonManager.getFirstLesson(courseId); return ResponseEntity.ok(lesson); } }