diff --git a/api/archives.js b/api/archives.js
new file mode 100644
index 0000000..263f6cc
--- /dev/null
+++ b/api/archives.js
@@ -0,0 +1,58 @@
+/*
+This file contains all endpoints related to archives
+*/
+
+var Articles = require('../models/article.js');
+var Topics = require('../models/topic.js');
+var Archives = require('../models/archive.js');
+var Users = require('../models/user.js');
+
+var db = require('../db.js'); //this file contains the knex file import. it's equal to knex=require('knex')
+
+module.exports = function(app){
+ app.get('/archives/:id/',function(req,res){
+ /*
+ This is a GET endpoint that responds with one article of the specific ID (identified through the ID param)
+ the article is present in the data object in the returning object.
+ the error key in the returning object is a boolen which is false if there is no error and true otherwise
+ */
+ Archives.forge({id: req.params.id})
+ .fetch()
+ .then(function (archive) {
+ console.log("ARCHIVE=================================");
+ console.log(archive);
+ Users.forge({id: archive.attributes.user_id}).fetch().then(function(user){
+ archiveObj = archive.toJSON();
+ userObj = user.toJSON();
+ archiveObj.user = {
+ id: userObj.id,
+ name: userObj.name,
+ email: userObj.email,
+ about: userObj.about
+ };
+ })
+ .then(function(){
+ res.json({
+ error: {
+ error: false,
+ message: ''
+ },
+ code: 'B113',
+ data: archiveObj
+ });
+ })
+ })
+ .catch(function (error) {
+ res.status(500).json({
+ error: {
+ error: true,
+ message: error.message
+ },
+ code: 'B114',
+ data: {
+
+ }
+ });
+ });
+ });
+}
diff --git a/client/app/index.jsx b/client/app/index.jsx
index dc233e9..5694ecf 100644
--- a/client/app/index.jsx
+++ b/client/app/index.jsx
@@ -10,6 +10,7 @@ import Product from './static/product.jsx';
import Article from './static/article.jsx';
import NewArticle from './static/new.jsx';
import EditArticle from './static/edit.jsx';
+import ArticleHistory from './static/history.jsx';
render(
{this.state.article.user.about}
Edit + History diff --git a/client/app/static/browse_archives.jsx b/client/app/static/browse_archives.jsx new file mode 100644 index 0000000..f69ba19 --- /dev/null +++ b/client/app/static/browse_archives.jsx @@ -0,0 +1,75 @@ +import React from 'react'; +import Error from './error.jsx'; +import Loader from './loader.jsx'; +import {hashHistory} from 'react-router'; + +class BrowseArchives extends React.Component { + constructor(props) { + super(props); + this.archiveSelect = this.archiveSelect.bind(this); + this.state = {error: "", archives: []}; + } + + componentDidMount() { + console.log("Component Mounted!"); + var myHeaders = new Headers({ + "Content-Type": "application/x-www-form-urlencoded", + "x-access-token": localStorage.getItem('userToken') + }); + var myInit = { method: 'GET', + headers: myHeaders, + }; + var that = this; + var url = '/api/articles/'+this.props.articleId+'/history'; + fetch(url,myInit) + .then(function(response) { + console.log(response); + return response.json(); + }) + .then(function(response) { + if(response.error.error) + that.setState({error: response.error.message}) + else { + that.setState({archives: response.data}) + console.log(that.state.archives); + } + console.log(response); + }); + } + + archiveSelect(id,e) { + e.preventDefault(); + this.props.archiveChange(id) + } + + + render () { + if(this.state.error) { + returnPlease select the archive