Skip to content

Commit 989c95a

Browse files
committed
🎉 mock json server added and service created for get events 🎉
1 parent 579643d commit 989c95a

File tree

9 files changed

+214
-26
lines changed

9 files changed

+214
-26
lines changed

db.json

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
{
2+
"events": [
3+
{
4+
"id": 1,
5+
"title": "Beach Cleanup",
6+
"date": "Aug 28 2018",
7+
"time": "10:00",
8+
"location": "Daytona Beach",
9+
"description": "Let's clean up this beach.",
10+
"organizer": "Adam Jahr",
11+
"category": "sustainability",
12+
"attendees": [
13+
{
14+
"id": "abc123",
15+
"name": "Adam Jahr"
16+
},
17+
{
18+
"id": "def456",
19+
"name": "Gregg Pollack"
20+
},
21+
{
22+
"id": "ghi789",
23+
"name": "Beth Swanson"
24+
},
25+
{
26+
"id": "jkl101",
27+
"name": "Mary Gordon"
28+
}
29+
]
30+
},
31+
{
32+
"id": 2,
33+
"title": "Park Cleanup",
34+
"date": "Nov 12 2018",
35+
"time": "12:00",
36+
"location": "132 N Magnolia Street, Orlando, Florida",
37+
"description": "We're going to clean up this park.",
38+
"organizer": "Adam Jahr",
39+
"category": "nature",
40+
"attendees": [
41+
{
42+
"id": "ghi789",
43+
"name": "Beth Swanson"
44+
},
45+
{
46+
"id": "jkl101",
47+
"name": "Mary Gordon"
48+
}
49+
]
50+
},
51+
{
52+
"id": 3,
53+
"title": "Pet Adoption Day",
54+
"date": "Dec 2 2018",
55+
"time": "12:00",
56+
"location": "132 N Magnolia Street, Orlando, Florida",
57+
"description": "Help animals find new homes.",
58+
"organizer": "Gregg Pollack",
59+
"category": "animal welfare",
60+
"attendees": [
61+
{
62+
"id": "abc123",
63+
"name": "Adam Jahr"
64+
},
65+
{
66+
"id": "ghi789",
67+
"name": "Beth Swanson"
68+
},
69+
{
70+
"id": "jkl101",
71+
"name": "Mary Gordon"
72+
}
73+
]
74+
}
75+
]
76+
}

package-lock.json

Lines changed: 11 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"lint": "vue-cli-service lint"
99
},
1010
"dependencies": {
11+
"axios": "^0.18.0",
1112
"lodash": "^4.17.11",
1213
"vue": "^2.5.22",
1314
"vue-router": "^3.0.1",

src/components/BaseButton.vue

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<template>
2+
<div>
3+
4+
</div>
5+
</template>
6+
7+
<script>
8+
export default {
9+
10+
}
11+
</script>
12+
13+
<style scoped>
14+
15+
</style>

src/components/BaseIcon.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<svg class="icon" :width="width" :height="height">
44
<use v-bind="{ 'xlink:href': '/feather-sprite.svg#' + name }"></use>
55
</svg>
6+
<slot></slot>
67
</div>
78
</template>
89

src/components/EventCard.vue

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,27 @@
11
<template>
22
<router-link
33
class="event-link"
4-
:to="{ name: 'event-show', params: { id: '3' } }"
4+
:to="{ name: 'event-show', params: { id: event.id } }"
55
>
66
<div class="event-card -shadow">
77
<span class="eyebrow">@{{ event.time }} on {{ event.date }}</span>
88
<h4>{{ event.title }}</h4>
9-
<BaseIcon name="users" width="15" height="15" />
10-
<span>{{ event.attendees.length }}</span>
9+
<BaseIcon name="users" width="15" height="15"
10+
>{{ event.attendees.length }} attending</BaseIcon
11+
>
1112
</div>
1213
</router-link>
1314
</template>
1415

1516
<script>
1617
export default {
17-
data() {
18-
return {
19-
event: {
20-
id: 1,
21-
title: 'Park Cleanup',
22-
date: 'Tue Aug 20 2019',
23-
time: '5:00 AM',
24-
attendees: [
25-
{ id: 'abc123', name: 'Pratik Panchal' },
26-
{ id: 'pqr123', name: 'Prakash' },
27-
{ id: 'xyz321', name: 'Chetan' }
28-
]
29-
}
18+
props: {
19+
event: {
20+
type: Object
3021
}
22+
},
23+
data() {
24+
return {}
3125
}
3226
}
3327
</script>

src/services/EventService.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import axios from 'axios'
2+
3+
const apiClient = axios.create({
4+
baseURL: 'http://localhost:3000',
5+
withCredentials: false,
6+
headers: {
7+
Accept: 'application/json',
8+
'Content-Type': 'application/json'
9+
}
10+
})
11+
12+
export default {
13+
getEvents() {
14+
return apiClient.get('/events')
15+
},
16+
getEvent(id) {
17+
return apiClient.get(`events/${id}`)
18+
}
19+
}

src/views/EventList.vue

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,30 @@
22
<div>
33
<h1>Event List Page</h1>
44

5-
<EventCard />
5+
<EventCard v-for="event in events" v-bind:key="event.id" :event="event" />
66
</div>
77
</template>
88

99
<script>
1010
import EventCard from '@/components/EventCard.vue'
11+
import EventService from '@/services/EventService.js'
1112
export default {
13+
data() {
14+
return {
15+
events: []
16+
}
17+
},
1218
components: {
1319
EventCard
20+
},
21+
created() {
22+
EventService.getEvents()
23+
.then(response => {
24+
this.events = response.data
25+
})
26+
.catch(error => {
27+
console.log(error)
28+
})
1429
}
1530
}
1631
</script>

src/views/EventShow.vue

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,79 @@
11
<template>
22
<div>
3-
<h1>Event Show Page{{ id }}</h1>
3+
<div class="event-header">
4+
<span class="eyebrow">@{{ event.time }} on {{ event.date }}</span>
5+
<h1 class="title">{{ event.title }}</h1>
6+
<h5>Organized by {{ event.organizer }}</h5>
7+
<h5>Category: {{ event.category }}</h5>
8+
</div>
9+
10+
<BaseIcon name="map">
11+
<h2>Location</h2>
12+
</BaseIcon>
13+
14+
<address>{{ event.location }}</address>
15+
16+
<h2>Event details</h2>
17+
<p>{{ event.description }}</p>
18+
19+
<h2>
20+
Attendees
21+
<span class="badge -fill-gradient">
22+
{{
23+
event.attendees ? event.attendees.length : 0
24+
}}
25+
</span>
26+
</h2>
27+
<ul class="list-group">
28+
<li v-for="(attendee, index) in event.attendees" :key="index" class="list-item">
29+
<b>{{ attendee.name }}</b>
30+
</li>
31+
</ul>
432
</div>
533
</template>
634

735
<script>
36+
import EventService from '@/services/EventService.js'
837
export default {
938
props: {
1039
id: {
11-
type: String
40+
type: [String, Number]
41+
}
42+
},
43+
data() {
44+
return {
45+
event: {}
1246
}
47+
},
48+
created() {
49+
EventService.getEvent(this.id)
50+
.then(response => {
51+
this.event = response.data
52+
})
53+
.catch(err => {
54+
console.log(err)
55+
})
1356
}
1457
}
1558
</script>
1659

17-
<style scoped></style>
60+
<style scoped>
61+
.location {
62+
margin-bottom: 0;
63+
}
64+
.location > .icon {
65+
margin-left: 10px;
66+
}
67+
.event-header > .title {
68+
margin: 0;
69+
}
70+
.list-group {
71+
margin: 0;
72+
padding: 0;
73+
list-style: none;
74+
}
75+
.list-group > .list-item {
76+
padding: 1em 0;
77+
border-bottom: solid 1px #e5e5e5;
78+
}
79+
</style>

0 commit comments

Comments
 (0)