@startuml

autonumber
autoactivate off

actor "Administrator" as administrator
participant " : CreateProfileRoute(UI)" as route
participant " createProfileController : CreateProfileController" as controller
participant " createProfileService : CreateProfileService" as service
participant " name : Name" as name
participant " profileRepository : ProfileRepository" as repo
participant " profileFactoryInterface : ProfileFactoryInterface" as Ifactory
participant " profile : Profile" as profile
'participant " profileID : ProfileID" as ID
participant " profileDTOAssembler : ProfileDTOAssembler" as DTOassembler
participant " profileDTO : ProfileDTO" as profileDTO


activate administrator
administrator -> route :I want to create a User Profile

activate route
administrator <-- route: request data(name)

administrator -> route : Post /profiles/ (json)
route -> controller: createProfile(json)
activate controller

controller --> controller : validate(json)
controller -> service : createProfile(profileDTO)
activate service
service --> name **: createName(profileDTO.name)

deactivate name

service -> repo :  existsByName(name)
activate repo
repo --> service : existsName
deactivate repo

service -> Ifactory : createProfile(name)
activate Ifactory


Ifactory --> profile **: create(name)
deactivate Ifactory


'ID --> profile : profileID

'profile --> service : profile
deactivate profile

service -> repo : save(Profile)
activate repo

ref over repo
SSD_JPA_Implementation
end ref

repo --> service : profileSaved
deactivate repo

service -> DTOassembler : toNative(profileSaved)
activate DTOassembler

DTOassembler -->  profileDTO **:create(profileSaved)

DTOassembler --> service : profileDTO
deactivate DTOassembler

service --> controller : optionalProfileDTO
deactivate service

controller --> controller : generateResponse(json)
route <-- controller : Response
deactivate controller

administrator <-- route: response
deactivate route


@enduml

