소스 검색

:recycle: depluralize api and frontend getters and routes

tags/0.9.0
j 4 년 전
부모
커밋
c3f2e4dcd7

+ 28
- 28
plugins/cia-endpoints/cia-end-points.php 파일 보기

@@ -25,28 +25,28 @@ add_action( 'rest_api_init', function () {
25 25
      * The standard wordpress post_types
26 26
      */
27 27
     $page_controller = new Make_Endpoint_For('page');
28
-    $page_controller->register_custom_route('pages');
28
+    $page_controller->register_custom_route('page');
29 29
 
30 30
     $media_controller = new Make_Endpoint_For('media');
31 31
     $media_controller->register_custom_route('media');
32 32
 
33 33
     $post_controller = new Make_Endpoint_For('post');
34
-    $post_controller->register_custom_route('posts');
34
+    $post_controller->register_custom_route('post');
35 35
 
36 36
     /**
37 37
      * Craft in America custom post_types
38 38
      */
39 39
     $episode_controller = new Make_Endpoint_For('episode');
40
-    $episode_controller->register_custom_route('episodes');
40
+    $episode_controller->register_custom_route('episode');
41 41
 
42 42
     $artist_controller = new Make_Endpoint_For('artist');
43
-    $artist_controller->register_custom_route('artists');
43
+    $artist_controller->register_custom_route('artist');
44 44
 
45 45
     $event_controller = new Make_Endpoint_For('event');
46
-    $event_controller->register_custom_route('events');
46
+    $event_controller->register_custom_route('event');
47 47
 
48 48
     $exhibition_controller = new Make_Endpoint_For('exhibition');
49
-    $exhibition_controller->register_custom_route('exhibitions');
49
+    $exhibition_controller->register_custom_route('exhibition');
50 50
 
51 51
     $sticky_controller = new Make_Sticky_Endpoint();
52 52
     $sticky_controller->register_custom_route('sticky');
@@ -55,25 +55,25 @@ add_action( 'rest_api_init', function () {
55 55
      * Craft in America custom sort_types
56 56
      */
57 57
     $sort_controller = new Make_Sort_By('artist', 'by_alpha');
58
-    $sort_controller->register_custom_route('artists/by-alpha');
58
+    $sort_controller->register_custom_route('artist/by-alpha');
59 59
     $sort_controller = new Make_Sort_By('artist', 'by_material');
60
-    $sort_controller->register_custom_route('artists/by-material');
60
+    $sort_controller->register_custom_route('artist/by-material');
61 61
     $sort_controller = new Make_Sort_By('event', 'by_past');
62
-    $sort_controller->register_custom_route('events/by-past');
62
+    $sort_controller->register_custom_route('event/by-past');
63 63
     $sort_controller = new Make_Sort_By('exhibition', 'by_past');
64
-    $sort_controller->register_custom_route('exhibitions/by-past');
64
+    $sort_controller->register_custom_route('exhibition/by-past');
65 65
     $sort_controller = new Make_Sort_By('event', 'by_current');
66
-    $sort_controller->register_custom_route('events/by-current');
66
+    $sort_controller->register_custom_route('event/by-current');
67 67
     $sort_controller = new Make_Sort_By('exhibition', 'by_current');
68
-    $sort_controller->register_custom_route('exhibitions/by-current');
68
+    $sort_controller->register_custom_route('exhibition/by-current');
69 69
     $sort_controller = new Make_Sort_By('event', 'by_upcoming');
70
-    $sort_controller->register_custom_route('events/by-upcoming');
70
+    $sort_controller->register_custom_route('event/by-upcoming');
71 71
     $sort_controller = new Make_Sort_By('exhibition', 'by_upcoming');
72
-    $sort_controller->register_custom_route('exhibitions/by-upcoming');
72
+    $sort_controller->register_custom_route('exhibition/by-upcoming');
73 73
     $sort_controller = new Make_Sort_By('event', 'by_current_and_upcoming');
74
-    $sort_controller->register_custom_route('events/by-current-and-upcoming');
74
+    $sort_controller->register_custom_route('event/by-current-and-upcoming');
75 75
     $sort_controller = new Make_Sort_By('exhibition', 'by_current_and_upcoming');
76
-    $sort_controller->register_custom_route('exhibitions/by-current-and-upcoming');
76
+    $sort_controller->register_custom_route('exhibition/by-current-and-upcoming');
77 77
 });
78 78
 
79 79
 /**
@@ -83,22 +83,22 @@ add_action( 'rest_api_init', function () {
83 83
  */
84 84
 add_filter('wp_rest_cache/allowed_endpoints', function () {
85 85
     // The standard wordpress post_types
86
-    if ( !isset($allowed_endpoints['craft/v2']) || !in_array('posts', $allowed_endpoints['craft/v2']) )
87
-        $allowed_endpoints['craft/v2'][] = 'posts';
88
-    if ( !isset($allowed_endpoints['craft/v2']) || !in_array('pages', $allowed_endpoints['craft/v2']) )
89
-        $allowed_endpoints['craft/v2'][] = 'pages';
86
+    if ( !isset($allowed_endpoints['craft/v2']) || !in_array('post', $allowed_endpoints['craft/v2']) )
87
+        $allowed_endpoints['craft/v2'][] = 'post';
88
+    if ( !isset($allowed_endpoints['craft/v2']) || !in_array('page', $allowed_endpoints['craft/v2']) )
89
+        $allowed_endpoints['craft/v2'][] = 'page';
90 90
     if ( !isset($allowed_endpoints['craft/v2']) || !in_array('media', $allowed_endpoints['craft/v2']) )
91 91
         $allowed_endpoints['craft/v2'][] = 'media';
92 92
 
93 93
     // Craft in America custom post_types
94
-    if ( !isset($allowed_endpoints['craft/v2']) || !in_array('episodes', $allowed_endpoints['craft/v2']) )
95
-        $allowed_endpoints['craft/v2'][] = 'episodes';
96
-    if ( !isset($allowed_endpoints['craft/v2']) || !in_array('events', $allowed_endpoints['craft/v2']) )
97
-        $allowed_endpoints['craft/v2'][] = 'events';
98
-    if ( !isset($allowed_endpoints['craft/v2']) || !in_array('exhibitions', $allowed_endpoints['craft/v2']) )
99
-        $allowed_endpoints['craft/v2'][] = 'exhibitions';
100
-    if ( !isset($allowed_endpoints['craft/v2']) || !in_array('artists', $allowed_endpoints['craft/v2']) )
101
-        $allowed_endpoints['craft/v2'][] = 'artists';
94
+    if ( !isset($allowed_endpoints['craft/v2']) || !in_array('episode', $allowed_endpoints['craft/v2']) )
95
+        $allowed_endpoints['craft/v2'][] = 'episode';
96
+    if ( !isset($allowed_endpoints['craft/v2']) || !in_array('event', $allowed_endpoints['craft/v2']) )
97
+        $allowed_endpoints['craft/v2'][] = 'event';
98
+    if ( !isset($allowed_endpoints['craft/v2']) || !in_array('exhibition', $allowed_endpoints['craft/v2']) )
99
+        $allowed_endpoints['craft/v2'][] = 'exhibition';
100
+    if ( !isset($allowed_endpoints['craft/v2']) || !in_array('artist', $allowed_endpoints['craft/v2']) )
101
+        $allowed_endpoints['craft/v2'][] = 'artist';
102 102
 
103 103
     return $allowed_endpoints;
104 104
 }, 10, 1);

+ 7
- 7
vue-theme/src/pages/list.vue 파일 보기

@@ -13,7 +13,7 @@
13 13
 
14 14
         .posts(v-if="posts && loaded" :class="{ 'is-grid': grid }")
15 15
             section(v-for="(post, i) in posts" :key="post.slug").shadow.post
16
-                card(:content="post" :type="type" :wide="type == 'exhibitions' && i > 1 || type == 'events' && i > 1 ")
16
+                card(:content="post" :type="type" :wide="type == 'exhibition' && i > 1 || type == 'event' && i > 1 ")
17 17
 
18 18
         footer
19 19
             p {{ `${type} count: ${Object.values(posts).length}` }}
@@ -47,16 +47,16 @@ export default {
47 47
             return typeFromRoute(this.$route)
48 48
         },
49 49
         dispatchName() {
50
-            let type = convertTitleCase(this.type)
50
+            let type = convertTitleCase(this.type) + 's'
51 51
             return this.sortBy ? `getAll${type.split('/')[0]}` : `getAll${type}`
52 52
         },
53 53
         loaded() {
54
-            let type = convertTitleCase(this.type)
54
+            let type = convertTitleCase(this.type) + 's'
55 55
             if (!type) return
56 56
             return this[`all${type}Loaded`]
57 57
         },
58 58
         posts() {
59
-            let type = convertTitleCase(this.type)
59
+            let type = convertTitleCase(this.type) + 's'
60 60
             if (!type) return
61 61
             return this[`all${type}`]
62 62
         },
@@ -71,7 +71,7 @@ export default {
71 71
                       .filter(p => p)
72 72
                       .pop()
73 73
 
74
-            // console.log('Gettings posts:', this.type)
74
+            console.log('Gettings posts:', this.type)
75 75
             // if (!Object.values(sortTypes).includes(sort)) {
76 76
             //     console.log('Sort not found:', sort)
77 77
             //     sort = null
@@ -81,13 +81,13 @@ export default {
81 81
             if (this.type && this.dispatchName) {
82 82
                 this.$store.dispatch(this.dispatchName, sort)
83 83
 
84
-                if (this.type == 'events') {
84
+                if (this.type == 'event') {
85 85
                     this.$store.dispatch(
86 86
                         'getAllExhibitions',
87 87
                         sortTypes.currentAndUpcoming,
88 88
                     )
89 89
                 }
90
-                if (this.type == 'exhibitions') {
90
+                if (this.type == 'exhibition') {
91 91
                     this.$store.dispatch(
92 92
                         'getAllEvents',
93 93
                         sortTypes.currentAndUpcoming,

+ 3
- 1
vue-theme/src/pages/mixin-post-types.js 파일 보기

@@ -1,4 +1,5 @@
1 1
 import { convertTitleCase, postTypes } from '@/utils/helpers'
2
+import { capitalize } from '@vue/shared'
2 3
 import { mapGetters, mapState } from 'vuex'
3 4
 
4 5
 /**
@@ -8,7 +9,8 @@ import { mapGetters, mapState } from 'vuex'
8 9
  */
9 10
 const getterHelper = {}
10 11
 for (let type of postTypes) {
11
-    const capitalized = convertTitleCase(type)
12
+    const capitalized = convertTitleCase(type) + 's'
13
+    console.log(capitalized)
12 14
     getterHelper[`all${capitalized}BySlug`] = `all${capitalized}BySlug`
13 15
     getterHelper[`all${capitalized}`] = `all${capitalized}`
14 16
     getterHelper[`all${capitalized}Loaded`] = `all${capitalized}Loaded`

+ 5
- 5
vue-theme/src/pages/single.vue 파일 보기

@@ -15,7 +15,7 @@
15 15
             //- p(v-if="post.type") type: {{ post.type }}
16 16
             //- p(v-if="post.subtypes") subtypes: {{ post.subtypes }}
17 17
 
18
-            .date-info(v-if="['exhibitions', 'events'].includes(type)")
18
+            .date-info(v-if="['exhibition', 'event'].includes(type)")
19 19
                 p start: {{ dateFrom(post.start) }}
20 20
                 p end: {{ dateFrom(post.end) }}
21 21
 
@@ -23,13 +23,13 @@
23 23
         section.content(v-html="post.content")
24 24
 
25 25
         //- related artists section for episodes
26
-        section(v-if="type === 'episodes' && post" :post="post")
26
+        section(v-if="type === 'episode' && post" :post="post")
27 27
             h2.t-up featured in this episode
28 28
             ul
29 29
                 li.f-row.between(v-for="artist in p2pPostsByType['artist']")
30
-                    card(:content="artist" type="artists" :wide="true" :hide-type="true")
30
+                    card(:content="artist" type="artist" :wide="true" :hide-type="true")
31 31
             
32
-        credits(v-if="type === 'episodes' && post" :post="post")
32
+        credits(v-if="type === 'episode' && post" :post="post")
33 33
 
34 34
         //- end of article icon     
35 35
         footer.f-col
@@ -196,7 +196,7 @@ export default {
196 196
              * which is derived from the route
197 197
              * !: posts watcher fires when this finishes
198 198
              */
199
-            let type = convertTitleCase(this.type)
199
+            let type = convertTitleCase(this.type) + 's'
200 200
 
201 201
             if (!this.$store.state[this.type]) return
202 202
 

+ 4
- 4
vue-theme/src/router/routes.js 파일 보기

@@ -9,23 +9,23 @@ export default [
9 9
     { path: '/', component: indexPage },
10 10
     // List Pages
11 11
     {
12
-        path: '/episodes',
12
+        path: '/episode',
13 13
         component: listPage,
14 14
         props: { sidebar: false, grid: true, sortBy: null },
15 15
     },
16 16
     {
17
-        path: '/artists',
17
+        path: '/artist',
18 18
         component: listPage,
19 19
         props: { sidebar: true, grid: true, sortBy: null },
20 20
     },
21 21
     // Sorted List Pages
22 22
     {
23
-        path: `/artists/${sortTypes.alpha}`,
23
+        path: `/artist/${sortTypes.alpha}`,
24 24
         component: listPage,
25 25
         props: { sidebar: true, grid: true, sortBy: `${sortTypes.alpha}` },
26 26
     },
27 27
     {
28
-        path: `/artists/${sortTypes.material}`,
28
+        path: `/artist/${sortTypes.material}`,
29 29
         component: listPage,
30 30
         props: { sidebar: true, grid: true, sortBy: `${sortTypes.material}` },
31 31
     },

+ 2
- 2
vue-theme/src/store/modules/artist.js 파일 보기

@@ -20,7 +20,7 @@ const actions = {
20 20
     getAllArtists({ commit }, sortType) {
21 21
         commit('CLEAR_ARTISTS')
22 22
         commit('ARTISTS_LOADED', false)
23
-        return api.getByType('artists', sortType, artists => {
23
+        return api.getByType('artist', sortType, artists => {
24 24
             commit('STORE_FETCHED_ARTISTS', { artists })
25 25
             commit('ARTISTS_LOADED', true)
26 26
         })
@@ -28,7 +28,7 @@ const actions = {
28 28
     getSingleArtist({ commit }, id) {
29 29
         commit('CLEAR_SINGLE_ARTISTS')
30 30
         commit('ARTISTS_LOADED', false)
31
-        api.getSingleType('artists', id, artist => {
31
+        api.getSingleType('artist', id, artist => {
32 32
             commit('STORE_FETCHED_SINGLE_ARTIST', artist)
33 33
             commit('ARTISTS_LOADED', true)
34 34
         })

+ 2
- 2
vue-theme/src/store/modules/episode.js 파일 보기

@@ -20,7 +20,7 @@ const actions = {
20 20
     getAllEpisodes({ commit }, sortType) {
21 21
         commit('CLEAR_EPISODES')
22 22
         commit('EPISODES_LOADED', false)
23
-        return api.getByType('episodes', sortType, episodes => {
23
+        return api.getByType('episode', sortType, episodes => {
24 24
             commit('STORE_FETCHED_EPISODES', { episodes })
25 25
             commit('EPISODES_LOADED', true)
26 26
         })
@@ -29,7 +29,7 @@ const actions = {
29 29
         console.log('clearing single ep from getSingle')
30 30
         commit('CLEAR_SINGLE_EPISODES')
31 31
         commit('EPISODES_LOADED', false)
32
-        api.getSingleType('episodes', id, episode => {
32
+        api.getSingleType('episode', id, episode => {
33 33
             commit('STORE_FETCHED_SINGLE_EPISODE', episode)
34 34
             commit('EPISODES_LOADED', true)
35 35
         })

+ 2
- 2
vue-theme/src/store/modules/event.js 파일 보기

@@ -27,7 +27,7 @@ const actions = {
27 27
     getAllEvents({ commit }, sortType) {
28 28
         commit('CLEAR_EVENTS')
29 29
         commit('EVENTS_LOADED', false)
30
-        return api.getByType('events', sortType, events => {
30
+        return api.getByType('event', sortType, events => {
31 31
             commit('STORE_FETCHED_EVENTS', { events })
32 32
             commit('EVENTS_LOADED', true)
33 33
         })
@@ -35,7 +35,7 @@ const actions = {
35 35
     getSingleEvent({ commit }, id) {
36 36
         commit('CLEAR_SINGLE_EVENTS')
37 37
         commit('EVENTS_LOADED', false)
38
-        api.getSingleType('events', id, event => {
38
+        api.getSingleType('event', id, event => {
39 39
             commit('STORE_FETCHED_SINGLE_EVENT', event)
40 40
             commit('EVENTS_LOADED', true)
41 41
         })

+ 2
- 2
vue-theme/src/store/modules/exhibition.js 파일 보기

@@ -29,7 +29,7 @@ const actions = {
29 29
     getAllExhibitions({ commit }, sortType) {
30 30
         commit('CLEAR_EXHIBITIONS')
31 31
         commit('EXHIBITIONS_LOADED', false)
32
-        return api.getByType('exhibitions', sortType, exhibitions => {
32
+        return api.getByType('exhibition', sortType, exhibitions => {
33 33
             commit('STORE_FETCHED_EXHIBITIONS', { exhibitions })
34 34
             commit('EXHIBITIONS_LOADED', true)
35 35
         })
@@ -37,7 +37,7 @@ const actions = {
37 37
     getSingleExhibition({ commit }, id) {
38 38
         commit('CLEAR_SINGLE_EXHIBITIONS')
39 39
         commit('EXHIBITIONS_LOADED', false)
40
-        api.getSingleType('exhibitions', id, exhibition => {
40
+        api.getSingleType('exhibition', id, exhibition => {
41 41
             commit('STORE_FETCHED_SINGLE_EXHIBITION', exhibition)
42 42
             commit('EXHIBITIONS_LOADED', true)
43 43
         })

+ 2
- 2
vue-theme/src/store/modules/page.js 파일 보기

@@ -17,7 +17,7 @@ const getters = {
17 17
 const actions = {
18 18
     async getAllPages({ commit }, sortType) {
19 19
         commit('PAGES_LOADED', false)
20
-        return await api.getByType('pages', sortType, pages => {
20
+        return await api.getByType('page', sortType, pages => {
21 21
             commit('STORE_FETCHED_PAGES', { pages })
22 22
             commit('PAGES_LOADED', true)
23 23
         })
@@ -25,7 +25,7 @@ const actions = {
25 25
     getSinglePage({ commit }, id) {
26 26
         commit('CLEAR_SINGLE_PAGE')
27 27
         commit('PAGES_LOADED', false)
28
-        api.getSingleType('pages', id, page => {
28
+        api.getSingleType('page', id, page => {
29 29
             commit('STORE_FETCHED_SINGLE_PAGE', page)
30 30
             commit('PAGES_LOADED', true)
31 31
         })

+ 2
- 2
vue-theme/src/store/modules/post.js 파일 보기

@@ -15,7 +15,7 @@ const actions = {
15 15
     getAllPosts({ commit }, sortType) {
16 16
         commit('CLEAR_POSTS')
17 17
         commit('POSTS_LOADED', false)
18
-        return api.getByType('posts', sortType, posts => {
18
+        return api.getByType('post', sortType, posts => {
19 19
             commit('STORE_FETCHED_POSTS', { posts })
20 20
             commit('POSTS_LOADED', true)
21 21
         })
@@ -23,7 +23,7 @@ const actions = {
23 23
     getSinglePost({ commit }, id) {
24 24
         commit('CLEAR_SINGLE_POSTS')
25 25
         commit('POSTS_LOADED', false)
26
-        api.getSingleType('posts', id, post => {
26
+        api.getSingleType('post', id, post => {
27 27
             commit('STORE_FETCHED_SINGLE_POST', post)
28 28
             commit('POSTS_LOADED', true)
29 29
         })

+ 1
- 1
vue-theme/src/utils/api.js 파일 보기

@@ -64,7 +64,7 @@ export default {
64 64
     },
65 65
     getPosts(limit = 5, cb) {
66 66
         axios
67
-            .get(SETTINGS.API_BASE_PATH + 'posts')
67
+            .get(SETTINGS.API_BASE_PATH + 'post')
68 68
             .then(response => {
69 69
                 cb(response.data)
70 70
             })

+ 7
- 7
vue-theme/src/utils/helpers.js 파일 보기

@@ -26,12 +26,12 @@ const sortTypes = {
26 26
  */
27 27
 const postTypes = [
28 28
     'sticky',
29
-    'episodes',
30
-    'artists',
31
-    'exhibitions',
32
-    'events',
33
-    'posts',
34
-    'pages',
29
+    'episode',
30
+    'artist',
31
+    'exhibition',
32
+    'event',
33
+    'post',
34
+    'page',
35 35
 ]
36 36
 
37 37
 /**
@@ -50,7 +50,7 @@ const typeFromRoute = route => {
50 50
 
51 51
         // Only take the first match
52 52
         type = type[0]
53
-        // console.log(`type derived from route.path: ${type}`)
53
+        console.log(`type derived from route.path: ${type}`)
54 54
     }
55 55
 
56 56
     return type

Loading…
취소
저장