如何在 PlantUml 中使用 alt-else-end 和手动激活

问题描述 投票:0回答:1

下面是描述用户如何登录应用程序的序列图:

@startuml
autonumber
actor Individual as individual <<registered>>
boundary "Sign In Page" as signInPage <<ui>>
control "Auth Service" as auth
entity User as user
database Repository as repo

individual -> signInPage ++ : enter username or email
individual -> signInPage : enter password
individual -> signInPage : sign in
signInPage -> auth ++ : auth user
auth -> repo ++ : get user by username or email
return user
auth -> auth ++-- : granted = user exists and credentials are correct
return granted
alt granted is true
autonumber stop
autonumber 9 1
signInPage -> signInPage ++-- : redirect to home page
signInPage --> individual : home page
else granted is false
autonumber stop
autonumber 9 1
signInPage -> signInPage ++-- : redirect to error page
return error page
end
@enduml

上图已正确渲染...

enter image description here

但是

alt
的实现至少是丑陋的。如果授予访问权限,
Sign In Page
应重定向至主页;否则,如果访问被拒绝,
Sign In Page
将重定向到错误页面。正如你所看到的,为了处理手动
activation
,在
alt
部分我必须向
Individual
发回一条消息,而在
else
部分我必须使用
return
语句。有没有更好的方式来表示这一点?

plantuml
1个回答
0
投票

这是基于我对上述问题的评论的答案。

@startuml
'round the notes to look like activity boxes
skinparam roundcorner 10
autonumber
actor Individual as individual <<registered>>
boundary "Sign In Page" as signInPage <<ui>>
control "Auth Service" as auth
entity User as user
database Repository as repo

individual -> signInPage ++ : enter username or email
individual -> signInPage : enter password
individual -> signInPage : sign in
signInPage -> auth ++ : auth user
auth -> repo ++ : get user by username or email
return user
rnote over auth: granted = user exists\nand credentials\nare correct
return granted
rnote over signInPage: page = granted ?\nlogin page :\nerror page
return page
@enduml

PlantUML Sequence Diagram with notes as action boxes over lifelines

© www.soinside.com 2019 - 2024. All rights reserved.