Skip to content

Commit 7eea9ba

Browse files
authored
#19, #21, #22 - 유저는 쪽지를 보내고, 보낸 쪽지를 수정, 확인할 수 있다 (#52)
* feat: message 타입 추가 * feat: MessageSendLimitValidator 추가 * feat: MessageTimeValidator 추가 * refactor: Message 도메인 수정 isSent -> isSend sentAt -> sendAt 으로 변경 * feat: MessageFinder 추가 * feat: MessageDto 추가 * feat: CursorUtils 추가 커서 id 가 0인 경우 맥스값 설정하는 유틸 함수 * feat: repository 설정 및 message 쿼리 작성 * feat: SendMessage 개발 * feat: ModifyMessage 개발 * feat: GetMessage 개발 * test: messageService 단위 테스트 추가 * refactor: controller api 추가 및 findById 오류 수정 * feat: message url 추가 * fix: 안쓰는 import 삭제 * fix: import log 삭제 * refactor: 도메인에 로직 추가 * test: 쪽지 생성 전 시간 조정 * refactor: message Service 삭제 * fix: rebase 오류 수정 * fix: test 시간 추가
1 parent 42035af commit 7eea9ba

40 files changed

+1489
-66
lines changed

app/src/main/kotlin/com/wespot/auth/AuthController.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import org.springframework.web.bind.annotation.RequestMapping
1414
import org.springframework.web.bind.annotation.RestController
1515

1616
@RestController
17-
@RequestMapping("/v1/auth")
17+
@RequestMapping("/api/v1/auth")
1818
class AuthController(
1919
private val authService: AuthService
2020
) {

app/src/main/kotlin/com/wespot/config/security/CustomUrlFilter.kt

+6-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ class CustomUrlFilter(
2323
private val validUrlPatterns = listOf(
2424
"/health",
2525
"/",
26-
"/h2-console",
2726
"/api/v1/auth/reissue",
2827
"/api/v1/auth/login",
2928
"/api/v1/auth/signup",
@@ -39,7 +38,12 @@ class CustomUrlFilter(
3938
"/api/v1/votes/received",
4039
"/api/v1/votes/sent/options",
4140
"/api/v1/votes/received/options",
42-
"/api/v1/reports/users"
41+
"/api/v1/reports/users",
42+
"/api/v1/messages",
43+
"/api/v1/messages/send",
44+
"/api/v1/messages/status/me",
45+
"/api/v1/messages/check-profanity",
46+
"/api/v1/messages/**",
4347
)
4448

4549
override fun doFilterInternal(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.wespot.message
2+
3+
import com.wespot.message.dto.response.MessageListResponse
4+
import com.wespot.message.dto.response.MessageResponse
5+
import com.wespot.message.dto.response.SendMessageStatusResponse
6+
import com.wespot.message.port.`in`.GetMessageUseCase
7+
import org.springframework.http.ResponseEntity
8+
import org.springframework.web.bind.annotation.*
9+
10+
@RestController
11+
@RequestMapping("/api/v1/messages")
12+
class GetMessageController(
13+
private val getMessageUseCase: GetMessageUseCase
14+
) {
15+
16+
@GetMapping("/status/me")
17+
fun getSendStatus(): ResponseEntity<SendMessageStatusResponse> {
18+
val status = getMessageUseCase.status()
19+
20+
return ResponseEntity.ok()
21+
.body(status)
22+
}
23+
24+
@GetMapping("")
25+
fun getMessages(
26+
@RequestParam(required = false, defaultValue = "0") cursorId: Long,
27+
@RequestParam type: MessageType
28+
): ResponseEntity<Any> {
29+
val response: MessageListResponse = when (type) {
30+
MessageType.SENT -> getMessageUseCase.getSendMessages(cursorId)
31+
MessageType.RECEIVED -> getMessageUseCase.getReceivedMessages(cursorId)
32+
}
33+
34+
return ResponseEntity.ok()
35+
.body(response)
36+
}
37+
38+
@GetMapping("/{messageId}")
39+
fun getMessage(
40+
@PathVariable messageId: Long
41+
): ResponseEntity<MessageResponse> {
42+
val response = getMessageUseCase.getMessage(messageId)
43+
44+
return ResponseEntity.ok()
45+
.body(response)
46+
}
47+
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.wespot.message
2+
3+
import com.wespot.message.dto.request.UpdateMessageRequest
4+
import com.wespot.message.dto.response.UpdateMessageResponse
5+
import com.wespot.message.port.`in`.ModifyMessageUseCase
6+
import org.springframework.http.ResponseEntity
7+
import org.springframework.web.bind.annotation.*
8+
9+
@RestController
10+
@RequestMapping("/api/v1/messages")
11+
class ModifyMessageController(
12+
private val modifyMessageUseCase: ModifyMessageUseCase
13+
) {
14+
15+
@PutMapping("/{messageId}")
16+
fun modifyMessage(
17+
@PathVariable messageId: Long,
18+
@RequestBody updateMessageRequest: UpdateMessageRequest
19+
): ResponseEntity<Unit> {
20+
modifyMessageUseCase.updateMessage(
21+
messageId = messageId,
22+
updateMessageRequest = updateMessageRequest
23+
)
24+
25+
return ResponseEntity.noContent()
26+
.build()
27+
}
28+
29+
@PutMapping("/{messageId}/read")
30+
fun readMessage(
31+
@PathVariable messageId: Long
32+
): ResponseEntity<Unit> {
33+
modifyMessageUseCase.readMessage(messageId)
34+
35+
return ResponseEntity.noContent()
36+
.build()
37+
}
38+
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.wespot.message
2+
3+
import com.wespot.message.dto.request.SendMessageRequest
4+
import com.wespot.message.dto.response.SendMessageResponse
5+
import com.wespot.message.port.`in`.SendMessageUseCase
6+
import org.springframework.http.ResponseEntity
7+
import org.springframework.web.bind.annotation.PostMapping
8+
import org.springframework.web.bind.annotation.RequestBody
9+
import org.springframework.web.bind.annotation.RequestMapping
10+
import org.springframework.web.bind.annotation.RestController
11+
12+
@RestController
13+
@RequestMapping("/api/v1/messages")
14+
class SendMessageController(
15+
private val sendMessageUseCase: SendMessageUseCase
16+
) {
17+
18+
@PostMapping("/send")
19+
fun sendMessage(
20+
@RequestBody sendMessageRequest: SendMessageRequest
21+
): ResponseEntity<SendMessageResponse> {
22+
val response = sendMessageUseCase.send(sendMessageRequest)
23+
24+
return ResponseEntity.ok()
25+
.body(response)
26+
}
27+
28+
}

app/src/main/kotlin/com/wespot/user/UserController.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import org.springframework.http.ResponseEntity
99
import org.springframework.web.bind.annotation.*
1010

1111
@RestController
12-
@RequestMapping("/v1/users")
12+
@RequestMapping("/api/v1/users")
1313
class UserController(
1414
private val userUseCase: UserUseCase
1515
) {
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.wespot.message.fixture
22

33
import com.wespot.message.Message
4+
import com.wespot.message.MessageType
45
import java.time.LocalDateTime
56

67

@@ -10,11 +11,13 @@ object MessageFixture {
1011
id = id,
1112
content = "content",
1213
senderId = 1,
14+
senderName = "senderName",
1315
receiverId = 2,
1416
isReceiverRead = true,
17+
messageType = MessageType.SENT,
1518
readAt = LocalDateTime.now(),
16-
isSent = true,
17-
sentAt = LocalDateTime.now(),
19+
isSend = true,
20+
sendAt = LocalDateTime.now(),
1821
createdAt = LocalDateTime.now(),
1922
updatedAt = LocalDateTime.now(),
2023
receivedAt = LocalDateTime.now()
@@ -24,14 +27,53 @@ object MessageFixture {
2427
id = id,
2528
content = "content",
2629
senderId = senderId,
30+
senderName = "senderName",
2731
receiverId = receiverId,
2832
isReceiverRead = true,
2933
readAt = LocalDateTime.now(),
30-
isSent = true,
31-
sentAt = LocalDateTime.now(),
34+
messageType = MessageType.SENT,
35+
isSend = true,
36+
sendAt = LocalDateTime.now(),
3237
createdAt = LocalDateTime.now(),
3338
updatedAt = LocalDateTime.now(),
3439
receivedAt = LocalDateTime.now()
3540
)
3641

42+
fun createMessageWithReceived(
43+
content: String,
44+
receiverId: Long,
45+
senderId: Long,
46+
senderName: String
47+
): Message {
48+
return Message(
49+
id = 0,
50+
content = content,
51+
senderId = senderId,
52+
senderName = senderName,
53+
receiverId = receiverId,
54+
isReceiverRead = false,
55+
messageType = MessageType.RECEIVED,
56+
readAt = null,
57+
isSend = false,
58+
sendAt = null,
59+
receivedAt = null,
60+
createdAt = LocalDateTime.now(),
61+
updatedAt = LocalDateTime.now(),
62+
)
63+
}
64+
65+
fun createMessage(
66+
content: String,
67+
receiverId: Long,
68+
senderId: Long,
69+
senderName: String
70+
): Message {
71+
return Message.sendMessage(
72+
content = content,
73+
receiverId = receiverId,
74+
senderId = senderId,
75+
senderName = senderName
76+
)
77+
}
78+
3779
}

0 commit comments

Comments
 (0)