-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathBlockController.java
More file actions
125 lines (98 loc) · 3.79 KB
/
BlockController.java
File metadata and controls
125 lines (98 loc) · 3.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package com.umc.timeto.block.controller;
import com.umc.timeto.block.dto.BlockAddDTO;
import com.umc.timeto.block.dto.BlockResponseDTO;
import com.umc.timeto.block.dto.BlockResponseDetailDTO;
import com.umc.timeto.block.dto.BlockResponseNumDTO;
import com.umc.timeto.block.service.BlockService;
import com.umc.timeto.global.apiPayload.code.ResponseCode;
import com.umc.timeto.global.apiPayload.dto.ResponseDTO;
import lombok.RequiredArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.*;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.YearMonth;
import java.util.List;
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/block")
public class BlockController implements BlockControllerDocs {
private final BlockService blockService;
private Long getMemberId(Authentication authentication) {
return (Long) authentication.getPrincipal();
}
@PatchMapping("/{todoId}")
@Override
public ResponseEntity<ResponseDTO<BlockResponseDTO>> createBlock(
@PathVariable Long todoId,
@RequestBody BlockAddDTO req,
Authentication authentication
) {
var res= blockService.createBlock(todoId, req, getMemberId(authentication));
return ResponseEntity
.status(ResponseCode.SUCCESS_ADD_BLOCK.getStatus().value())
.body(new ResponseDTO<>(ResponseCode.SUCCESS_ADD_BLOCK, res));
}
@GetMapping("/day")
@Override
public ResponseEntity<ResponseDTO<List<BlockResponseDetailDTO>>> getBlockByDay(
// 기본 format: yyyy-MM-DD
@RequestParam LocalDate date,
Authentication authentication
) {
var res= blockService.getBlockByDay(date, getMemberId(authentication));
return ResponseEntity
.status(ResponseCode.SUCCESS_GET_BLOCKLIST.getStatus().value())
.body(new ResponseDTO<>(ResponseCode.SUCCESS_GET_BLOCKLIST, res));
}
@GetMapping("/month")
@Override
public ResponseEntity<ResponseDTO<List<BlockResponseNumDTO>>> getBlockNumByMonth(
@RequestParam
@DateTimeFormat(pattern = "yyyy-MM")
YearMonth yearMonth,
Authentication authentication
) {
var res = blockService.getBlockNumByMonth(yearMonth, getMemberId(authentication));
return ResponseEntity
.status(ResponseCode.SUCCESS_GET_BLOCK_NUMBER.getStatus().value())
.body(new ResponseDTO<>(ResponseCode.SUCCESS_GET_BLOCK_NUMBER, res));
}
@PatchMapping("/{blockId}/duration")
@Override
public ResponseEntity<ResponseDTO<Void>> updateDuration(
@PathVariable Long blockId,
@RequestParam LocalTime duration,
Authentication authentication
) {
blockService.updateBlockDuration(
blockId,
getMemberId(authentication),
duration
);
return ResponseEntity.ok(
new ResponseDTO<>(ResponseCode.SUCCESS_UPDATE_BLOCK, null)
);
}
@PatchMapping("/{blockId}/move")
@Override
public ResponseEntity<ResponseDTO<Void>> moveBlock(
@PathVariable Long blockId,
@RequestParam
@DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm")
LocalDateTime startAt,
Authentication authentication
) {
blockService.moveBlock(
blockId,
getMemberId(authentication),
startAt
);
return ResponseEntity.ok(
new ResponseDTO<>(ResponseCode.SUCCESS_UPDATE_BLOCK, null)
);
}
}