Commit 554b71ae authored by Kriengkrai Yothee's avatar Kriengkrai Yothee

complate

parent 4f7a21d8
const mongoose = require('mongoose');
const util = require('util');
const debug = require('debug')('express-mongoose-es6-rest-api:index');
const config = require('../server/config/config');
const Post = require('../server/models/post.model');
// connect to mongo db
const mongoUri = config.mongo.host;
mongoose.connect(mongoUri, { keepAlive: 1 });
mongoose.connection.on('error', () => {
throw new Error(`unable to connect to database: ${mongoUri}`);
});
const posts = [
{ _id: ObjectID(),user_id: ObjectID('5f9705b44394c80bd85c3299'), user_name: 'born',category: 'เม่ามอย', title: 'เราเจอคนหนึ่่งในวิทยาการคอมพ์',body: "สายตาคนทั่วๆไป อยากระบายว่า คนที่สอบเข้ามาเนี่ย จะมีซักกี่% ... 1 สาขา เขียนโปรแกรมแทบไม่เป็นนะครับ แต่ทุกวันนี้ก็ได้ดิบได้ดีทางสายคอมพ์ ... ส่วนตัวเจอมาแบบนี้เลยรู้สึกไม่ดีกับพวก เรียนจบเกรดสูงสักเท่าไหร่ ... เราทำไม่ได้อ่ะ เพราะไม่ชอบเขียนโปรแกรม" ,tag: "comsci",createdAt:Date.now},
{ _id: ObjectID(),user_id: ObjectID('5f9705b44394c80bd85c3299'), user_name: 'born',category: 'การบ้านการเมือง', title: 'ออกไปปราหยุด' ,body:"ส.ส. ฝ่ายค้านเกือบทุกรายที่ลุกขึ้นอภิปรายกลางรัฐสภา ได้ รับลูก หนึ่งในข้อเสนอของผู้ชุมนุมต่อต้านรัฐบาล ด้วยการเรียกร้องให้ พล.อ. ประยุทธ์ จันทร์โอชา นายกรัฐมนตรี และ รมว.กลาโหม ลาออกจากตำแหน่ง ขณะที่รองนายกฯ มือกฎหมายของรัฐบาลขู่อาจพบทางตัน หากระดมเสียงในรัฐสภาได้ไม่ถึง 366 เสียงเพื่อโหวตเลือกนายกฯ เล็งแก้เกมกลับด้วยการโยนประชาชนตัดสินผ่านกลไกประชามติ",tag:'ออกเถอะ',createdAt:Date.now},
{ _id: ObjectID(),user_id: ObjectID('5f9705b44394c80bd85c3299'), user_name: 'born',category: 'การเรียนและความรู้', title: 'nodeJs ดีอ่ะ',body: 'Angular is a TypeScript-based open-source web application framework led by the Angular Team at Google and by a community of individuals and corporations. Angular is a complete rewrite from the same team that built AngularJS.',tag:'angular',createdAt:Date.now},
{ _id: ObjectID(),user_id: ObjectID('5f9705b44394c80bd85c3299'), user_name: 'born', category: 'ความรัก', title: 'เจอกันที่บ้านเพื่อน',body: 'เรื่องของเรื่องก็คือว่า พ่อแม่ของฉันเจ้ากี้เจ้าการและเป็นห่วงฉันมากจนเกินไปแทบจะตลอดชีวิตที่ผ่านมา ตอนเป็นเด็ก ฉันไม่เคยได้รับอนุญาตให้ไปเล่นบ้านเพื่อนเลย',tag:'',createdAt:Date.now},
{ _id: ObjectID(),user_id: ObjectID('5f9705b44394c80bd85c3299'), user_name: 'born',category: 'ชีวะประวัติ', title: 'Mark Elliot Zuckerberg' ,body: 'โดยปกติแล้ว มาร์คนั้น มีความสนใจเกี่ยวกับเรื่องคอมพิวเตอร์ตั้งแต่วัยเด็ก เมื่ออายุได้เพียงสิบขวบต้น ๆ ช่วงประถมปลายเขาก็สามารถเขียนโปรแกรมคอมพิวเตอร์ได้แล้ว โดยมาร์คได้เริ่มใช้ทักษะการเขียนโปรแกรมนี้ให้คุณพ่อของเขาไปใช้ในคลินิกทันตกรรม โดยสร้างโปรแกรมแชทขึ้นมา โดยใช้ชื่อว่า ZuckNet ทำให้พนักงานภายในคลีนิค สามารถสื่อสารกันเองแทนการตะโกนบอกกัน และในช่วงมัธยมต้นเขาก็สามารถเขียนเกมขึ้นมาเล่นเองได้อีกด้วย',tag:'Facebook',createdAt:Date.now},
];
// user_id: { type: String, required: true },
// user_name: { type: String, required: true },
// category: { type: String, required: true },
// title: { type: String, required: true },
// body: { type: String, required: true },
// tag: { type: String, required: true },
// createdAt: { type: Date, default: Date.now },
Post.insertMany(posts, (error, docs) => {
if (error) {
console.error(error);
} else {
console.log(docs);
}
mongoose.connection.close();
});
const Joi = require("joi");
const Post = require("../models/post.model");
const postSchema = Joi.object({
// sid: Joi.number().integer().required(),
user_id: Joi.string().required(),
user_name: Joi.string().required(),
category: Joi.string().required(),
title: Joi.string().required(),
body: Joi.string().required(),
tag: Joi.string().required(),
});
module.exports = {
insert,
get,
getAll,
search,
deleteData,
updateData,
};
async function insert(post) {
post = await Joi.validate(post, postSchema, { abortEarly: false });
return await new Post(post).save();
}
/**
* อ่านเพิ่มเติม https://mongoosejs.com/docs/api.html
*/
async function get(_id) {
return await Post.find({ _id: _id });
}
async function getAll() {
return await Post.find();
}
async function search(key, value) {
let query = {};
query[key] = value;
return await Post.find(query);
}
async function deleteData(_id) {
return await Post.findByIdAndDelete(_id);
}
async function updateData(_id,data) {
return Post.findByIdAndUpdate(_id, data);
}
const mongoose = require("mongoose");
/**
* อ่านเพิ่มเติม https://mongoosejs.com/docs/guide.html
*/
const PostSchema = new mongoose.Schema(
{
user_id: { type: String, required: true },
user_name: { type: String, required: true },
category: { type: String, required: true },
title: { type: String, required: true },
body: { type: String, required: true },
tag: { type: String, required: true },
createdAt: { type: Date, default: Date.now },
},
{
versionKey: false,
}
);
module.exports = mongoose.model("Post", PostSchema);
const express = require('express');
const userRoutes = require('./user.route');
const reviewRoutes = require('./review.route');
const postRoutes = require('./post.route');
const authRoutes = require('./auth.route');
const router = express.Router(); // eslint-disable-line new-cap
......@@ -12,6 +12,6 @@ router.get('/health-check', (req, res) =>
router.use('/auth', authRoutes);
router.use('/user', userRoutes);
router.use('/review', reviewRoutes);
router.use('/post', postRoutes);
module.exports = router;
const express = require('express');
const asyncHandler = require('express-async-handler');
const postCtrl = require('../controllers/post.controller');
const router = express.Router();
module.exports = router;
//router.use(passport.authenticate('jwt', { session: false }))
router.route('/').post(asyncHandler(insert));
router.route('/get/:_id').get(asyncHandler(get));
router.route('/all').get(asyncHandler(getAll));
router.route('/search').get(asyncHandler(search));
router.route('/delete/:_id').delete(asyncHandler(deleteData));
router.route('/update/:_id').put(asyncHandler(updateData));
async function insert(req, res) {
let post = await postCtrl.insert(req.body);
res.json(post);
}
async function get(req, res) {
let all_posts = await postCtrl.get(req.params['_id']);
res.json(all_posts);
}
async function getAll(req, res) {
let all_posts = await postCtrl.getAll();
res.json(all_posts);
}
async function search(req, res) {
let result = await postCtrl.search(req.params['key'], req.params['value']);
res.json(result);
}
async function deleteData(req, res) {
let all_posts = await postCtrl.deleteData(req.params['_id']);
res.json(all_posts);
}
async function updateData(req, res) {
let all_posts = await postCtrl.updateData(req.params['_id'],req.body);
res.json(all_posts);
}
......@@ -23,21 +23,21 @@
<use xlink:href="#icon-pinned"></use>
</svg>
<strong> {{ reviewAdd.namemovie}}</strong>
<strong> {{ postAdd.title}}</strong>
</a></h6>
<div class="row align-items-center no-gutters">
<div class="col-11">
<ul class="tt-list-badge">
<li class="show-mobile"><a href="#"><span
class="tt-color01 tt-badge">politics</span></a></li>
<li><a href="#"><span class="tt-badge">#{{reviewAdd.description}}</span></a></li>
<li><a href="#"><span class="tt-badge">#{{postAdd.tag}}</span></a></li>
</ul>
</div>
</div>
</div>
<div class="tt-col-category"><span class="tt-color01 tt-badge">{{ reviewAdd.catagory }}</span></div>
<div class="tt-col-category"><span class="tt-color01 tt-badge">{{ postAdd.category }}</span></div>
</div>
<div class="tt-item">
......@@ -48,7 +48,7 @@
</div>
<div class="tt-col-description">
<h6 class="tt-title"><a >
{{ reviewAdd.title}}
{{ postAdd.title}}
</a></h6>
<div class="row align-items-center no-gutters hide-desktope">
<div class="col-11">
......@@ -72,8 +72,8 @@
<div class="tt-value-wrapper">
<input type="text" matInput
placeholder="Placeholder"
name="namemovie"
[(ngModel)]="reviewAdd.namemovie" class="form-control" id="inputTopicTitle" placeholder="Subject of your topic">
name="title"
[(ngModel)]="postAdd.title" class="form-control" id="inputTopicTitle" placeholder="Subject of your topic">
<span class="tt-value-input">99</span>
</div>
<div class="tt-note">Describe your topic well, while keeping the subject as short as possible.</div>
......@@ -90,13 +90,13 @@
<textarea matInput
placeholder="Placeholder"
name="title"
[(ngModel)]="reviewAdd.title" class="form-control" rows="5" placeholder="Lets get started"></textarea>
[(ngModel)]="postAdd.body" class="form-control" rows="5" placeholder="Lets get started"></textarea>
</div>
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label for="inputTopicTitle">Category</label>
<select class="form-control" [(ngModel)]="reviewAdd.catagory" name="catagory">
<select class="form-control" [(ngModel)]="postAdd.category" name="catagory">
<option value="option"
*ngFor="let catagory of catagorys"
[value]="catagory.type"
......@@ -108,19 +108,19 @@
<div class="col-md-8">
<div class="form-group">
<label for="inputTopicTags">Tags</label>
<input type="text" name="description" [(ngModel)]="reviewAdd.description" class="form-control" id="inputTopicTags" placeholder=" #tags">
<input type="text" name="description" [(ngModel)]="postAdd.tag" class="form-control" id="inputTopicTags" placeholder=" #tags">
</div>
</div>
</div>
<div class="row">
<div class="col-auto ml-md-auto">
<a (click)="submitReviewAdd()"
<a (click)="submitPostAdd()"
color="primary"
*ngIf="
reviewAdd.catagory &&
reviewAdd.namemovie &&
reviewAdd.title &&
reviewAdd.description
postAdd.category &&
postAdd.title &&
postAdd.body &&
postAdd.tag
" class="btn btn-secondary btn-width-lg">Create Post</a>
</div>
</div>
......
import { Component, OnInit , Input} from '@angular/core';
import { catagory } from '../../catagory';
import { category } from '../../category';
import { CreateService } from '../service/create.service';
import { AuthService } from '@app/shared/services';
import { Router } from '@angular/router';
......@@ -12,36 +12,40 @@ import { User } from '@app/shared/interfaces';
export class CreateComponent implements OnInit {
@Input() user: User | null = null;
user_data: any;
reviewAdd = {
postAdd = {
'user_id': '',
'catagory': '',
'namemovie': '',
'user_name': '',
'category': '',
'title': '',
'description': ''
'body': '',
'tag': '',
'createdAt': '',
};
catagorys = catagory;
catagorys = category;
constructor(private createService: CreateService, private authService: AuthService ,private router: Router,) { }
ngOnInit(): void {
this.authService.getUser().subscribe(data => this.user_data = data);
this.reviewAdd = {
this.postAdd = {
'user_id': this.user_data._id,
'catagory': '',
'namemovie': '',
'user_name': this.user_data.fullname,
'category': '',
'title': '',
'description': ''
'body': '',
'tag': '',
'createdAt': this.user_data.createAt,
};
}
submitReviewAdd() {
this.createService.postReview(this.reviewAdd).subscribe((response: {}) =>
submitPostAdd() {
this.createService.postPost(this.postAdd).subscribe((response: {}) =>
{alert('บันทึกเรียบร้อย'),
this.router.navigateByUrl('/');
}
);
console.warn(this.createService.postReview(this.reviewAdd));
console.warn(this.reviewAdd);
console.warn(this.createService.postPost(this.postAdd));
console.warn(this.postAdd);
};
......
......@@ -23,21 +23,21 @@
<svg class="tt-icon">
<use xlink:href="#icon-pinned"></use>
</svg>
<strong> {{ data.namemovie}}</strong>
<strong> {{ data.title}}</strong>
</a></h6>
<div class="row align-items-center no-gutters">
<div class="col-11">
<ul class="tt-list-badge">
<li class="show-mobile"><a href="#"><span
class="tt-color01 tt-badge">politics</span></a></li>
<li><a href="#"><span class="tt-badge">{{data.description}}</span></a></li>
<li><a href="#"><span class="tt-badge">{{data.tag}}</span></a></li>
</ul>
</div>
</div>
</div>
<div class="tt-col-category"><span class="tt-color01 tt-badge">{{ data.catagory }}</span></div>
<div class="tt-col-category"><span class="tt-color01 tt-badge">{{ data.category }}</span></div>
</div>
<div class="tt-item">
......@@ -72,8 +72,8 @@
<div class="tt-value-wrapper">
<input type="text" matInput
placeholder="Placeholder"
name="namemovie"
[(ngModel)]="data.namemovie" class="form-control" id="inputTopicTitle" placeholder="Subject of your topic">
name="title"
[(ngModel)]="data.title" class="form-control" id="inputTopicTitle" placeholder="Subject of your topic">
<span class="tt-value-input">99</span>
</div>
<div class="tt-note">Describe your topic well, while keeping the subject as short as possible.</div>
......@@ -90,17 +90,17 @@
<textarea matInput
placeholder="Placeholder"
name="title"
[(ngModel)]="data.title" class="form-control" rows="5" placeholder="Lets get started"></textarea>
[(ngModel)]="data.body" class="form-control" rows="5" placeholder="Lets get started"></textarea>
</div>
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label for="inputTopicTitle">Category</label>
<select class="form-control" [(ngModel)]="data.catagory" name="catagory">
<select class="form-control" [(ngModel)]="data.category" name="category">
<option value="option"
*ngFor="let catagory of catagorys"
[value]="catagory.type"
>{{ catagory.type }}</option>
*ngFor="let category of categorys"
[value]="category.type"
>{{ category.type }}</option>
</select>
</div>
......@@ -108,7 +108,7 @@
<div class="col-md-8">
<div class="form-group">
<label for="inputTopicTags">Tags</label>
<input type="text" name="description" [(ngModel)]="data.description" class="form-control" id="inputTopicTags" placeholder="Use comma to separate tags">
<input type="text" name="description" [(ngModel)]="data.tag" class="form-control" id="inputTopicTags" placeholder="Use comma to separate tags">
</div>
</div>
</div>
......@@ -117,10 +117,10 @@
<a (click)="submitUpdate()"
color="primary"
*ngIf="
data.catagory &&
data.namemovie &&
data.category &&
data.title &&
data.description
data.body &&
data.tag
" class="btn btn-primary btn-width-lg">Update Post</a>
</div>
</div>
......
import { Component, OnInit } from '@angular/core';
import { catagory } from '../../catagory';
import { category } from '../../category';
import { EditService } from '../service/edit.service';
import { ActivatedRoute } from '@angular/router';
import { Router } from '@angular/router';
......@@ -9,7 +9,7 @@ import { Router } from '@angular/router';
styleUrls: ['./edit.component.css']
})
export class EditComponent implements OnInit {
catagorys = catagory;
categorys = category;
dataId: any;
data: any;
constructor(private route: ActivatedRoute, private editService: EditService,private router: Router) { }
......@@ -18,7 +18,7 @@ export class EditComponent implements OnInit {
this.route.paramMap.subscribe(params => {
this.dataId = params.get('dataId');
});
this.editService.getReviewsById(this.dataId).subscribe(response => {
this.editService.getPostsById(this.dataId).subscribe(response => {
this.data = response[0];
console.log(this.data);
});
......
......@@ -29,7 +29,7 @@
<!-- /toggle mobile menu -->
<!-- logo -->
<div class="tt-logo" *ngIf="!user">
<a ><img src="../../assets/images/logo.png" alt=""></a>
<a routerLink="/auth/login"><img src="../../assets/images/logo.png" alt=""></a>
</div>
<div class="tt-logo" *ngIf="user">
<a routerLink="/"><img src="../../assets/images/logo.png" alt=""></a>
......@@ -37,11 +37,11 @@
<!-- /logo -->
<!-- desctop menu -->
<div class="tt-desktop-menu" *ngIf="!user">
<nav id="tt-desktop-m enu" >
<nav id="tt-desktop-menu" >
<ul>
<li><a routerLink="/cate"><span>Categories</span></a></li>
<li><a routerLink="/about"><span>About</span></a></li>
<li><a routerLink="/"><span>Categories</span></a></li>
<li><a routerLink="/"><span>About</span></a></li>
</ul>
</nav>
......@@ -50,8 +50,8 @@
<nav id="tt-desktop-menu" >
<ul>
<li><a routerLink="/create"><span>Create-Topic</span></a></li>
<li><a routerLink="/cate"><span>Categories</span></a></li>
<li><a routerLink="/about"><span>About</span></a></li>
<li><a routerLink="/"><span>Categories</span></a></li>
<li><a routerLink="/"><span>About</span></a></li>
</ul>
</nav>
......@@ -80,7 +80,10 @@
</svg>
</button>
</div>
<div class="search-results">
<button type="button" class="tt-view-all" data-toggle="modal" data-target="#modalAdvancedSearch">Advanced Search</button>
</div>
</form>
</div>
<!-- /tt-search -->
......@@ -106,41 +109,27 @@
<div class="col-auto ml-auto">
<div class="tt-user-info d-flex justify-content-center" *ngIf="user">
<div class="tt-desktop-menu">
<i>{{ user.fullname }}</i>
<div class="col-auto ml-auto" *ngIf="user">
</div>
<div class="tt-user-info d-flex justify-content-center">
<!-- <div class="tt-avatar-icon tt-size-md ">
<i class="tt-icon "><svg>
<use xlink:href="#icon-ava-u"></use>
</svg></i>
</div> -->
<div class="tt-avatar-icon tt-size-md" (click)="logout()">
<i class="tt-btn-icon"><svg>
<use xlink:href="#icon-exit"></use>
</svg>LogOut</i>
<div class="tt-avatar-icon tt-size-md">
<mat-icon class="tt-avatar-icon tt-size-md">account_circle</mat-icon>
</div>
<!-- <div class="custom-select-01" >
<div>
<a class="links side" *ngIf="user" [matMenuTriggerFor]="menu">
{{ user.fullname }}
<select >
<option >{{ user.fullname }}</option>
<option *ngIf="user?.isAdmin" routerLink="/admin">admin</option>
<option routerLink="logout()" (click)="logout()">logout</option>
</a>
<mat-menu #menu="matMenu">
<button mat-menu-item *ngIf="user?.isAdmin" routerLink="/admin">admin</button>
<button mat-menu-item (click)="logout()">logout</button>
</mat-menu>
</div>
</select>
<div routerLink="logout()" (click)="logout()">LogOut</div>
</div> -->
</div>
</div>
</div>
......
......@@ -6,40 +6,42 @@
<div class="tt-topic-list" >
<div class="tt-list-header" >
<div class="tt-col-topic">Topic</div>
<div class="tt-col-category">Category</div>
<div class="tt-col-value hide-mobile">Likes</div>
<div class="tt-col-value hide-mobile">Views</div>
<div class="tt-col-value">Activity</div>
<!-- <div class="tt-col-value" *ngIf="user_data._id == review.user_id">Edited</div>
<div class="tt-col-value" *ngIf="user_data._id == review.user_id" >Delete</div> -->
<!-- <div class="tt-col-value" *ngIf="user_data._id == post.user_id">Edited</div>
<div class="tt-col-value" *ngIf="user_data._id == post.user_id" >Delete</div> -->
</div>
<div class="tt-item tt-itemselect" *ngFor="let review of reviews">
<div class="tt-col-avatar">
<svg class="tt-icon">
<use xlink:href="#icon-ava-k"></use>
</svg>
</div>
<div class="tt-item tt-itemselect" *ngFor="let post of posts">
<div class="tt-col-description">
<h6 class="tt-title"><a [routerLink]="['/viewdata', review._id]">
<h1 class="tt-title"><a [routerLink]="['/viewdata', post._id]">
<span class="tt-color11 tt-badge"><mat-icon class="tt-avatar-icon">account_circle</mat-icon>: {{ post.user_name }}</span>
<br><br>
<svg class="tt-icon">
<use xlink:href="#icon-pinned"></use>
</svg>
<strong>{{ review.namemovie }}</strong>
<use xlink:href="#icon-pencil"></use>
</svg><strong >{{ post.title }} </strong>
</a> <div [routerLink]="['/edit', review._id]" class="tt-color05 tt-badge btn btn-secondary btn-width-lg" *ngIf="user_data._id == review.user_id">แก้ไข</div>
<div (click)="deleteData(review._id)" class="tt-color06 tt-badge btn btn-primary btn-width-lg" *ngIf="user_data._id == review.user_id">ลบ</div></h6>
</a></h1>
<div class="row align-items-center no-gutters">
<div class="col-11">
<ul class="tt-list-badge">
<li class="show-mobile"><a href="#"><span
class="tt-color05 tt-badge">{{ review.catagory }}</span></a></li>
<li><a ><span class="tt-badge">#{{ review.description }}</span></a></li>
<li class="show-mobile"><a ><span
class="tt-color01 tt-badge">{{ post.category }}</span></a></li>
<li></li>
<li><a ><span class="tt-badge">#{{ post.tag }}</span></a></li>
<li ><a ><span [routerLink]="['/edit', post._id]" class="tt-color05 tt-badge btn btn-secondary btn-width-lg" *ngIf="user_data._id == post.user_id">แก้ไข</span></a></li>
<li ><a ><span (click)="deleteData(post._id)" class="tt-color06 tt-badge btn btn-primary btn-width-lg" *ngIf="user_data._id == post.user_id">ลบ</span></a></li>
</ul>
</div>
......@@ -47,13 +49,13 @@
</div>
<div class="tt-col-category"><span class="tt-color01 tt-badge">{{ review.catagory }}</span></div>
<div class="tt-col-category"><span class="tt-color01 tt-badge">{{ post.category }}</span></div>
<div class="tt-col-value hide-mobile">985</div>
<div class="tt-col-value hide-mobile">25 k</div>
<div class="tt-col-value hide-mobile">{{ review.createdAt | date }}</div>
<!-- <div [routerLink]="['/edit', review._id]" class="tt-col-value btn btn-secondary btn-width-lg" *ngIf="user_data._id == review.user_id">แก้ไข</div>
<div (click)="deleteData(review._id)" class="tt-col-value btn btn-primary btn-width-lg" *ngIf="user_data._id == review.user_id">ลบ</div> -->
<div class="tt-col-value hide-mobile">33 </div>
<div class="tt-col-value hide-mobile">{{ post.createdAt |date: "HH:M:s d-mm-yyyy" }} </div>
<!-- <div [routerLink]="['/edit', post._id]" class="tt-col-value btn btn-secondary btn-width-lg" *ngIf="user_data._id == post.user_id">แก้ไข</div>
<div (click)="deleteData(post._id)" class="tt-col-value btn btn-primary btn-width-lg" *ngIf="user_data._id == post.user_id">ลบ</div> -->
</div>
......@@ -69,7 +71,8 @@
</div>
</div>
</main>
<a routerLink="/create" class="tt-btn-create-topic" >
<a routerLink="/create" class="tt-btn-create-topic">
<span class="tt-icon">
<svg>
<use xlink:href="#icon-create_new"></use>
......
import { Component, OnInit, Input } from '@angular/core';
import { HomeService } from '../service/home.service';
import { catagory } from '../../catagory';
import { category } from '../../category';
import { AuthService } from '@app/shared/services';
@Component({
......@@ -9,9 +9,9 @@ import { AuthService } from '@app/shared/services';
styleUrls: ['./home.component.scss']
})
export class HomeComponent implements OnInit {
reviews: any;
posts: any;
user_data: any;
catagorys = catagory;
constructor(private homeService: HomeService, private authService: AuthService) { }
......@@ -20,8 +20,8 @@ export class HomeComponent implements OnInit {
this.authService.getUser().subscribe(data => this.user_data = data);
}
fetchData() {
this.homeService.getReviews().subscribe(response => {
this.reviews = response;
this.homeService.getPosts().subscribe(response => {
this.posts = response;
});
}
pageroute(data: any) {
......@@ -30,7 +30,7 @@ export class HomeComponent implements OnInit {
deleteData(data: any) {
console.log(data);
this.homeService.deleteReview(data).subscribe((response: {}) => alert('ลบเรียบร้อย'));
this.homeService.deletePost(data).subscribe((response: {}) => alert('ลบเรียบร้อย'));
this.fetchData();
}
}
......@@ -6,7 +6,7 @@ import { Observable } from 'rxjs';
providedIn: 'root'
})
export class CreateService {
baseUrl = 'http://localhost:4040/api/review';
baseUrl = 'http://localhost:4040/api/post';
constructor(public http: HttpClient) { }
......@@ -16,7 +16,7 @@ export class CreateService {
'Accept': 'application/json'
})
};
postReview(data: any): Observable<any> {
postPost(data: any): Observable<any> {
return this.http.post<any>(`${this.baseUrl}`, JSON.stringify(data), this.httpOptions);
}
}
......@@ -6,7 +6,7 @@ import { Observable } from 'rxjs';
providedIn: 'root'
})
export class EditService {
baseUrl = 'http://localhost:4040/api/review';
baseUrl = 'http://localhost:4040/api/post';
constructor(public http: HttpClient) { }
......@@ -17,7 +17,7 @@ export class EditService {
})
};
getReviewsById(_id: any): Observable<any> {
getPostsById(_id: any): Observable<any> {
return this.http.get<any>(`${this.baseUrl}/get/${_id}`);
}
......
......@@ -6,7 +6,7 @@ import { Observable } from 'rxjs';
providedIn: 'root'
})
export class HomeService {
baseUrl = 'http://localhost:4040/api/review';
baseUrl = 'http://localhost:4040/api/post';
constructor(public http: HttpClient) { }
......@@ -16,10 +16,10 @@ export class HomeService {
'Accept': 'application/json'
})
};
getReviews(): Observable<any> {
getPosts(): Observable<any> {
return this.http.get<any>(`${this.baseUrl}/all`);
}
deleteReview(data: any): Observable<any> {
deletePost(data: any): Observable<any> {
return this.http.delete<any>(`${this.baseUrl}/delete/${data}`, this.httpOptions);
}
}
......@@ -6,7 +6,7 @@ import { Observable } from 'rxjs';
providedIn: 'root'
})
export class ViewdataService {
baseUrl = 'http://localhost:4040/api/review';
baseUrl = 'http://localhost:4040/api/post';
constructor(public http: HttpClient) { }
......@@ -16,11 +16,14 @@ export class ViewdataService {
'Accept': 'application/json'
})
};
getReviews(): Observable<any> {
getPosts(): Observable<any> {
return this.http.get<any>(`${this.baseUrl}/all`);
}
getReviewsById(_id: any): Observable<any> {
getPostsById(_id: any): Observable<any> {
return this.http.get<any>(`${this.baseUrl}/get/${_id}`,this.httpOptions);
}
getPostsByFullname(fullname: any): Observable<any> {
return this.http.get<any>(`${this.baseUrl}/get/${fullname}`,this.httpOptions);
}
}
<main id="tt-pageContent">
<div class="container">
<div class="tt-single-topic-list">
<div class="tt-single-topic-list" >
<div class="tt-item">
<div class="tt-single-topic">
<div class="tt-item-header">
<div class="tt-item-info info-top">
<div class="tt-avatar-icon">
<i class="tt-icon"><svg><use xlink:href="#icon-ava-d"></use></svg></i>
<i class="tt-icon"><svg><use xlink:href="#icon-user"></use></svg></i>
</div>
<div class="tt-avatar-title">
<a >{{ data._id }}</a>
<strong class="tt-color11 tt-badge">{{ data.user_name }}</strong>
</div>
<a href="#" class="tt-info-time">
<i class="tt-icon"><svg><use xlink:href="#icon-time"></use></svg></i>{{ data.createAt| date }}
<i class="tt-icon"><svg><use xlink:href="#icon-time"></use></svg></i>{{ data.createAt}}
</a>
</div>
<h2 class="tt-item-title">
<a ><strong>{{ data.namemovie}}</strong></a>
<h1 >{{ data.title}}</h1>
</h2>
<div class="tt-item-tag">
<ul class="tt-list-badge">
<li><a ><span class="tt-color03 tt-badge">#{{ data.description }}</span></a></li>
<li><a ><span class="tt-color03 tt-badge">#{{ data.tag }}</span></a></li>
<!-- <li><a href="#"><span class="tt-badge">themeforest</span></a></li>
<li><a href="#"><span class="tt-badge">elements</span></a></li> -->
</ul>
......@@ -30,7 +30,7 @@
<div class="tt-item-description">
<p>
{{ data.title }}
{{ data.body }}
</p>
</div>
......@@ -64,7 +64,8 @@
<h4 class="tt-title-separator"><span>สามารถแสดงความคิดเห็นได้</span></h4>
</div>
<div class="tt-item">
<!-- <div class="tt-item"> -->
<div class="tt-single-topic">
<div class="tt-item-description">
......@@ -101,7 +102,7 @@
<div class="col-separator"></div>
<a href="#" class="tt-icon-btn tt-hover-02 tt-small-indent">
<i class="tt-icon"><svg><use xlink:href="#icon-time"></use></svg></i>
6 Jan,2019
6 Jan,2019 {{ data.createAt|json}}
</a>
</div>
......@@ -109,11 +110,11 @@
</div>
</div>
<div class="container">
<div class="tt-single-topic-list" >
<div class="tt-wrapper-inner">
<div class="pt-editor form-default">
<h6 class="pt-title">Post Your Reply</h6>
<h6 class="pt-title">Post Your Commant</h6>
<div class="form-group">
<textarea name="message" class="form-control" rows="5" placeholder="Lets get started"></textarea>
......@@ -136,5 +137,5 @@
</div>
</div>
</div>
</div></div>
</main>
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment