Skip to content
This repository was archived by the owner on Jul 7, 2025. It is now read-only.

Commit 1c41cfc

Browse files
committed
ASAP-390 실물 편지 임시저장 삭제, 저장한 수 조회 api 추가
1 parent 4ce6ceb commit 1c41cfc

15 files changed

Lines changed: 277 additions & 10 deletions

File tree

Application-Module/src/main/kotlin/com/asap/application/letter/port/in/GetPhysicalDraftLetterUsecase.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ interface GetPhysicalDraftLetterUsecase {
88

99
fun getByKey(query: Query.ByKey): Response.ByKey
1010

11+
fun count(query: Query.All): Response.Count
12+
1113
sealed class Query {
1214
data class All(
1315
val userId: String,
@@ -31,5 +33,9 @@ interface GetPhysicalDraftLetterUsecase {
3133
val images: List<String>,
3234
val lastUpdated: LocalDateTime,
3335
) : Response()
36+
37+
data class Count(
38+
val count: Int,
39+
) : Response()
3440
}
3541
}

Application-Module/src/main/kotlin/com/asap/application/letter/port/in/RemoveDraftLetterUsecase.kt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
package com.asap.application.letter.port.`in`
22

33
interface RemoveDraftLetterUsecase {
4-
fun deleteBy(command: Command.Draft)
4+
fun deleteBy(command: Command.Send)
55

66
fun deleteBy(command: Command.User)
77

8-
// data class Command(
9-
// val draftId: String,
10-
// val userId: String,
11-
// )
8+
fun deleteBy(command: Command.Physical)
129

1310
sealed class Command {
1411
data class User(
1512
val userId: String,
1613
) : Command()
1714

18-
data class Draft(
15+
data class Send(
16+
val draftId: String,
17+
val userId: String,
18+
) : Command()
19+
20+
data class Physical(
1921
val draftId: String,
2022
val userId: String,
2123
) : Command()

Application-Module/src/main/kotlin/com/asap/application/letter/port/out/ReceiveDraftLetterManagementPort.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,8 @@ interface ReceiveDraftLetterManagementPort {
99
fun getDraftLetterNotNull(draftId: DomainId, ownerId: DomainId): ReceiveDraftLetter
1010

1111
fun getAllDrafts(ownerId: DomainId): List<ReceiveDraftLetter>
12+
13+
fun countDrafts(ownerId: DomainId): Int
14+
15+
fun remove(receiveDraftLetter: ReceiveDraftLetter)
1216
}

Application-Module/src/main/kotlin/com/asap/application/letter/service/DraftLetterCommandService.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class DraftLetterCommandService(
4646
draftLetterManagementPort.save(draftLetter)
4747
}
4848

49-
override fun deleteBy(command: RemoveDraftLetterUsecase.Command.Draft) {
49+
override fun deleteBy(command: RemoveDraftLetterUsecase.Command.Send) {
5050
draftLetterManagementPort
5151
.getDraftLetterNotNull(
5252
draftId = DomainId(command.draftId),
@@ -64,6 +64,16 @@ class DraftLetterCommandService(
6464
}
6565
}
6666

67+
override fun deleteBy(command: RemoveDraftLetterUsecase.Command.Physical) {
68+
receiveDraftLetterManagementPort
69+
.getDraftLetterNotNull(
70+
draftId = DomainId(command.draftId),
71+
ownerId = DomainId(command.userId),
72+
).let {
73+
receiveDraftLetterManagementPort.remove(it)
74+
}
75+
}
76+
6777
override fun command(command: UpdateDraftLetterUsecase.Command.Physical) {
6878
val receiveDraftLetter =
6979
receiveDraftLetterManagementPort.getDraftLetterNotNull(

Application-Module/src/main/kotlin/com/asap/application/letter/service/DraftLetterQueryService.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,9 @@ class DraftLetterQueryService(
7878
lastUpdated = draft.lastUpdated
7979
)
8080
}
81+
82+
override fun count(query: GetPhysicalDraftLetterUsecase.Query.All): GetPhysicalDraftLetterUsecase.Response.Count {
83+
val count = receiveDraftLetterManagementPort.countDrafts(DomainId(query.userId))
84+
return GetPhysicalDraftLetterUsecase.Response.Count(count)
85+
}
8186
}

Application-Module/src/test/kotlin/com/asap/application/letter/service/DraftLetterCommandServiceTest.kt

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class DraftLetterCommandServiceTest :
6262
}
6363

6464
given("임시 저장 편지를 삭제할 때") {
65-
val command = RemoveDraftLetterUsecase.Command.Draft(draftId = "draftId", userId = "userId")
65+
val command = RemoveDraftLetterUsecase.Command.Send(draftId = "draftId", userId = "userId")
6666
val draftLetter = DraftLetter.default(DomainId(command.userId))
6767
every {
6868
mockGenerateDraftKeyUsecase.getDraftLetterNotNull(
@@ -135,4 +135,38 @@ class DraftLetterCommandServiceTest :
135135
}
136136
}
137137
}
138+
139+
given("받은 임시 저장편지를 삭제할 때"){
140+
141+
`when`("사용자 아이디와 임시 저장 편지 아이디를 입력하면"){
142+
val command = RemoveDraftLetterUsecase.Command.Physical(draftId = "draftId", userId = "userId")
143+
val receiveDraftLetter = ReceiveDraftLetter.default(DomainId(command.userId))
144+
every {
145+
mockReceiveDraftLetterManagementPort.getDraftLetterNotNull(
146+
draftId = receiveDraftLetter.id,
147+
ownerId = receiveDraftLetter.ownerId,
148+
)
149+
} returns receiveDraftLetter
150+
draftLetterCommandService.deleteBy(command)
151+
then("받은 임시 저장편지를 삭제한다"){
152+
verify { mockReceiveDraftLetterManagementPort.remove(any()) }
153+
}
154+
}
155+
156+
`when`("임시 저장 편지가 없으면"){
157+
158+
val command = RemoveDraftLetterUsecase.Command.Physical(draftId = "draftId", userId = "userId")
159+
every {
160+
mockReceiveDraftLetterManagementPort.getDraftLetterNotNull(
161+
draftId = DomainId(command.draftId),
162+
ownerId = DomainId(command.userId),
163+
)
164+
} throws LetterException.DraftLetterNotFoundException()
165+
then("임시 저장 편지가 삭제되지 않는다"){
166+
verify(exactly = 0) {
167+
mockReceiveDraftLetterManagementPort.remove(any())
168+
}
169+
}
170+
}
171+
}
138172
})

Application-Module/src/test/kotlin/com/asap/application/letter/service/DraftLetterQueryServiceTest.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,17 @@ class DraftLetterQueryServiceTest :
144144
}
145145
}
146146
}
147+
148+
given("임시 저장한 실물 편지 개수를 조회할 때") {
149+
val userId = "userId"
150+
val query = GetPhysicalDraftLetterUsecase.Query.All(userId)
151+
val draftCount = 1
152+
every { mockReceiveLetterManagementPort.countDrafts(DomainId(userId)) } returns draftCount
153+
`when`("사용자 아이디를 입력하면") {
154+
val response = draftLetterQueryService.count(query)
155+
then("임시 저장한 실물 편지 개수를 반환한다") {
156+
response.count shouldBe draftCount
157+
}
158+
}
159+
}
147160
})

Bootstrap-Module/src/main/kotlin/com/asap/bootstrap/web/letter/api/DraftLetterApi.kt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,25 @@ interface DraftLetterApi {
174174
@AccessUser userId: String,
175175
): GetDraftLetterCountResponse
176176

177+
@Operation(summary = "실물 편지 임시 저장 개수 조회")
178+
@GetMapping("/physical/count")
179+
@ApiResponses(
180+
value = [
181+
ApiResponse(
182+
responseCode = "200",
183+
description = "임시 저장 개수 조회 성공",
184+
content = [
185+
Content(
186+
schema = Schema(implementation = GetPhysicalDraftLetterCountResponse::class),
187+
),
188+
],
189+
),
190+
],
191+
)
192+
fun getPhysicalDraftCount(
193+
@AccessUser userId: String,
194+
): GetPhysicalDraftLetterCountResponse
195+
177196
@Operation(summary = "임시 저장 삭제")
178197
@DeleteMapping("/{draftId}")
179198
@ApiResponses(
@@ -185,4 +204,16 @@ interface DraftLetterApi {
185204
@PathVariable draftId: String,
186205
@AccessUser userId: String,
187206
)
207+
208+
@Operation(summary = "실물 편지 임시 저장 삭제")
209+
@DeleteMapping("/physical/{draftId}")
210+
@ApiResponses(
211+
value = [
212+
ApiResponse(responseCode = "200", description = "임시 저장 삭제 성공"),
213+
],
214+
)
215+
fun deletePhysicalDraft(
216+
@PathVariable draftId: String,
217+
@AccessUser userId: String,
218+
)
188219
}

Bootstrap-Module/src/main/kotlin/com/asap/bootstrap/web/letter/controller/DraftLetterController.kt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,26 @@ class DraftLetterController(
123123
return GetDraftLetterCountResponse(response.count)
124124
}
125125

126+
override fun getPhysicalDraftCount(userId: String): GetPhysicalDraftLetterCountResponse {
127+
val response = getPhysicalDraftLetterUsecase.count(GetPhysicalDraftLetterUsecase.Query.All(userId))
128+
return GetPhysicalDraftLetterCountResponse(response.count)
129+
}
130+
126131
override fun deleteDraft(
127132
draftId: String,
128133
userId: String,
129134
) {
130135
removeDraftLetterUsecase.deleteBy(
131-
RemoveDraftLetterUsecase.Command.Draft(
136+
RemoveDraftLetterUsecase.Command.Send(
137+
draftId = draftId,
138+
userId = userId,
139+
),
140+
)
141+
}
142+
143+
override fun deletePhysicalDraft(draftId: String, userId: String) {
144+
removeDraftLetterUsecase.deleteBy(
145+
RemoveDraftLetterUsecase.Command.Physical(
132146
draftId = draftId,
133147
userId = userId,
134148
),
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.asap.bootstrap.web.letter.dto
2+
3+
data class GetPhysicalDraftLetterCountResponse(
4+
val count: Int
5+
) {
6+
}

0 commit comments

Comments
 (0)