nodecdtheque => MyMusicLibrary & new UI for adding album
This commit is contained in:
parent
a35c8899ac
commit
a502fe9088
14 changed files with 231 additions and 37 deletions
|
@ -13,8 +13,9 @@ import { isXhr } from "./helpers";
|
|||
|
||||
import indexRouter from "./routes";
|
||||
import addAlbumRouter from "./routes/addAlbum";
|
||||
import importRouterApiV1 from "./routes/api/v1";
|
||||
|
||||
import importAlbumRouterApiV1 from "./routes/api/v1/albums";
|
||||
import importSearchRouterApiV1 from "./routes/api/v1/search";
|
||||
|
||||
// Mongoose schema init
|
||||
require("./models/users");
|
||||
|
@ -81,8 +82,8 @@ app.use(
|
|||
|
||||
app.use("/", indexRouter);
|
||||
app.use("/ajouter-un-album", addAlbumRouter);
|
||||
app.use("/api/v1", importRouterApiV1);
|
||||
app.use("/api/v1/albums", importAlbumRouterApiV1);
|
||||
app.use("/api/v1/search", importSearchRouterApiV1);
|
||||
|
||||
// Handle 404
|
||||
app.use((req, res) => {
|
||||
|
|
|
@ -9,7 +9,7 @@ import http from "http";
|
|||
import app from "../app";
|
||||
import { port } from "../config";
|
||||
|
||||
const debug = debugLib("nodecdtheque:server");
|
||||
const debug = debugLib("mymusiclibrary:server");
|
||||
const server = http.createServer(app);
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
module.exports = {
|
||||
nodeEnv: process.env.NODE_ENV || "development",
|
||||
port: parseInt(process.env.PORT || "3001", 10),
|
||||
mongoDbUri: process.env.MONGODB_URI || "mongodb://nodecdtheque-db/cdtheque",
|
||||
mongoDbUri:
|
||||
process.env.MONGODB_URI || "mongodb://mymusiclibrary-db/mymusiclibrary",
|
||||
secret: process.env.SECRET || "waemaeMe5ahc6ce1chaeKohKa6Io8Eik",
|
||||
discogsToken: process.env.DISCOGS_TOKEN,
|
||||
};
|
||||
|
|
|
@ -38,6 +38,10 @@ class Pages {
|
|||
this.pageContent.page[field] = value;
|
||||
}
|
||||
|
||||
getPageContent(field) {
|
||||
return this.pageContent.page[field];
|
||||
}
|
||||
|
||||
/**
|
||||
* Rendu de la page
|
||||
* @return {Object}
|
||||
|
|
|
@ -2,16 +2,26 @@ import express from "express";
|
|||
import { ensureLoggedIn } from "connect-ensure-login";
|
||||
|
||||
import { sendResponse } from "../../../libs/format";
|
||||
import { searchSong } from "../../../helpers";
|
||||
import { searchSong, getAlbumDetails } from "../../../helpers";
|
||||
|
||||
// eslint-disable-next-line new-cap
|
||||
const router = express.Router();
|
||||
|
||||
router.route("/").get(ensureLoggedIn("/connexion"), async (req, res, next) => {
|
||||
try {
|
||||
const data = await searchSong(req.query.q);
|
||||
|
||||
sendResponse(req, res, data);
|
||||
} catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
|
||||
router
|
||||
.route("/search")
|
||||
.route("/:discogsId")
|
||||
.get(ensureLoggedIn("/connexion"), async (req, res, next) => {
|
||||
try {
|
||||
const data = await searchSong(req.query.q);
|
||||
const data = await getAlbumDetails(req.params.discogsId);
|
||||
|
||||
sendResponse(req, res, data);
|
||||
} catch (err) {
|
|
@ -12,15 +12,12 @@ import render from "../libs/format";
|
|||
const router = express.Router();
|
||||
|
||||
router.route("/").get((req, res, next) => {
|
||||
if (req.user) {
|
||||
return res.redirect("/ma-collection");
|
||||
}
|
||||
try {
|
||||
const page = new Pages(req, "home");
|
||||
|
||||
return render(res, page);
|
||||
render(res, page);
|
||||
} catch (err) {
|
||||
return next(err);
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -88,7 +85,11 @@ router
|
|||
|
||||
await page.loadMyCollection();
|
||||
|
||||
render(res, page);
|
||||
if (page.getPageContent("artists").length > 0) {
|
||||
render(res, page);
|
||||
} else {
|
||||
res.redirect("/ajouter-un-album");
|
||||
}
|
||||
} catch (err) {
|
||||
next(err);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue