дописала get в контроллерах

This commit is contained in:
Elena Ponomareva
2026-04-19 16:06:44 +03:00
parent d69419b90d
commit 88837d2e18
5 changed files with 44 additions and 8 deletions
@@ -9,6 +9,7 @@ import com.project.movienight.application.ports.input.DeleteFilmUseCase
import com.project.movienight.application.ports.input.EditFilmCommand
import com.project.movienight.application.ports.input.EditFilmUseCase
import com.project.movienight.application.services.FilmService
import com.project.movienight.domain.exception.EntityNotFoundException
import org.springframework.http.HttpStatus
import org.springframework.web.bind.annotation.*
import java.util.UUID
@@ -57,6 +58,14 @@ class FilmController(
@PathVariable id: UUID,
) = deleteFilmUseCase.delete(id)
@GetMapping("/{id}")
fun getById(
@PathVariable id: UUID,
): FilmResponse =
FilmResponse.fromDomain(
filmService.findById(id) ?: throw EntityNotFoundException("Film", id.toString())
)
@GetMapping("/search")
fun searchByTitle(
@RequestParam title: String,
@@ -50,6 +50,19 @@ class FilmLibraryController(
),
)
@GetMapping("/films")
fun getAllFilmsInLibrary(
@PathVariable userId: UUID,
): List<FilmResponse> {
val library = getFilmLibraryUseCase.getLibrary(
GetFilmLibraryQuery(userId = userId)
)
val film = filmService.findById(library.filmId)
return film?.let { listOf(FilmResponse.fromDomain(it)) } ?: emptyList()
}
@PostMapping("/films/{filmId}")
@ResponseStatus(HttpStatus.CREATED)
fun addFilm(
@@ -8,15 +8,10 @@ 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.application.services.UserService
import com.project.movienight.domain.exception.EntityNotFoundException
import org.springframework.http.HttpStatus
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 org.springframework.web.bind.annotation.*
import java.util.UUID
@RestController
@@ -25,6 +20,7 @@ class UserController(
private val createUserUseCase: CreateUserUseCase,
private val editUserUseCase: EditUserUseCase,
private val deleteUserUseCase: DeleteUserUseCase,
private val userService: UserService,
) {
@PostMapping
@ResponseStatus(HttpStatus.CREATED)
@@ -40,6 +36,18 @@ class UserController(
),
)
@GetMapping
fun getAll(): List<UserResponse> =
userService.findAll().map { UserResponse.fromDomain(it) }
@GetMapping("/{id}")
fun getById(
@PathVariable id: UUID,
): UserResponse =
UserResponse.fromDomain(
userService.findById(id) ?: throw EntityNotFoundException("User", id.toString())
)
@PatchMapping("/{id}")
fun edit(
@PathVariable id: UUID,
@@ -66,4 +66,6 @@ class FilmService(
fun findByTitle(title: String): Film? = filmRepository.findByTitle(title)
fun findAll(): List<Film> = filmRepository.findAll()
fun findById(id: UUID): Film? = filmRepository.findById(id)
}
@@ -57,4 +57,8 @@ class UserService(
userRepository.deleteById(id)
}
fun findAll(): List<User> = userRepository.findAll()
fun findById(id: UUID): User? = userRepository.findById(id)
}