File tree Expand file tree Collapse file tree 7 files changed +89
-6
lines changed
src/main/kotlin/andreas311/miso/domain
purchase/application/service Expand file tree Collapse file tree 7 files changed +89
-6
lines changed Original file line number Diff line number Diff line change @@ -31,17 +31,13 @@ class PurchaseItemService(
31
31
throw ItemSoldOutException ()
32
32
}
33
33
34
- item.removeAmount()
35
-
36
34
if (item.price > user.point) {
37
35
throw PointNotEnoughException ()
38
36
}
39
37
40
- user.removePoint(item.price)
41
-
42
- commandItemPort.saveItem(item)
38
+ commandItemPort.saveItem(item.removeAmount())
43
39
44
- commandUserPort.saveUser(user)
40
+ commandUserPort.saveUser(user.removePoint(item.price) )
45
41
46
42
commandPurchasePort.savePurchase(
47
43
Purchase (
Original file line number Diff line number Diff line change
1
+ package andreas311.miso.domain.user.adapter.input
2
+
3
+ import andreas311.miso.common.annotation.RequestController
4
+ import andreas311.miso.domain.user.adapter.input.data.response.UserInfoResponse
5
+ import andreas311.miso.domain.user.adapter.input.mapper.UserDataMapper
6
+ import andreas311.miso.domain.user.application.port.input.UserInfoUseCase
7
+ import org.springframework.http.HttpStatus
8
+ import org.springframework.http.ResponseEntity
9
+ import org.springframework.web.bind.annotation.GetMapping
10
+
11
+ @RequestController(" /user" )
12
+ class UserAdapter (
13
+ private val userDataMapper : UserDataMapper ,
14
+ private val userInfoUseCase : UserInfoUseCase
15
+ ) {
16
+ @GetMapping
17
+ fun userInfo (): ResponseEntity <UserInfoResponse > =
18
+ userInfoUseCase.execute()
19
+ .let { userDataMapper.toResponse(it) }
20
+ .let { ResponseEntity .status(HttpStatus .OK ).body(it) }
21
+ }
Original file line number Diff line number Diff line change
1
+ package andreas311.miso.domain.user.adapter.input.data.response
2
+
3
+ import andreas311.miso.domain.user.domain.Role
4
+ import java.util.*
5
+
6
+ data class UserInfoResponse (
7
+ val id : UUID ,
8
+ val email : String ,
9
+ val role : Role
10
+ )
Original file line number Diff line number Diff line change
1
+ package andreas311.miso.domain.user.adapter.input.mapper
2
+
3
+ import andreas311.miso.domain.user.adapter.input.data.response.UserInfoResponse
4
+ import andreas311.miso.domain.user.application.port.input.dto.UserInfoDto
5
+ import org.springframework.stereotype.Component
6
+
7
+ @Component
8
+ class UserDataMapper {
9
+ fun toResponse (userInfoDto : UserInfoDto ): UserInfoResponse =
10
+ UserInfoResponse (
11
+ id = userInfoDto.id,
12
+ email = userInfoDto.email,
13
+ role = userInfoDto.role
14
+ )
15
+ }
Original file line number Diff line number Diff line change
1
+ package andreas311.miso.domain.user.application.port.input
2
+
3
+ import andreas311.miso.domain.user.application.port.input.dto.UserInfoDto
4
+
5
+ interface UserInfoUseCase {
6
+ fun execute (): UserInfoDto
7
+ }
Original file line number Diff line number Diff line change
1
+ package andreas311.miso.domain.user.application.port.input.dto
2
+
3
+ import andreas311.miso.domain.user.domain.Role
4
+ import andreas311.miso.domain.user.domain.User
5
+ import java.util.*
6
+
7
+ data class UserInfoDto (
8
+ val id : UUID ,
9
+ val email : String ,
10
+ val role : Role
11
+ ) {
12
+ constructor (user: User ) : this (
13
+ id = user.id,
14
+ email = user.email,
15
+ role = user.role
16
+ )
17
+ }
Original file line number Diff line number Diff line change
1
+ package andreas311.miso.domain.user.application.service
2
+
3
+ import andreas311.miso.common.annotation.ReadOnlyRollbackService
4
+ import andreas311.miso.domain.auth.application.port.output.UserSecurityPort
5
+ import andreas311.miso.domain.user.application.port.input.UserInfoUseCase
6
+ import andreas311.miso.domain.user.application.port.input.dto.UserInfoDto
7
+
8
+ @ReadOnlyRollbackService
9
+ class UserInfoService (
10
+ private val userSecurityPort : UserSecurityPort
11
+ ) : UserInfoUseCase {
12
+ override fun execute (): UserInfoDto {
13
+ val user = userSecurityPort.currentUser()
14
+
15
+ return UserInfoDto (user)
16
+ }
17
+ }
You can’t perform that action at this time.
0 commit comments