chore(web): refactored REST controllers

This commit is contained in:
ITQ
2026-04-18 13:16:17 +03:00
parent 4113c1a873
commit dd36ecdcbd
3 changed files with 101 additions and 77 deletions
@@ -1,13 +1,22 @@
package com.project.movienight.adapters.web
import com.project.movienight.adapters.web.dto.request.CreateUserRequest
import com.project.movienight.adapters.web.dto.request.EditUserRequest
import com.project.movienight.adapters.web.dto.response.UserResponse
import com.project.movienight.application.ports.input.CreateUserCommand
import com.project.movienight.application.ports.input.CreateUserUseCase
import com.project.movienight.application.ports.input.DeleteUserUseCase
import com.project.movienight.application.ports.input.EditUserCommand
import com.project.movienight.application.ports.input.EditUserUseCase
import com.project.movienight.domain.model.User
import org.springframework.http.HttpStatus
import org.springframework.web.bind.annotation.*
import org.springframework.web.bind.annotation.DeleteMapping
import org.springframework.web.bind.annotation.PatchMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.ResponseStatus
import org.springframework.web.bind.annotation.RestController
import java.util.UUID
@RestController
@@ -17,40 +26,38 @@ class UserController(
private val editUserUseCase: EditUserUseCase,
private val deleteUserUseCase: DeleteUserUseCase,
) {
@PostMapping
@ResponseStatus(HttpStatus.CREATED)
fun create(@RequestBody request: CreateUserRequest): User =
createUserUseCase.create(
CreateUserCommand(
name = request.name,
email = request.email,
)
fun create(
@RequestBody request: CreateUserRequest,
): UserResponse =
UserResponse.fromDomain(
createUserUseCase.create(
CreateUserCommand(
name = request.name,
email = request.email,
),
),
)
@PatchMapping("/{id}")
fun edit(
@PathVariable id: UUID,
@RequestBody request: EditUserRequest,
): User =
editUserUseCase.edit(
id = id,
command = EditUserCommand(
name = request.name,
)
): UserResponse =
UserResponse.fromDomain(
editUserUseCase.edit(
id = id,
command =
EditUserCommand(
name = request.name,
),
),
)
@DeleteMapping("/{id}")
@ResponseStatus(HttpStatus.NO_CONTENT)
fun delete(@PathVariable id: UUID) =
deleteUserUseCase.delete(id)
fun delete(
@PathVariable id: UUID,
) = deleteUserUseCase.delete(id)
}
data class CreateUserRequest(
val name: String,
val email: String,
)
data class EditUserRequest(
val name: String,
)