@@ -7,14 +7,16 @@ use owo_colors::OwoColorize;
77use reqwest:: header:: { AUTHORIZATION , HeaderMap } ;
88use reqwest:: { ClientBuilder , StatusCode } ;
99
10- use crate :: commands:: user:: { UserAction , UserCommand } ;
10+ use crate :: commands:: user:: { FollowArg , UserAction , UserCommand } ;
1111use crate :: context:: Context ;
1212use crate :: context:: config:: Cache ;
1313use crate :: tools:: http:: IntoNoParseResult ;
1414use crate :: { api, models} ;
1515
1616pub async fn endpoint ( cmd : UserCommand , ctx : & mut Context ) -> anyhow:: Result < ( ) > {
1717 match cmd. commands {
18+ UserAction :: Follower ( arg) => handle_followers ( ctx, arg) . await ,
19+ UserAction :: Following ( arg) => handle_following ( ctx, arg) . await ,
1820 UserAction :: Login { token } => handle_login ( token, ctx) . await ,
1921 UserAction :: Logout => handle_logout ( ctx) ,
2022 UserAction :: Status => user_info ( ctx) . await ,
@@ -68,3 +70,37 @@ async fn user_info(ctx: &mut Context) -> Result<()> {
6870fn handle_logout ( ctx : & Context ) -> Result < ( ) > {
6971 ctx. clean ( )
7072}
73+
74+ async fn handle_followers ( ctx : & mut Context , arg : FollowArg ) -> Result < ( ) > {
75+ let followers = api:: user:: user_followers ( & ctx. client , & arg) . await ?;
76+
77+ ctx. terminal . writeln (
78+ format ! (
79+ "{} 人关注了您, 当前{}页,每页数量{}" ,
80+ followers. total_count, arg. page_index, arg. page_size
81+ )
82+ . bright_green ( ) ,
83+ ) ?;
84+
85+ followers
86+ . items
87+ . iter ( )
88+ . for_each ( |f| ctx. terminal . writeln ( f. as_format ( ) ) . unwrap ( ) ) ;
89+ Ok ( ( ) )
90+ }
91+
92+ async fn handle_following ( ctx : & mut Context , arg : FollowArg ) -> Result < ( ) > {
93+ let following = api:: user:: user_following ( & ctx. client , & arg) . await ?;
94+ ctx. terminal . writeln (
95+ format ! (
96+ "您关注了 {} 人, 当前{}页,每页数量{}" ,
97+ following. total_count, arg. page_index, arg. page_size
98+ )
99+ . bright_green ( ) ,
100+ ) ?;
101+ following
102+ . items
103+ . iter ( )
104+ . for_each ( |f| ctx. terminal . writeln ( f. as_format ( ) ) . unwrap ( ) ) ;
105+ Ok ( ( ) )
106+ }
0 commit comments