Skip to content
This repository was archived by the owner on Apr 5, 2024. It is now read-only.

Commit 7888677

Browse files
committed
Replaces IDs with slugs
1 parent 53b1c0b commit 7888677

File tree

4 files changed

+14
-10
lines changed

4 files changed

+14
-10
lines changed

app/Api/Controllers/PostController.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,10 @@ public function update(Request $request, $slug)
107107
* @param int $id
108108
* @return \Illuminate\Http\Response
109109
*/
110-
public function destroy($id)
110+
public function destroy($slug)
111111
{
112+
$id = $this->repository->decodeSlug($slug);
113+
112114
$deletedPost = $this->repository->skipPresenter(false)->delete($id);
113115

114116
return $this->response->success(['message' => 'post deleted']);

resources/assets/js/pages/Overview/Overview.jsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,29 +97,29 @@ const OverviewComponent = ({ getPosts, deletePost, posts }) => {
9797
<table className="w-full text-left mb-4">
9898
<thead>
9999
<tr>
100-
<th>id</th>
100+
<th>slug</th>
101101
<th>title</th>
102102
<th>body</th>
103103
</tr>
104104
</thead>
105105
<tbody>
106-
{posts.map(({ id, title, body }) => (
107-
<tr key={id}>
108-
<td>{id}</td>
106+
{posts.map(({ slug, title, body }) => (
107+
<tr key={slug}>
108+
<td>{slug}</td>
109109
<td>{title}</td>
110110
<td>{body}</td>
111111
<td>
112112
<span
113113
className="text-red inline-block mr-6"
114-
onClick={() => deletePost(id)}
114+
onClick={() => deletePost(slug)}
115115
>
116116
delete
117117
</span>
118118
<ModalConsumer>
119119
{({ showModal }) => (
120120
<span
121121
onClick={() =>
122-
showModal(UpdatePostModal, { id, title, body })
122+
showModal(UpdatePostModal, { slug, title, body })
123123
}
124124
className="text-green"
125125
>

resources/assets/js/store/action-creators/posts/posts.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ export const createPost = data => async dispatch => {
2727

2828
export const updatePost = data => async dispatch => {
2929
const response = await dispatch(
30-
makeRequest(`update-post-${data.id}`, () =>
31-
axios.put(`/api/posts/${data.id}`, data)
30+
makeRequest(`update-post-${data.slug}`, () =>
31+
axios.put(`/api/posts/${data.slug}`, data)
3232
)
3333
)
3434

resources/assets/js/store/reducers/entities/entities.reducer.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ import { initialState } from 'store/initialState'
55
import { createReducer } from 'store/reducers/utilities'
66

77
import { usersReducer } from './users.reducer'
8+
import { postsReducer } from './posts.reducer'
89

910
const { entities } = initialState
1011

1112
const singleEntitiesReducer = combineReducers({
12-
users: usersReducer
13+
users: usersReducer,
14+
posts: postsReducer
1315
})
1416

1517
const wholeEntitiesReducer = createReducer(entities, {})

0 commit comments

Comments
 (0)