diff --git a/app.js b/app.js index 07ba150..965a903 100644 --- a/app.js +++ b/app.js @@ -243,6 +243,7 @@ app.get( //Resource API for ENACT-Data-Apps app.get("/api/v0/resources/", resourceController.getResources); app.get("/api/v0/resources/all", resourceController.getAllResources); +app.get("/api/v0/resources/sets", resourceController.getResourceUnique); app.get("/api/v0/resources/allstats", resourceController.getResourcesAndStats); app.get("/api/v0/resources/stats", resourceController.getResourceStats); app.get("/api/v0/resources/search", (req, res) => { diff --git a/controllers/resourceController.js b/controllers/resourceController.js index 0ced0ca..cd035a4 100644 --- a/controllers/resourceController.js +++ b/controllers/resourceController.js @@ -8,22 +8,6 @@ const AuthorAlt = require('../models/AuthorAlternative') const mongoose = require('mongoose'); -// Function to retrieve all resources -// exports.getAllResources = async (req, res, next) => { -// try { -// // Retrieve all resource documents -// const allResources = await Resource.find({}); -// // Optionally, modify or filter the documents as needed here - -// // Return or send the array of all resources -// res.json(allResources); -// } catch (e) { -// // Handle any errors that occur during the process -// next(e); -// } -// }; - - // Function to retrieve all resources with expanded owner and course information exports.getAllResources = async (req, res, next) => { try { @@ -358,6 +342,51 @@ exports.getResourceStats = async (req, res, next) => { } }; +exports.getResourceUnique = async (req, res, next) => { + try { + // Aggregation pipelines for collecting unique sets + const contentTypesPipeline = [ + { $group: { _id: null, contentTypes: { $addToSet: "$contentType" } } }, + { $project: { _id: 0, contentTypes: 1 } } + ]; + + const mediaTypesPipeline = [ + { $group: { _id: null, mediaTypes: { $addToSet: "$mediaType" } } }, + { $project: { _id: 0, mediaTypes: 1 } } + ]; + + const institutionsPipeline = [ + { $group: { _id: null, institutions: { $addToSet: "$institution" } } }, + { $project: { _id: 0, institutions: 1 } } + ]; + + const yearsPipeline = [ + { $group: { _id: null, years: { $addToSet: "$yearOfCreation" } } }, + { $project: { _id: 0, years: 1 } } + ]; + + // Execute the aggregation pipelines + const [contentTypes] = await Resource.aggregate(contentTypesPipeline); + const [mediaTypes] = await Resource.aggregate(mediaTypesPipeline); + const [institutions] = await Resource.aggregate(institutionsPipeline); + const [years] = await Resource.aggregate(yearsPipeline); + + // Construct the final sets response + const sets = { + contentTypes: contentTypes ? contentTypes.contentTypes : [], + mediaTypes: mediaTypes ? mediaTypes.mediaTypes : [], + institutions: institutions ? institutions.institutions : [], + years: years ? years.years : [] + }; + + // Send back the sets of values + res.json(sets); + } catch (e) { + next(e); + } +}; + + diff --git a/package.json b/package.json index 6b60e27..2028120 100644 --- a/package.json +++ b/package.json @@ -47,6 +47,7 @@ "passport-local": "^1.0.0", "react": "^18.3.1", "react-dom": "^18.3.1", + "react-loading-skeleton": "^3.4.0", "session": "^0.1.0" }, "devDependencies": { @@ -58,10 +59,12 @@ "babel-plugin-transform-runtime": "^6.23.0", "chai": "^5.1.0", "concurrently": "^8.2.2", + "css-loader": "^7.1.2", "cypress": "^13.8.1", "dateformat": "^3.0.3", "lodash.template": ">=4.5.0", "mocha": "^10.4.0", + "style-loader": "^4.0.0", "supertest": "^7.0.0", "webpack": "^5.91.0", "webpack-cli": "^5.1.4", diff --git a/public/js/bundle.js b/public/js/bundle.js index 6328042..73f6a4d 100644 --- a/public/js/bundle.js +++ b/public/js/bundle.js @@ -1,2 +1,499 @@ -/*! For license information please see bundle.js.LICENSE.txt */ -(()=>{var e={551:(e,t,n)=>{"use strict";var r=n(540),l=n(982);function a(e){for(var t="https://reactjs.org/docs/error-decoder.html?invariant="+e,n=1;n