22using BangumiNet . Api . Helpers ;
33using BangumiNet . Api . Interfaces ;
44using BangumiNet . Api . V0 . Models ;
5+ using BangumiNet . Common ;
6+ using BangumiNet . Models ;
57using System . Reactive ;
68using System . Reactive . Linq ;
79
@@ -106,6 +108,7 @@ public async Task<bool> LoadPage(CancellationToken ct = default)
106108 RelatedItemType . Photo => await ApiC . P1 . Blogs [ id ] . Photos . GetAsync ( c => c . Paging ( Limit , Offset ) , ct ) ,
107109 _ => throw new NotImplementedException ( ) ,
108110 } ,
111+ ItemType . Index => await ApiC . P1 . Indexes [ id ] . Related . GetAsync ( c => c . Paging ( Limit , Offset ) , ct ) ,
109112 _ => throw new NotImplementedException ( ) ,
110113 } ;
111114 }
@@ -144,6 +147,7 @@ public async Task<bool> LoadPage(CancellationToken ct = default)
144147 Api . P1 . Models . Topic st => new TopicViewModel ( st , ItemType . Subject ) ,
145148 Api . P1 . Models . BlogPhoto bp => new PhotoViewModel ( bp ) ,
146149 Api . P1 . Models . SlimIndex si => new IndexViewModel ( si ) ,
150+ Api . P1 . Models . IndexRelated ir => IndexRelatedToVM ( ir ) ,
147151 _ => new TextViewModel ( $ "RelatedItemListViewModel.ConvertToVM: { obj } ") ,
148152 } ;
149153
@@ -153,6 +157,42 @@ public async Task<bool> LoadPage(CancellationToken ct = default)
153157 _ => ConvertToVM ( obj ) ,
154158 } ;
155159
160+ public static ViewModelBase IndexRelatedToVM ( Api . P1 . Models . IndexRelated related )
161+ {
162+ ItemViewModelBase item ;
163+ if ( related . Subject != null )
164+ item = new SubjectViewModel ( related . Subject ) ;
165+ else if ( related . Character != null )
166+ item = new CharacterViewModel ( related . Character ) ;
167+ else if ( related . Person != null )
168+ item = new PersonViewModel ( related . Person ) ;
169+ else if ( related . Episode != null )
170+ item = new EpisodeViewModel ( related . Episode ) ;
171+ else if ( related . Blog != null )
172+ item = new BlogViewModel ( related . Blog ) ;
173+ else if ( related . GroupTopic != null )
174+ item = new TopicViewModel ( related . GroupTopic , false ) ;
175+ else if ( related . SubjectTopic != null )
176+ item = new TopicViewModel ( related . SubjectTopic , false ) ;
177+ else
178+ throw new NotImplementedException ( ) ;
179+
180+ item . Order = related . Order ;
181+ item . IndexRelation = new IndexRelation
182+ {
183+ Category = ( IndexRelatedCategory ? ) related . Cat ,
184+ Type = ( SubjectType ? ) related . Type ,
185+ Id = related . Id ,
186+ IndexId = related . Rid ,
187+ ItemId = related . Sid ,
188+ Order = related . Order ,
189+ Comment = related . Comment ,
190+ Award = related . Award ,
191+ CreationTime = CommonUtils . ParseBangumiTime ( related . CreatedAt ) ,
192+ } ;
193+ return item ;
194+ }
195+
156196 [ Reactive ] public partial RelatedItemType Type { get ; set ; }
157197 [ Reactive ] public partial ItemType ParentType { get ; set ; }
158198 [ Reactive ] public partial int ? ParentId { get ; set ; }
0 commit comments