дописала get в контроллерах
This commit is contained in:
@@ -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.EditFilmCommand
|
||||||
import com.project.movienight.application.ports.input.EditFilmUseCase
|
import com.project.movienight.application.ports.input.EditFilmUseCase
|
||||||
import com.project.movienight.application.services.FilmService
|
import com.project.movienight.application.services.FilmService
|
||||||
|
import com.project.movienight.domain.exception.EntityNotFoundException
|
||||||
import org.springframework.http.HttpStatus
|
import org.springframework.http.HttpStatus
|
||||||
import org.springframework.web.bind.annotation.*
|
import org.springframework.web.bind.annotation.*
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
@@ -57,6 +58,14 @@ class FilmController(
|
|||||||
@PathVariable id: UUID,
|
@PathVariable id: UUID,
|
||||||
) = deleteFilmUseCase.delete(id)
|
) = deleteFilmUseCase.delete(id)
|
||||||
|
|
||||||
|
@GetMapping("/{id}")
|
||||||
|
fun getById(
|
||||||
|
@PathVariable id: UUID,
|
||||||
|
): FilmResponse =
|
||||||
|
FilmResponse.fromDomain(
|
||||||
|
filmService.findById(id) ?: throw EntityNotFoundException("Film", id.toString())
|
||||||
|
)
|
||||||
|
|
||||||
@GetMapping("/search")
|
@GetMapping("/search")
|
||||||
fun searchByTitle(
|
fun searchByTitle(
|
||||||
@RequestParam title: String,
|
@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}")
|
@PostMapping("/films/{filmId}")
|
||||||
@ResponseStatus(HttpStatus.CREATED)
|
@ResponseStatus(HttpStatus.CREATED)
|
||||||
fun addFilm(
|
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.DeleteUserUseCase
|
||||||
import com.project.movienight.application.ports.input.EditUserCommand
|
import com.project.movienight.application.ports.input.EditUserCommand
|
||||||
import com.project.movienight.application.ports.input.EditUserUseCase
|
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.http.HttpStatus
|
||||||
import org.springframework.web.bind.annotation.DeleteMapping
|
import org.springframework.web.bind.annotation.*
|
||||||
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
|
import java.util.UUID
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@@ -25,6 +20,7 @@ class UserController(
|
|||||||
private val createUserUseCase: CreateUserUseCase,
|
private val createUserUseCase: CreateUserUseCase,
|
||||||
private val editUserUseCase: EditUserUseCase,
|
private val editUserUseCase: EditUserUseCase,
|
||||||
private val deleteUserUseCase: DeleteUserUseCase,
|
private val deleteUserUseCase: DeleteUserUseCase,
|
||||||
|
private val userService: UserService,
|
||||||
) {
|
) {
|
||||||
@PostMapping
|
@PostMapping
|
||||||
@ResponseStatus(HttpStatus.CREATED)
|
@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}")
|
@PatchMapping("/{id}")
|
||||||
fun edit(
|
fun edit(
|
||||||
@PathVariable id: UUID,
|
@PathVariable id: UUID,
|
||||||
|
|||||||
@@ -66,4 +66,6 @@ class FilmService(
|
|||||||
fun findByTitle(title: String): Film? = filmRepository.findByTitle(title)
|
fun findByTitle(title: String): Film? = filmRepository.findByTitle(title)
|
||||||
|
|
||||||
fun findAll(): List<Film> = filmRepository.findAll()
|
fun findAll(): List<Film> = filmRepository.findAll()
|
||||||
|
|
||||||
|
fun findById(id: UUID): Film? = filmRepository.findById(id)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,4 +57,8 @@ class UserService(
|
|||||||
|
|
||||||
userRepository.deleteById(id)
|
userRepository.deleteById(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun findAll(): List<User> = userRepository.findAll()
|
||||||
|
|
||||||
|
fun findById(id: UUID): User? = userRepository.findById(id)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user