4
4
using JsonApiDotNetCore . Models ;
5
5
using JsonApiDotNetCore . Services ;
6
6
using Microsoft . AspNetCore . Mvc ;
7
- using Microsoft . Extensions . Logging ;
8
7
9
8
namespace JsonApiDotNetCore . Controllers
10
9
{
@@ -105,7 +104,7 @@ public BaseJsonApiController(
105
104
106
105
public virtual async Task < IActionResult > GetAsync ( )
107
106
{
108
- if ( _getAll == null ) throw new JsonApiException ( 405 , "Get requests are not supported" ) ;
107
+ if ( _getAll == null ) throw Exceptions . UnSupportedRequestMethod ;
109
108
110
109
var entities = await _getAll . GetAsync ( ) ;
111
110
@@ -114,7 +113,7 @@ public virtual async Task<IActionResult> GetAsync()
114
113
115
114
public virtual async Task < IActionResult > GetAsync ( TId id )
116
115
{
117
- if ( _getById == null ) throw new JsonApiException ( 405 , "Get by Id requests are not supported" ) ;
116
+ if ( _getById == null ) throw Exceptions . UnSupportedRequestMethod ;
118
117
119
118
var entity = await _getById . GetAsync ( id ) ;
120
119
@@ -126,7 +125,7 @@ public virtual async Task<IActionResult> GetAsync(TId id)
126
125
127
126
public virtual async Task < IActionResult > GetRelationshipsAsync ( TId id , string relationshipName )
128
127
{
129
- if ( _getRelationships == null ) throw new JsonApiException ( 405 , "Get Relationships requests are not supported" ) ;
128
+ if ( _getRelationships == null ) throw Exceptions . UnSupportedRequestMethod ;
130
129
131
130
var relationship = await _getRelationships . GetRelationshipsAsync ( id , relationshipName ) ;
132
131
if ( relationship == null )
@@ -137,7 +136,7 @@ public virtual async Task<IActionResult> GetRelationshipsAsync(TId id, string re
137
136
138
137
public virtual async Task < IActionResult > GetRelationshipAsync ( TId id , string relationshipName )
139
138
{
140
- if ( _getRelationship == null ) throw new JsonApiException ( 405 , "Get Relationship requests are not supported" ) ;
139
+ if ( _getRelationship == null ) throw Exceptions . UnSupportedRequestMethod ;
141
140
142
141
var relationship = await _getRelationship . GetRelationshipAsync ( id , relationshipName ) ;
143
142
@@ -146,7 +145,7 @@ public virtual async Task<IActionResult> GetRelationshipAsync(TId id, string rel
146
145
147
146
public virtual async Task < IActionResult > PostAsync ( [ FromBody ] T entity )
148
147
{
149
- if ( _create == null ) throw new JsonApiException ( 405 , "Post requests are not supported" ) ;
148
+ if ( _create == null ) throw Exceptions . UnSupportedRequestMethod ;
150
149
151
150
if ( entity == null )
152
151
return UnprocessableEntity ( ) ;
@@ -161,7 +160,7 @@ public virtual async Task<IActionResult> PostAsync([FromBody] T entity)
161
160
162
161
public virtual async Task < IActionResult > PatchAsync ( TId id , [ FromBody ] T entity )
163
162
{
164
- if ( _update == null ) throw new JsonApiException ( 405 , "Patch requests are not supported" ) ;
163
+ if ( _update == null ) throw Exceptions . UnSupportedRequestMethod ;
165
164
166
165
if ( entity == null )
167
166
return UnprocessableEntity ( ) ;
@@ -176,7 +175,7 @@ public virtual async Task<IActionResult> PatchAsync(TId id, [FromBody] T entity)
176
175
177
176
public virtual async Task < IActionResult > PatchRelationshipsAsync ( TId id , string relationshipName , [ FromBody ] List < DocumentData > relationships )
178
177
{
179
- if ( _updateRelationships == null ) throw new JsonApiException ( 405 , "Relationship Patch requests are not supported" ) ;
178
+ if ( _updateRelationships == null ) throw Exceptions . UnSupportedRequestMethod ;
180
179
181
180
await _updateRelationships . UpdateRelationshipsAsync ( id , relationshipName , relationships ) ;
182
181
@@ -185,7 +184,7 @@ public virtual async Task<IActionResult> PatchRelationshipsAsync(TId id, string
185
184
186
185
public virtual async Task < IActionResult > DeleteAsync ( TId id )
187
186
{
188
- if ( _delete == null ) throw new JsonApiException ( 405 , "Delete requests are not supported" ) ;
187
+ if ( _delete == null ) throw Exceptions . UnSupportedRequestMethod ;
189
188
190
189
var wasDeleted = await _delete . DeleteAsync ( id ) ;
191
190
0 commit comments