Skip to content

Commit

Permalink
Add logger
Browse files Browse the repository at this point in the history
  • Loading branch information
blaz-cerpnjak committed Mar 6, 2024
1 parent 62212ae commit 24108f2
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@ import org.bson.types.ObjectId
import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.*
import java.util.logging.Logger


@RestController
@CrossOrigin
class UserController(private val dao: UserRepository) {

companion object {
private val log = Logger.getLogger(UserController::class.java.toString())
}

@GetMapping("/users")
fun getAllUsers(): Iterable<com.blazc.usermanagementapi.dto.User> {
return User.toDtoList(dao.findAll())
Expand All @@ -20,6 +26,7 @@ class UserController(private val dao: UserRepository) {
fun getUserById(@PathVariable id: String): ResponseEntity<com.blazc.usermanagementapi.dto.User> {
val user = dao.findById(ObjectId(id))
if (user.isEmpty) {
log.info { "/users/$id ; User not found!" }
return ResponseEntity(HttpStatus.NOT_FOUND)
}
return ResponseEntity.ok(user.get().toDto())
Expand All @@ -35,6 +42,7 @@ class UserController(private val dao: UserRepository) {
fun updateUser(@PathVariable id: String, @RequestBody user: com.blazc.usermanagementapi.dto.User): ResponseEntity<com.blazc.usermanagementapi.dto.User> {
val existingUser = dao.findById(ObjectId(id))
if (existingUser.isEmpty) {
log.info {"/users/$id ; User not found!" }
return ResponseEntity(HttpStatus.NOT_FOUND)
}

Expand All @@ -49,6 +57,7 @@ class UserController(private val dao: UserRepository) {
fun deleteUser(@PathVariable id: String): ResponseEntity<String> {
val existingUser = dao.findById(ObjectId(id))
if (existingUser.isEmpty) {
log.info {"/users/$id ; User not found!" }
return ResponseEntity(HttpStatus.NOT_FOUND)
}

Expand Down

0 comments on commit 24108f2

Please sign in to comment.