-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
93 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
import { RootStore } from "../stores/root"; | ||
import { RootApi } from "./root"; | ||
|
||
export class CommentApi { | ||
constructor(private api: RootApi, private store: RootStore) {} | ||
constructor(private api: RootApi) {} | ||
|
||
async getByPostId(postId: number) { | ||
const res = await this.api.client.get(`/posts/${postId}/comments`); | ||
this.store.comment.load(res.data); | ||
|
||
return res.data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,23 @@ | ||
import { RootStore } from "../stores/root"; | ||
import { RootApi } from "./root"; | ||
|
||
export class PostApi { | ||
constructor(private api: RootApi, private store: RootStore) {} | ||
constructor(private api: RootApi) {} | ||
|
||
async getAll() { | ||
const res = await this.api.client.get(`/posts`); | ||
this.store.post.load(res.data); | ||
|
||
return res.data; | ||
} | ||
|
||
async getById(id: number) { | ||
const res = await this.api.client.get(`/posts/${id}`); | ||
this.store.post.load([res.data]); | ||
|
||
return res.data; | ||
} | ||
|
||
async getByUserId(userId: number) { | ||
const res = await this.api.client.get(`/posts?userId=${userId}`); | ||
this.store.post.load(res.data); | ||
|
||
return res.data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,17 @@ | ||
import { RootStore } from "../stores/root"; | ||
import { RootApi } from "./root"; | ||
|
||
export class UserApi { | ||
constructor(private api: RootApi, private store: RootStore) {} | ||
constructor(private api: RootApi) {} | ||
|
||
async getAll() { | ||
const res = await this.api.client.get(`/users`); | ||
this.store.user.load(res.data); | ||
|
||
return res.data; | ||
} | ||
|
||
async getById(id: number) { | ||
const res = await this.api.client.get(`/users/${id}`); | ||
this.store.user.load([res.data]); | ||
|
||
return res.data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
import { RootApi } from "../apis/root"; | ||
import { CommentStore } from "./comment"; | ||
import { PostStore } from "./post"; | ||
import { UserStore } from "./user"; | ||
|
||
export class RootStore { | ||
user = new UserStore(this); | ||
post = new PostStore(this); | ||
comment = new CommentStore(this); | ||
constructor(private api: RootApi) {} | ||
|
||
user = new UserStore(this, this.api); | ||
post = new PostStore(this, this.api); | ||
comment = new CommentStore(this, this.api); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters