File tree Expand file tree Collapse file tree 4 files changed +6
-11
lines changed
src/main/kotlin/com/codersee/springcoroutines Expand file tree Collapse file tree 4 files changed +6
-11
lines changed Original file line number Diff line number Diff line change @@ -74,15 +74,11 @@ class CompanyController(
74
74
id = id,
75
75
requestedCompany = companyRequest.toModel()
76
76
)
77
- ? .let { company ->
77
+ .let { company ->
78
78
company.toResponse(
79
79
users = findCompanyUsers(company)
80
80
)
81
81
}
82
- ? : throw ResponseStatusException (
83
- HttpStatus .INTERNAL_SERVER_ERROR ,
84
- " Unexpected error during company update."
85
- )
86
82
87
83
private suspend fun findCompanyUsers (company : Company ) =
88
84
userService.findUsersByCompanyId(company.id!! )
Original file line number Diff line number Diff line change @@ -58,8 +58,7 @@ class UserController(
58
58
id = id,
59
59
requestedUser = userRequest.toModel()
60
60
)
61
- ?.let (User ::toResponse)
62
- ? : throw ResponseStatusException (HttpStatus .INTERNAL_SERVER_ERROR , " Unexpected error during user update." )
61
+ .toResponse()
63
62
}
64
63
65
64
private fun UserRequest.toModel (): User =
Original file line number Diff line number Diff line change @@ -4,10 +4,10 @@ import com.codersee.springcoroutines.model.Company
4
4
import com.codersee.springcoroutines.repository.CompanyRepository
5
5
import kotlinx.coroutines.flow.Flow
6
6
import org.springframework.http.HttpStatus
7
- import org.springframework.stereotype.Component
7
+ import org.springframework.stereotype.Service
8
8
import org.springframework.web.server.ResponseStatusException
9
9
10
- @Component
10
+ @Service
11
11
class CompanyService (
12
12
private val companyRepository : CompanyRepository
13
13
) {
@@ -33,7 +33,7 @@ class CompanyService(
33
33
suspend fun findAllCompaniesByNameLike (name : String ): Flow <Company > =
34
34
companyRepository.findByNameContaining(name)
35
35
36
- suspend fun updateCompany (id : Long , requestedCompany : Company ): Company ? {
36
+ suspend fun updateCompany (id : Long , requestedCompany : Company ): Company {
37
37
val foundCompany = companyRepository.findById(id)
38
38
39
39
return if (foundCompany == null )
Original file line number Diff line number Diff line change @@ -34,7 +34,7 @@ class UserService(
34
34
userRepository.deleteById(id)
35
35
}
36
36
37
- suspend fun updateUser (id : Long , requestedUser : User ): User ? {
37
+ suspend fun updateUser (id : Long , requestedUser : User ): User {
38
38
val foundUser = userRepository.findById(id)
39
39
40
40
return if (foundUser == null )
You can’t perform that action at this time.
0 commit comments