Skip to content
Snippets Groups Projects
Commit 87641311 authored by JunGu Kang's avatar JunGu Kang
Browse files

Merge branch '#31' into 'development'

#31 Add Trainee Create View

See merge request !27
parents 1b7e09f7 90dfcc42
No related branches found
No related tags found
2 merge requests!37Deploy,!27#31 Add Trainee Create View
Pipeline #4341 passed
...@@ -53,6 +53,11 @@ const routes = [ ...@@ -53,6 +53,11 @@ const routes = [
name: 'TraineeList', name: 'TraineeList',
component: () => import('@/views/TraineeList.vue'), component: () => import('@/views/TraineeList.vue'),
}, },
{
path: '/trainee/create',
name: 'TraineeCreate',
component: () => import('@/views/TraineeCreate.vue'),
},
{ {
path: '/trainee/:id', path: '/trainee/:id',
name: 'TraineeDetail', name: 'TraineeDetail',
......
<template>
<div class="trainee-detail">
<v-row>
<v-col cols="12">
<v-card :loading="isProcessing">
<v-card-title>회원 등록</v-card-title>
<v-card-text>
<v-alert
v-if="error.isError"
dense
text
type="error"
>
{{ error.message }}
</v-alert>
<v-text-field
label="이메일"
v-model="trainee.email"
></v-text-field>
<v-text-field
label="비밀번호"
type="password"
v-model="trainee.password"
></v-text-field>
<v-text-field
label="이름"
v-model="trainee.name"
></v-text-field>
<v-text-field
label="연락처"
v-model="trainee.phone"
></v-text-field>
<v-menu
:close-on-content-click="false"
min-width="290px"
offset-y
v-model="showDatePicker"
>
<template v-slot:activator="{ on }">
<v-text-field
label="생년월일"
readonly
v-model="trainee.birthDate"
v-on="on"
></v-text-field>
</template>
<v-date-picker
v-model="trainee.birthDate"
@input="showDatePicker = false"
></v-date-picker>
</v-menu>
</v-card-text>
<v-card-actions>
<v-spacer></v-spacer>
<v-btn
color="error"
outlined
@click="cancel"
>
<v-icon left>mdi-delete</v-icon>
취소
</v-btn>
<v-btn
color="primary"
outlined
@click="createTrainee"
>
<v-icon left>mdi-content-save</v-icon>
저장
</v-btn>
</v-card-actions>
</v-card>
</v-col>
</v-row>
</div>
</template>
<script>
import APISetting from '@/settings/api';
export default {
name: 'TraineeCreate',
data: () => ({
isProcessing: false,
error: {
isError: false,
message: '',
},
showDatePicker: false,
trainee: {
email: '',
password: '',
name: '',
phone: '',
birthDate: '',
},
}),
methods: {
createTrainee() {
this.error.isError = false;
this.error.message = '';
this.isProcessing = true;
fetch(APISetting.endpoints.trainee.list, APISetting.settings.post(this.trainee))
.then((res) => {
if ([201, 400, 500].includes(res.status)) return Promise.all([res.json(), res]);
throw new Error('알 수 없는 응답입니다.');
})
.then((values) => {
const [json, res] = values;
if (res.status !== 201) throw new Error(json.message);
this.$router.push('/trainee');
})
.catch((e) => {
this.error.message = e.message;
this.error.isError = true;
})
.finally(() => {
this.isProcessing = false;
});
},
cancel() {
this.$router.push('/trainee');
},
},
};
</script>
<template> <template>
<div class="trainee-detail"> <div class="trainee-detail">
<v-card <v-row>
:loading="isProcessing" <v-col cols="12">
> <v-card :loading="isProcessing">
<v-card-title>회원 정보</v-card-title> <v-card-title>회원 정보</v-card-title>
<v-card-text> <v-card-text>
<v-alert <v-alert
...@@ -36,9 +36,7 @@ ...@@ -36,9 +36,7 @@
offset-y offset-y
v-model="showDatePicker" v-model="showDatePicker"
> >
<template <template v-slot:activator="{ on }">
v-slot:activator="{ on }"
>
<v-text-field <v-text-field
label="생년월일" label="생년월일"
readonly readonly
...@@ -69,11 +67,7 @@ ...@@ -69,11 +67,7 @@
outlined outlined
@click="deleteTrainee(id)" @click="deleteTrainee(id)"
> >
<v-icon <v-icon left>mdi-delete</v-icon>
left
>
mdi-delete
</v-icon>
삭제 삭제
</v-btn> </v-btn>
<v-btn <v-btn
...@@ -81,19 +75,19 @@ ...@@ -81,19 +75,19 @@
outlined outlined
@click="updateTrainee(id)" @click="updateTrainee(id)"
> >
<v-icon <v-icon left>mdi-content-save</v-icon>
left
>
mdi-content-save
</v-icon>
저장 저장
</v-btn> </v-btn>
</v-card-actions> </v-card-actions>
</v-card> </v-card>
</v-col>
</v-row>
</div> </div>
</template> </template>
<script> <script>
import moment from 'moment';
import APISetting from '@/settings/api'; import APISetting from '@/settings/api';
export default { export default {
...@@ -111,8 +105,8 @@ export default { ...@@ -111,8 +105,8 @@ export default {
name: '', name: '',
phone: '', phone: '',
birthDate: '', birthDate: '',
updatedAt: '',
createdAt: '', createdAt: '',
updatedAt: '',
}, },
}), }),
...@@ -139,7 +133,10 @@ export default { ...@@ -139,7 +133,10 @@ export default {
const [json, res] = values; const [json, res] = values;
if (res.status === 404) throw new Error('존재하지 않는 데이터입니다.'); if (res.status === 404) throw new Error('존재하지 않는 데이터입니다.');
if (res.status !== 200) throw new Error(json.message); if (res.status !== 200) throw new Error(json.message);
this.trainee = json.trainee; const { trainee } = json;
trainee.createdAt = moment(trainee.createdAt).format('YYYY-MM-DD HH:mm:ss');
trainee.updatedAt = moment(trainee.updatedAt).format('YYYY-MM-DD HH:mm:ss');
this.trainee = trainee;
}) })
.catch((e) => { .catch((e) => {
this.error.message = e.message; this.error.message = e.message;
...@@ -164,7 +161,10 @@ export default { ...@@ -164,7 +161,10 @@ export default {
const [json, res] = values; const [json, res] = values;
if (res.status === 404) throw new Error('존재하지 않는 데이터입니다.'); if (res.status === 404) throw new Error('존재하지 않는 데이터입니다.');
if (res.status !== 200) throw new Error(json.message); if (res.status !== 200) throw new Error(json.message);
this.trainee = json.trainee; const { trainee } = json;
trainee.createdAt = moment(trainee.createdAt).format('YYYY-MM-DD HH:mm:ss');
trainee.updatedAt = moment(trainee.updatedAt).format('YYYY-MM-DD HH:mm:ss');
this.trainee = trainee;
}) })
.catch((e) => { .catch((e) => {
this.error.message = e.message; this.error.message = e.message;
...@@ -183,7 +183,6 @@ export default { ...@@ -183,7 +183,6 @@ export default {
.then((res) => { .then((res) => {
if ([204, 404].includes(res.status)) return Promise.all([null, res]); if ([204, 404].includes(res.status)) return Promise.all([null, res]);
if ([400, 500].includes(res.status)) return Promise.all([res.json(), res]); if ([400, 500].includes(res.status)) return Promise.all([res.json(), res]);
// If response status is not equal to 204, 400, 404, or 500, go to catch.
throw new Error('알 수 없는 응답입니다.'); throw new Error('알 수 없는 응답입니다.');
}) })
.then((values) => { .then((values) => {
......
<template> <template>
<div class="trainee-list"> <div class="trainee-list">
<v-row>
<v-col cols="12">
<v-card> <v-card>
<v-card-title>회원 목록</v-card-title> <v-card-title>회원 목록</v-card-title>
<v-card-text> <v-card-text>
<v-row <v-row>
justify="end" <v-col
align-self="center"
cols="12"
sm="8"
md="9"
lg="9"
xl="10"
>
<v-btn
color="success"
outlined
@click="createTrainee"
> >
<v-icon left>
mdi-plus
</v-icon>
새 회원 등록
</v-btn>
</v-col>
<v-col <v-col
cols="12" cols="12"
sm="4" sm="4"
...@@ -48,10 +67,14 @@ ...@@ -48,10 +67,14 @@
</v-data-table> </v-data-table>
</v-card-text> </v-card-text>
</v-card> </v-card>
</v-col>
</v-row>
</div> </div>
</template> </template>
<script> <script>
import moment from 'moment';
import APISetting from '@/settings/api'; import APISetting from '@/settings/api';
export default { export default {
...@@ -81,6 +104,14 @@ export default { ...@@ -81,6 +104,14 @@ export default {
text: '연락처', text: '연락처',
value: 'phone', value: 'phone',
}, },
{
text: '생년월일',
value: 'birthDate',
},
{
text: '등록 시각',
value: 'createdAt',
},
{ {
text: '', text: '',
value: 'action', value: 'action',
...@@ -101,11 +132,14 @@ export default { ...@@ -101,11 +132,14 @@ export default {
fetch(APISetting.endpoints.trainee.list, APISetting.settings.get) fetch(APISetting.endpoints.trainee.list, APISetting.settings.get)
.then((res) => { .then((res) => {
if (res.status === 200) return res.json(); if (res.status === 200) return res.json();
// If response status is not equal to 200, go to catch.
throw new Error('알 수 없는 응답입니다.'); throw new Error('알 수 없는 응답입니다.');
}) })
.then((json) => { .then((json) => {
this.traineeList.data = json.trainees; this.traineeList.data = json.trainees;
this.traineeList.data.forEach((trainee) => {
// eslint-disable-next-line no-param-reassign
trainee.createdAt = moment(trainee.createAt).format('YYYY-MM-DD HH:mm:ss');
});
}) })
.catch((e) => { .catch((e) => {
this.error.message = e.message; this.error.message = e.message;
...@@ -115,31 +149,34 @@ export default { ...@@ -115,31 +149,34 @@ export default {
this.isProcessing = false; this.isProcessing = false;
}); });
}, },
createTrainee() {
this.$router.push('/trainee/create');
},
editTrainee(id) { editTrainee(id) {
this.$router.push(`/trainee/${id}`); this.$router.push(`/trainee/${id}`);
}, },
deleteTrainee(id) { deleteTrainee(id) {
this.error.isError = false; this.error.isError = false;
this.error.message = ''; this.error.message = '';
this.isProcessing = true;
fetch(APISetting.endpoints.trainee.detail(id), APISetting.settings.delete) fetch(APISetting.endpoints.trainee.detail(id), APISetting.settings.delete)
.then((res) => { .then((res) => {
if (res.status === 204) return Promise.all([null, res]); if (res.status === 204) return Promise.all([null, res]);
if ([204, 400, 404, 500].includes(res.status)) return Promise.all([res.json(), res]); if ([400, 404, 500].includes(res.status)) return Promise.all([res.json(), res]);
// If response status is not equal to 204, 400, 404, 500, go to catch.
throw new Error('알 수 없는 응답입니다.'); throw new Error('알 수 없는 응답입니다.');
}) })
.then((values) => { .then((values) => {
const [json, res] = values; const [json, res] = values;
// If trainee successfully deleted and response status is equal to 204,
// update trainee list.
if (res.status === 204) return this.getTraineeList(); if (res.status === 204) return this.getTraineeList();
// Otherwise, go to catch.
throw new Error(json.message); throw new Error(json.message);
}) })
.catch((e) => { .catch((e) => {
this.error.message = e.message; this.error.message = e.message;
this.error.isError = true; this.error.isError = true;
})
.finally(() => {
this.isProcessing = false;
}); });
}, },
}, },
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment