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

complate

parent 4f7a21d8
File moved
File moved
File moved
File moved
File moved
File moved
File moved
File moved
File moved
File moved
File moved
File moved
File moved
File moved
File moved
File moved
File moved
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);
}
File moved
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 express = require('express');
const userRoutes = require('./user.route'); const userRoutes = require('./user.route');
const reviewRoutes = require('./review.route'); const postRoutes = require('./post.route');
const authRoutes = require('./auth.route'); const authRoutes = require('./auth.route');
const router = express.Router(); // eslint-disable-line new-cap const router = express.Router(); // eslint-disable-line new-cap
...@@ -12,6 +12,6 @@ router.get('/health-check', (req, res) => ...@@ -12,6 +12,6 @@ router.get('/health-check', (req, res) =>
router.use('/auth', authRoutes); router.use('/auth', authRoutes);
router.use('/user', userRoutes); router.use('/user', userRoutes);
router.use('/review', reviewRoutes); router.use('/post', postRoutes);
module.exports = router; 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);
}
File moved
...@@ -23,21 +23,21 @@ ...@@ -23,21 +23,21 @@
<use xlink:href="#icon-pinned"></use> <use xlink:href="#icon-pinned"></use>
</svg> </svg>
<strong> {{ reviewAdd.namemovie}}</strong> <strong> {{ postAdd.title}}</strong>
</a></h6> </a></h6>
<div class="row align-items-center no-gutters"> <div class="row align-items-center no-gutters">
<div class="col-11"> <div class="col-11">
<ul class="tt-list-badge"> <ul class="tt-list-badge">
<li class="show-mobile"><a href="#"><span <li class="show-mobile"><a href="#"><span
class="tt-color01 tt-badge">politics</span></a></li> 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> </ul>
</div> </div>
</div> </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>
<div class="tt-item"> <div class="tt-item">
...@@ -48,7 +48,7 @@ ...@@ -48,7 +48,7 @@
</div> </div>
<div class="tt-col-description"> <div class="tt-col-description">
<h6 class="tt-title"><a > <h6 class="tt-title"><a >
{{ reviewAdd.title}} {{ postAdd.title}}
</a></h6> </a></h6>
<div class="row align-items-center no-gutters hide-desktope"> <div class="row align-items-center no-gutters hide-desktope">
<div class="col-11"> <div class="col-11">
...@@ -72,8 +72,8 @@ ...@@ -72,8 +72,8 @@
<div class="tt-value-wrapper"> <div class="tt-value-wrapper">
<input type="text" matInput <input type="text" matInput
placeholder="Placeholder" placeholder="Placeholder"
name="namemovie" name="title"
[(ngModel)]="reviewAdd.namemovie" class="form-control" id="inputTopicTitle" placeholder="Subject of your topic"> [(ngModel)]="postAdd.title" class="form-control" id="inputTopicTitle" placeholder="Subject of your topic">
<span class="tt-value-input">99</span> <span class="tt-value-input">99</span>
</div> </div>
<div class="tt-note">Describe your topic well, while keeping the subject as short as possible.</div> <div class="tt-note">Describe your topic well, while keeping the subject as short as possible.</div>
...@@ -90,13 +90,13 @@ ...@@ -90,13 +90,13 @@
<textarea matInput <textarea matInput
placeholder="Placeholder" placeholder="Placeholder"
name="title" 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>
<div class="row"> <div class="row">
<div class="col-md-4"> <div class="col-md-4">
<div class="form-group"> <div class="form-group">
<label for="inputTopicTitle">Category</label> <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" <option value="option"
*ngFor="let catagory of catagorys" *ngFor="let catagory of catagorys"
[value]="catagory.type" [value]="catagory.type"
...@@ -108,19 +108,19 @@ ...@@ -108,19 +108,19 @@
<div class="col-md-8"> <div class="col-md-8">
<div class="form-group"> <div class="form-group">
<label for="inputTopicTags">Tags</label> <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>
</div> </div>
<div class="row"> <div class="row">
<div class="col-auto ml-md-auto"> <div class="col-auto ml-md-auto">
<a (click)="submitReviewAdd()" <a (click)="submitPostAdd()"
color="primary" color="primary"
*ngIf=" *ngIf="
reviewAdd.catagory && postAdd.category &&
reviewAdd.namemovie && postAdd.title &&
reviewAdd.title && postAdd.body &&
reviewAdd.description postAdd.tag
" class="btn btn-secondary btn-width-lg">Create Post</a> " class="btn btn-secondary btn-width-lg">Create Post</a>
</div> </div>
</div> </div>
......
import { Component, OnInit , Input} from '@angular/core'; import { Component, OnInit , Input} from '@angular/core';
import { catagory } from '../../catagory'; import { category } from '../../category';
import { CreateService } from '../service/create.service'; import { CreateService } from '../service/create.service';
import { AuthService } from '@app/shared/services'; import { AuthService } from '@app/shared/services';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
...@@ -12,36 +12,40 @@ import { User } from '@app/shared/interfaces'; ...@@ -12,36 +12,40 @@ import { User } from '@app/shared/interfaces';
export class CreateComponent implements OnInit { export class CreateComponent implements OnInit {
@Input() user: User | null = null; @Input() user: User | null = null;
user_data: any; user_data: any;
reviewAdd = { postAdd = {
'user_id': '', 'user_id': '',
'user_name': '',
'catagory': '', 'category': '',
'namemovie': '',
'title': '', 'title': '',
'description': '' 'body': '',
'tag': '',
'createdAt': '',
}; };
catagorys = catagory; catagorys = category;
constructor(private createService: CreateService, private authService: AuthService ,private router: Router,) { } constructor(private createService: CreateService, private authService: AuthService ,private router: Router,) { }
ngOnInit(): void { ngOnInit(): void {
this.authService.getUser().subscribe(data => this.user_data = data); this.authService.getUser().subscribe(data => this.user_data = data);
this.reviewAdd = { this.postAdd = {
'user_id': this.user_data._id, 'user_id': this.user_data._id,
'user_name': this.user_data.fullname,
'catagory': '', 'category': '',
'namemovie': '',
'title': '', 'title': '',
'description': '' 'body': '',
'tag': '',
'createdAt': this.user_data.createAt,
}; };
} }
submitReviewAdd() { submitPostAdd() {
this.createService.postReview(this.reviewAdd).subscribe((response: {}) => this.createService.postPost(this.postAdd).subscribe((response: {}) =>
{alert('บันทึกเรียบร้อย'), {alert('บันทึกเรียบร้อย'),
this.router.navigateByUrl('/'); this.router.navigateByUrl('/');
} }
); );
console.warn(this.createService.postReview(this.reviewAdd)); console.warn(this.createService.postPost(this.postAdd));
console.warn(this.reviewAdd); console.warn(this.postAdd);
}; };
......
...@@ -23,21 +23,21 @@ ...@@ -23,21 +23,21 @@
<svg class="tt-icon"> <svg class="tt-icon">
<use xlink:href="#icon-pinned"></use> <use xlink:href="#icon-pinned"></use>
</svg> </svg>
<strong> {{ data.namemovie}}</strong> <strong> {{ data.title}}</strong>
</a></h6> </a></h6>
<div class="row align-items-center no-gutters"> <div class="row align-items-center no-gutters">
<div class="col-11"> <div class="col-11">
<ul class="tt-list-badge"> <ul class="tt-list-badge">
<li class="show-mobile"><a href="#"><span <li class="show-mobile"><a href="#"><span
class="tt-color01 tt-badge">politics</span></a></li> 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> </ul>
</div> </div>
</div> </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>
<div class="tt-item"> <div class="tt-item">
...@@ -72,8 +72,8 @@ ...@@ -72,8 +72,8 @@
<div class="tt-value-wrapper"> <div class="tt-value-wrapper">
<input type="text" matInput <input type="text" matInput
placeholder="Placeholder" placeholder="Placeholder"
name="namemovie" name="title"
[(ngModel)]="data.namemovie" class="form-control" id="inputTopicTitle" placeholder="Subject of your topic"> [(ngModel)]="data.title" class="form-control" id="inputTopicTitle" placeholder="Subject of your topic">
<span class="tt-value-input">99</span> <span class="tt-value-input">99</span>
</div> </div>
<div class="tt-note">Describe your topic well, while keeping the subject as short as possible.</div> <div class="tt-note">Describe your topic well, while keeping the subject as short as possible.</div>
...@@ -90,17 +90,17 @@ ...@@ -90,17 +90,17 @@
<textarea matInput <textarea matInput
placeholder="Placeholder" placeholder="Placeholder"
name="title" 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>
<div class="row"> <div class="row">
<div class="col-md-4"> <div class="col-md-4">
<div class="form-group"> <div class="form-group">
<label for="inputTopicTitle">Category</label> <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" <option value="option"
*ngFor="let catagory of catagorys" *ngFor="let category of categorys"
[value]="catagory.type" [value]="category.type"
>{{ catagory.type }}</option> >{{ category.type }}</option>
</select> </select>
</div> </div>
...@@ -108,7 +108,7 @@ ...@@ -108,7 +108,7 @@
<div class="col-md-8"> <div class="col-md-8">
<div class="form-group"> <div class="form-group">
<label for="inputTopicTags">Tags</label> <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> </div>
</div> </div>
...@@ -117,10 +117,10 @@ ...@@ -117,10 +117,10 @@
<a (click)="submitUpdate()" <a (click)="submitUpdate()"
color="primary" color="primary"
*ngIf=" *ngIf="
data.catagory && data.category &&
data.namemovie &&
data.title && data.title &&
data.description data.body &&
data.tag
" class="btn btn-primary btn-width-lg">Update Post</a> " class="btn btn-primary btn-width-lg">Update Post</a>
</div> </div>
</div> </div>
......
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { catagory } from '../../catagory'; import { category } from '../../category';
import { EditService } from '../service/edit.service'; import { EditService } from '../service/edit.service';
import { ActivatedRoute } from '@angular/router'; import { ActivatedRoute } from '@angular/router';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
...@@ -9,7 +9,7 @@ import { Router } from '@angular/router'; ...@@ -9,7 +9,7 @@ import { Router } from '@angular/router';
styleUrls: ['./edit.component.css'] styleUrls: ['./edit.component.css']
}) })
export class EditComponent implements OnInit { export class EditComponent implements OnInit {
catagorys = catagory; categorys = category;
dataId: any; dataId: any;
data: any; data: any;
constructor(private route: ActivatedRoute, private editService: EditService,private router: Router) { } constructor(private route: ActivatedRoute, private editService: EditService,private router: Router) { }
...@@ -18,7 +18,7 @@ export class EditComponent implements OnInit { ...@@ -18,7 +18,7 @@ export class EditComponent implements OnInit {
this.route.paramMap.subscribe(params => { this.route.paramMap.subscribe(params => {
this.dataId = params.get('dataId'); this.dataId = params.get('dataId');
}); });
this.editService.getReviewsById(this.dataId).subscribe(response => { this.editService.getPostsById(this.dataId).subscribe(response => {
this.data = response[0]; this.data = response[0];
console.log(this.data); console.log(this.data);
}); });
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
<!-- /toggle mobile menu --> <!-- /toggle mobile menu -->
<!-- logo --> <!-- logo -->
<div class="tt-logo" *ngIf="!user"> <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>
<div class="tt-logo" *ngIf="user"> <div class="tt-logo" *ngIf="user">
<a routerLink="/"><img src="../../assets/images/logo.png" alt=""></a> <a routerLink="/"><img src="../../assets/images/logo.png" alt=""></a>
...@@ -37,11 +37,11 @@ ...@@ -37,11 +37,11 @@
<!-- /logo --> <!-- /logo -->
<!-- desctop menu --> <!-- desctop menu -->
<div class="tt-desktop-menu" *ngIf="!user"> <div class="tt-desktop-menu" *ngIf="!user">
<nav id="tt-desktop-m enu" > <nav id="tt-desktop-menu" >
<ul> <ul>
<li><a routerLink="/cate"><span>Categories</span></a></li> <li><a routerLink="/"><span>Categories</span></a></li>
<li><a routerLink="/about"><span>About</span></a></li> <li><a routerLink="/"><span>About</span></a></li>
</ul> </ul>
</nav> </nav>
...@@ -50,8 +50,8 @@ ...@@ -50,8 +50,8 @@
<nav id="tt-desktop-menu" > <nav id="tt-desktop-menu" >
<ul> <ul>
<li><a routerLink="/create"><span>Create-Topic</span></a></li> <li><a routerLink="/create"><span>Create-Topic</span></a></li>
<li><a routerLink="/cate"><span>Categories</span></a></li> <li><a routerLink="/"><span>Categories</span></a></li>
<li><a routerLink="/about"><span>About</span></a></li> <li><a routerLink="/"><span>About</span></a></li>
</ul> </ul>
</nav> </nav>
...@@ -80,7 +80,10 @@ ...@@ -80,7 +80,10 @@
</svg> </svg>
</button> </button>
</div> </div>
<div class="search-results">
<button type="button" class="tt-view-all" data-toggle="modal" data-target="#modalAdvancedSearch">Advanced Search</button>
</div>
</form> </form>
</div> </div>
<!-- /tt-search --> <!-- /tt-search -->
...@@ -106,41 +109,27 @@ ...@@ -106,41 +109,27 @@
<div class="col-auto ml-auto"> <div class="col-auto ml-auto" *ngIf="user">
<div class="tt-user-info d-flex justify-content-center" *ngIf="user">
<div class="tt-desktop-menu">
<i>{{ user.fullname }}</i>
</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()"> <div class="tt-avatar-icon tt-size-md">
<i class="tt-btn-icon"><svg> <mat-icon class="tt-avatar-icon tt-size-md">account_circle</mat-icon>
<use xlink:href="#icon-exit"></use>
</svg>LogOut</i>
</div> </div>
<!-- <div class="custom-select-01" > <div>
<a class="links side" *ngIf="user" [matMenuTriggerFor]="menu">
{{ user.fullname }} {{ user.fullname }}
<select > </a>
<option >{{ user.fullname }}</option> <mat-menu #menu="matMenu">
<option *ngIf="user?.isAdmin" routerLink="/admin">admin</option> <button mat-menu-item *ngIf="user?.isAdmin" routerLink="/admin">admin</button>
<option routerLink="logout()" (click)="logout()">logout</option> <button mat-menu-item (click)="logout()">logout</button>
</mat-menu>
</div>
</select>
<div routerLink="logout()" (click)="logout()">LogOut</div>
</div> -->
</div> </div>
</div> </div>
</div> </div>
......
...@@ -6,40 +6,42 @@ ...@@ -6,40 +6,42 @@
<div class="tt-topic-list" > <div class="tt-topic-list" >
<div class="tt-list-header" > <div class="tt-list-header" >
<div class="tt-col-topic">Topic</div> <div class="tt-col-topic">Topic</div>
<div class="tt-col-category">Category</div> <div class="tt-col-category">Category</div>
<div class="tt-col-value hide-mobile">Likes</div> <div class="tt-col-value hide-mobile">Likes</div>
<div class="tt-col-value hide-mobile">Views</div> <div class="tt-col-value hide-mobile">Views</div>
<div class="tt-col-value">Activity</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 == post.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" >Delete</div> -->
</div> </div>
<div class="tt-item tt-itemselect" *ngFor="let review of reviews"> <div class="tt-item tt-itemselect" *ngFor="let post of posts">
<div class="tt-col-avatar">
<svg class="tt-icon">
<use xlink:href="#icon-ava-k"></use>
</svg>
</div>
<div class="tt-col-description"> <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"> <svg class="tt-icon">
<use xlink:href="#icon-pinned"></use> <use xlink:href="#icon-pencil"></use>
</svg> </svg><strong >{{ post.title }} </strong>
<strong>{{ review.namemovie }}</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> </a></h1>
<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>
<div class="row align-items-center no-gutters"> <div class="row align-items-center no-gutters">
<div class="col-11"> <div class="col-11">
<ul class="tt-list-badge"> <ul class="tt-list-badge">
<li class="show-mobile"><a href="#"><span <li class="show-mobile"><a ><span
class="tt-color05 tt-badge">{{ review.catagory }}</span></a></li> class="tt-color01 tt-badge">{{ post.category }}</span></a></li>
<li><a ><span class="tt-badge">#{{ review.description }}</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> </ul>
</div> </div>
...@@ -47,13 +49,13 @@ ...@@ -47,13 +49,13 @@
</div> </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">985</div>
<div class="tt-col-value hide-mobile">25 k</div> <div class="tt-col-value hide-mobile">33 </div>
<div class="tt-col-value hide-mobile">{{ review.createdAt | date }}</div> <div class="tt-col-value hide-mobile">{{ post.createdAt |date: "HH:M:s d-mm-yyyy" }} </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 [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(review._id)" class="tt-col-value btn btn-primary btn-width-lg" *ngIf="user_data._id == review.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> </div>
...@@ -69,7 +71,8 @@ ...@@ -69,7 +71,8 @@
</div> </div>
</div> </div>
</main> </main>
<a routerLink="/create" class="tt-btn-create-topic" >
<a routerLink="/create" class="tt-btn-create-topic">
<span class="tt-icon"> <span class="tt-icon">
<svg> <svg>
<use xlink:href="#icon-create_new"></use> <use xlink:href="#icon-create_new"></use>
......
import { Component, OnInit, Input } from '@angular/core'; import { Component, OnInit, Input } from '@angular/core';
import { HomeService } from '../service/home.service'; import { HomeService } from '../service/home.service';
import { catagory } from '../../catagory'; import { category } from '../../category';
import { AuthService } from '@app/shared/services'; import { AuthService } from '@app/shared/services';
@Component({ @Component({
...@@ -9,9 +9,9 @@ import { AuthService } from '@app/shared/services'; ...@@ -9,9 +9,9 @@ import { AuthService } from '@app/shared/services';
styleUrls: ['./home.component.scss'] styleUrls: ['./home.component.scss']
}) })
export class HomeComponent implements OnInit { export class HomeComponent implements OnInit {
reviews: any; posts: any;
user_data: any; user_data: any;
catagorys = catagory;
constructor(private homeService: HomeService, private authService: AuthService) { } constructor(private homeService: HomeService, private authService: AuthService) { }
...@@ -20,8 +20,8 @@ export class HomeComponent implements OnInit { ...@@ -20,8 +20,8 @@ export class HomeComponent implements OnInit {
this.authService.getUser().subscribe(data => this.user_data = data); this.authService.getUser().subscribe(data => this.user_data = data);
} }
fetchData() { fetchData() {
this.homeService.getReviews().subscribe(response => { this.homeService.getPosts().subscribe(response => {
this.reviews = response; this.posts = response;
}); });
} }
pageroute(data: any) { pageroute(data: any) {
...@@ -30,7 +30,7 @@ export class HomeComponent implements OnInit { ...@@ -30,7 +30,7 @@ export class HomeComponent implements OnInit {
deleteData(data: any) { deleteData(data: any) {
console.log(data); console.log(data);
this.homeService.deleteReview(data).subscribe((response: {}) => alert('ลบเรียบร้อย')); this.homeService.deletePost(data).subscribe((response: {}) => alert('ลบเรียบร้อย'));
this.fetchData(); this.fetchData();
} }
} }
...@@ -6,7 +6,7 @@ import { Observable } from 'rxjs'; ...@@ -6,7 +6,7 @@ import { Observable } from 'rxjs';
providedIn: 'root' providedIn: 'root'
}) })
export class CreateService { export class CreateService {
baseUrl = 'http://localhost:4040/api/review'; baseUrl = 'http://localhost:4040/api/post';
constructor(public http: HttpClient) { } constructor(public http: HttpClient) { }
...@@ -16,7 +16,7 @@ export class CreateService { ...@@ -16,7 +16,7 @@ export class CreateService {
'Accept': 'application/json' '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); return this.http.post<any>(`${this.baseUrl}`, JSON.stringify(data), this.httpOptions);
} }
} }
...@@ -6,7 +6,7 @@ import { Observable } from 'rxjs'; ...@@ -6,7 +6,7 @@ import { Observable } from 'rxjs';
providedIn: 'root' providedIn: 'root'
}) })
export class EditService { export class EditService {
baseUrl = 'http://localhost:4040/api/review'; baseUrl = 'http://localhost:4040/api/post';
constructor(public http: HttpClient) { } constructor(public http: HttpClient) { }
...@@ -17,7 +17,7 @@ export class EditService { ...@@ -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}`); return this.http.get<any>(`${this.baseUrl}/get/${_id}`);
} }
......
...@@ -6,7 +6,7 @@ import { Observable } from 'rxjs'; ...@@ -6,7 +6,7 @@ import { Observable } from 'rxjs';
providedIn: 'root' providedIn: 'root'
}) })
export class HomeService { export class HomeService {
baseUrl = 'http://localhost:4040/api/review'; baseUrl = 'http://localhost:4040/api/post';
constructor(public http: HttpClient) { } constructor(public http: HttpClient) { }
...@@ -16,10 +16,10 @@ export class HomeService { ...@@ -16,10 +16,10 @@ export class HomeService {
'Accept': 'application/json' 'Accept': 'application/json'
}) })
}; };
getReviews(): Observable<any> { getPosts(): Observable<any> {
return this.http.get<any>(`${this.baseUrl}/all`); 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); return this.http.delete<any>(`${this.baseUrl}/delete/${data}`, this.httpOptions);
} }
} }
...@@ -6,7 +6,7 @@ import { Observable } from 'rxjs'; ...@@ -6,7 +6,7 @@ import { Observable } from 'rxjs';
providedIn: 'root' providedIn: 'root'
}) })
export class ViewdataService { export class ViewdataService {
baseUrl = 'http://localhost:4040/api/review'; baseUrl = 'http://localhost:4040/api/post';
constructor(public http: HttpClient) { } constructor(public http: HttpClient) { }
...@@ -16,11 +16,14 @@ export class ViewdataService { ...@@ -16,11 +16,14 @@ export class ViewdataService {
'Accept': 'application/json' 'Accept': 'application/json'
}) })
}; };
getReviews(): Observable<any> { getPosts(): Observable<any> {
return this.http.get<any>(`${this.baseUrl}/all`); 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); 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"> <main id="tt-pageContent">
<div class="container"> <div class="container">
<div class="tt-single-topic-list"> <div class="tt-single-topic-list" >
<div class="tt-item"> <div class="tt-item">
<div class="tt-single-topic"> <div class="tt-single-topic">
<div class="tt-item-header"> <div class="tt-item-header">
<div class="tt-item-info info-top"> <div class="tt-item-info info-top">
<div class="tt-avatar-icon"> <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>
<div class="tt-avatar-title"> <div class="tt-avatar-title">
<a >{{ data._id }}</a> <strong class="tt-color11 tt-badge">{{ data.user_name }}</strong>
</div> </div>
<a href="#" class="tt-info-time"> <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> </a>
</div> </div>
<h2 class="tt-item-title"> <h2 class="tt-item-title">
<a ><strong>{{ data.namemovie}}</strong></a> <h1 >{{ data.title}}</h1>
</h2> </h2>
<div class="tt-item-tag"> <div class="tt-item-tag">
<ul class="tt-list-badge"> <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">themeforest</span></a></li>
<li><a href="#"><span class="tt-badge">elements</span></a></li> --> <li><a href="#"><span class="tt-badge">elements</span></a></li> -->
</ul> </ul>
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
<div class="tt-item-description"> <div class="tt-item-description">
<p> <p>
{{ data.title }} {{ data.body }}
</p> </p>
</div> </div>
...@@ -64,7 +64,8 @@ ...@@ -64,7 +64,8 @@
<h4 class="tt-title-separator"><span>สามารถแสดงความคิดเห็นได้</span></h4> <h4 class="tt-title-separator"><span>สามารถแสดงความคิดเห็นได้</span></h4>
</div> </div>
<div class="tt-item"> <!-- <div class="tt-item"> -->
<div class="tt-single-topic"> <div class="tt-single-topic">
<div class="tt-item-description"> <div class="tt-item-description">
...@@ -101,7 +102,7 @@ ...@@ -101,7 +102,7 @@
<div class="col-separator"></div> <div class="col-separator"></div>
<a href="#" class="tt-icon-btn tt-hover-02 tt-small-indent"> <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> <i class="tt-icon"><svg><use xlink:href="#icon-time"></use></svg></i>
6 Jan,2019 6 Jan,2019 {{ data.createAt|json}}
</a> </a>
</div> </div>
...@@ -109,11 +110,11 @@ ...@@ -109,11 +110,11 @@
</div> </div>
</div> </div>
<div class="container">
<div class="tt-single-topic-list" >
<div class="tt-wrapper-inner"> <div class="tt-wrapper-inner">
<div class="pt-editor form-default"> <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"> <div class="form-group">
<textarea name="message" class="form-control" rows="5" placeholder="Lets get started"></textarea> <textarea name="message" class="form-control" rows="5" placeholder="Lets get started"></textarea>
...@@ -136,5 +137,5 @@ ...@@ -136,5 +137,5 @@
</div> </div>
</div> </div>
</div> </div></div>
</main> </main>
\ No newline at end of file
...@@ -2,7 +2,7 @@ import { Component, OnInit } from '@angular/core'; ...@@ -2,7 +2,7 @@ import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router'; import { ActivatedRoute } from '@angular/router';
import { create } from 'domain'; import { create } from 'domain';
import { ViewdataService } from '../service/viewdata.service'; import { ViewdataService } from '../service/viewdata.service';
import { catagory } from '../../catagory'; import { category } from '../../category';
import { AuthService } from '@app/shared/services'; import { AuthService } from '@app/shared/services';
@Component({ @Component({
selector: 'app-viewdata', selector: 'app-viewdata',
...@@ -10,20 +10,23 @@ import { AuthService } from '@app/shared/services'; ...@@ -10,20 +10,23 @@ import { AuthService } from '@app/shared/services';
styleUrls: ['./viewdata.component.css'] styleUrls: ['./viewdata.component.css']
}) })
export class ViewdataComponent implements OnInit { export class ViewdataComponent implements OnInit {
constructor(private route: ActivatedRoute, private reviewdataService: ViewdataService,private authService: AuthService) { }
dataId: any; dataId: any;
data: any; data: any;
user_data: any; user_data: any;
catagorys = catagory;
constructor(private route: ActivatedRoute, private postdataService: ViewdataService,private authService: AuthService) { }
ngOnInit(): void { ngOnInit(): void {
console.warn(this.user_data);
this.authService.getUser().subscribe(data => this.user_data = data); this.authService.getUser().subscribe(data => this.user_data = data);
this.route.paramMap.subscribe(params => { this.route.paramMap.subscribe(params => {
this.dataId = params.get('dataId'); this.dataId = params.get('dataId');
}); });
this.reviewdataService.getReviewsById(this.dataId).subscribe(response => { this.postdataService.getPostsById(this.dataId).subscribe(response => {
this.data = response[0]; this.data = response[0];
console.warn(this.data); console.warn("data at all : ",this.data);
}); });
......
File moved
export const catagory = [ export const category = [
{ {
type: 'การบ้านการเมือง', type: 'การบ้านการเมือง',
}, },
......
File moved
File moved
File moved
File moved
File moved
File moved
File moved
File moved
File moved
File moved
File moved
File moved
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 Student = require('../server/models/student.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 students = [
{ sid: 60112233440, first: 'ชูใจ', last: 'เลิศล้ำ' },
{ sid: 60112233441, first: 'มานี', last: 'รักเผ่าไทย' },
{ sid: 60112233442, first: 'ปิติ', last: 'พิทักษ์ถิ่น' },
{ sid: 60112233443, first: 'มานะ', last: 'รักเผ่าไทย' },
{ sid: 60112233444, first: 'วีระ', last: 'ประสงค์สุข' }
];
Student.insertMany(students, (error, docs) => {
if (error) {
console.error(error);
} else {
console.log(docs);
}
mongoose.connection.close();
});
header {
width: 100%;
.logo {
background-image: url('../../assets/logo.png');
width: 50px;
height: 50px;
background-size: contain;
background-repeat: no-repeat;
}
.example-spacer {
flex: 1 1 auto;
}
.links {
color: white;
font-family: 'Helvetica Neue', sans-serif;
font-size: 15px;
font-weight: initial;
letter-spacing: -1px;
line-height: 1;
text-align: center;
padding: 15px;
&.side {
padding: 0 14px;
}
}
.mat-toolbar {
background: black;
}
.mat-icon {
vertical-align: middle;
margin: 0 5px;
}
a {
cursor: pointer;
}
}
\ No newline at end of file
.example-icon {
padding: 0 14px;
}
.example-spacer {
flex: 1 1 auto;
}
.example-card {
width: 400px;
margin: 10% auto;
}
.mat-card-title {
font-size: 16px;
}
table {
border-collapse: collapse;
width: 100%;
}
th,
td {
padding: 8px;
text-align: center;
border-bottom: 1px solid #ddd;
}
\ No newline at end of file
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