@startuml

actor "Frontend" as front

box "Backend" #Lightgreen
control "DepartmentController" as controller
participant "DepartmentService" as service
database "Database" as db
end box

'autonumber

front -> controller++: GET /api/department/{id}
controller -> controller: Check user role
alt "User has any role"
    alt "Request is valid"
        controller -> service++: getById(id)
        service -> db++: findById(id)
        alt "Department is found"
            db --> service: Department
            service --> controller: Department
            controller --> front: 200: Department found
        else
            db --> service--: error: Department not found
            service --> controller--: exception
            controller --> front: 404: Department isn't found
        end
    else "Request is not valid"
        controller --> front: 400: Invalid path variable
    end
else "User doesn't have any role"
    controller -> front--: 401: User is not authenticated
end

@enduml
