Added on-air feature

This commit is contained in:
Damien Broqua 2023-12-31 18:02:02 +01:00
parent 8e0947ed4b
commit 6994170a04
3 changed files with 48 additions and 6 deletions

View File

@ -464,6 +464,31 @@ Publié automatiquement via #musictopus`;
); );
} }
/**
* Méthode permettant de choisir un album de manière aléatoire dans la collection d'un utilisateur
*/
async onAir() {
const { _id: User } = this.req.user;
const count = await AlbumsModel.count({
User,
});
const items = await AlbumsModel.find(
{
User,
},
[],
{
skip: Math.floor(Math.random() * (count + 1)),
limit: 1,
}
);
this.req.params.itemId = items[0]._id;
await this.loadItem();
}
/** /**
* Méthode permettant de créer la page "collection/:userId" * Méthode permettant de créer la page "collection/:userId"
*/ */

View File

@ -24,6 +24,20 @@ router.route("/").get(ensureLoggedIn("/connexion"), async (req, res, next) => {
} }
}); });
router
.route("/on-air")
.get(ensureLoggedIn("/connexion"), async (req, res, next) => {
try {
const page = new Albums(req, "mon-compte/ma-collection/details");
await page.onAir();
render(res, page);
} catch (err) {
next(err);
}
});
router router
.route("/exporter") .route("/exporter")
.get(ensureLoggedIn("/connexion"), async (req, res, next) => { .get(ensureLoggedIn("/connexion"), async (req, res, next) => {

View File

@ -87,12 +87,19 @@
<a class="navbar-item" href="/ma-collection"> <a class="navbar-item" href="/ma-collection">
Ma collection Ma collection
</a> </a>
<a class="navbar-item" href="/ma-collection/on-air">
On air
</a>
<a class="navbar-item" href="/ma-collection/exporter"> <a class="navbar-item" href="/ma-collection/exporter">
Exporter ma collection Exporter ma collection
</a> </a>
<a class="navbar-item" href="/ma-collection/importer"> <a class="navbar-item" href="/ma-collection/importer">
Importer une collection Importer une collection
</a> </a>
<hr />
<a class="navbar-item is-danger" href="/se-deconnecter">
Déconnexion
</a>
</div> </div>
</div> </div>
<% } %> <% } %>
@ -104,19 +111,15 @@
</label> </label>
</div> </div>
</div> </div>
<% if ( !user ) { %>
<div class="navbar-item"> <div class="navbar-item">
<div class="buttons"> <div class="buttons">
<% if ( !user ) { %>
<a class="button is-primary" href="/connexion"> <a class="button is-primary" href="/connexion">
<strong>Connexion</strong> <strong>Connexion</strong>
</a> </a>
<% } else { %>
<a class="button is-danger" href="/se-deconnecter">
Déconnexion
</a>
<% } %>
</div> </div>
</div> </div>
<% } %>
</div> </div>
</div> </div>
</nav> </nav>