-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat/#17 강의 등록 관련 API 개발 #20
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a8f70a8
feat/#17: 강의 신청 승인 / 거절controller 개발
gaau511 81d38f1
feat/#17: 강의 신청 승인 / 거절 Service 개발
gaau511 2c3be06
feat/#17: 신청 승인 / 거절 관련 status code 업데이트
gaau511 0956ee1
feat/#17: 신청 상태 변경 메소드 추가
gaau511 2e7d44d
feat/#17: ApplicationResponse에서 신청 상태를 반환하는 필드 추가
gaau511 b7bb725
feat/#17: Course Entity 생성, 강의 등록 기능 구현
gaau511 38119d9
feat/#17: Course 관련 클래스 주석/어노테이션 수정
gaau511 e736d6b
feat/#17: Lesson Entity 수정
gaau511 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
10 changes: 9 additions & 1 deletion
10
...main/java/inha/dayoook_e/application/api/controller/dto/response/ApplicationResponse.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 |
---|---|---|
@@ -1,10 +1,18 @@ | ||
package inha.dayoook_e.application.api.controller.dto.response; | ||
|
||
import inha.dayoook_e.application.domain.enums.Status; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import jakarta.persistence.EnumType; | ||
import jakarta.persistence.Enumerated; | ||
import jakarta.validation.constraints.NotNull; | ||
|
||
public record ApplicationResponse ( | ||
@NotNull | ||
@Schema(description = "신청 id", example = "1") | ||
Integer id | ||
Integer id, | ||
|
||
@NotNull | ||
@Schema(description = "신청 상태", example = "APPLYING") | ||
@Enumerated(EnumType.STRING) | ||
Status status | ||
) {} |
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
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
23 changes: 23 additions & 0 deletions
23
src/main/java/inha/dayoook_e/course/api/controller/dto/request/CreateCourseRequest.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,23 @@ | ||
package inha.dayoook_e.course.api.controller.dto.request; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import jakarta.validation.constraints.NotNull; | ||
|
||
public record CreateCourseRequest( | ||
@NotNull | ||
@Schema(description = "튜터 id", example = "1") | ||
Integer tutorId, | ||
|
||
@NotNull | ||
@Schema(description = "튜티 id", example = "1") | ||
Integer tuteeId, | ||
|
||
@NotNull | ||
@Schema(description = "신청 요일 id", example = "1") | ||
Integer dayId, | ||
|
||
@NotNull | ||
@Schema(description = "신청 시간대 id", example = "1") | ||
Integer timeSlotId | ||
) { | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/inha/dayoook_e/course/api/controller/dto/response/CourseResponse.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,10 @@ | ||
package inha.dayoook_e.course.api.controller.dto.response; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import jakarta.validation.constraints.NotNull; | ||
|
||
public record CourseResponse ( | ||
@NotNull | ||
@Schema(description = "강의 id", example = "1") | ||
Integer id | ||
) {} |
34 changes: 34 additions & 0 deletions
34
src/main/java/inha/dayoook_e/course/api/mapper/CourseMapper.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,34 @@ | ||
package inha.dayoook_e.course.api.mapper; | ||
|
||
import inha.dayoook_e.application.api.controller.dto.response.ApplicationResponse; | ||
import inha.dayoook_e.application.domain.Application; | ||
import inha.dayoook_e.course.api.controller.dto.request.CreateCourseRequest; | ||
import inha.dayoook_e.course.api.controller.dto.response.CourseResponse; | ||
import inha.dayoook_e.course.domain.Course; | ||
import org.mapstruct.Mapper; | ||
import org.mapstruct.NullValuePropertyMappingStrategy; | ||
|
||
/** | ||
* CourseMapper은 강의와 관련된 데이터 변환 기능을 제공. | ||
*/ | ||
@Mapper(componentModel = "spring", nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE) | ||
public interface CourseMapper { | ||
|
||
/** | ||
* Application을 CreateCourseRequest로 변환해주는 매퍼 | ||
* @param application 등록할 신청 정보 | ||
* @return createCourseRequest | ||
*/ | ||
default CreateCourseRequest toCreateCourseRequest(Application application) { | ||
return new CreateCourseRequest(application.getTutor().getId(), application.getTutee().getId(), | ||
application.getDay().getId(), application.getTimeSlot().getId()); | ||
}; | ||
|
||
/** | ||
* Course를 CourseResponse로 변환하는 매퍼 | ||
* | ||
* @param savedCourse 강의 | ||
* @return CourseResponse | ||
*/ | ||
CourseResponse toCourseResponse(Course savedCourse); | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/inha/dayoook_e/course/api/service/CourseService.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 inha.dayoook_e.course.api.service; | ||
|
||
import inha.dayoook_e.course.api.controller.dto.request.CreateCourseRequest; | ||
import inha.dayoook_e.course.api.controller.dto.response.CourseResponse; | ||
|
||
public interface CourseService { | ||
CourseResponse createCourse(CreateCourseRequest createCourseRequest); | ||
} |
67 changes: 67 additions & 0 deletions
67
src/main/java/inha/dayoook_e/course/api/service/CourseServiceImpl.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,67 @@ | ||
package inha.dayoook_e.course.api.service; | ||
|
||
import inha.dayoook_e.common.exceptions.BaseException; | ||
import inha.dayoook_e.course.api.controller.dto.request.CreateCourseRequest; | ||
import inha.dayoook_e.course.api.controller.dto.response.CourseResponse; | ||
import inha.dayoook_e.course.api.mapper.CourseMapper; | ||
import inha.dayoook_e.course.domain.Course; | ||
import inha.dayoook_e.course.domain.repository.CourseJpaRepository; | ||
import inha.dayoook_e.mapping.domain.Day; | ||
import inha.dayoook_e.mapping.domain.TimeSlot; | ||
import inha.dayoook_e.mapping.domain.repository.DayJpaRepository; | ||
import inha.dayoook_e.mapping.domain.repository.TimeSlotJpaRepository; | ||
import inha.dayoook_e.user.domain.User; | ||
import inha.dayoook_e.user.domain.repository.UserJpaRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
import static inha.dayoook_e.common.BaseEntity.State.ACTIVE; | ||
import static inha.dayoook_e.common.code.status.ErrorStatus.*; | ||
|
||
/** | ||
* CourseServiceImpl은 강의 관련 비즈니스 로직을 처리하는 서비스 클래스. | ||
*/ | ||
@Service | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
@Transactional | ||
public class CourseServiceImpl implements CourseService{ | ||
|
||
private final CourseMapper courseMapper; | ||
private final CourseJpaRepository courseJpaReposiotry; | ||
private final UserJpaRepository userJpaRepository; | ||
private final TimeSlotJpaRepository timeSlotJpaRepository; | ||
private final DayJpaRepository dayJpaRepository; | ||
|
||
@Override | ||
public CourseResponse createCourse(CreateCourseRequest createCourseRequest) { | ||
// 1. 튜터,튜티,요일,시간대 조회 | ||
User tutor = userJpaRepository.findByIdAndState(createCourseRequest.tutorId(), ACTIVE) | ||
.orElseThrow(() -> new BaseException(NOT_FIND_USER)); | ||
User tutee = userJpaRepository.findByIdAndState(createCourseRequest.tuteeId(), ACTIVE) | ||
.orElseThrow(() -> new BaseException(NOT_FIND_USER)); | ||
Day day = dayJpaRepository.findById(createCourseRequest.dayId()) | ||
.orElseThrow(() -> new BaseException(NOT_FIND_DAY)); | ||
TimeSlot timeSlot = timeSlotJpaRepository.findById(createCourseRequest.timeSlotId()) | ||
.orElseThrow(() -> new BaseException(NOT_FIND_TIMESLOT)); | ||
|
||
|
||
// 2. 강의 생성 | ||
// Mapper 동작 오류로 인해 직접 생성 | ||
Course course = Course.builder() | ||
.tutor(tutor) | ||
.tutee(tutee) | ||
.day(day) | ||
.timeSlot(timeSlot) | ||
.createdAt(LocalDateTime.now()) | ||
.build(); | ||
|
||
// 3. 강의 등록 | ||
Course savedCourse = courseJpaReposiotry.save(course); | ||
return courseMapper.toCourseResponse(savedCourse); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@PreAuthorize("hasAuthority('�tutor:create')")이런식으로 어노테이션 추가하면 튜터, 관리자만 호출할 수 있는 api로 지정할 수 있어요
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
! 확인했습니다. 감사합니다.