Skip to content

Commit e85b672

Browse files
committed
models/crate: Use memberAction() for follow|unfollow() implementations
1 parent f3bc316 commit e85b672

File tree

2 files changed

+4
-19
lines changed

2 files changed

+4
-19
lines changed

app/adapters/crate.js

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

33
export default ApplicationAdapter.extend({
4-
follow(id) {
5-
return this.ajax(this.urlForFollowAction(id), 'PUT');
6-
},
7-
84
async inviteOwner(id, username) {
95
let result = await this.ajax(this.urlForOwnerAction(id), 'PUT', {
106
data: {
@@ -27,14 +23,6 @@ export default ApplicationAdapter.extend({
2723
});
2824
},
2925

30-
unfollow(id) {
31-
return this.ajax(this.urlForFollowAction(id), 'DELETE');
32-
},
33-
34-
urlForFollowAction(id) {
35-
return `${this.buildURL('crate', id)}/follow`;
36-
},
37-
3826
urlForOwnerAction(id) {
3927
return `${this.buildURL('crate', id)}/owners`;
4028
},

app/models/crate.js

Lines changed: 4 additions & 7 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,9 +40,8 @@ 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-
},
43+
follow: memberAction({ type: 'PUT', path: 'follow' }),
44+
unfollow: memberAction({ type: 'DELETE', path: 'follow' }),
4445

4546
inviteOwner(username) {
4647
return this.store.adapterFor('crate').inviteOwner(this.id, username);
@@ -49,8 +50,4 @@ export default Model.extend({
4950
removeOwner(username) {
5051
return this.store.adapterFor('crate').removeOwner(this.id, username);
5152
},
52-
53-
unfollow() {
54-
return this.store.adapterFor('crate').unfollow(this.id);
55-
},
5653
});

0 commit comments

Comments
 (0)