Co-authored-by: dbroqua <contact@darkou.fr>
Reviewed-on: #57
This commit is contained in:
Damien Broqua 2022-08-29 23:22:28 +02:00
parent d473899b20
commit 6320764743
3 changed files with 127 additions and 11 deletions

View file

@ -5,13 +5,25 @@ import { discogsToken } from "../config";
export const getBaseUrl = (req) => `${req.protocol}://${req.get("host")}`; export const getBaseUrl = (req) => `${req.protocol}://${req.get("host")}`;
export const searchSong = async (q) => { export const searchSong = async (q, format, year, country) => {
const dis = new Discogs({ userToken: discogsToken }).database(); const dis = new Discogs({ userToken: discogsToken }).database();
const res = await dis.search({ const params = {
q, q,
type: "release", type: "release",
}); };
if (format) {
params.format = format;
}
if (year) {
params.year = year;
}
if (country) {
params.country = country;
}
const res = await dis.search(params);
return res; return res;
}; };

View file

@ -9,7 +9,12 @@ const router = express.Router();
router.route("/").get(ensureLoggedIn("/connexion"), async (req, res, next) => { router.route("/").get(ensureLoggedIn("/connexion"), async (req, res, next) => {
try { try {
const data = await searchSong(req.query.q); const data = await searchSong(
req.query.q,
req.query.format || null,
req.query.year || null,
req.query.country || null
);
sendResponse(req, res, data); sendResponse(req, res, data);
} catch (err) { } catch (err) {

View file

@ -1,19 +1,37 @@
<main class="layout-maxed ajouter-un-album" id="app"> <main class="layout-maxed ajouter-un-album" id="app">
<h1>Ajouter un album</h1> <h1>Ajouter un album</h1>
<form @submit="search">
<div class="grid sm:grid-cols-2"> <div class="grid sm:grid-cols-2">
<div> <div>
<form @submit="search">
<label for="q">Nom de l'album ou code barre</label> <label for="q">Nom de l'album ou code barre</label>
<div class="field has-addons"> <div class="field has-addons">
<input type="text" name="q" id="q" v-model="q" placeholder="ex : Hybrid Theory" autofocus> <input type="text" name="q" id="q" v-model="q" placeholder="ex : Iron Maiden - Powerslave" autofocus>
<button class="button is-primary" :disabled="loading" aria-label="Chercher"> <button class="button is-primary" :disabled="loading" aria-label="Chercher">
<i class="icon-search" v-if="!loading"></i> <i class="icon-search" v-if="!loading"></i>
<i class="icon-spin animate-spin" v-if="loading"></i> <i class="icon-spin animate-spin" v-if="loading"></i>
</button> </button>
</div> </div>
<div class="grid sm:grid-cols-3 gap-5">
<div class="field">
<label for="format">Trier par</label>
<select id="format" v-model="format">
<option value="">Tous</option>
<option v-for="format in orderedItems(formats)" :value="format">{{format}}</option>
</select>
</div>
<div class="field">
<label for="year">Année</label>
<input type="number" name="year" v-model="year" id="year" placeholder="1984">
</div>
<div class="field">
<label for="country">Pays</label>
<input type="string" name="country" v-model="country" id="country" placeholder="France">
</div>
</div>
</div>
</div>
</form> </form>
</div>
</div>
<div class="grid grid-cols-1 md:grid-cols-2 list hover"> <div class="grid grid-cols-1 md:grid-cols-2 list hover">
<div class="item" v-if="!loading" v-for="item in items"> <div class="item" v-if="!loading" v-for="item in items">
@ -158,10 +176,77 @@
data() { data() {
return { return {
q: '', q: '',
year: '',
country: '',
format: '',
loading: false, loading: false,
items: [], items: [],
details: {}, details: {},
modalIsVisible: false, modalIsVisible: false,
formats: [
'Vinyl',
'Acetate',
'Flexi-disc',
'Lathe Cut',
'Mighty Tiny',
'Shellac',
'Sopic',
'Pathé Disc',
'Edison Disc',
'Cylinder',
'CD',
'CDr',
'CDV',
'DVD',
'DVDr',
'HD DVD',
'HD DVD-R',
'Blu-ray',
'Blu-ray-R',
'Ultra HD Blu-ray',
'SACD',
'4-Track Cartridge',
'8-Track Cartridge',
'Cassette',
'DC-International',
'Elcaset',
'PlayTape',
'RCA Tape Cartridge',
'DAT',
'DCC',
'Microcassette',
'NT Cassette',
'Pocket Rocker',
'Revere Magnetic Stereo Tape Ca',
'Tefifon',
'Reel-To-Reel',
'Sabamobil',
'Betacam',
'Betacam SP',
'Betamax',
'Cartrivision',
'MiniDV',
'Super VHS',
'U-matic',
'VHS',
'Video 2000',
'Video8',
'Film Reel',
'HitClips',
'Laserdisc',
'SelectaVision',
'VHD',
'Wire Recording',
'Minidisc',
'MVD',
'UMD',
'Floppy Disk',
'File',
'Memory Stick',
'Hybrid',
'All Media',
'Box Set',
]
} }
}, },
methods: { methods: {
@ -173,8 +258,19 @@
} }
this.loading = true; this.loading = true;
let url = `/api/v1/search?q=${this.q}`;
axios.get(`/api/v1/search?q=${this.q}`) if ( this.year ) {
url += `&year=${this.year}`;
}
if ( this.country ) {
url += `&country=${this.country}`;
}
if ( this.format ) {
url += `&format=${this.format}`;
}
axios.get(url)
.then( response => { .then( response => {
const { const {
results, results,
@ -242,6 +338,9 @@
showToastr(err.response?.data?.message || "Impossible d'ajouter cet album pour le moment…"); showToastr(err.response?.data?.message || "Impossible d'ajouter cet album pour le moment…");
}); });
}, },
orderedItems(items) {
return items.sort();
}
} }
}).mount('#app'); }).mount('#app');
</script> </script>