-
Notifications
You must be signed in to change notification settings - Fork 1
[FEAT] 화면공유 DTO 변경 #243
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
base: develop
Are you sure you want to change the base?
[FEAT] 화면공유 DTO 변경 #243
Changes from all commits
84d7c07
d30f7de
e82a65e
c955a7f
d759353
d37b99d
6939a7f
f9235ac
9bf17a8
c079342
1dbb47a
59051a9
53ba917
46c6cba
c197ad5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,25 +1,29 @@ | ||
| package com.debatetimer.controller.sharing; | ||
|
|
||
| import com.debatetimer.controller.auth.AuthMember; | ||
| import com.debatetimer.domain.member.Member; | ||
| import com.debatetimer.dto.sharing.request.SharingRequest; | ||
| import com.debatetimer.dto.sharing.response.SharingResponse; | ||
| import com.debatetimer.service.sharing.SharingService; | ||
| import jakarta.validation.Valid; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.messaging.handler.annotation.DestinationVariable; | ||
| import org.springframework.messaging.handler.annotation.MessageMapping; | ||
| import org.springframework.messaging.handler.annotation.Payload; | ||
| import org.springframework.messaging.handler.annotation.SendTo; | ||
| import org.springframework.stereotype.Controller; | ||
|
|
||
| @Controller | ||
| @RequiredArgsConstructor | ||
| public class SharingController { | ||
|
|
||
| private final SharingService sharingService; | ||
|
|
||
| @MessageMapping("/event/{roomId}") | ||
| @SendTo("/room/{roomId}") | ||
| public SharingResponse share( | ||
| @AuthMember Member member, | ||
| @DestinationVariable(value = "roomId") long roomId, | ||
| @Payload SharingRequest request | ||
| @Valid @Payload SharingRequest request | ||
| ) { | ||
| return new SharingResponse(request.time()); | ||
|
|
||
| return sharingService.share(request); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package com.debatetimer.domain.sharing; | ||
|
|
||
| import jakarta.annotation.Nullable; | ||
| import jakarta.validation.constraints.NotNull; | ||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| public class TimerEvent { | ||
|
|
||
| @NotNull | ||
| private final TimerEventType eventType; | ||
|
|
||
| @Nullable | ||
| private final TimerEventData timerEventData; | ||
|
|
||
| public TimerEvent( | ||
| TimerEventType eventType, | ||
| @Nullable TimerEventData timerEventData | ||
| ) { | ||
| eventType.validateEventData(timerEventData); | ||
| this.eventType = eventType; | ||
| this.timerEventData = timerEventData; | ||
| } | ||
|
|
||
| public TimerEvent(TimerEventType eventType) { | ||
| this(eventType, null); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| package com.debatetimer.domain.sharing; | ||
|
|
||
| import com.debatetimer.domain.customize.CustomizeBoxType; | ||
| import com.debatetimer.domain.customize.Stance; | ||
| import com.debatetimer.exception.custom.DTClientErrorException; | ||
| import com.debatetimer.exception.errorcode.ClientErrorCode; | ||
| import jakarta.annotation.Nullable; | ||
| import jakarta.validation.constraints.NotNull; | ||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| public class TimerEventData { | ||
|
|
||
| @NotNull | ||
| private final CustomizeBoxType timerType; | ||
|
|
||
| private final int sequence; | ||
|
|
||
| @Nullable | ||
| private final Stance currentTeam; | ||
|
|
||
| private final long remainingTime; | ||
|
|
||
| public TimerEventData( | ||
| CustomizeBoxType timerType, | ||
| int sequence, | ||
| @Nullable Stance currentTeam, | ||
| long remainingTime | ||
| ) { | ||
| validateCurrentTeam(timerType, currentTeam); | ||
| this.timerType = timerType; | ||
| this.sequence = sequence; | ||
| this.currentTeam = currentTeam; | ||
| this.remainingTime = remainingTime; | ||
| } | ||
|
|
||
| private void validateCurrentTeam(CustomizeBoxType timerType, Stance currentTeam) { | ||
| if (timerType.isTimeBased() && currentTeam == null) { | ||
| throw new DTClientErrorException(ClientErrorCode.INVALID_TIME_BASED_TIMER_EVENT_DATA); | ||
| } | ||
|
|
||
| if (!timerType.isTimeBased() && currentTeam != null) { | ||
| throw new DTClientErrorException(ClientErrorCode.INVALID_NORMAL_TIMER_EVENT_DATA); | ||
| } | ||
| } | ||
| } | ||
|
Comment on lines
+11
to
+46
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (질문) 여기 전부 다 NotNull 맞아요? 특정 부분은 Nullable 이라면
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ✅ 반영 완료 |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package com.debatetimer.domain.sharing; | ||
|
|
||
| import com.debatetimer.exception.custom.DTClientErrorException; | ||
| import com.debatetimer.exception.errorcode.ClientErrorCode; | ||
| import java.util.Objects; | ||
| import java.util.function.Predicate; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @RequiredArgsConstructor | ||
| public enum TimerEventType { | ||
|
|
||
| NEXT(Objects::nonNull), | ||
| BEFORE(Objects::nonNull), | ||
| STOP(Objects::nonNull), | ||
| PLAY(Objects::nonNull), | ||
| RESET(Objects::nonNull), | ||
| TEAM_SWITCH(Objects::nonNull), | ||
| FINISHED(Objects::isNull), | ||
| ; | ||
|
|
||
| private final Predicate<Object> eventDataValidator; | ||
|
|
||
| public void validateEventData(Object eventData) { | ||
| if (!eventDataValidator.test(eventData)) { | ||
| throw new DTClientErrorException(ClientErrorCode.INVALID_TIMER_EVENT); | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,9 +1,25 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||
| package com.debatetimer.dto.sharing.request; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| import java.time.LocalDateTime; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import com.debatetimer.domain.sharing.TimerEvent; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import com.debatetimer.domain.sharing.TimerEventType; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import jakarta.annotation.Nullable; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import jakarta.validation.Valid; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import jakarta.validation.constraints.NotNull; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import java.util.Optional; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| public record SharingRequest( | ||||||||||||||||||||||||||||||||||||||||||||||||
| LocalDateTime time | ||||||||||||||||||||||||||||||||||||||||||||||||
| @NotNull | ||||||||||||||||||||||||||||||||||||||||||||||||
| TimerEventType eventType, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| @Valid | ||||||||||||||||||||||||||||||||||||||||||||||||
| @Nullable | ||||||||||||||||||||||||||||||||||||||||||||||||
| TimerEventInfoRequest data | ||||||||||||||||||||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| public TimerEvent toTimerEvent() { | ||||||||||||||||||||||||||||||||||||||||||||||||
| return Optional.ofNullable(data) | ||||||||||||||||||||||||||||||||||||||||||||||||
| .map(TimerEventInfoRequest::toTimerEventInfo) | ||||||||||||||||||||||||||||||||||||||||||||||||
| .map(eventData -> new TimerEvent(eventType, eventData)) | ||||||||||||||||||||||||||||||||||||||||||||||||
| .orElseGet(() -> new TimerEvent(eventType)); | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
10
to
25
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ✅ [반영 완료] Optional 반환하도록 수정했습니다 |
||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package com.debatetimer.dto.sharing.request; | ||
|
|
||
| import com.debatetimer.domain.customize.CustomizeBoxType; | ||
| import com.debatetimer.domain.customize.Stance; | ||
| import com.debatetimer.domain.sharing.TimerEventData; | ||
| import jakarta.annotation.Nullable; | ||
| import jakarta.validation.constraints.NotNull; | ||
|
|
||
| public record TimerEventInfoRequest( | ||
| @NotNull | ||
| CustomizeBoxType timerType, | ||
|
|
||
| @Nullable | ||
| Stance currentTeam, | ||
|
|
||
| int sequence, | ||
| long remainingTime | ||
| ) { | ||
|
|
||
| public TimerEventData toTimerEventInfo() { | ||
| return new TimerEventData( | ||
| timerType, | ||
| sequence, | ||
| currentTeam, | ||
| remainingTime | ||
| ); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,16 @@ | ||
| package com.debatetimer.dto.sharing.response; | ||
|
|
||
| import java.time.LocalDateTime; | ||
| import com.debatetimer.domain.sharing.TimerEventType; | ||
| import jakarta.annotation.Nullable; | ||
|
|
||
| public record SharingResponse( | ||
| LocalDateTime time | ||
| TimerEventType eventType, | ||
|
|
||
| @Nullable | ||
| TimerEventDataResponse data | ||
| ) { | ||
|
|
||
| public SharingResponse(TimerEventType eventType) { | ||
| this(eventType, null); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| package com.debatetimer.dto.sharing.response; | ||
|
|
||
|
|
||
| import com.debatetimer.domain.customize.CustomizeBoxType; | ||
| import com.debatetimer.domain.customize.Stance; | ||
| import com.debatetimer.domain.sharing.TimerEventData; | ||
| import jakarta.annotation.Nullable; | ||
| import jakarta.validation.constraints.NotNull; | ||
|
|
||
| public record TimerEventDataResponse( | ||
| @NotNull | ||
| CustomizeBoxType timerType, | ||
|
|
||
| @Nullable | ||
| Stance currentTeam, | ||
|
|
||
| int sequence, | ||
| long remainingTime | ||
| ) { | ||
|
|
||
| public TimerEventDataResponse(TimerEventData timerEventInfo) { | ||
| this( | ||
| timerEventInfo.getTimerType(), | ||
| timerEventInfo.getCurrentTeam(), | ||
| timerEventInfo.getSequence(), | ||
| timerEventInfo.getRemainingTime() | ||
| ); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| package com.debatetimer.service.sharing; | ||
|
|
||
| import com.debatetimer.domain.sharing.TimerEvent; | ||
| import com.debatetimer.dto.sharing.request.SharingRequest; | ||
| import com.debatetimer.dto.sharing.response.SharingResponse; | ||
| import com.debatetimer.dto.sharing.response.TimerEventDataResponse; | ||
| import java.util.Optional; | ||
| import org.springframework.stereotype.Service; | ||
|
|
||
| @Service | ||
| public class SharingService { | ||
|
|
||
| public SharingResponse share(SharingRequest request) { | ||
| TimerEvent timerEvent = request.toTimerEvent(); | ||
| return Optional.ofNullable(timerEvent.getTimerEventData()) | ||
| .map(eventData -> new SharingResponse( | ||
| request.eventType(), | ||
| new TimerEventDataResponse(eventData) | ||
| )) | ||
| .orElse(new SharingResponse(request.eventType(), null)); | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.