import {Injectable} from '@angular/core'; import {Article, ArticleReq} from '../class/Article'; import {HttpService} from './http/http.service'; import {PageList} from '../class/HttpReqAndResp'; import {Category, Tag} from '../class/Tag'; import {Comment, CommentReq} from '../class/Comment'; import {ApplyLinkReq, Link} from '../class/Link'; import {LoginReq, User} from '../class/User'; import {Visitor} from '../class/Visitor'; import {UpdateInfo} from '../class/UpdateInfo'; @Injectable({ providedIn: 'root' }) export class ApiService { constructor(private httpService: HttpService) { } createArticle(article: ArticleReq) { article.id = null; return this.httpService.service
({ path: '/admin/article/create', contentType: 'application/json', method: 'POST', data: article }); } deleteArticle(id: number) { return this.httpService.service({ path: '/admin/article/del', method: 'DELETE', queryParam: {articleID: id} }); } articles(pageNumber: number = 1, pageSize: number = 5) { return this.httpService.service>({ path: '/articles', method: 'GET', queryParam: { page: pageNumber, count: pageSize } }); } adminArticles(pageNumber: number = 1, pageSize: number = 10) { return this.httpService.service>({ path: '/admin/articles', method: 'GET', queryParam: { page: pageNumber, count: pageSize } }); } updateArticle(article: ArticleReq) { return this.httpService.service
({ path: '/admin/article/update', method: 'PUT', contentType: 'application/json', data: article }); } getArticle(articleId: number, is4Update: boolean = false) { return this.httpService.service
({ path: `/article/articleID/${articleId}`, method: 'GET', queryParam: {update: is4Update}, }); } articlesByCategory(category: string, pageNumber: number = 1, pageSize: number = 10) { return this.httpService.service>({ path: `/articles/category/${category}`, method: 'GET', queryParam: { page: pageNumber, count: pageSize } }); } articlesByTag(tag: string, pageNumber: number = 1, pageSize: number = 10) { return this.httpService.service>({ path: `/articles/tag/${tag}`, method: 'GET', queryParam: { page: pageNumber, count: pageSize } }); } categories() { return this.httpService.service>({ path: '/categories', method: 'GET' }); } createCategory(nameStr: string) { return this.httpService.service({ path: '/admin/category/create', method: 'POST', queryParam: {name: nameStr} }); } deleteCategory(categoryId: number) { return this.httpService.service({ path: '/admin/category/del', method: 'DELETE', queryParam: {id: categoryId} }); } updateCategory(categoryId: number, nameStr: string) { return this.httpService.service({ path: '/admin/category/update', method: 'PUT', queryParam: {id: categoryId, name: nameStr} }); } tags(pageNumber: number = 1, pageSize: number = 10) { return this.httpService.service>({ path: '/tags', method: 'GET', queryParam: { page: pageNumber, count: pageSize } }); } tagsNac() { return this.httpService.service<{ name: string; size: number }[]>({ path: '/tags/nac', method: 'GET' }); } createTag(nameStr: string) { return this.httpService.service({ path: '/admin/tag/create', method: 'POST', queryParam: {name: nameStr} }); } deleteTag(tagId: number) { return this.httpService.service({ path: '/admin/tag/del', method: 'DELETE', queryParam: {id: tagId} }); } updateTag(tagId: number, nameStr: string) { return this.httpService.service({ path: '/admin/tag/update', method: 'PUT', queryParam: {id: tagId, name: nameStr} }); } getCommentByTypeForAdmin(pagePath: string, pageNumber: number = 1, pageSize: number = 10) { return this.httpService.service>({ path: `/admin/comment/pagePath/${pagePath}`, method: 'GET', queryParam: { page: pageNumber, count: pageSize } }); } getCommentByTypeForUser(pagePath: string, pageNumber: number = 1, pageSize: number = 10) { return this.httpService.service>({ path: `/user/comment/pagePath/${pagePath}`, method: 'GET', queryParam: { page: pageNumber, count: pageSize } }); } deleteComment(idNumer: number) { return this.httpService.service({ path: `/user/comment/del`, method: 'DELETE', queryParam: {id: idNumer} }); } updateComment(commentReq: CommentReq) { return this.httpService.service({ path: `/user/comment/update`, method: 'PUT', data: commentReq, contentType: 'application/json' }); } comments(pagePath: string, pageSize: number = 10, pageNumber: number = 1) { return this.httpService.service>({ path: `/comment/pagePath/${pagePath}`, method: 'GET', queryParam: { count: pageSize, page: pageNumber } }); } createComment(commentReq: CommentReq) { return this.httpService.service({ path: '/user/comment/create', method: 'POST', contentType: 'application/json', data: commentReq }); } counts() { return this.httpService.service<{ articleCount: number; visitorCount: number; categoryCount: number; tagCount: number; commentCount: number; }>({ path: '/counts', method: 'GET' }); } adminLinks(pageSize: number = 10, pageNumber: number = 1) { return this.httpService.service>({ path: '/admin/links', method: 'GET', queryParam: { count: pageSize, page: pageNumber } }); } createLink(linkReq: Link) { return this.httpService.service({ path: '/admin/links/create', method: 'POST', data: linkReq, contentType: 'application/json' }); } deleteLink(idNumber: number) { return this.httpService.service({ path: `/admin/links/del/${idNumber}`, method: 'DELETE', }); } updateLink(linkReq: Link) { return this.httpService.service({ path: '/admin/links/update', method: 'PUT', data: linkReq, contentType: 'application/json' }); } applyLink(link: ApplyLinkReq) { return this.httpService.service({ path: '/apply', method: 'POST', data: link, contentType: 'application/json' }); } reapplyLink(keyStr: string) { return this.httpService.service({ path: '/reapply', method: 'POST', queryParam: { key: keyStr } }); } links() { return this.httpService.service({ path: '/links', method: 'GET', }); } verifyImgCode(codeStr: string) { return this.httpService.service({ path: '/verCode', method: 'POST', queryParam: {code: codeStr} }); } login(loginReq: LoginReq) { return this.httpService.service({ path: '/login', method: 'POST', contentType: 'application/json', data: loginReq }); } logout() { return this.httpService.service({ path: '/logout', method: 'GET', }); } registration(emailStr: string, pwd: string) { return this.httpService.service({ path: '/registration', method: 'POST', queryParam: { email: emailStr, password: pwd } }); } resetPwd(idStr: string, emailStr: string, pwdStr: string) { return this.httpService.service({ path: '/resetPwd', method: 'POST', queryParam: { verifyId: idStr, email: emailStr, pwd: pwdStr } }); } emailVerify(idStr: string, emailStr: string) { return this.httpService.service({ path: '/emailVerify', method: 'POST', queryParam: { verifyId: idStr, email: emailStr } }); } sendResetPwdEmail(emailStr: string) { return this.httpService.service({ path: '/sendResetPwdEmail', method: 'POST', queryParam: {email: emailStr} }); } sendVerifyEmail(emailStr: string) { return this.httpService.service({ path: '/sendVerifyEmail', method: 'POST', queryParam: {email: emailStr} }); } userInfo() { return this.httpService.service({ path: '/user/userInfo', method: 'GET', }); } adminUpdateUser(user: User) { return this.httpService.service({ path: '/admin/user', method: 'PUT', data: user, contentType: 'application/json' }); } deleteUser(id: number) { return this.httpService.service({ path: `/admin/user/delete/${id}`, method: 'DELETE', }); } multipleDeleteUser(idArray: number[]) { return this.httpService.service<{ id: number; msg: string; status: boolean }[]>({ path: `/admin/user/delete`, method: 'DELETE', data: idArray, contentType: 'application/json' }); } // 获取邮件是否已注册 emailStatus(email: string) { return this.httpService.service({ path: `/emailStatus/${email}`, method: 'GET' }); } updateUserInfo(descStr: string, disPlayNameStr: string) { return this.httpService.service({ path: '/user/userInfo/update', method: 'PUT', queryParam: { desc: descStr, displayName: disPlayNameStr } }); } adminUsers(pageSize: number = 10, pageNumber: number = 1) { return this.httpService.service>({ path: '/admin/users', method: 'GET', queryParam: { count: pageSize, page: pageNumber } }); } visit() { return this.httpService.service({ path: '/visit', method: 'POST' }); } adminVisitors(location: boolean = false, pageSize: number = 10, pageNumber: number = 1) { return this.httpService.service>({ path: '/admin/visitor/page', method: 'GET', queryParam: { count: pageSize, page: pageNumber, showLocation: location } }); } dayVisitCount() { return this.httpService.service({ path: '/dayVisitCount', method: 'GET', }); } getLocalIp() { return this.httpService.service({ path: '/ip', method: 'GET', }); } getIpLocation(ip: string) { return this.httpService.service({ path: `/ip/${ip}`, method: 'GET', }); } visitorCount() { return this.httpService.service({ path: `/visitor/count`, method: 'GET', }); } webUpdate() { return this.httpService.service<{ id: number; info: string; time: string }[]>({ path: '/webUpdate', method: 'GET' }); } webUpdatePage(pageSize: number = 10, pageNumber: number = 1) { return this.httpService.service>({ path: '/webUpdate/pages', method: 'GET', queryParam: { count: pageSize, page: pageNumber, } }); } lastestUpdate() { return this.httpService.service<{ lastUpdateTime: string; lastUpdateInfo: string; lastCommit: string; committerAuthor: string; committerDate: string; commitUrl: string; }>({ path: '/lastestUpdate', method: 'GET' }); } createWebUpdateInfo(infoStr: string) { return this.httpService.service({ path: '/admin/webUpdate/create', method: 'POST', queryParam: {info: infoStr} }); } deleteWebUpdateInfo(idNumber: number) { return this.httpService.service({ path: `/admin/webUpdate/del/${idNumber}`, method: 'DELETE', }); } updateWebUpdateInfo(idNumber: number, infoStr: string) { return this.httpService.service({ path: '/admin/webUpdate/update', method: 'PUT', queryParam: {id: idNumber, info: infoStr} }); } bingPic() { return this.httpService.service({ path: '/bingPic', method: 'GET' }); } setPwd(pwdStr: string, newPwdStr: string, confirmPwdStr: string,) { return this.httpService.service({ path: '/user/setPwd', method: 'POST', queryParam: { pwd: pwdStr, newPwd: newPwdStr, confirmPwd: confirmPwdStr, } }); } }