-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #994 from UniversityOfHelsinkiCS/trunk
tags, trasferredFrom and feature toggled shit away
- Loading branch information
Showing
10 changed files
with
272 additions
and
26 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
...backend/oodikone2-backend/src/database/migrations_kone/20190606_02_create_student_tags.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
const router = require('express').Router() | ||
const Tags = require('../services/tags') | ||
const TagStudent = require('../services/tagstudent') | ||
|
||
router.get('/tags', async (req, res) => { | ||
try { | ||
const tags = await Tags.findTags() | ||
res.status(200).json(tags) | ||
} catch (err) { | ||
console.log(err) | ||
res.status(400).json(err) | ||
} | ||
}) | ||
|
||
router.post('/tags', async (req, res) => { | ||
const { tag } = req.body | ||
try { | ||
const result = await Tags.createNewTag(tag) | ||
res.status(200).json(result) | ||
} catch (err) { | ||
console.log(err) | ||
res.status(400).json(err.message) | ||
} | ||
}) | ||
|
||
router.get('/studenttags', async (req, res) => { | ||
try { | ||
const result = await TagStudent.getStudentTags() | ||
res.status(200).json(result) | ||
} catch (err) { | ||
console.log(err) | ||
res.status(400).json(err) | ||
} | ||
}) | ||
|
||
router.post('/studenttags', async (req,res) => { | ||
console.log('trying to post?') | ||
}) | ||
|
||
module.exports = router |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const Sequelize = require('sequelize') | ||
const { Tag } = require('../models') | ||
|
||
const Op = Sequelize.Op | ||
|
||
const findTags = () => Tag.findAll({}) | ||
|
||
const createNewTag = async (tag) => { | ||
return Tag.create(tag) | ||
} | ||
|
||
module.exports = { | ||
createNewTag, | ||
findTags | ||
} |
8 changes: 8 additions & 0 deletions
8
services/backend/oodikone2-backend/src/services/tagstudent.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
const Sequelize = require('sequelize') | ||
const { TagStudent } = require('../models') | ||
|
||
const getStudentTags = () => TagStudent.findAll({}) | ||
|
||
module.exports = { | ||
getStudentTags | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { callController } from '../apiConnection' | ||
|
||
export const getTags = () => { | ||
const route = '/tags' | ||
const prefix = 'GET_TAGS_' | ||
return callController(route, prefix) | ||
} | ||
|
||
export const createTag = (tag) => { | ||
const route = '/tags' | ||
const prefix = 'CREATE_TAG_' | ||
const method = 'post' | ||
const data = { tag } | ||
return callController(route, prefix, data, method) | ||
} | ||
|
||
const reducer = (state = { data: [] }, action) => { | ||
switch (action.type) { | ||
case 'GET_TAGS_ATTEMPT': | ||
return { | ||
...state, | ||
pending: true | ||
} | ||
case 'GET_TAGS_SUCCESS': | ||
return { | ||
...state, | ||
pending: false, | ||
data: action.response || {} | ||
} | ||
case 'GET_TAGS_FAILURE': | ||
return { | ||
...state, | ||
pending: false | ||
} | ||
case 'CREATE_TAG_ATTEMPT': | ||
return { | ||
...state, | ||
pending: true | ||
} | ||
case 'CREATE_TAG_FAILURE': | ||
return { | ||
...state, | ||
pending: false | ||
} | ||
case 'CREATE_TAG_SUCCESS': | ||
return { | ||
...state, | ||
pending: false | ||
} | ||
default: | ||
return state | ||
} | ||
} | ||
|
||
export default reducer |
Oops, something went wrong.