StickyBoard
Search
K
Comment on page

Back-end Customization

Database

You have to set your own relational database(MySQL or MariaDB) to use StickyBoard.
You can change database end-point by modifying .env file.
When you run StickyBoard, it will create default tables below.
ERD of StickyBoard

API

You can add your own API to StickyBoard back-end server.
Let's see how you can add custom API.
First of all, you must create route file like below.
You would add Sequelize query or other processing method here.
src/models/MySQL/UserLayoutRoute.js
var StatusCode = require('../../../../../network/StatusCode');
var UserLayout = require('../UserLayout')
var User = require('../User')
var UserLayoutRoute = {
// Create
create: function (req, res) {
var userId = req.params.userId;
var route = req.body.route;
var layout = req.body.layout;
UserLayout.find({
where: {
user_id: userId,
route: route,
}
})
.then(function (result) {
if (result !== null) {
res.status(StatusCode.CONFLICT).json({msg: 'Error'})
} else {
UserLayout.create({
user_id: userId,
route: route,
layout: layout,
})
.then(function (result) {
res.json(result)
})
.catch(function (err) {
console.log(err)
})
}
})
},
// Read
read: function (req, res) {
...
},
// Update
update: function (req, res) {
...
},
// Delete
delete: function (req, res) {
...
}
}
module.exports = UserLayoutRoute
And next, import the route file and add a routing code like below.
app.js
...
var UserLayoutRoute = require('./src/database/models/MySQL/User/routes/UserLayoutRoute');
...
var router = Express.Router();
/******************
API routing
******************/
...
// User Layout
router.post('/user/:userId/layout/$', function (req, res) { UserLayoutRoute.create(req, res) });
router.get('/user/:userId/layout/$', function (req, res) { UserLayoutRoute.read(req, res) });
router.put('/user/:userId/layout/$', function (req, res) { UserLayoutRoute.update(req, res) });
router.delete('/user/:userId/layout/$', function (req, res) { UserLayoutRoute.delete(req, res) });
...
It's all done! Test your newly added API.