-
Notifications
You must be signed in to change notification settings - Fork 0
Feat: 일정 생성 API #21
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
Merged
Merged
Feat: 일정 생성 API #21
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
559b2d4
[#19] feat: 서비스 계층 로그 어노테이션
west-eastH 20a4690
[#19] feat: 서비스 계층 로그 어노테이션 파라미터 추가
west-eastH 9a8f63d
[#19] feat: 멤버가 속한 크루 어노테이션
west-eastH e71d033
[#19] feat: 멤버가 속한 크루 어노테이션
west-eastH 8d386ee
[#19] feat: 멤버가 속한 크루 어노테이션
west-eastH 011c7df
[#19] feat: 운영진(크루장 포함) Role 리턴
west-eastH 45919f2
[#19] feat: 일정 생성 API
west-eastH 0ae5b68
[#19] feat: 러닝캡 역할 제한 수정
west-eastH 1d9bd87
[#19] feat: 일정 생성 중복 코드 제거 & 멤버, 일정 유틸 함수 추가
west-eastH aafecd5
[#19] chore: 러닝캡 에러 이름 수정
west-eastH 2164848
[#19] test: 일정 생성 테스트 코드
west-eastH 0986f45
[#19] chore: ddl 옵션 변경
west-eastH 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 hidden or 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 |
|---|---|---|
|
|
@@ -43,4 +43,5 @@ secrets.yml | |
| .idea | ||
| .env | ||
| src/test/resources/application.yml | ||
| /uploads | ||
| /uploads | ||
| ./scripts | ||
This file contains hidden or 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
34 changes: 34 additions & 0 deletions
34
src/main/java/run/backend/domain/crew/repository/JoinCrewRepository.java
This file contains hidden or 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 run.backend.domain.crew.repository; | ||
|
|
||
| import java.util.Optional; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
| import org.springframework.data.jpa.repository.Query; | ||
| import org.springframework.data.repository.query.Param; | ||
| import run.backend.domain.crew.entity.JoinCrew; | ||
| import run.backend.domain.crew.enums.JoinStatus; | ||
| import run.backend.domain.event.dto.response.EventCreationValidationDto; | ||
|
|
||
| public interface JoinCrewRepository extends JpaRepository<JoinCrew, Long> { | ||
|
|
||
| @Query("SELECT jc FROM JoinCrew jc WHERE jc.member.id = :memberId AND jc.joinStatus = :status") | ||
| Optional<JoinCrew> findByMemberIdAndJoinStatus(@Param("memberId") Long memberId, | ||
| @Param("status") JoinStatus status); | ||
|
|
||
| @Query(""" | ||
| SELECT new run.backend.domain.event.dto.response.EventCreationValidationDto( | ||
| requesterJoin.crew, | ||
| captainJoin.member | ||
| ) | ||
| FROM JoinCrew requesterJoin | ||
| INNER JOIN JoinCrew captainJoin ON requesterJoin.crew.id = captainJoin.crew.id | ||
| WHERE requesterJoin.member.id = :requesterId | ||
| AND requesterJoin.joinStatus = :status | ||
| AND captainJoin.member.id = :runningCaptainId | ||
| AND captainJoin.joinStatus = :status | ||
| """) | ||
| Optional<EventCreationValidationDto> validateEventCreation( | ||
| @Param("requesterId") Long requesterId, | ||
| @Param("runningCaptainId") Long runningCaptainId, | ||
| @Param("status") JoinStatus status | ||
| ); | ||
| } |
36 changes: 36 additions & 0 deletions
36
src/main/java/run/backend/domain/event/controller/EventController.java
This file contains hidden or 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,36 @@ | ||
| package run.backend.domain.event.controller; | ||
|
|
||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import io.swagger.v3.oas.annotations.tags.Tag; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.security.access.prepost.PreAuthorize; | ||
| import org.springframework.web.bind.annotation.PostMapping; | ||
| import org.springframework.web.bind.annotation.RequestBody; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
| import run.backend.domain.event.dto.request.EventInfoRequest; | ||
| import run.backend.domain.event.service.EventServiceImpl; | ||
| import run.backend.domain.member.entity.Member; | ||
| import run.backend.global.annotation.member.Login; | ||
| import run.backend.global.common.response.CommonResponse; | ||
|
|
||
| @RestController | ||
| @RequiredArgsConstructor | ||
| @RequestMapping("/api/v1/events") | ||
| @Tag(name = "Events", description = "일정 관련 API") | ||
| public class EventController { | ||
|
|
||
| private final EventServiceImpl eventService; | ||
|
|
||
| @PostMapping | ||
| @PreAuthorize("hasRole('MANAGER') or hasRole('LEADER')") | ||
| @Operation(summary = "일정 생성", description = "러닝 일정를 생성합니다. LEADER 또는 MANAGER 권한이 필요합니다.") | ||
| public CommonResponse<Void> createEvent( | ||
| @RequestBody EventInfoRequest eventInfoRequest, | ||
| @Login Member member | ||
| ) { | ||
|
|
||
| eventService.createEvent(eventInfoRequest, member); | ||
| return new CommonResponse<>("일정 생성 성공"); | ||
| } | ||
| } | ||
20 changes: 19 additions & 1 deletion
20
src/main/java/run/backend/domain/event/dto/request/EventInfoRequest.java
This file contains hidden or 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,4 +1,22 @@ | ||
| package run.backend.domain.event.dto.request; | ||
|
|
||
| public record EventInfoRequest() { | ||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
| import java.time.LocalDate; | ||
| import java.time.LocalTime; | ||
| import run.backend.domain.event.enums.RepeatCycle; | ||
| import run.backend.domain.event.enums.WeekDay; | ||
|
|
||
| public record EventInfoRequest( | ||
| String title, | ||
| LocalDate baseDate, | ||
| @Schema(description = "반복 주기", example = "NONE / WEEKLY") | ||
| RepeatCycle repeatCycle, | ||
| @Schema(description = "반복 요일", example = "MONDAY / TUESDAY / WEDNESDAY / THURSDAY / FRIDAY / SATURDAY / SUNDAY", nullable = true) | ||
| WeekDay repeatDays, | ||
| LocalTime startTime, | ||
| LocalTime endTime, | ||
| String place, | ||
| @Schema(description = "러닝캡틴 ID", example = "1") | ||
| Long runningCaptainId | ||
| ) { | ||
| } |
8 changes: 8 additions & 0 deletions
8
src/main/java/run/backend/domain/event/dto/response/EventCreationValidationDto.java
This file contains hidden or 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 run.backend.domain.event.dto.response; | ||
|
|
||
| import run.backend.domain.crew.entity.Crew; | ||
| import run.backend.domain.member.entity.Member; | ||
|
|
||
| public record EventCreationValidationDto(Crew crew, Member runningCaptain) { | ||
|
|
||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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
15 changes: 15 additions & 0 deletions
15
src/main/java/run/backend/domain/event/exception/EventErrorCode.java
This file contains hidden or 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,15 @@ | ||
| package run.backend.domain.event.exception; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
| import run.backend.global.exception.ErrorCode; | ||
|
|
||
| @Getter | ||
| @AllArgsConstructor | ||
| public enum EventErrorCode implements ErrorCode { | ||
|
|
||
| RUNNING_CAPTAIN_NOT_CREW_MEMBER(6001, "러닝캡이 크루원이 아닙니다."); | ||
|
|
||
| private final int errorCode; | ||
| private final String errorMessage; | ||
| } |
16 changes: 16 additions & 0 deletions
16
src/main/java/run/backend/domain/event/exception/EventException.java
This file contains hidden or 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,16 @@ | ||
| package run.backend.domain.event.exception; | ||
|
|
||
| import run.backend.global.exception.CustomException; | ||
|
|
||
| public class EventException extends CustomException { | ||
|
|
||
| public EventException(final EventErrorCode eventErrorCode) { | ||
| super(eventErrorCode); | ||
| } | ||
|
|
||
| public static class InvalidEventCreationRequest extends EventException { | ||
| public InvalidEventCreationRequest() { | ||
| super(EventErrorCode.RUNNING_CAPTAIN_NOT_CREW_MEMBER); | ||
| } | ||
| } | ||
| } |
8 changes: 8 additions & 0 deletions
8
src/main/java/run/backend/domain/event/repository/EventRepository.java
This file contains hidden or 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 run.backend.domain.event.repository; | ||
|
|
||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
| import run.backend.domain.event.entity.Event; | ||
|
|
||
| public interface EventRepository extends JpaRepository<Event, Long> { | ||
|
|
||
| } |
8 changes: 8 additions & 0 deletions
8
src/main/java/run/backend/domain/event/repository/JoinEventRepository.java
This file contains hidden or 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 run.backend.domain.event.repository; | ||
|
|
||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
| import run.backend.domain.event.entity.JoinEvent; | ||
|
|
||
| public interface JoinEventRepository extends JpaRepository<JoinEvent, Long> { | ||
|
|
||
| } |
7 changes: 7 additions & 0 deletions
7
src/main/java/run/backend/domain/event/repository/PeriodicEventRepository.java
This file contains hidden or 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,7 @@ | ||
| package run.backend.domain.event.repository; | ||
|
|
||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
| import run.backend.domain.event.entity.PeriodicEvent; | ||
|
|
||
| public interface PeriodicEventRepository extends JpaRepository<PeriodicEvent, Long> { | ||
| } |
17 changes: 9 additions & 8 deletions
17
src/main/java/run/backend/domain/event/service/EventService.java
This file contains hidden or 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,16 +1,17 @@ | ||
| package run.backend.domain.event.service; | ||
|
|
||
|
|
||
| import run.backend.domain.event.dto.request.EventInfoRequest; | ||
| import run.backend.domain.event.dto.response.EventInfoResponse; | ||
| import run.backend.domain.member.entity.Member; | ||
|
|
||
| public interface EventService { | ||
|
|
||
| void updateEvent(EventInfoRequest eventInfoRequest); | ||
|
|
||
| void joinEvent(Long eventId, Long memberId); | ||
|
|
||
| void deleteEvent(Long eventId); | ||
| void createEvent(EventInfoRequest eventInfoRequest, Member member); | ||
|
|
||
| EventInfoResponse getEventDetails(Long eventId); | ||
| // void updateEvent(EventInfoRequest eventInfoRequest); | ||
| // | ||
| // void joinEvent(Long eventId, Long memberId); | ||
| // | ||
| // void deleteEvent(Long eventId); | ||
| // | ||
| // EventInfoResponse getEventDetails(Long eventId); | ||
| } |
89 changes: 89 additions & 0 deletions
89
src/main/java/run/backend/domain/event/service/EventServiceImpl.java
This file contains hidden or 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,89 @@ | ||
| package run.backend.domain.event.service; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
| import run.backend.domain.crew.entity.Crew; | ||
| import run.backend.domain.crew.enums.JoinStatus; | ||
| import run.backend.domain.crew.repository.JoinCrewRepository; | ||
| import run.backend.domain.event.dto.request.EventInfoRequest; | ||
| import run.backend.domain.event.dto.response.EventCreationValidationDto; | ||
| import run.backend.domain.event.entity.Event; | ||
| import run.backend.domain.event.entity.JoinEvent; | ||
| import run.backend.domain.event.entity.PeriodicEvent; | ||
| import run.backend.domain.event.enums.RepeatCycle; | ||
| import run.backend.domain.event.exception.EventException.InvalidEventCreationRequest; | ||
| import run.backend.domain.event.repository.EventRepository; | ||
| import run.backend.domain.event.repository.JoinEventRepository; | ||
| import run.backend.domain.event.repository.PeriodicEventRepository; | ||
| import run.backend.domain.member.entity.Member; | ||
| import run.backend.global.annotation.global.Logging; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| @Transactional(readOnly = true) | ||
| public class EventServiceImpl implements EventService { | ||
|
|
||
| private final EventRepository eventRepository; | ||
| private final PeriodicEventRepository periodicEventRepository; | ||
| private final JoinCrewRepository joinCrewRepository; | ||
| private final JoinEventRepository joinEventRepository; | ||
|
|
||
| @Override | ||
| @Transactional | ||
| @Logging | ||
| public void createEvent(EventInfoRequest eventInfoRequest, Member member) { | ||
| EventCreationValidationDto validation = joinCrewRepository | ||
| .validateEventCreation( | ||
| member.getId(), | ||
| eventInfoRequest.runningCaptainId(), | ||
| JoinStatus.APPROVED | ||
| ) | ||
| .orElseThrow(InvalidEventCreationRequest::new); | ||
|
|
||
| Crew crew = validation.crew(); | ||
| Member runningCaptain = validation.runningCaptain(); | ||
|
|
||
| if (eventInfoRequest.repeatCycle() != RepeatCycle.NONE) { | ||
| createPeriodicEvent(eventInfoRequest, crew, runningCaptain); | ||
| } | ||
| createSingleEvent(eventInfoRequest, crew, runningCaptain); | ||
| } | ||
|
|
||
| private void createPeriodicEvent(EventInfoRequest request, Crew crew, Member runningCaptain) { | ||
| PeriodicEvent periodicEvent = PeriodicEvent.builder() | ||
| .title(request.title()) | ||
| .baseDate(request.baseDate()) | ||
| .repeatCycle(request.repeatCycle()) | ||
| .repeatDays(request.repeatDays()) | ||
| .startTime(request.startTime()) | ||
| .endTime(request.endTime()) | ||
| .place(request.place()) | ||
| .crew(crew) | ||
| .member(runningCaptain) | ||
| .build(); | ||
|
|
||
| periodicEventRepository.save(periodicEvent); | ||
| } | ||
|
|
||
| private void createSingleEvent(EventInfoRequest request, Crew crew, Member runningCaptain) { | ||
| Event event = Event.builder() | ||
| .title(request.title()) | ||
| .date(request.baseDate()) | ||
| .startTime(request.startTime()) | ||
| .endTime(request.endTime()) | ||
| .place(request.place()) | ||
| .crew(crew) | ||
| .member(runningCaptain) | ||
| .build(); | ||
|
|
||
| Event savedEvent = eventRepository.save(event); | ||
|
|
||
| JoinEvent joinEvent = JoinEvent.builder() | ||
| .event(savedEvent) | ||
| .member(runningCaptain) | ||
| .build(); | ||
|
|
||
| joinEventRepository.save(joinEvent); | ||
| } | ||
| } |
This file contains hidden or 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
12 changes: 12 additions & 0 deletions
12
src/main/java/run/backend/global/annotation/global/Logging.java
This file contains hidden or 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,12 @@ | ||
| package run.backend.global.annotation.global; | ||
|
|
||
| import java.lang.annotation.ElementType; | ||
| import java.lang.annotation.Retention; | ||
| import java.lang.annotation.RetentionPolicy; | ||
| import java.lang.annotation.Target; | ||
|
|
||
| @Target(ElementType.METHOD) | ||
| @Retention(RetentionPolicy.RUNTIME) | ||
| public @interface Logging { | ||
| String description() default ""; | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
오!!! 이거 완전 좋네요!!
이거 하면 시큐리티 파일에서 따로 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.
맞아요~