Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Story map admin #105

Draft
wants to merge 35 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
76f6d20
Adapt storymap api for admin console
gdozot2 Apr 10, 2024
52b6937
Get data modifications
gdozot2 Apr 15, 2024
115bde7
Standardize stories DB name
gdozot2 Apr 15, 2024
c92a6f4
Log error
gdozot2 Apr 15, 2024
31f7c47
adapt story and chapters
gdozot2 Apr 16, 2024
d42c87b
Update DB + fix order
gdozot2 Apr 24, 2024
ea297ab
Rework story + add tests
gdozot2 May 8, 2024
26ccb9d
update tests
gdozot2 May 8, 2024
f636914
update tests + update update method
gdozot2 May 14, 2024
aa48e95
Refactor chapter and add tests
gdozot2 May 28, 2024
0275ea6
update db storymap
gdozot2 May 13, 2024
afb47fe
revert code
gdozot2 May 14, 2024
9f41e61
Add type
gdozot2 May 14, 2024
783f709
add news table migration
zweiro Apr 9, 2024
649cb45
wip: add news feature
zweiro Apr 15, 2024
523977f
test: add news /GET tests
zweiro Apr 16, 2024
9eb904c
refactor: add img_alt field to news schema
zweiro Apr 22, 2024
fca3af1
refactor: switch created_at news field to published at
zweiro Apr 26, 2024
177751f
test: update news pagination test values to be hardcoded
zweiro Apr 26, 2024
1cccfe7
Add langFallback ENV variable to show english when local lang does no…
zweiro May 22, 2024
fd14b9c
Get data modifications
gdozot2 Apr 15, 2024
1663646
Standardize stories DB name
gdozot2 Apr 15, 2024
b13c242
Rework story + add tests
gdozot2 May 8, 2024
47e1752
update tests + update update method
gdozot2 May 14, 2024
6aea0e0
Add some tests, fix some issues, add some fixtures
gdozot2 Jun 10, 2024
597c04a
Improve code
gdozot2 Jun 10, 2024
719d95c
fix join sequelize
gdozot2 Jun 10, 2024
0209156
update code to add owner + nbChapters + update all tests and addd mis…
gdozot2 Jun 20, 2024
b820ffb
Story creation and retrieve base on owner management
gdozot2 Jun 24, 2024
d6e748d
Fix tests with user authorization
gdozot2 Jun 24, 2024
128b5b2
Add not authorized user tests
gdozot2 Jun 26, 2024
bc42979
Manage owner right for addition, supression and modification of story…
gdozot2 Jun 26, 2024
6d4a053
improve
gdozot2 Aug 22, 2024
d5f8922
Fix latest test error
gdozot2 Sep 6, 2024
4b8c21b
Merge branch 'main' into story-map-admin
gdozot2 Sep 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
2 changes: 2 additions & 0 deletions .env.test.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,5 @@ AUTH_FACEBOOK_APP_ID=foo
AUTH_FACEBOOK_APP_SECRET=foo

TZ=Europe/Zurich

SMAPCOMPUTE_URL=http://localhost:5000/generate
71 changes: 41 additions & 30 deletions app/api/chapters/chapter.openapi.yml
Original file line number Diff line number Diff line change
@@ -1,46 +1,40 @@
/chapters:
get:
summary: Retrieve all chapters
parameters:
- name: page
in: query
required: false
schema:
type: integer
minimum: 1
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: "#/components/schemas/ChaptersList"

/stories/{storyId}/chapters:
post:
summary: Add a chapter to the db.
operationId: addChapter
parameters:
- name: storyId
in: path
required: true
schema:
type: string
requestBody:
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/Chapters"
$ref: "#/components/schemas/ChaptersRequest"
responses:
'200':
'201':
description: OK
content:
application/json:
schema:
$ref: "#/components/schemas/Chapters"

'404':
$ref: "#/components/responses/NotFoundError"
$ref: "#/components/schemas/ChaptersResponse"
'403':
$ref: "#/components/responses/UnauthorizedError"


/chapters/{id}:
/stories/{storyId}/chapters/{id}:
get:
summary: Retrieve a chapter by ID
parameters:
- name: storyId
in: path
required: true
schema:
type: string
- name: id
in: path
required: true
Expand All @@ -52,13 +46,18 @@
content:
application/json:
schema:
$ref: "#/components/schemas/Chapters"
$ref: "#/components/schemas/ChaptersResponse"
'404':
$ref: "#/components/responses/NotFoundError"

put:
summary: update a chapter.
parameters:
- name: storyId
in: path
required: true
schema:
type: string
- name: id
in: path
required: true
Expand All @@ -70,27 +69,39 @@
content:
application/json:
schema:
$ref: "#/components/schemas/Chapters"
$ref: "#/components/schemas/ChaptersPutRequest"
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: "#/components/schemas/Chapters"

$ref: "#/components/schemas/ChaptersResponse"
'403':
$ref: "#/components/responses/UnauthorizedError"
'404':
$ref: "#/components/responses/NotFoundError"

delete:
summary: Delete a chapter by ID
operationId: deleteChapter
parameters:
- name: storyId
in: path
required: true
schema:
type: string
- name: id
in: path
required: true
schema:
type: string
responses:
'200':
description: OK
description: Successful request.
content:
application/json:
schema:
$ref: "#/components/schemas/SuccessMessageResponse"
'403':
$ref: "#/components/responses/UnauthorizedError"
125 changes: 50 additions & 75 deletions app/api/chapters/chapters.controller.js
Original file line number Diff line number Diff line change
@@ -1,97 +1,72 @@
const { Stories_chapters } = require('../../models');
const models = require("../../models");
const { notFoundError } = require('../../utils/errors');
const { validateStoryRight } = require('../../utils/story');
const { route } = require("../../utils/express");


//get all the chapters
const getChapters = async (req, res) => {
try {
const chapters = await Stories_chapters.sequelize.query(`
SELECT stories_chapters.title, stories_chapters.type, picture_id,
stories_chapters.url_media, stories_chapters.description, stories_chapters.zoom, stories_chapters.story, stories_chapters.view_custom ,
ST_X(images.location) as longitude, ST_Y(images.location) as latitude
FROM stories_chapters, images
WHERE stories_chapters.picture_id = images.id`,
{type: Stories_chapters.sequelize.QueryTypes.SELECT},
)
res.json(chapters);
} catch (error) {
res.status(500).json({ error: 'Une erreur s\'est produite lors de la récupération des chapitres.' });
}
};


//get a chapter by id
const getChapterById = async (req, res) => {
const getChapterById = route(async (req, res) => {
const { id } = req.params;
try {
const chapter = await Stories_chapters.findByPk(id);
if (chapter) {
res.json(JSON.stringify({ "chapters": chapter }));
} else {
res.status(404).json({ error: 'Aucun chapitre trouvé avec cet ID.' });
}
} catch (error) {
res.status(500).json({ error: `Une erreur s'est produite lors de la récupération du chapitre avec l'ID ${id}.` });
const chapter = await models.stories_chapters.findByPk(id);
if (chapter) {
res.json(chapter);
} else {
throw notFoundError(req);
}
};

});

//Add a chapter to the db
const addChapter = async (req, res) => {
const { title, type, picture_id, url_media, description, zoom, story, indexInStory } = req.body;
try {
const newChapter = await Stories_chapters.create({
const addChapter = route(async (req, res) => {
await validateStoryRight(req, res, req.params.storyId);
const { storyId } = req.params;
gdozot2 marked this conversation as resolved.
Show resolved Hide resolved
const { title, type, picture_id, url_media, description, zoom, indexinstory, view_custom } = req.body;
const newChapter = await models.stories_chapters.create({
title,
type,
picture_id,
url_media,
description,
zoom,
story,
indexInStory
});
res.status(201).json(newChapter); // Return the ID of the newly created chapter
} catch (error) {
res.status(500).json({ error: 'Une erreur s\'est produite lors de l\'ajout du chapitre.' });
}
};
story_id: storyId,
indexinstory,
view_custom
});
res.status(201).json(newChapter); // Return the ID of the newly created chapter
});


//Update a chapter
const updateChapter = async (req, res) => {
const { title, type, picture_id, url_media, description, zoom, story, indexInStory } = req.body;
try {
const updatedChapter = await Stories_chapters.update({
title,
type,
picture_id,
url_media,
description,
zoom,
story,
indexInStory
},{
const updateChapter = route(async (req, res) => {
await validateStoryRight(req, res, req.params.storyId);
const { storyId, id } = req.params;
gdozot2 marked this conversation as resolved.
Show resolved Hide resolved
const { title, type, picture_id, url_media, description, zoom, indexinstory, view_custom } = req.body;
const updatedChapter = await models.stories_chapters.update({
title,
type,
picture_id,
url_media,
description,
zoom,
story_id: storyId,
indexinstory,
view_custom
},
{
where: {id: id}, returning: true, plain: true
});
res.status(200).json(updatedChapter[1]); // Return the ID of the newly created chapter
});

where: {id: req.params.id},
});
res.status(201).json(updatedChapter); // Return the ID of the newly created chapter
} catch (error) {
res.status(500).json({ error: 'Une erreur s\'est produite lors de la misz à jour du chapitre.' });
}
};
const deleteChapter = route(async (req, res) => {
await validateStoryRight(req, res, req.params.storyId);

const deleteChapter = async (req, res) =>{

try{
const deletedChapter = await Stories_chapters.destroy({where: {id:req.params.id}});
res.status(200).json(deletedChapter);

}catch(error){
res.status(500).json({error: "Une erreur c'est produite lors de la supression du chapitre"});
}
}
await models.stories_chapters.destroy({where: {id:req.params.id}});
gdozot2 marked this conversation as resolved.
Show resolved Hide resolved
res.send({
message: "The story was deleted."
});

});

module.exports = {
getChapters,
getChapterById,
addChapter,
updateChapter,
Expand Down
Loading