diff --git a/doochul/src/main/java/org/doochul/application/LessonService.java b/doochul/src/main/java/org/doochul/application/LessonService.java index 466e3b8..883fa33 100644 --- a/doochul/src/main/java/org/doochul/application/LessonService.java +++ b/doochul/src/main/java/org/doochul/application/LessonService.java @@ -5,15 +5,10 @@ import org.doochul.domain.lesson.LessonRepository; import org.doochul.domain.membership.MemberShip; import org.doochul.domain.membership.MemberShipRepository; -import org.doochul.domain.user.User; -import org.doochul.domain.user.UserRepository; import org.doochul.ui.dto.LessonRequest; - import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.List; - @Service @RequiredArgsConstructor public class LessonService { @@ -22,11 +17,8 @@ public class LessonService { private final MemberShipRepository memberShipRepository; @Transactional - // request 받아서 save 하는 로직 public Long save(final Long membershipId, final LessonRequest lessonRequest) { final MemberShip memberShip = memberShipRepository.findById(membershipId).orElseThrow(); return lessonRepository.save(Lesson.of(memberShip, lessonRequest.getStartedAt(), lessonRequest.getEndedAt(), lessonRequest.getRecord())).getId(); } - - } diff --git a/doochul/src/main/java/org/doochul/domain/lesson/Lesson.java b/doochul/src/main/java/org/doochul/domain/lesson/Lesson.java index 09c9c88..4f490fd 100644 --- a/doochul/src/main/java/org/doochul/domain/lesson/Lesson.java +++ b/doochul/src/main/java/org/doochul/domain/lesson/Lesson.java @@ -14,9 +14,6 @@ import lombok.NoArgsConstructor; import org.doochul.domain.BaseEntity; import org.doochul.domain.membership.MemberShip; -import org.doochul.domain.user.User; -import org.doochul.ui.dto.LessonRequest; -import org.doochul.ui.dto.LessonResponse; @Entity @Getter @@ -44,7 +41,8 @@ public Lesson(Long id, MemberShip memberShip, LocalDateTime startedAt, LocalDate this.endedAt = endedAt; this.record = record; } + public static Lesson of(MemberShip memberShip, LocalDateTime startedAt, LocalDateTime endedAt, String record) { - return new Lesson(null, memberShip,startedAt,endedAt,record); + return new Lesson(null, memberShip, startedAt, endedAt, record); } } diff --git a/doochul/src/main/java/org/doochul/ui/LessonController.java b/doochul/src/main/java/org/doochul/ui/LessonController.java index 98ff921..ce2fe74 100644 --- a/doochul/src/main/java/org/doochul/ui/LessonController.java +++ b/doochul/src/main/java/org/doochul/ui/LessonController.java @@ -2,25 +2,17 @@ import lombok.RequiredArgsConstructor; import org.doochul.application.LessonService; -import org.doochul.domain.lesson.Lesson; -import org.doochul.domain.user.User; - import org.doochul.ui.dto.LessonRequest; -import org.doochul.ui.dto.LessonResponse; -import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; - - @RestController @RequiredArgsConstructor @RequestMapping("/lesson") public class LessonController { - private final LessonService lessonService; + @PostMapping("/save/{membershipId}") public Long save(final @PathVariable Long membershipId, final @RequestBody LessonRequest lessonRequest) { - return lessonService.save(membershipId,lessonRequest); + return lessonService.save(membershipId, lessonRequest); } - } diff --git a/doochul/src/main/java/org/doochul/ui/dto/LessonResponse.java b/doochul/src/main/java/org/doochul/ui/dto/LessonResponse.java index 508f458..0450c2a 100644 --- a/doochul/src/main/java/org/doochul/ui/dto/LessonResponse.java +++ b/doochul/src/main/java/org/doochul/ui/dto/LessonResponse.java @@ -16,7 +16,7 @@ public record LessonResponse( String record ) { public static LessonResponse from(final Lesson lesson) { - return new LessonResponse(lesson.getId(), lesson.getMemberShip(), lesson.getStartedAt(), lesson.getEndedAt(),lesson.getRecord()); + return new LessonResponse(lesson.getId(), lesson.getMemberShip(), lesson.getStartedAt(), lesson.getEndedAt(), lesson.getRecord()); } public static List fromList(final List lessons) { @@ -24,7 +24,4 @@ public static List fromList(final List lessons) { .map(LessonResponse::from) .toList(); } - - - }