Skip to content

Commit 63bc7f8

Browse files
authored
Merge pull request #1134 from woowacourse-teams/BE/dev
[BE] 카테고리 & 페어룸 버그 수정 테스트 서버로 이동
2 parents 7c07a61 + 29cd8ff commit 63bc7f8

File tree

12 files changed

+46
-46
lines changed

12 files changed

+46
-46
lines changed

backend/src/main/java/site/coduo/pairroom/domain/PairRoomStatus.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
@Getter
1414
public enum PairRoomStatus {
1515

16-
IN_PROGRESS("in_progress"),
17-
COMPLETED("completed"),
18-
DELETED("deleted");
16+
IN_PROGRESS("IN_PROGRESS"),
17+
COMPLETED("COMPLETED"),
18+
DELETED("DELETED");
1919

2020
private static final Map<String, PairRoomStatus> STATUS = Arrays.stream(values())
2121
.collect(Collectors.toMap(PairRoomStatus::name, Function.identity()));
22-
private final String name;
22+
private final String message;
2323

2424
public static PairRoomStatus findByName(String value) {
2525
if (STATUS.containsKey(value)) {

backend/src/main/java/site/coduo/pairroom/service/PairRoomService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public void completePairRoom(final String accessCode) {
173173
final PairRoomEntity pairRoomEntity = pairRoomRepository.fetchByAccessCode(accessCode);
174174
checkPairRoomIsActive(pairRoomEntity);
175175
pairRoomEntity.updateStatus(PairRoomStatus.COMPLETED);
176-
pairRoomStompManager.send(accessCode, PairRoomStatus.COMPLETED);
176+
pairRoomStompManager.sendStatus(accessCode, PairRoomStatus.COMPLETED);
177177
}
178178

179179
private void checkPairRoomIsDeleted(final PairRoomEntity pairRoomEntity) {

backend/src/main/java/site/coduo/pairroom/service/PairRoomStompManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ public class PairRoomStompManager {
1515

1616
private final SimpMessagingTemplate simpMessagingTemplate;
1717

18-
public void send(final String accessCode, final PairRoomStatus pairRoomStatus) {
18+
public void sendStatus(final String accessCode, final PairRoomStatus pairRoomStatus) {
1919
simpMessagingTemplate.convertAndSend(
2020
String.format(STATUS_DESTINATION, accessCode),
21-
new PairRoomStatusResponse(pairRoomStatus.getName())
21+
new PairRoomStatusResponse(pairRoomStatus.getMessage())
2222
);
2323
}
2424
}

backend/src/main/java/site/coduo/referencelink/service/CategoryService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public CategoryUpdateResponse updateCategoryName(final String accessCode,
6464
validateDuplicated(request.value(), pairRoomEntity);
6565
final CategoryEntity categoryEntity = categoryRepository.fetchByPairRoomAndCategoryId(pairRoomEntity,
6666
categoryId);
67-
final Category category = new Category(categoryEntity.getCategoryName());
67+
final Category category = new Category(request.value());
6868
categoryEntity.updateCategoryName(category);
6969
return new CategoryUpdateResponse(categoryEntity.getCategoryName());
7070
}

backend/src/main/java/site/coduo/timer/controller/TimerController.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ public class TimerController implements TimerDocs {
2424
private final SchedulerService schedulerService;
2525

2626
@PatchMapping("/{accessCode}/timer/start")
27-
public ResponseEntity<Void> createTimerStart(@PathVariable("accessCode") final String accessCode) {
27+
public ResponseEntity<Void> startTimer(@PathVariable("accessCode") final String accessCode) {
2828
schedulerService.start(accessCode);
2929
return ResponseEntity.noContent()
3030
.build();
3131
}
3232

33-
@PatchMapping("/{accessCode}/timer/stop")
34-
public ResponseEntity<Void> createTimerStop(@PathVariable("accessCode") final String accessCode) {
33+
@PatchMapping("/{accessCode}/timer/pause")
34+
public ResponseEntity<Void> pauseTimer(@PathVariable("accessCode") final String accessCode) {
3535
schedulerService.pause(accessCode);
3636
return ResponseEntity.noContent()
3737
.build();

backend/src/main/java/site/coduo/timer/controller/docs/TimerDocs.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ public interface TimerDocs {
1818
@Operation(summary = "타이머를 시작한다.")
1919
@ApiResponse(responseCode = "204", description = "타이머 시작 성공")
2020
@ApiResponse(responseCode = "4xx", description = "페어룸 시작 실패", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = ApiErrorResponse.class)))
21-
ResponseEntity<Void> createTimerStart(String accessCode);
21+
ResponseEntity<Void> startTimer(String accessCode);
2222

2323
@Operation(summary = "타이머를 중지한다.")
2424
@ApiResponse(responseCode = "204", description = "타이머 즁자 성공")
2525
@ApiResponse(responseCode = "4xx", description = "페어룸 중지 실패", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = ApiErrorResponse.class)))
26-
ResponseEntity<Void> createTimerStop(String accessCode);
26+
ResponseEntity<Void> pauseTimer(String accessCode);
2727

2828
@Operation(summary = "타이머를 업데이트한다.")
2929
@ApiResponse(responseCode = "204", description = "타이머 업데이트 성공", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE))

backend/src/main/java/site/coduo/timer/domain/TimerStatus.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
@RequiredArgsConstructor
88
public enum TimerStatus {
99

10-
START("start"),
11-
PAUSE("pause"),
12-
STOP("stop"),
13-
RUNNING("running"),
14-
UPDATE("update");
10+
START("START"),
11+
PAUSE("PAUSE"),
12+
STOP("STOP"),
13+
RUNNING("RUNNING"),
14+
UPDATE("UPDATE");
1515

16-
private final String name;
16+
private final String message;
1717
}

backend/src/main/java/site/coduo/timer/service/SchedulerService.java

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
import site.coduo.timer.domain.TimerStatus;
1717
import site.coduo.timer.repository.TimerEntity;
1818
import site.coduo.timer.repository.TimerRepository;
19-
import site.coduo.timer.service.dto.TimerStartResponse;
20-
import site.coduo.timer.service.dto.TimerStatusResponse;
2119

2220
@Transactional
2321
@Slf4j
@@ -37,7 +35,7 @@ public void start(final String key) {
3735
if (schedulerRegistry.isActive(key)) {
3836
return;
3937
}
40-
timerStompManager.send(key, new TimerStatusResponse(TimerStatus.START.getName(), null));
38+
timerStompManager.sendStatus(key, TimerStatus.START);
4139
if (isInitial(key)) {
4240
final Timer timer = timerRepository.fetchTimerByAccessCode(key)
4341
.toDomain();
@@ -61,38 +59,33 @@ private void scheduling(final String key, final Timer timer) {
6159

6260
private void runTimer(final String key, final Timer timer) {
6361
if (timer.isTimeUp() && schedulerRegistry.has(key)) {
64-
stop(key, timer);
62+
reset(key, timer);
6563
return;
6664
}
67-
if (timerStompManager.isTimerIdle(key) && schedulerRegistry.has(key)) {
68-
pauseTimer(key);
65+
if (timerStompManager.isTimerIdle(key) && schedulerRegistry.isActive(key)) {
66+
schedulerRegistry.release(key);
6967
return;
7068
}
7169
timer.decreaseRemainingTime(DELAY_SECOND.toMillis());
72-
timerStompManager.send(key, new TimerStartResponse(timer.getRemainingTime()));
70+
timerStompManager.sendTime(key, timer.getRemainingTime());
7371
}
7472

75-
private void pauseTimer(final String key) {
73+
public void pause(final String key) {
7674
if (schedulerRegistry.isActive(key)) {
7775
schedulerRegistry.release(key);
7876
}
77+
timerStompManager.sendStatus(key, TimerStatus.PAUSE);
7978
}
8079

81-
public void pause(final String key) {
82-
pauseTimer(key);
83-
timerStompManager.send(key, new TimerStatusResponse(TimerStatus.PAUSE.getName(), null));
84-
}
85-
86-
private void stop(final String key, final Timer timer) {
87-
// timerStompManager.send(key, new TimerStatusResponse(TimerStatus.STOP.getName(), null));
80+
private void reset(final String key, final Timer timer) {
8881
schedulerRegistry.release(key);
8982
final Timer initalTimer = new Timer(timer.getAccessCode(), timer.getDuration(), timer.getDuration());
9083
timestampRegistry.register(key, initalTimer);
9184
}
9285

9386
public void notifyTimerStatus(final String key) {
9487
if (schedulerRegistry.isActive(key)) {
95-
timerStompManager.send(key, new TimerStatusResponse(TimerStatus.RUNNING.getName(), null));
88+
timerStompManager.sendStatus(key, TimerStatus.RUNNING);
9689
}
9790
}
9891

backend/src/main/java/site/coduo/timer/service/TimerService.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import site.coduo.timer.domain.TimerStatus;
1212
import site.coduo.timer.repository.TimerEntity;
1313
import site.coduo.timer.repository.TimerRepository;
14-
import site.coduo.timer.service.dto.TimerStatusResponse;
1514
import site.coduo.timer.service.dto.TimerUpdateRequest;
1615

1716
@Transactional(readOnly = true)
@@ -45,7 +44,6 @@ public void updateTimer(final String accessCode, final TimerUpdateRequest update
4544
);
4645
timerEntity.updateTimer(newTimer);
4746
timestampRegistry.register(accessCode, newTimer);
48-
timerStompManager.send(accessCode,
49-
new TimerStatusResponse(TimerStatus.UPDATE.getName(), newTimer.getDuration()));
47+
timerStompManager.sendStatusAndTime(accessCode, TimerStatus.UPDATE, newTimer.getDuration());
5048
}
5149
}

backend/src/main/java/site/coduo/timer/service/TimerStompManager.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.springframework.stereotype.Component;
55

66
import lombok.RequiredArgsConstructor;
7+
import site.coduo.timer.domain.TimerStatus;
78
import site.coduo.timer.service.dto.TimerStartResponse;
89
import site.coduo.timer.service.dto.TimerStatusResponse;
910
import site.coduo.websocket.stomp.StompSubscriptionService;
@@ -18,12 +19,22 @@ public class TimerStompManager {
1819
private final StompSubscriptionService stompSubscriptionService;
1920
private final SimpMessagingTemplate simpMessagingTemplate;
2021

21-
public void send(final String accessCode, final TimerStatusResponse payload) {
22-
simpMessagingTemplate.convertAndSend(String.format(STATUS_DESTINATION, accessCode), payload);
22+
public void sendStatus(final String accessCode, final TimerStatus status) {
23+
simpMessagingTemplate.convertAndSend(
24+
String.format(STATUS_DESTINATION, accessCode),
25+
new TimerStatusResponse(status.getMessage(), null)
26+
);
2327
}
2428

25-
public void send(final String accessCode, final TimerStartResponse payload) {
26-
simpMessagingTemplate.convertAndSend(String.format(TIME_DESTINATION, accessCode), payload);
29+
public void sendTime(final String accessCode, final long time) {
30+
simpMessagingTemplate.convertAndSend(String.format(TIME_DESTINATION, accessCode), new TimerStartResponse(time));
31+
}
32+
33+
public void sendStatusAndTime(final String accessCode, final TimerStatus status, final long time) {
34+
simpMessagingTemplate.convertAndSend(
35+
String.format(STATUS_DESTINATION, accessCode),
36+
new TimerStatusResponse(status.getMessage(), time)
37+
);
2738
}
2839

2940
public boolean isTimerIdle(final String accessCode) {

0 commit comments

Comments
 (0)