11use callisto:: {
2- mega_code_review_comment , mega_code_review_thread,
3- sea_orm_active_enums:: { DiffSideEnum , ThreadStatusEnum } ,
2+ mega_code_review_thread,
3+ sea_orm_active_enums:: { DiffSideEnum , PositionStatusEnum , ThreadStatusEnum } ,
44} ;
55use jupiter:: model:: code_review_dto:: {
6- CodeReviewViews , CommentReviewView , FileReviewView , ThreadReviewView ,
6+ AnchorView , CodeReviewViews , CommentReviewView , FileReviewView , PositionView , ThreadReviewView ,
77} ;
88use serde:: { Deserialize , Serialize } ;
99use utoipa:: ToSchema ;
1010
11- #[ derive( Deserialize , Serialize , ToSchema ) ]
11+ #[ derive( Debug , Deserialize , Serialize , ToSchema ) ]
1212pub struct InitializeCommentRequest {
1313 pub file_path : String ,
14- pub line_number : i32 ,
14+ pub anchor_commit_sha : String ,
15+ pub original_line_number : i32 ,
16+ pub normalized_content : String ,
17+ pub context_before : String ,
18+ pub context_after : String ,
1519 pub diff_side : DiffSide ,
1620 pub content : String ,
1721}
1822
19- #[ derive( Deserialize , Serialize , ToSchema ) ]
23+ #[ derive( Debug , Deserialize , Serialize , ToSchema ) ]
2024pub struct CommentReplyRequest {
2125 pub parent_comment_id : i64 ,
2226 pub content : String ,
2327}
2428
25- #[ derive( Deserialize , Serialize , ToSchema ) ]
29+ #[ derive( Debug , Deserialize , Serialize , ToSchema ) ]
2630pub struct UpdateCommentRequest {
2731 pub content : String ,
2832}
2933
3034#[ derive( Debug , Clone , PartialEq , Eq , Serialize , Deserialize , ToSchema ) ]
3135pub enum DiffSide {
32- Old ,
33- New ,
36+ Deletions ,
37+ Additions ,
3438}
3539
3640#[ derive( Debug , Clone , PartialEq , Eq , Serialize , Deserialize , ToSchema ) ]
@@ -39,40 +43,68 @@ pub enum ThreadStatus {
3943 Resolved ,
4044}
4145
42- #[ derive( Deserialize , Serialize , ToSchema ) ]
46+ #[ derive( Debug , Clone , PartialEq , Eq , Serialize , Deserialize , ToSchema ) ]
47+ pub enum PositionStatus {
48+ Exact ,
49+ Shifted ,
50+ PendingReanchor ,
51+ Ambiguous ,
52+ NotFound ,
53+ }
54+
55+ #[ derive( Debug , Deserialize , Serialize , ToSchema ) ]
4356pub struct CodeReviewResponse {
4457 pub link : String ,
4558 pub files : Vec < FileReviewResponse > ,
4659}
4760
48- #[ derive( Deserialize , Serialize , ToSchema ) ]
61+ #[ derive( Debug , Deserialize , Serialize , ToSchema ) ]
4962pub struct FileReviewResponse {
5063 pub file_path : String ,
5164 pub threads : Vec < ThreadReviewResponse > ,
5265}
5366
54- #[ derive( Deserialize , Serialize , ToSchema ) ]
67+ #[ derive( Debug , Deserialize , Serialize , ToSchema ) ]
5568pub struct ThreadReviewResponse {
5669 pub thread_id : i64 ,
57- pub line_number : i32 ,
58- pub diff_side : DiffSide ,
5970 pub status : ThreadStatus ,
6071 pub created_at : String ,
6172 pub updated_at : String ,
73+ pub anchor : AnchorResponse ,
74+ pub position : PositionResponse ,
6275 pub comments : Vec < CommentReviewResponse > ,
6376}
6477
65- #[ derive( Deserialize , Serialize , ToSchema ) ]
78+ #[ derive( Debug , Deserialize , Serialize , ToSchema ) ]
6679pub struct ThreadStatusResponse {
6780 pub thread_id : i64 ,
6881 pub link : String ,
82+ pub status : ThreadStatus ,
83+ }
84+
85+ #[ derive( Debug , Deserialize , Serialize , ToSchema ) ]
86+ pub struct AnchorResponse {
87+ pub anchor_id : i64 ,
6988 pub file_path : String ,
70- pub line_number : i32 ,
7189 pub diff_side : DiffSide ,
72- pub status : ThreadStatus ,
90+ pub anchor_commit_sha : String ,
91+ pub original_line_number : i32 ,
92+ pub normalized_content : String ,
93+ pub context_before : String ,
94+ pub context_after : String ,
7395}
7496
75- #[ derive( Deserialize , Serialize , ToSchema ) ]
97+ #[ derive( Debug , Deserialize , Serialize , ToSchema ) ]
98+ pub struct PositionResponse {
99+ pub position_id : i64 ,
100+ pub anchor_id : i64 ,
101+ pub commit_sha : String ,
102+ pub line_number : i32 ,
103+ pub confidence : i32 ,
104+ pub position_status : PositionStatus ,
105+ }
106+
107+ #[ derive( Debug , Deserialize , Serialize , ToSchema ) ]
76108pub struct CommentReviewResponse {
77109 pub comment_id : i64 ,
78110 pub user_name : String ,
@@ -82,28 +114,20 @@ pub struct CommentReviewResponse {
82114 pub updated_at : String ,
83115}
84116
85- impl From < mega_code_review_comment :: Model > for CommentReviewResponse {
86- fn from ( value : mega_code_review_comment :: Model ) -> Self {
117+ impl From < CodeReviewViews > for CodeReviewResponse {
118+ fn from ( value : CodeReviewViews ) -> Self {
87119 Self {
88- comment_id : value. id ,
89- user_name : value. user_name ,
90- content : value. content ,
91- parent_id : value. parent_id ,
92- created_at : value. created_at . to_string ( ) ,
93- updated_at : value. updated_at . to_string ( ) ,
120+ link : value. link ,
121+ files : value. files . into_iter ( ) . map ( Into :: into) . collect ( ) ,
94122 }
95123 }
96124}
97125
98- impl From < CommentReviewView > for CommentReviewResponse {
99- fn from ( value : CommentReviewView ) -> Self {
126+ impl From < FileReviewView > for FileReviewResponse {
127+ fn from ( value : FileReviewView ) -> Self {
100128 Self {
101- comment_id : value. comment_id ,
102- user_name : value. user_name ,
103- content : value. content ,
104- parent_id : value. parent_id ,
105- created_at : value. created_at . to_string ( ) ,
106- updated_at : value. updated_at . to_string ( ) ,
129+ file_path : value. file_path ,
130+ threads : value. threads . into_iter ( ) . map ( Into :: into) . collect ( ) ,
107131 }
108132 }
109133}
@@ -112,60 +136,81 @@ impl From<ThreadReviewView> for ThreadReviewResponse {
112136 fn from ( value : ThreadReviewView ) -> Self {
113137 Self {
114138 thread_id : value. thread_id ,
115- line_number : value. line_number ,
116- diff_side : value. diff_side . into ( ) ,
117139 status : value. status . into ( ) ,
118140 created_at : value. created_at . to_string ( ) ,
119141 updated_at : value. updated_at . to_string ( ) ,
142+ anchor : value. anchor . into ( ) ,
143+ position : value. position . into ( ) ,
120144 comments : value. comments . into_iter ( ) . map ( Into :: into) . collect ( ) ,
121145 }
122146 }
123147}
124148
125- impl From < mega_code_review_thread :: Model > for ThreadStatusResponse {
126- fn from ( value : mega_code_review_thread :: Model ) -> Self {
149+ impl From < AnchorView > for AnchorResponse {
150+ fn from ( value : AnchorView ) -> Self {
127151 Self {
128- thread_id : value. id ,
129- link : value. link ,
152+ anchor_id : value. anchor_id ,
130153 file_path : value. file_path ,
131- line_number : value. line_number ,
132154 diff_side : value. diff_side . into ( ) ,
133- status : value. thread_status . into ( ) ,
155+ anchor_commit_sha : value. anchor_commit_sha ,
156+ original_line_number : value. original_line_number ,
157+ normalized_content : value. normalized_content ,
158+ context_before : value. context_before ,
159+ context_after : value. context_after ,
134160 }
135161 }
136162}
137163
138- impl From < FileReviewView > for FileReviewResponse {
139- fn from ( value : FileReviewView ) -> Self {
164+ impl From < PositionView > for PositionResponse {
165+ fn from ( value : PositionView ) -> Self {
140166 Self {
141- file_path : value. file_path ,
142- threads : value. threads . into_iter ( ) . map ( Into :: into) . collect ( ) ,
167+ position_id : value. position_id ,
168+ anchor_id : value. anchor_id ,
169+ commit_sha : value. commit_sha ,
170+ line_number : value. line_number ,
171+ confidence : value. confidence ,
172+ position_status : value. position_status . into ( ) ,
143173 }
144174 }
145175}
146- impl From < CodeReviewViews > for CodeReviewResponse {
147- fn from ( value : CodeReviewViews ) -> Self {
176+
177+ impl From < CommentReviewView > for CommentReviewResponse {
178+ fn from ( value : CommentReviewView ) -> Self {
148179 Self {
180+ comment_id : value. comment_id ,
181+ user_name : value. user_name ,
182+ content : value. content ,
183+ parent_id : value. parent_id ,
184+ created_at : value. created_at . to_string ( ) ,
185+ updated_at : value. updated_at . to_string ( ) ,
186+ }
187+ }
188+ }
189+
190+ impl From < mega_code_review_thread:: Model > for ThreadStatusResponse {
191+ fn from ( value : mega_code_review_thread:: Model ) -> Self {
192+ Self {
193+ thread_id : value. id ,
149194 link : value. link ,
150- files : value. files . into_iter ( ) . map ( Into :: into) . collect ( ) ,
195+ status : value. thread_status . into ( ) ,
151196 }
152197 }
153198}
154199
155200impl From < DiffSideEnum > for DiffSide {
156201 fn from ( value : DiffSideEnum ) -> Self {
157202 match value {
158- DiffSideEnum :: Old => DiffSide :: Old ,
159- DiffSideEnum :: New => DiffSide :: New ,
203+ DiffSideEnum :: Old => DiffSide :: Deletions ,
204+ DiffSideEnum :: New => DiffSide :: Additions ,
160205 }
161206 }
162207}
163208
164209impl From < DiffSide > for DiffSideEnum {
165210 fn from ( value : DiffSide ) -> Self {
166211 match value {
167- DiffSide :: Old => DiffSideEnum :: Old ,
168- DiffSide :: New => DiffSideEnum :: New ,
212+ DiffSide :: Deletions => DiffSideEnum :: Old ,
213+ DiffSide :: Additions => DiffSideEnum :: New ,
169214 }
170215 }
171216}
@@ -187,3 +232,27 @@ impl From<ThreadStatus> for ThreadStatusEnum {
187232 }
188233 }
189234}
235+
236+ impl From < PositionStatus > for PositionStatusEnum {
237+ fn from ( value : PositionStatus ) -> Self {
238+ match value {
239+ PositionStatus :: Exact => PositionStatusEnum :: Exact ,
240+ PositionStatus :: Shifted => PositionStatusEnum :: Shifted ,
241+ PositionStatus :: PendingReanchor => PositionStatusEnum :: PendingReanchor ,
242+ PositionStatus :: Ambiguous => PositionStatusEnum :: Ambiguous ,
243+ PositionStatus :: NotFound => PositionStatusEnum :: NotFound ,
244+ }
245+ }
246+ }
247+
248+ impl From < PositionStatusEnum > for PositionStatus {
249+ fn from ( value : PositionStatusEnum ) -> Self {
250+ match value {
251+ PositionStatusEnum :: Exact => PositionStatus :: Exact ,
252+ PositionStatusEnum :: Shifted => PositionStatus :: Shifted ,
253+ PositionStatusEnum :: PendingReanchor => PositionStatus :: PendingReanchor ,
254+ PositionStatusEnum :: Ambiguous => PositionStatus :: Ambiguous ,
255+ PositionStatusEnum :: NotFound => PositionStatus :: NotFound ,
256+ }
257+ }
258+ }
0 commit comments