@@ -20,9 +20,10 @@ public FunctionsRepository(IHttpClientFactory httpClientFactory, TokenProvider t
2020 _tokenProvider = tokenProvider ;
2121 this . _httpClient . DefaultRequestHeaders . Authorization = new System . Net . Http . Headers . AuthenticationHeaderValue ( "Bearer" , tokenProvider . AccessToken ) ;
2222 }
23- public Task < IEnumerable < BaseKit > > GetAllBaseKits ( )
23+
24+ public async Task < IEnumerable < BaseKit > > GetAllBaseKits ( )
2425 {
25- throw new NotImplementedException ( ) ;
26+ return await _httpClient . GetFromJsonAsync < IList < BaseKit > > ( "basekits" ) ;
2627 }
2728
2829 public async Task < IEnumerable < HazardHunt > > GetAllHazardHunts ( )
@@ -35,9 +36,9 @@ public async Task<IEnumerable<HazardInfo>> GetAllHazardInfos()
3536 return await _httpClient . GetFromJsonAsync < IList < HazardInfo > > ( "hazardinfo-list" ) ;
3637 }
3738
38- public Task < BaseKit > GetBaseKitById ( string id )
39+ public async Task < BaseKit > GetBaseKitById ( string id )
3940 {
40- throw new NotImplementedException ( ) ;
41+ return await _httpClient . GetFromJsonAsync < BaseKit > ( $ "basekit-by-id/ { id } " ) ;
4142 }
4243
4344 public async Task < HazardHunt > GetHazardHuntById ( string id )
@@ -50,9 +51,17 @@ public async Task<HazardInfo> GetHazardInfoById(string id)
5051 return await _httpClient . GetFromJsonAsync < HazardInfo > ( $ "hazardinfo-by-id/{ id } ") ;
5152 }
5253
53- public Task < BaseKitItem > SaveBaseKitItem ( BaseKitItem kit )
54+ public async Task < BaseKit > SaveBaseKit ( BaseKit kit )
5455 {
55- throw new NotImplementedException ( ) ;
56+ var response = await _httpClient . PutAsJsonAsync ( "basekits-update" , kit ) ;
57+ if ( response . IsSuccessStatusCode )
58+ {
59+ return await response . Content . ReadFromJsonAsync < BaseKit > ( ) ;
60+ }
61+ else
62+ {
63+ throw new Exception ( "Error saving base kit" ) ;
64+ }
5665 }
5766
5867 public async Task < HazardHunt > SaveHazardHunt ( HazardHunt hazardHunt )
@@ -74,14 +83,26 @@ public async Task<HazardInfo> SaveHazardInfo(HazardInfo hazardInfo)
7483 if ( response . IsSuccessStatusCode )
7584 {
7685 return await response . Content . ReadFromJsonAsync < HazardInfo > ( ) ;
77- }
86+ }
7887 else
7988 {
8089 throw new Exception ( "Error saving hazard info" ) ;
8190 }
8291 }
8392
84-
93+ public async Task < BaseKit > CreateBaseKit ( BaseKit kit )
94+ {
95+ var response = await _httpClient . PostAsJsonAsync ( "basekit-create" , kit ) ;
96+ if ( response . IsSuccessStatusCode )
97+ {
98+ return await response . Content . ReadFromJsonAsync < BaseKit > ( ) ;
99+ }
100+ else
101+ {
102+ throw new Exception ( "Error saving base kit" ) ;
103+ }
104+ }
105+
85106 public async Task < HazardInfo > CreateHazardInfo ( HazardInfo hazardInfo )
86107 {
87108 var response = await _httpClient . PostAsJsonAsync ( "hazardinfo-create" , hazardInfo ) ;
@@ -107,5 +128,44 @@ public async Task<HazardHunt> CreateHazardHunt(HazardHunt hazardHunt)
107128 throw new Exception ( "Error saving hazard hunt" ) ;
108129 }
109130 }
131+
132+ public async Task < bool > DeleteBaseKit ( string id )
133+ {
134+ var response = await _httpClient . DeleteAsync ( $ "basekit-delete/{ id } ") ;
135+ if ( response . IsSuccessStatusCode )
136+ {
137+ return true ;
138+ }
139+ else
140+ {
141+ throw new Exception ( "Error deleting base kit" ) ;
142+ }
143+ }
144+
145+ public async Task < bool > DeleteHazardHunt ( string id )
146+ {
147+ var response = await _httpClient . DeleteAsync ( $ "hazardhunt-delete/{ id } ") ;
148+ if ( response . IsSuccessStatusCode )
149+ {
150+ return true ;
151+ }
152+ else
153+ {
154+ throw new Exception ( "Error deleting hazard hunt" ) ;
155+ }
156+ }
157+
158+ public async Task < bool > DeleteHazardInfo ( string id )
159+ {
160+ var response = await _httpClient . DeleteAsync ( $ "hazardinfo-delete/{ id } ") ;
161+ if ( response . IsSuccessStatusCode )
162+ {
163+ return true ;
164+ }
165+ else
166+ {
167+ throw new Exception ( "Error deleting hazard info" ) ;
168+ }
169+ }
110170 }
111171}
0 commit comments