diff --git a/index/src/app/view/admin/services/article/article.service.ts b/index/src/app/view/admin/services/article/article.service.ts deleted file mode 100644 index 6d38494..0000000 --- a/index/src/app/view/admin/services/article/article.service.ts +++ /dev/null @@ -1,48 +0,0 @@ -import {Injectable} from '@angular/core'; -import {HttpService} from '../http.service'; -import {PageList} from "../../../../class/HttpReqAndResp"; -import {Article} from "../../../../class/Article"; -import {exist} from "../../../../utils/dataUtil"; - -@Injectable({ - providedIn: 'root' -}) -export class ArticleService { - - - constructor(public http: HttpService) { - } - - // 存储所有已经请求过的数据<首页数据> - pageList: PageList
[] = []; - - currentPage: PageList
; - - /** - * 获取文章 - * @param pageNum 页码数 - * @param pageSize 单页数据量 - */ - getArticle(pageNum: number, pageSize: number) { - const articlePage = exist
(pageNum, pageSize, this.pageList); - if (articlePage) { - articlePage.subscribe(data => { - this.currentPage = data; - }); - return articlePage; - } - const observable = this.http.get('/admin/articles?page=' + pageNum + '&count=' + pageSize); - observable.subscribe(data => { - if (data.code === 0) { - this.currentPage = data.result; - this.pageList.push(data.result); - } - }); - return observable; - } - - deleteArticle(id) { - return this.http.delete('/admin/article/del?articleID=' + id); - } - -} diff --git a/index/src/app/view/admin/services/category/category.service.ts b/index/src/app/view/admin/services/category/category.service.ts deleted file mode 100644 index bfc7b9b..0000000 --- a/index/src/app/view/admin/services/category/category.service.ts +++ /dev/null @@ -1,56 +0,0 @@ -import {Injectable} from '@angular/core'; -import {HttpService} from '../http.service'; -import {Category} from '../../classes/category'; - -@Injectable({ - providedIn: 'root' -}) -export class CategoryService { - - // FIXME : !!!!!!!!!!!!!!!!!!数据处理全部放到一个模块中!!!!!!!!!!!!!!!!!! - constructor(public http: HttpService) { - } - - categories: Category[]; - - getAllCategory() { - const observable = this.http.get('/categories'); - observable.subscribe((data) => { - if (data.code === 0) { - this.categories = data.result; - } - } - ); - return observable; - } - - update(submitBody: { id: number, name: string }) { - return this.http.put('/admin/category/update', submitBody, false); - } - - create(nameStr: string) { - const observable = this.http.post('/admin/category/create', {name: nameStr}, false); - observable.subscribe(data => { - if (data.code === 0) { - this.categories.push(data.result); - } - }); - return observable; - } - - delete(id: number) { - const observable = this.http.delete(`/admin/category/del?id=${id}`); - observable.subscribe(data => { - if (data.code === 0) { - // tslint:disable-next-line:prefer-for-of - for (let i = 0; i < this.categories.length; i++) { - if (this.categories[i].id === id) { - this.categories.splice(i, 1); - } - } - } - }); - return observable; - } - -} diff --git a/index/src/app/view/admin/services/comment/comment.service.ts b/index/src/app/view/admin/services/comment/comment.service.ts deleted file mode 100644 index 5448ebc..0000000 --- a/index/src/app/view/admin/services/comment/comment.service.ts +++ /dev/null @@ -1,98 +0,0 @@ -import {Injectable} from '@angular/core'; -import {HttpService} from '../http.service'; -import {Page} from '../../classes/page'; -import {Comment} from '../../classes/comment'; -import {exist} from '../../utils/dataUtil'; -import {CommentReq} from "../../classes/commentReq"; - -@Injectable({ - providedIn: 'root' -}) -export class CommentService { - - constructor(public http: HttpService) { - } - - // 存放 - leaveMsgPage: Page[] = []; - - commentPage: Page[] = []; - - currentComment: Page; - - currentLeaveMsg: Page; - - /** - * 获取 评论 - * @param pageNum 页码 - * @param pageSize 单页数据数量 - * @param isAdmin 是否是管理员 - */ - getComments(pageNum: number, pageSize: number, isAdmin: boolean) { - const exist1 = exist(pageNum, pageSize, this.commentPage); - if (exist1) { - exist1.subscribe(data => { - this.currentComment = data; - }); - return exist1; - } - const observable = this.http.get(`/${isAdmin ? 'admin' : 'user'}/comment/type/1?count=${pageSize}&page=${pageNum}`); - observable.subscribe(data => { - if (data.code === 0) { - this.commentPage.unshift(data.result); - this.currentComment = data.result; - } - }); - return observable; - } - - /** - * 获取 留言 - * @param pageNum 页码 - * @param pageSize 单页数据数量 - * @param isAdmin 是否是管理员 - */ - getLeaveMsg(pageNum: number, pageSize: number, isAdmin: boolean) { - const exist1 = exist(pageNum, pageSize, this.leaveMsgPage); - if (exist1) { - exist1.subscribe(data => { - this.currentLeaveMsg = data; - }); - return exist1; - } - const observable = this.http.get(`/${isAdmin ? 'admin' : 'user'}/comment/type/0?count=${pageSize}&page=${pageNum}`); - observable.subscribe(data => { - if (data.code === 0) { - this.leaveMsgPage.unshift(data.result); - this.currentLeaveMsg = data.result; - } - }); - return observable; - } - - /** - * 回复评论/留言 - * @param responseComment 请求体 - */ - rely(responseComment: CommentReq) { - return this.http.post('/user/comment/create', responseComment, true); - } - - /** - * 通过父评论 获取回复 - * @param pid 父评论id - */ - getByPid(pid: number) { - return this.http.get('/comment/pid/' + pid + '?count=5&page=1'); - } - - update(subComment) { - return this.http.put('/user/comment/update', subComment); - } - - delete(id: number) { - return this.http.delete('/user/comment/del?id=' + id); - } - - -} diff --git a/index/src/app/view/admin/services/link/link.service.ts b/index/src/app/view/admin/services/link/link.service.ts deleted file mode 100644 index 334900b..0000000 --- a/index/src/app/view/admin/services/link/link.service.ts +++ /dev/null @@ -1,39 +0,0 @@ -import {Injectable} from '@angular/core'; -import {HttpService} from '../http.service'; -import {Link} from '../../classes/link'; -import {Page} from '../../classes/page'; - -@Injectable({ - providedIn: 'root' -}) -export class LinkService { - - constructor(public http: HttpService) { - } - - // 不采取存储page[] :: 数据量较少 - public currentPage: Page; - - getLinks(pageNum: number, pageSize: number) { - const observable = this.http.get(`/admin/links?page=${pageNum}&count=${pageSize}`); - observable.subscribe(data => { - if (data.code === 0) { - this.currentPage = data.result; - } - }); - return observable; - } - - update(submitBody: Link) { - return this.http.put('/admin/links/update', submitBody, true); - } - - create(submitBody: Link) { - submitBody.id = null; - return this.http.post('/admin/links/create', submitBody, true); - } - - delete(id) { - return this.http.delete(`/admin/links/del/${id}`); - } -} diff --git a/index/src/app/view/admin/services/log/log.service.ts b/index/src/app/view/admin/services/log/log.service.ts deleted file mode 100644 index 6ba2892..0000000 --- a/index/src/app/view/admin/services/log/log.service.ts +++ /dev/null @@ -1,22 +0,0 @@ -import {Injectable} from '@angular/core'; -import {HttpService} from '../http.service'; - -@Injectable({ - providedIn: 'root' -}) -export class LogService { - - constructor(private http: HttpService) { - } - - logText: string; - - getLog() { - // @ts-ignore - const observable = this.http.httpClient.get('https://api.celess.cn/blog.log', {responseType: 'text'}); - observable.subscribe(data => { - this.logText = data; - }); - return observable; - } -} diff --git a/index/src/app/view/admin/services/tag/tag.service.ts b/index/src/app/view/admin/services/tag/tag.service.ts deleted file mode 100644 index 080a95c..0000000 --- a/index/src/app/view/admin/services/tag/tag.service.ts +++ /dev/null @@ -1,43 +0,0 @@ -import {Injectable} from '@angular/core'; -import {HttpService} from '../http.service'; -import {Tag} from '../../classes/tag'; -import {Page} from '../../classes/page'; -import {exist} from '../../utils/dataUtil'; - -@Injectable({ - providedIn: 'root' -}) -export class TagService { - - constructor(public http: HttpService) { - } - - tagPages: Page[] = []; - currentTagPage: Page; - - getTags(pageNum: number, pageSize: number) { - const exist1 = exist(pageNum, pageSize, this.tagPages); - if (exist1) { - exist1.subscribe(data => { - this.currentTagPage = data; - }); - return exist1; - } - const observable = this.http.get(`/tags?count=${pageSize}&page=${pageNum}`); - observable.subscribe(data => { - if (data.code === 0) { - this.currentTagPage = data.result; - this.tagPages.unshift(data.result); - } - }); - } - - update(id: number, name: string) { - return this.http.put(`/admin/tag/update?id=${id}&name=${name}`, null); - } - - delete(id: number) { - return this.http.delete(`/admin/tag/del?id=${id}`); - } - -} diff --git a/index/src/app/view/admin/services/update/web-update.service.ts b/index/src/app/view/admin/services/update/web-update.service.ts deleted file mode 100644 index 7042a14..0000000 --- a/index/src/app/view/admin/services/update/web-update.service.ts +++ /dev/null @@ -1,48 +0,0 @@ -import {Injectable} from '@angular/core'; -import {HttpService} from '../http.service'; -import {UpdateInfo} from '../../classes/updateInfo'; -import {Page} from '../../classes/page'; - -@Injectable({ - providedIn: 'root' -}) -export class WebUpdateService { - - constructor(public http: HttpService) { - } - - public updateInfoList: Page; - - public lastestUpdateTime: string; - - getUpdateInfo(pageNum: number, pageSize: number) { - const observable = this.http.get(`/webUpdate/pages?page=${pageNum}&count=${pageSize}`); - observable.subscribe((data: any) => { - if (data.code === 0) { - this.updateInfoList = data.result; - } - }); - return observable; - } - - getLastestUpdateTime() { - this.http.get('/lastestUpdateTime').subscribe(data => { - if (data.code === 0) { - this.lastestUpdateTime = data.result; - } - }) - } - - - update(submitBody: { id: number, info: string }) { - return this.http.put('/admin/webUpdate/update', submitBody, false); - } - - create(infoStr: string) { - return this.http.post('/admin/webUpdate/create', {info: infoStr}, false); - } - - delete(id: number) { - return this.http.delete(`/admin/webUpdate/del/${id}`); - } -} diff --git a/index/src/app/view/admin/services/user/user.service.ts b/index/src/app/view/admin/services/user/user.service.ts deleted file mode 100644 index 3da2711..0000000 --- a/index/src/app/view/admin/services/user/user.service.ts +++ /dev/null @@ -1,90 +0,0 @@ -import {Injectable} from '@angular/core'; -import {HttpService} from '../http.service'; -import {User} from '../../classes/user'; -import {Page} from '../../classes/page'; -import {exist} from '../../utils/dataUtil'; - -@Injectable({ - providedIn: 'root' -}) -export class UserService { - - userInfo: User; - - avatarHost: string = 'http://cdn.celess.cn'; - - constructor(public http: HttpService) { - } - - userPage: Page[] = []; - currentUserPage: Page; - - /** - * 获取用户信息 - */ - getUserInfo() { - return this.http.get('/user/userInfo'); - } - - /** - * 注销登录 - */ - logout() { - this.http.get('/logout').subscribe((data: any) => { - if (data.code === 0) { - this.userInfo = null; - this.http.removeToken(); - } - }); - } - - - updateInfo(submitBody: { desc: string, displayName: string }) { - const observable = this.http.put('/user/userInfo/update', submitBody, false); - observable.subscribe(data => { - if (data.code === 0) { - this.userInfo.desc = submitBody.desc; - this.userInfo.displayName = submitBody.displayName; - } - }); - return observable; - } - - - sendEmail() { - return this.http.post('/sendVerifyEmail', {email: this.userInfo.email}, false); - } - - /** - * 获取分页数据 - * @param pageNum 页码 - * @param pageSize 单页数据量 - * @param refresh 是否强制刷新 - */ - getPageUser(pageNum: number, pageSize: number, refresh: boolean = false) { - const existData = exist(pageNum, pageSize, this.userPage); - if (existData && !refresh) { - existData.subscribe(data => { - this.currentUserPage = data; - }); - } - this.http.get(`/admin/users?page=${pageNum}&count=${pageSize}`).subscribe(data => { - if (data.code === 0) { - this.currentUserPage = data.result; - this.userPage.unshift(data.result); - } - }); - } - - delete(id: number) { - return this.http.delete(`/admin/user/delete/${id}`); - } - - update(user: User) { - return this.http.put('/admin/user', user, true); - } - - getExistOfEmail(email: string) { - return this.http.get(`/emailStatus/${email}`); - } -} diff --git a/index/src/app/view/admin/services/visitor/visitor.service.ts b/index/src/app/view/admin/services/visitor/visitor.service.ts deleted file mode 100644 index 2f0937d..0000000 --- a/index/src/app/view/admin/services/visitor/visitor.service.ts +++ /dev/null @@ -1,76 +0,0 @@ -import {Injectable} from '@angular/core'; -import {HttpService} from '../http.service'; -import {Page} from '../../classes/page'; -import {Visitor} from '../../classes/visitor'; - -@Injectable({ - providedIn: 'root' -}) -export class VisitorService { - - constructor(public http: HttpService) { - } - - public pageList: Page[] = []; - public currentPage: Page; - - public dayVisit: number; - public totalVisitCount: number; - - private ipLocationList: { ip: string, location: string }[] = []; - - getVisitor(pageNum: number, pageSize: number) { - const observable = this.http.get(`/admin/visitor/page?count=${pageSize}&page=${pageNum}&showLocation=false`); - observable.subscribe(data => { - if (data.code === 0) { - this.pageList.unshift(data.result); - this.currentPage = data.result; - } - }); - } - - getDayVisitor() { - this.http.get('/dayVisitCount').subscribe(data => { - if (data.code === 0) { - this.dayVisit = data.result; - } - }); - } - - getTotalVisitorCount() { - this.http.get('/visitor/count').subscribe(data => { - this.totalVisitCount = data.result; - }); - } - - - getIp(ip: string) { - const location = this.exist(ip); - if (location) { - return location; - } - const observable = this.http.get(`/ip/${ip}`); - observable.subscribe(data => { - if (data.code === 0) { - this.ipLocationList.unshift(data.result); - } - }); - return observable; - } - - getLocalIp() { - return this.http.get('/ip'); - } - - private exist(ip): string { - if (this.ipLocationList.length === 0) { - return null; - } - // tslint:disable-next-line:prefer-for-of - for (let i = 0; i < this.ipLocationList.length; i++) { - if (this.ipLocationList[i].ip === ip) { - return this.ipLocationList[i].location; - } - } - } -}