Skip to content

Commit 1c52460

Browse files
committed
Auto merge of #2406 - Turbo87:api-actions, r=pichfl
Use `ember-api-actions` to perform custom API actions see https://github.com/mike-north/ember-api-actions r? @locks
2 parents c88f4a4 + 93e6a9b commit 1c52460

File tree

6 files changed

+650
-65
lines changed

6 files changed

+650
-65
lines changed

app/adapters/crate.js

Lines changed: 0 additions & 41 deletions
This file was deleted.

app/adapters/user.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
import ApplicationAdapter from './application';
22

33
export default ApplicationAdapter.extend({
4-
stats(id) {
5-
return this.ajax(this.urlForStatsAction(id), 'GET');
6-
},
7-
8-
urlForStatsAction(id) {
9-
return `${this.buildURL('user', id)}/stats`;
10-
},
11-
124
queryRecord(store, type, query) {
135
let url = this.urlForFindRecord(query.user_id, 'user');
146
return this.ajax(url, 'GET');

app/models/crate.js

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import Model, { attr, hasMany } from '@ember-data/model';
22
import { map, sort } from '@ember/object/computed';
33

4+
import { memberAction } from 'ember-api-actions';
5+
46
export default Model.extend({
57
name: attr('string'),
68
downloads: attr('number'),
@@ -38,19 +40,29 @@ export default Model.extend({
3840
categories: hasMany('categories', { async: true }),
3941
reverse_dependencies: hasMany('dependency', { async: true }),
4042

41-
follow() {
42-
return this.store.adapterFor('crate').follow(this.id);
43-
},
44-
45-
inviteOwner(username) {
46-
return this.store.adapterFor('crate').inviteOwner(this.id, username);
47-
},
43+
follow: memberAction({ type: 'PUT', path: 'follow' }),
44+
unfollow: memberAction({ type: 'DELETE', path: 'follow' }),
4845

49-
removeOwner(username) {
50-
return this.store.adapterFor('crate').removeOwner(this.id, username);
51-
},
46+
inviteOwner: memberAction({
47+
type: 'PUT',
48+
path: 'owners',
49+
before(username) {
50+
return { owners: [username] };
51+
},
52+
after(response) {
53+
if (response.ok) {
54+
return response;
55+
} else {
56+
throw response;
57+
}
58+
},
59+
}),
5260

53-
unfollow() {
54-
return this.store.adapterFor('crate').unfollow(this.id);
55-
},
61+
removeOwner: memberAction({
62+
type: 'DELETE',
63+
path: 'owners',
64+
before(username) {
65+
return { owners: [username] };
66+
},
67+
}),
5668
});

app/models/user.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import Model, { attr } from '@ember-data/model';
22

3+
import { memberAction } from 'ember-api-actions';
4+
35
export default Model.extend({
46
email: attr('string'),
57
email_verified: attr('boolean'),
@@ -10,7 +12,5 @@ export default Model.extend({
1012
url: attr('string'),
1113
kind: attr('string'),
1214

13-
stats() {
14-
return this.store.adapterFor('user').stats(this.id);
15-
},
15+
stats: memberAction({ type: 'GET', path: 'stats' }),
1616
});

0 commit comments

Comments
 (0)