rename model list to usercollection & fixed redlated errors
This commit is contained in:
1 parent
60b517500f
commit
b48b395574
37 files changed
+2479
-1210
No files matched your search
+3
-3
@@ -13,7 +13,7 @@
|
||||
"build": {
|
||||
"builder": "@angular-devkit/build-angular:application",
|
||||
"options": {
|
||||
"outputPath": "frontend/dist/show-z",
|
||||
"outputPath": "dist/show-z",
|
||||
"index": "frontend/src/index.html",
|
||||
"browser": "frontend/src/main.ts",
|
||||
"polyfills": ["zone.js"],
|
||||
@@ -63,8 +63,8 @@
|
||||
"budgets": [
|
||||
{
|
||||
"type": "initial",
|
||||
"maximumWarning": "500kb",
|
||||
"maximumError": "1mb"
|
||||
"maximumWarning": "5000kb",
|
||||
"maximumError": "5mb"
|
||||
},
|
||||
{
|
||||
"type": "anyComponentStyle",
|
||||
|
||||
+16
-16
@@ -1,11 +1,11 @@
|
||||
// Import models
|
||||
const Collection = require('../models/Collection');
|
||||
const Franchise = require('../models/Franchise');
|
||||
const Entry = require('../models/Entry')
|
||||
const EntryId = require('../models/EntryId')
|
||||
const EntryRating = require('../models/EntryRating')
|
||||
const EntrySeen = require('../models/EntrySeen');
|
||||
const List = require('../models/List');
|
||||
const ListEntry = require('../models/ListEntry');
|
||||
const UserCollection = require('../models/UserCollection');
|
||||
const UserCollectionEntry = require('../models/UserCollectionEntry');
|
||||
const Season = require('../models/Season');
|
||||
const Episode = require('../models/Episode');
|
||||
const EpisodeSeen = require('../models/EpisodeSeen');
|
||||
@@ -36,26 +36,26 @@ Entry.hasMany(EntrySeen, { foreignKey: 'entry_id', onDelete: 'CASCADE', });
|
||||
EntrySeen.belongsTo(Entry, { foreignKey: 'entry_id' });
|
||||
|
||||
// * ENTRY & LIST - MANY TO MANY
|
||||
Entry.belongsToMany(List, {
|
||||
through: ListEntry,
|
||||
Entry.belongsToMany(UserCollection, {
|
||||
through: UserCollectionEntry,
|
||||
foreignKey: 'entry_id',
|
||||
otherKey: 'list_id',
|
||||
otherKey: 'user_collection_id',
|
||||
onDelete: 'CASCADE',
|
||||
as: 'entries',
|
||||
as: 'userCollections',
|
||||
});
|
||||
|
||||
List.belongsToMany(Entry, {
|
||||
through: ListEntry,
|
||||
foreignKey: 'list_id',
|
||||
UserCollection.belongsToMany(Entry, {
|
||||
through: UserCollectionEntry,
|
||||
foreignKey: 'user_collection_id',
|
||||
otherKey: 'entry_id',
|
||||
onDelete: 'CASCADE',
|
||||
as: 'entries',
|
||||
});
|
||||
|
||||
Entry.hasMany(ListEntry, { foreignKey: 'entry_id', as: 'listEntries' });
|
||||
ListEntry.belongsTo(Entry, { foreignKey: 'entry_id', as: 'entry' });
|
||||
List.hasMany(ListEntry, { foreignKey: 'list_id', as: 'listEntries' });
|
||||
ListEntry.belongsTo(List, { foreignKey: 'list_id', as: 'list' });
|
||||
Entry.hasMany(UserCollectionEntry, { foreignKey: 'entry_id', as: 'userCollectionEntries' });
|
||||
UserCollectionEntry.belongsTo(Entry, { foreignKey: 'entry_id', as: 'entry' });
|
||||
UserCollection.hasMany(UserCollectionEntry, { foreignKey: 'user_collection_id', as: 'userCollectionEntries' });
|
||||
UserCollectionEntry.belongsTo(UserCollection, { foreignKey: 'user_collection_id', as: 'userCollection' });
|
||||
|
||||
// * ENTRY & SEASON - ONE TO MANY
|
||||
Entry.hasMany(Season, { foreignKey: 'entry_id', onDelete: 'CASCADE', });
|
||||
@@ -69,5 +69,5 @@ Episode.belongsTo(Season, { foreignKey: 'season_id' });
|
||||
Episode.hasMany(EpisodeSeen, { foreignKey: 'episode_id', onDelete: 'CASCADE', });
|
||||
EpisodeSeen.belongsTo(Episode, { foreignKey: 'episode_id' });
|
||||
|
||||
Collection.hasMany(Entry, { foreignKey: 'collection_id' });
|
||||
Entry.belongsTo(Collection, { foreignKey: 'collection_id' });
|
||||
Franchise.hasMany(Entry, { foreignKey: 'franchise_id' });
|
||||
Entry.belongsTo(Franchise, { foreignKey: 'franchise_id' });
|
||||
@@ -1,7 +1,7 @@
|
||||
const { DataTypes } = require('sequelize');
|
||||
const sequelize = require('../db/database');
|
||||
|
||||
const Collection = sequelize.define("collection",
|
||||
const Franchise = sequelize.define("franchise",
|
||||
{
|
||||
id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
|
||||
title: { type: DataTypes.STRING(50) },
|
||||
@@ -10,4 +10,4 @@ const Collection = sequelize.define("collection",
|
||||
}
|
||||
);
|
||||
|
||||
module.exports = Collection;
|
||||
module.exports = Franchise;
|
||||
@@ -1,26 +0,0 @@
|
||||
const { DataTypes } = require('sequelize');
|
||||
const sequelize = require('../db/database');
|
||||
|
||||
const ListEntry = sequelize.define('listEntry', {
|
||||
list_id: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
references: {
|
||||
model: 'Lists',
|
||||
key: 'id'
|
||||
}
|
||||
},
|
||||
entry_id: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
references: {
|
||||
model: 'Entries',
|
||||
key: 'id'
|
||||
}
|
||||
},
|
||||
order: {
|
||||
type: DataTypes.INTEGER
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = ListEntry;
|
||||
@@ -1,7 +1,7 @@
|
||||
const { DataTypes } = require('sequelize');
|
||||
const sequelize = require('../db/database');
|
||||
|
||||
const List = sequelize.define("list",
|
||||
const UserCollection = sequelize.define("userCollection",
|
||||
{
|
||||
id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
|
||||
|
||||
@@ -13,4 +13,4 @@ const List = sequelize.define("list",
|
||||
}
|
||||
);
|
||||
|
||||
module.exports = List;
|
||||
module.exports = UserCollection;
|
||||
@@ -0,0 +1,30 @@
|
||||
const { DataTypes } = require('sequelize');
|
||||
const sequelize = require('../db/database');
|
||||
|
||||
const UserCollectionEntry = sequelize.define('userCollectionEntry',
|
||||
{
|
||||
user_collection_id: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
references: {
|
||||
model: 'UserCollections',
|
||||
key: 'id'
|
||||
}
|
||||
},
|
||||
entry_id: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
references: {
|
||||
model: 'Entries',
|
||||
key: 'id'
|
||||
}
|
||||
},
|
||||
order: {
|
||||
type: DataTypes.INTEGER
|
||||
}
|
||||
},
|
||||
{
|
||||
primaryKey: ['user_collection_id', 'entry_id'],
|
||||
});
|
||||
|
||||
module.exports = UserCollectionEntry;
|
||||
@@ -4,7 +4,7 @@ const router = express.Router();
|
||||
|
||||
// ! /entry-seen
|
||||
// * POST - CREATE ENTRY SEEN
|
||||
router.post('/entry-seen', async (req, res) => {
|
||||
router.post('/', async (req, res) => {
|
||||
try {
|
||||
const { entry_id, date_seen, seen_with } = req.body;
|
||||
const newEntrySeen = await EntrySeen.create({ entry_id, date_seen, seen_with });
|
||||
@@ -15,7 +15,7 @@ router.post('/entry-seen', async (req, res) => {
|
||||
});
|
||||
|
||||
// * GET - ALL ENTRY SEEN
|
||||
router.get('/entry-seen', async (req, res) => {
|
||||
router.get('/', async (req, res) => {
|
||||
try {
|
||||
const entrySeens = await EntrySeen.findAll();
|
||||
res.status(200).json(entrySeens);
|
||||
@@ -25,7 +25,7 @@ router.get('/entry-seen', async (req, res) => {
|
||||
});
|
||||
|
||||
// * GET - ENTRY SEEN BY ID
|
||||
router.get('/entry-seen/:id', async (req, res) => {
|
||||
router.get('/:id', async (req, res) => {
|
||||
try {
|
||||
const entrySeen = await EntrySeen.findByPk(req.params.id);
|
||||
if (entrySeen) {
|
||||
@@ -39,7 +39,7 @@ router.get('/entry-seen/:id', async (req, res) => {
|
||||
});
|
||||
|
||||
// * GET - ENTRY SEEN BY ENTRY ID
|
||||
router.get('/entry-seen/by-entry/:entryId', async (req, res) => {
|
||||
router.get('/by-entry/:entryId', async (req, res) => {
|
||||
try {
|
||||
const { entryId } = req.params;
|
||||
const entrySeens = await EntrySeen.findAll({
|
||||
@@ -58,7 +58,7 @@ router.get('/entry-seen/by-entry/:entryId', async (req, res) => {
|
||||
});
|
||||
|
||||
// * PUT - UPDATE ENTRY SEEN
|
||||
router.put('/entry-seen/:id', async (req, res) => {
|
||||
router.put('/:id', async (req, res) => {
|
||||
try {
|
||||
const { date_seen, seen_with } = req.body;
|
||||
const updated = await EntrySeen.update({ date_seen, seen_with }, { where: { id: req.params.id } });
|
||||
@@ -75,7 +75,7 @@ router.put('/entry-seen/:id', async (req, res) => {
|
||||
});
|
||||
|
||||
// * DELETE - ENTRY SEEN
|
||||
router.delete('/entry-seen/:id', async (req, res) => {
|
||||
router.delete('/:id', async (req, res) => {
|
||||
try {
|
||||
const deleted = await EntrySeen.destroy({ where: { id: req.params.id } });
|
||||
if (deleted) {
|
||||
|
||||
@@ -1,208 +0,0 @@
|
||||
const express = require('express');
|
||||
const List = require('../models/List');
|
||||
const ListEntry = require('../models/ListEntry');
|
||||
const Entry = require('../models/Entry');
|
||||
const EntryId = require('../models/EntryId');
|
||||
const EntryRating = require('../models/EntryRating');
|
||||
const router = express.Router();
|
||||
|
||||
|
||||
// ! /lists
|
||||
// * POST - CREATE LIST
|
||||
router.post('/', async (req, res) => {
|
||||
try {
|
||||
const { name, description, user_rating, poster_path } = req.body;
|
||||
const newList = await List.create({ name, description, user_rating, poster_path });
|
||||
res.status(201).json(newList);
|
||||
} catch (error) {
|
||||
res.status(400).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
// * GET - ALL LISTS
|
||||
router.get('/', async (req, res) => {
|
||||
let lists; // Declare outside to broaden scope, albeit unnecessary in your given context
|
||||
try {
|
||||
lists = await List.findAll({
|
||||
include: [
|
||||
{ model: ListEntry, as: 'listEntries' },
|
||||
]
|
||||
});
|
||||
res.status(200).json(lists);
|
||||
} catch (error) {
|
||||
console.error("Error fetching lists:", error); // More detailed error logging
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
// * GET - LIST BY ID
|
||||
router.get('/:id', async (req, res) => {
|
||||
try {
|
||||
const list = await List.findByPk(req.params.id, {
|
||||
include: [{
|
||||
model: Entry,
|
||||
as: 'entries', // Make sure this matches your alias in the association, if any
|
||||
through: {
|
||||
attributes: [], // Exclude attributes from the join model, if you don't need them
|
||||
},
|
||||
}],
|
||||
});
|
||||
|
||||
if (list) {
|
||||
// Optionally, sort the entries here if needed, using JavaScript's sort()
|
||||
// This is a workaround for the direct ordering limitation via Sequelize in many-to-many relationships
|
||||
for (let i = 0; i < list.entries.length; i++) {
|
||||
list.entries[i] = await Entry.findByPk(list.entries[i].id,
|
||||
{
|
||||
include: [
|
||||
{ model: EntryId, as: 'entryId' },
|
||||
{ model: EntryRating, as: 'entryRating' }
|
||||
]
|
||||
})
|
||||
}
|
||||
res.status(200).json(list);
|
||||
} else {
|
||||
res.status(404).json({ message: 'List not found' });
|
||||
}
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
// * PUT - UPDATE A LIST
|
||||
router.put('/:id', async (req, res) => {
|
||||
try {
|
||||
const { name, description, user_rating, poster_path } = req.body;
|
||||
const [updated] = await List.update({ name, description, user_rating, poster_path }, { where: { id: req.params.id } });
|
||||
|
||||
if (updated) {
|
||||
const updatedList = await List.findByPk(req.params.id);
|
||||
res.status(200).json(updatedList);
|
||||
} else {
|
||||
res.status(404).json({ message: 'List not found' });
|
||||
}
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
// * DELETE - A LIST
|
||||
router.delete('/:id', async (req, res) => {
|
||||
try {
|
||||
const deleted = await List.destroy({ where: { id: req.params.id } });
|
||||
if (deleted) {
|
||||
res.status(204).send();
|
||||
} else {
|
||||
res.status(404).json({ message: 'List not found' });
|
||||
}
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// * POST - ADD ENTRY TO A LIST
|
||||
router.post('/:listId/entries/:entryId', async (req, res) => {
|
||||
try {
|
||||
const { listId, entryId } = req.params;
|
||||
const { order } = req.body; // Get entryOrder from the request body or query parameters
|
||||
|
||||
// Create a new record in the ListEntry table with listId, entryId, and entryOrder
|
||||
const newListEntry = await ListEntry.create({
|
||||
list_id: listId,
|
||||
entry_id: entryId,
|
||||
order: order
|
||||
});
|
||||
|
||||
// ? set a default poster if none exists
|
||||
await List.findByPk(listId).then(list => {
|
||||
if (list.poster_path == null || list.poster_path.toString().trim() == '') {
|
||||
Entry.findByPk(entryId).then(entry => {
|
||||
list.poster_path = entry.poster_path;
|
||||
list.save();
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
res.status(201).json(newListEntry);
|
||||
} catch (error) {
|
||||
res.status(400).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
// * PATCH - UPDATE ENTRY ORDER IN LIST
|
||||
router.patch('/:listId/entries/:entryId/order', async (req, res) => {
|
||||
try {
|
||||
const { listId, entryId } = req.params;
|
||||
const { newOrder } = req.body; // The new order value
|
||||
|
||||
// Assuming you have a model ListEntry for the junction table
|
||||
const updated = await ListEntry.update(
|
||||
{ entryOrder: newOrder }, // Set new order
|
||||
{
|
||||
where: {
|
||||
listId: listId,
|
||||
entryId: entryId
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
if (updated[0] > 0) {
|
||||
res.status(200).json({ message: 'Entry order updated successfully.' });
|
||||
} else {
|
||||
res.status(404).json({ message: 'List entry not found.' });
|
||||
}
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
// * DELETE - AND ENTRY FROM A LIST
|
||||
router.delete('/:listId/entries/:entryId', async (req, res) => {
|
||||
try {
|
||||
const { listId, entryId } = req.params;
|
||||
const deleted = await ListEntry.destroy({
|
||||
where: {
|
||||
list_id: listId,
|
||||
entry_id: entryId
|
||||
}
|
||||
});
|
||||
|
||||
if (deleted) {
|
||||
res.status(204).send();
|
||||
} else {
|
||||
res.status(404).json({ message: 'List entry not found.' });
|
||||
}
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
// * POST - CREATE LIST WITH ENTRY
|
||||
router.post('/lists-with-entry', async (req, res) => {
|
||||
const { listDetails, entryId, entryOrder } = req.body; // Destructure needed properties from the request body
|
||||
|
||||
try {
|
||||
const result = await sequelize.transaction(async (t) => {
|
||||
// Step 1: Create the list
|
||||
const newList = await List.create(listDetails, { transaction: t });
|
||||
|
||||
// Step 2: Add an entry to the newly created list
|
||||
const newListEntry = await ListEntry.create({
|
||||
listId: newList.id,
|
||||
entryId: entryId,
|
||||
entryOrder: entryOrder
|
||||
}, { transaction: t });
|
||||
|
||||
return { newList, newListEntry };
|
||||
});
|
||||
|
||||
// If the transaction is successful, send back the created list and entry relationship
|
||||
res.status(201).json(result);
|
||||
} catch (error) {
|
||||
console.error('Failed to create list and add entry:', error);
|
||||
res.status(500).json({ message: 'Failed to create list and add entry', error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
@@ -1,12 +1,12 @@
|
||||
const express = require('express');
|
||||
const entryRoutes = require('./entryRoutes');
|
||||
const listRoutes = require('./listRoutes');
|
||||
const userCollectionRoutes = require('./userCollectionRoutes');
|
||||
const entrySeenRoutes = require('./entrySeenRoutes');
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
router.use('/entries', entryRoutes);
|
||||
router.use('/lists', listRoutes);
|
||||
router.use('/user-collections', userCollectionRoutes);
|
||||
router.use('/entry-seen', entrySeenRoutes)
|
||||
|
||||
module.exports = router;
|
||||
@@ -0,0 +1,204 @@
|
||||
const express = require('express');
|
||||
const UserCollection = require('../models/UserCollection');
|
||||
const UserCollectionEntry = require('../models/UserCollectionEntry');
|
||||
const Entry = require('../models/Entry');
|
||||
const EntryId = require('../models/EntryId');
|
||||
const EntryRating = require('../models/EntryRating');
|
||||
const router = express.Router();
|
||||
|
||||
// ! /user-collections
|
||||
// * POST - CREATE UserCollection
|
||||
router.post('/', async (req, res) => {
|
||||
try {
|
||||
const { name, description, user_rating, poster_path } = req.body;
|
||||
const newUserCollection = await UserCollection.create({ name, description, user_rating, poster_path });
|
||||
res.status(201).json(newUserCollection);
|
||||
} catch (error) {
|
||||
res.status(400).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
// * GET - ALL UserCollections
|
||||
router.get('/', async (req, res) => {
|
||||
let userCollections; // Declare outside to broaden scope, albeit unnecessary in your given context
|
||||
try {
|
||||
userCollections = await UserCollection.findAll({
|
||||
include: [
|
||||
{ model: UserCollectionEntry, as: 'userCollectionEntries' },
|
||||
]
|
||||
});
|
||||
res.status(200).json(userCollections);
|
||||
} catch (error) {
|
||||
console.error("Error fetching UserCollections:", error); // More detailed error logging
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
// * GET - userCollection BY ID
|
||||
router.get('/:id', async (req, res) => {
|
||||
try {
|
||||
const userCollection = await UserCollection.findByPk(req.params.id, {
|
||||
include: [{
|
||||
model: Entry,
|
||||
as: 'entries', // Make sure this matches your alias in the association, if any
|
||||
through: {
|
||||
attributes: [], // Exclude attributes from the join model, if you don't need them
|
||||
},
|
||||
}],
|
||||
});
|
||||
|
||||
if (userCollection) {
|
||||
// Optionally, sort the entries here if needed, using JavaScript's sort()
|
||||
// This is a workaround for the direct ordering limitation via Sequelize in many-to-many relationships
|
||||
for (let i = 0; i < userCollection.entries.length; i++) {
|
||||
userCollection.entries[i] = await Entry.findByPk(userCollection.entries[i].id,
|
||||
{
|
||||
include: [
|
||||
{ model: EntryId, as: 'entryId' },
|
||||
{ model: EntryRating, as: 'entryRating' }
|
||||
]
|
||||
})
|
||||
}
|
||||
res.status(200).json(userCollection);
|
||||
} else {
|
||||
res.status(404).json({ message: 'UserCollection not found' });
|
||||
}
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
// * PUT - UPDATE A UserCollection
|
||||
router.put('/:id', async (req, res) => {
|
||||
try {
|
||||
const { name, description, user_rating, poster_path } = req.body;
|
||||
const [updated] = await UserCollection.update({ name, description, user_rating, poster_path }, { where: { id: req.params.id } });
|
||||
|
||||
if (updated) {
|
||||
const updatedUserCollection = await UserCollection.findByPk(req.params.id);
|
||||
res.status(200).json(updatedUserCollection);
|
||||
} else {
|
||||
res.status(404).json({ message: 'UserCollection not found' });
|
||||
}
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
// * DELETE - A UserCollection
|
||||
router.delete('/:id', async (req, res) => {
|
||||
try {
|
||||
const deleted = await UserCollection.destroy({ where: { id: req.params.id } });
|
||||
if (deleted) {
|
||||
res.status(204).send();
|
||||
} else {
|
||||
res.status(404).json({ message: 'UserCollection not found' });
|
||||
}
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// * POST - ADD ENTRY TO A UserCollection
|
||||
router.post('/:userCollectionId/entries/:entryId', async (req, res) => {
|
||||
try {
|
||||
const { userCollectionId, entryId } = req.params;
|
||||
const { order } = req.body;
|
||||
|
||||
const newUserCollectionEntry = await UserCollectionEntry.create({
|
||||
user_collection_id: userCollectionId,
|
||||
entry_id: entryId,
|
||||
order: order || 0
|
||||
});
|
||||
|
||||
// ? set a default poster if none exists
|
||||
const userCollection = await UserCollection.findByPk(userCollectionId);
|
||||
if (!userCollection.poster_path || userCollection.poster_path.trim() === '') {
|
||||
const entry = await Entry.findByPk(entryId);
|
||||
userCollection.poster_path = entry.poster_path;
|
||||
await userCollection.save();
|
||||
}
|
||||
|
||||
res.status(201).json(newUserCollectionEntry);
|
||||
} catch (error) {
|
||||
res.status(400).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
// * PATCH - UPDATE ENTRY ORDER IN UserCollection
|
||||
router.patch('/:userCollectionId/entries/:entryId/order', async (req, res) => {
|
||||
try {
|
||||
const { userCollectionId, entryId } = req.params;
|
||||
const { newOrder } = req.body; // The new order value
|
||||
|
||||
// Assuming you have a model UserCollectionEntry for the junction table
|
||||
const updated = await UserCollectionEntry.update(
|
||||
{ entryOrder: newOrder }, // Set new order
|
||||
{
|
||||
where: {
|
||||
userCollectionId: userCollectionId,
|
||||
entryId: entryId
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
if (updated[0] > 0) {
|
||||
res.status(200).json({ message: 'Entry order updated successfully.' });
|
||||
} else {
|
||||
res.status(404).json({ message: 'UserCollection entry not found.' });
|
||||
}
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
// * DELETE - AND ENTRY FROM A UserCollection
|
||||
router.delete('/:userCollectionId/entries/:entryId', async (req, res) => {
|
||||
try {
|
||||
const { userCollectionId, entryId } = req.params;
|
||||
const deleted = await UserCollectionEntry.destroy({
|
||||
where: {
|
||||
user_collection_id: userCollectionId,
|
||||
entry_id: entryId
|
||||
}
|
||||
});
|
||||
|
||||
if (deleted) {
|
||||
res.status(204).send();
|
||||
} else {
|
||||
res.status(404).json({ message: 'UserCollection entry not found.' });
|
||||
}
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
// * POST - CREATE UserCollection WITH ENTRY
|
||||
router.post('/lists-with-entry', async (req, res) => {
|
||||
const { listDetails, entryId, entryOrder } = req.body; // Destructure needed properties from the request body
|
||||
|
||||
try {
|
||||
const result = await sequelize.transaction(async (t) => {
|
||||
// Step 1: Create the userCollection
|
||||
const newUserCollection = await UserCollection.create(listDetails, { transaction: t });
|
||||
|
||||
// Step 2: Add an entry to the newly created userCollection
|
||||
const newUserCollectionEntry = await UserCollectionEntry.create({
|
||||
userCollectionId: newUserCollection.id,
|
||||
entryId: entryId,
|
||||
entryOrder: entryOrder
|
||||
}, { transaction: t });
|
||||
|
||||
return { newUserCollection, newUserCollectionEntry };
|
||||
});
|
||||
|
||||
// If the transaction is successful, send back the created userCollection and entry relationship
|
||||
res.status(201).json(result);
|
||||
} catch (error) {
|
||||
console.error('Failed to create userCollection and add entry:', error);
|
||||
res.status(500).json({ message: 'Failed to create userCollection and add entry', error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
@@ -35,7 +35,6 @@ sequelize
|
||||
// .sync({force: true})
|
||||
.sync({ alter: true })
|
||||
.then((result) => {
|
||||
// console.log(result);
|
||||
app.listen(PORT, () => {
|
||||
//const Entry = require("./models/Entry.js")
|
||||
console.log(`Backend server running on http://localhost:${PORT}`);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const Entry = require('../models/Entry.js')
|
||||
const Collection = require('../models/Collection.js')
|
||||
const Collection = require('../models/Franchise.js')
|
||||
const EntryId = require('../models/EntryId.js')
|
||||
const EntryRating = require('../models/EntryRating.js');
|
||||
const Season = require('../models/Season.js');
|
||||
|
||||
@@ -2,7 +2,7 @@ const axios = require('axios');
|
||||
const moment = require('../utils/moment.js')
|
||||
|
||||
const Entry = require('../models/Entry.js')
|
||||
const Collection = require('../models/Collection.js')
|
||||
const Collection = require('../models/Franchise.js')
|
||||
const EntryId = require('../models/EntryId.js')
|
||||
const EntryRating = require('../models/EntryRating.js');
|
||||
const { saveEntry } = require('./entryService.js');
|
||||
|
||||
@@ -26,7 +26,7 @@ import { LibraryComponent } from './features/library/library.component';
|
||||
import { DynamicEntryListComponent } from './shared/components/lists/dynamic-entry-list/dynamic-entry-list.component';
|
||||
import { NotificationPopupComponent } from './shared/components/notification-popup/notification-popup.component';
|
||||
import { MainCardComponent } from './shared/components/cards/main-card/main-card.component';
|
||||
import { ListSelectionModalComponent } from './shared/components/modals/list-selection-modal/list-selection-modal.component';
|
||||
import { UserCollectionsModalComponent } from './shared/components/modals/list-selection-modal/user-collections-modal.component';
|
||||
|
||||
@NgModule({
|
||||
declarations: [
|
||||
@@ -42,7 +42,7 @@ import { ListSelectionModalComponent } from './shared/components/modals/list-sel
|
||||
MainCardComponent,
|
||||
DynamicEntryListComponent,
|
||||
NotificationPopupComponent,
|
||||
ListSelectionModalComponent,
|
||||
UserCollectionsModalComponent,
|
||||
],
|
||||
imports: [
|
||||
CoreModule,
|
||||
|
||||
@@ -17,29 +17,20 @@
|
||||
<div class="card-header d-lg-none">
|
||||
<div class="position-relative">
|
||||
<input class="form-control rounded-5 px-5 mobile-search-control" type="text" placeholder="Search">
|
||||
<span
|
||||
class="material-icons-outlined position-absolute ms-3 translate-middle-y start-0 top-50">search</span>
|
||||
<span
|
||||
class="material-icons-outlined position-absolute me-3 translate-middle-y end-0 top-50 mobile-search-close">close</span>
|
||||
<span class="material-icons-outlined position-absolute ms-3 translate-middle-y start-0 top-50">search</span>
|
||||
<span class="material-icons-outlined position-absolute me-3 translate-middle-y end-0 top-50 mobile-search-close">close</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-body search-content">
|
||||
<div class="card-body search-content ps ps--active-y">
|
||||
<p class="search-title">Recent Searches</p>
|
||||
<div class="d-flex align-items-start flex-wrap gap-2 kewords-wrapper">
|
||||
<a href="javascript:;" class="kewords"><span>Angular Template</span><i
|
||||
class="material-icons-outlined fs-6">search</i></a>
|
||||
<a href="javascript:;" class="kewords"><span>Dashboard</span><i
|
||||
class="material-icons-outlined fs-6">search</i></a>
|
||||
<a href="javascript:;" class="kewords"><span>Admin Template</span><i
|
||||
class="material-icons-outlined fs-6">search</i></a>
|
||||
<a href="javascript:;" class="kewords"><span>Bootstrap 5 Admin</span><i
|
||||
class="material-icons-outlined fs-6">search</i></a>
|
||||
<a href="javascript:;" class="kewords"><span>Html eCommerce</span><i
|
||||
class="material-icons-outlined fs-6">search</i></a>
|
||||
<a href="javascript:;" class="kewords"><span>Sass</span><i
|
||||
class="material-icons-outlined fs-6">search</i></a>
|
||||
<a href="javascript:;" class="kewords"><span>laravel 9</span><i
|
||||
class="material-icons-outlined fs-6">search</i></a>
|
||||
<a href="javascript:;" class="kewords"><span>Angular Template</span><i class="material-icons-outlined fs-6">search</i></a>
|
||||
<a href="javascript:;" class="kewords"><span>Dashboard</span><i class="material-icons-outlined fs-6">search</i></a>
|
||||
<a href="javascript:;" class="kewords"><span>Admin Template</span><i class="material-icons-outlined fs-6">search</i></a>
|
||||
<a href="javascript:;" class="kewords"><span>Bootstrap 5 Admin</span><i class="material-icons-outlined fs-6">search</i></a>
|
||||
<a href="javascript:;" class="kewords"><span>Html eCommerce</span><i class="material-icons-outlined fs-6">search</i></a>
|
||||
<a href="javascript:;" class="kewords"><span>Sass</span><i class="material-icons-outlined fs-6">search</i></a>
|
||||
<a href="javascript:;" class="kewords"><span>laravel 9</span><i class="material-icons-outlined fs-6">search</i></a>
|
||||
</div>
|
||||
<hr>
|
||||
<p class="search-title">Tutorials</p>
|
||||
@@ -77,7 +68,7 @@
|
||||
<div class="search-list d-flex flex-column gap-2">
|
||||
<div class="search-list-item d-flex align-items-center gap-3">
|
||||
<div class="memmber-img">
|
||||
<img src="https://picsum.photos/32/32" width="32" height="32" class="rounded-circle" alt="">
|
||||
<img src="assets/images/logo3.png" width="32" height="32" class="rounded-circle" alt="">
|
||||
</div>
|
||||
<div class="">
|
||||
<h5 class="mb-0 search-list-title ">Andrew Stark</h5>
|
||||
@@ -86,7 +77,7 @@
|
||||
|
||||
<div class="search-list-item d-flex align-items-center gap-3">
|
||||
<div class="memmber-img">
|
||||
<img src="https://picsum.photos/32/32" width="32" height="32" class="rounded-circle" alt="">
|
||||
<img src="assets/images/logo3.png" width="32" height="32" class="rounded-circle" alt="">
|
||||
</div>
|
||||
<div class="">
|
||||
<h5 class="mb-0 search-list-title ">Snetro Jhonia</h5>
|
||||
@@ -95,7 +86,7 @@
|
||||
|
||||
<div class="search-list-item d-flex align-items-center gap-3">
|
||||
<div class="memmber-img">
|
||||
<img src="https://picsum.photos/32/32" width="32" height="32" class="rounded-circle" alt="">
|
||||
<img src="assets/images/logo3.png" width="32" height="32" class="rounded-circle" alt="">
|
||||
</div>
|
||||
<div class="">
|
||||
<h5 class="mb-0 search-list-title">Michle Clark</h5>
|
||||
@@ -103,7 +94,7 @@
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="ps__rail-x" style="left: 0px; bottom: 0px;"><div class="ps__thumb-x" tabindex="0" style="left: 0px; width: 0px;"></div></div><div class="ps__rail-y" style="top: 0px; right: 0px; height: 389px;"><div class="ps__thumb-y" tabindex="0" style="top: 0px; height: 281px;"></div></div></div>
|
||||
<div class="card-footer text-center bg-transparent">
|
||||
<a href="javascript:;" class="btn w-100">See All Search Results</a>
|
||||
</div>
|
||||
|
||||
@@ -74,13 +74,13 @@
|
||||
<div class="menu-title">Watchlist</div>
|
||||
</a>
|
||||
</li>
|
||||
<li routerLink="/lists" routerLinkActive="mm-active">
|
||||
<li routerLink="/user-collections" routerLinkActive="mm-active">
|
||||
<a>
|
||||
<div class="parent-icon"><span class="material-symbols-outlined">
|
||||
format_list_bulleted
|
||||
</span>
|
||||
</div>
|
||||
<div class="menu-title">Lists</div>
|
||||
<div class="menu-title">Collections</div>
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
@@ -4,19 +4,20 @@ import { CommonModule } from '@angular/common';
|
||||
import { TmdbService } from './services/tmdb.service';
|
||||
import { LibraryService } from './services/library.service';
|
||||
import { EntryService } from './services/entry.service';
|
||||
import { ListService } from './services/list.service';
|
||||
import { UserCollectionService } from './services/userCollection.service';
|
||||
import { ToggleService } from './services/toggle.service';
|
||||
import { SidebarComponent } from './components/sidebar/sidebar.component';
|
||||
import { NavbarComponent } from './components/navbar/navbar.component';
|
||||
import { RouterModule } from '@angular/router';
|
||||
|
||||
@NgModule({
|
||||
declarations: [SidebarComponent, NavbarComponent],
|
||||
imports: [CommonModule],
|
||||
imports: [CommonModule, RouterModule],
|
||||
providers: [
|
||||
TmdbService,
|
||||
LibraryService,
|
||||
EntryService,
|
||||
ListService,
|
||||
UserCollectionService,
|
||||
ToggleService,
|
||||
],
|
||||
exports: [SidebarComponent, NavbarComponent],
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
import { UserCollection } from '../../shared/models/userCollection.model';
|
||||
import { ListEntry } from '../../shared/models/listEntry.model';
|
||||
import { Entry } from '../../shared/models/entry.model';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class ListService {
|
||||
private backend_apiUrl = 'http://localhost:4000/api/v1';
|
||||
constructor(private http: HttpClient) {}
|
||||
|
||||
// get all lists
|
||||
getLists(): Observable<UserCollection[]> {
|
||||
return this.http.get<UserCollection[]>(`${this.backend_apiUrl}/lists`);
|
||||
}
|
||||
|
||||
// get a list by id
|
||||
getList(id: string) {
|
||||
return this.http.get<UserCollection[]>(`${this.backend_apiUrl}/lists/${id}`);
|
||||
}
|
||||
|
||||
// Create a new list
|
||||
createList(list: UserCollection): Observable<UserCollection> {
|
||||
return this.http.post<UserCollection>(`${this.backend_apiUrl}/lists`, list);
|
||||
}
|
||||
|
||||
// Delete a list by ID
|
||||
deleteList(id: number): Observable<any> {
|
||||
return this.http.delete(`${this.backend_apiUrl}/lists/${id}`);
|
||||
}
|
||||
|
||||
// Add an entry to a list
|
||||
addEntryToList(
|
||||
listId: number,
|
||||
entryId: number,
|
||||
order: number
|
||||
): Observable<ListEntry> {
|
||||
return this.http.post<ListEntry>(
|
||||
`${this.backend_apiUrl}/lists/${listId}/entries/${entryId}`,
|
||||
{ order: order }
|
||||
);
|
||||
}
|
||||
|
||||
// Update an entry's order in a list
|
||||
updateEntryOrder(
|
||||
listId: number,
|
||||
entryId: number,
|
||||
newOrder: number
|
||||
): Observable<any> {
|
||||
return this.http.patch(
|
||||
`${this.backend_apiUrl}/lists/${listId}/entries/${entryId}/order`,
|
||||
{ newOrder }
|
||||
);
|
||||
}
|
||||
|
||||
// Remove an entry from a list
|
||||
removeEntryFromList(listId: string, entryId: number): Observable<Entry> {
|
||||
return this.http.delete<Entry>(
|
||||
`${this.backend_apiUrl}/lists/${listId}/entries/${entryId}`
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
import { UserCollection } from '../../shared/models/userCollection.model';
|
||||
import { UserCollectionEntry } from '../../shared/models/userCollectionEntry.model';
|
||||
import { Entry } from '../../shared/models/entry.model';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class UserCollectionService {
|
||||
private backend_apiUrl = 'http://localhost:4000/api/v1';
|
||||
private apiAction = 'user-collections';
|
||||
|
||||
constructor(private http: HttpClient) {}
|
||||
|
||||
// get all lists
|
||||
getLists(): Observable<UserCollection[]> {
|
||||
return this.http.get<UserCollection[]>(
|
||||
`${this.backend_apiUrl}/${this.apiAction}`
|
||||
);
|
||||
}
|
||||
|
||||
// get a list by id
|
||||
getList(userCollectionId: string) {
|
||||
return this.http.get<UserCollection[]>(
|
||||
`${this.backend_apiUrl}/${this.apiAction}/${userCollectionId}`
|
||||
);
|
||||
}
|
||||
|
||||
// Create a new list
|
||||
createList(userCollection: UserCollection): Observable<UserCollection> {
|
||||
return this.http.post<UserCollection>(
|
||||
`${this.backend_apiUrl}/${this.apiAction}`,
|
||||
userCollection
|
||||
);
|
||||
}
|
||||
|
||||
// Delete a list by ID
|
||||
deleteList(userCollectionId: number): Observable<any> {
|
||||
return this.http.delete(
|
||||
`${this.backend_apiUrl}/${this.apiAction}/${userCollectionId}`
|
||||
);
|
||||
}
|
||||
|
||||
// Add an entry to a list
|
||||
addEntryToList(
|
||||
userCollectionId: number,
|
||||
entryId: number,
|
||||
order: number
|
||||
): Observable<UserCollectionEntry> {
|
||||
return this.http.post<UserCollectionEntry>(
|
||||
`${this.backend_apiUrl}/${this.apiAction}/${userCollectionId}/entries/${entryId}`,
|
||||
{ order: order }
|
||||
);
|
||||
}
|
||||
|
||||
// Update an entry's order in a list
|
||||
updateEntryOrder(
|
||||
userCollectionId: string,
|
||||
entryId: number,
|
||||
newOrder: number
|
||||
): Observable<any> {
|
||||
return this.http.patch(
|
||||
`${this.backend_apiUrl}/${this.apiAction}/${userCollectionId}/entries/${entryId}/order`,
|
||||
{ newOrder }
|
||||
);
|
||||
}
|
||||
|
||||
// Remove an entry from a list
|
||||
removeEntryFromList(
|
||||
userCollectionId: string,
|
||||
entryId: number
|
||||
): Observable<Entry> {
|
||||
return this.http.delete<Entry>(
|
||||
`${this.backend_apiUrl}/${this.apiAction}/${userCollectionId}/entries/${entryId}`
|
||||
);
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -3,7 +3,7 @@ import { MatDialog } from '@angular/material/dialog';
|
||||
import { LibraryService } from '../../../../core/services/library.service';
|
||||
import { Entry } from '../../../../shared/models/entry.model';
|
||||
import { trigger, transition, style, animate } from '@angular/animations';
|
||||
import { ListService } from '../../../../core/services/list.service';
|
||||
import { UserCollectionService } from '../../../../core/services/userCollection.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-userCollection-grid-card',
|
||||
@@ -26,7 +26,7 @@ export class UserCollectionGridCardComponent {
|
||||
|
||||
constructor(
|
||||
private libraryService: LibraryService,
|
||||
private listService: ListService,
|
||||
private listService: UserCollectionService,
|
||||
public dialog: MatDialog
|
||||
) {}
|
||||
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
import { Component } from '@angular/core';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { ListService } from '../../../../core/services/list.service';
|
||||
import { UserCollectionService } from '../../../../core/services/userCollection.service';
|
||||
import { UserCollection } from '../../../../shared/models/userCollection.model';
|
||||
import { Entry } from '../../../../shared/models/entry.model';
|
||||
import { DatePipe } from '@angular/common';
|
||||
@@ -18,7 +18,7 @@ export class UserCollectionInfoPageComponent {
|
||||
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
private listService: ListService,
|
||||
private listService: UserCollectionService,
|
||||
private datePipe: DatePipe
|
||||
) {}
|
||||
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
<div class="flex-grow-1 list-item-1">
|
||||
<h6 class="mb-0 list-title" (click)="redirectTo()">{{list.name}}</h6>
|
||||
<p class="mb-0">Created: {{getCreatedDate() | dateFormat}}</p>
|
||||
<p class="mb-0">Contains: {{list.listEntries.length}} title(s)</p>
|
||||
<p class="mb-0">Contains: {{list.userCollectionEntries.length}} title(s)</p>
|
||||
</div>
|
||||
<!-- <div class="form-check form-check-inline me-0">
|
||||
<input class="form-check-input ms-0" type="checkbox">
|
||||
|
||||
+3
-3
@@ -1,6 +1,6 @@
|
||||
import { Component, Input} from '@angular/core';
|
||||
import { UserCollection } from '../../../../shared/models/userCollection.model';
|
||||
import { ListService } from '../../../../core/services/list.service';
|
||||
import { UserCollectionService } from '../../../../core/services/userCollection.service';
|
||||
import { Router } from '@angular/router';
|
||||
import { trigger, transition, style, animate } from '@angular/animations';
|
||||
|
||||
@@ -25,7 +25,7 @@ import { trigger, transition, style, animate } from '@angular/animations';
|
||||
export class UserCollectionsListItemComponent {
|
||||
@Input() list!: UserCollection;
|
||||
|
||||
constructor(private listService: ListService, private router: Router) {}
|
||||
constructor(private listService: UserCollectionService, private router: Router) {}
|
||||
|
||||
getPostPath() {
|
||||
if (this.list.poster_path == null) return 'https://pic.pnnet.dev/256x256';
|
||||
@@ -40,7 +40,7 @@ export class UserCollectionsListItemComponent {
|
||||
}
|
||||
|
||||
redirectTo(): void {
|
||||
this.router.navigate([`/lists/${this.list.id}`]);
|
||||
this.router.navigate([`/user-collections/${this.list.id}`]);
|
||||
}
|
||||
|
||||
deleteList() {
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { FormControl } from '@angular/forms';
|
||||
import { UserCollection } from '../../../../shared/models/userCollection.model';
|
||||
import { ListService } from '../../../../core/services/list.service';
|
||||
import { UserCollectionService } from '../../../../core/services/userCollection.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-userCollections-page',
|
||||
@@ -16,7 +16,7 @@ export class UserCollectionsPageComponent implements OnInit {
|
||||
lists: UserCollection[] = [];
|
||||
listsToShow: UserCollection[] = [];
|
||||
|
||||
constructor(private listService: ListService) {}
|
||||
constructor(private listService: UserCollectionService) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.getLists();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Component, Input, OnInit } from '@angular/core';
|
||||
import { ListSelectionModalComponent } from '../../modals/list-selection-modal/list-selection-modal.component';
|
||||
import { UserCollectionsModalComponent } from '../../modals/list-selection-modal/user-collections-modal.component';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
import { trigger, transition, style, animate } from '@angular/animations';
|
||||
import { Entry } from '../../../models/entry.model';
|
||||
@@ -86,7 +86,7 @@ export class MainCardComponent implements OnInit {
|
||||
|
||||
showAddToListModal() {
|
||||
if (this.entry) {
|
||||
const dialogRef = this.dialog.open(ListSelectionModalComponent, {
|
||||
const dialogRef = this.dialog.open(UserCollectionsModalComponent, {
|
||||
width: '400px',
|
||||
height: '55%',
|
||||
data: {
|
||||
|
||||
-21
@@ -1,21 +0,0 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { ListSelectionModalComponent } from './list-selection-modal.component';
|
||||
|
||||
describe('ListSelectionModalComponent', () => {
|
||||
let component: ListSelectionModalComponent;
|
||||
let fixture: ComponentFixture<ListSelectionModalComponent>;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ListSelectionModalComponent]
|
||||
});
|
||||
fixture = TestBed.createComponent(ListSelectionModalComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
File renamed without changes.
+1
-1
@@ -38,7 +38,7 @@
|
||||
<div data-simplebar class="simplebar-content-wrapper">
|
||||
<div class="list-group">
|
||||
|
||||
<label *ngFor="let list of listsToShow" class="list-group-item">
|
||||
<label *ngFor="let list of userCollectionsToShow" class="list-group-item">
|
||||
<input class="form-check-input me-1" type="checkbox" [value]="list.id"
|
||||
(change)="onSelectionChange(list, $event)" [checked]="list.isChecked">
|
||||
{{ list.name }}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { UserCollectionsModalComponent } from './user-collections-modal.component';
|
||||
|
||||
describe('UserCollectionsModalComponent', () => {
|
||||
let component: UserCollectionsModalComponent;
|
||||
let fixture: ComponentFixture<UserCollectionsModalComponent>;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [UserCollectionsModalComponent]
|
||||
});
|
||||
fixture = TestBed.createComponent(UserCollectionsModalComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
+36
-26
@@ -1,10 +1,10 @@
|
||||
import { Component, Inject, Input, OnInit, ViewChild } from '@angular/core';
|
||||
import { FormControl } from '@angular/forms';
|
||||
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
|
||||
import { ListService } from '../../../../core/services/list.service';
|
||||
import { UserCollectionService } from '../../../../core/services/userCollection.service';
|
||||
import { NotificationPopupComponent } from '../../notification-popup/notification-popup.component';
|
||||
import { NotificationService } from '../../../services/notification.service';
|
||||
import { UserCollection } from '../../../../shared/models/userCollection.model';
|
||||
import { UserCollection } from '../../../models/userCollection.model';
|
||||
|
||||
import {
|
||||
trigger,
|
||||
@@ -15,9 +15,9 @@ import {
|
||||
} from '@angular/animations';
|
||||
|
||||
@Component({
|
||||
selector: 'app-list-selection-modal',
|
||||
templateUrl: './list-selection-modal.component.html',
|
||||
styleUrls: ['./list-selection-modal.component.css'],
|
||||
selector: 'app-user-collections-modal',
|
||||
templateUrl: './user-collections-modal.component.html',
|
||||
styleUrls: ['./user-collections-modal.component.css'],
|
||||
animations: [
|
||||
trigger('fadeInOut', [
|
||||
state('in', style({ opacity: 1 })),
|
||||
@@ -36,20 +36,20 @@ import {
|
||||
]),
|
||||
],
|
||||
})
|
||||
export class ListSelectionModalComponent implements OnInit {
|
||||
export class UserCollectionsModalComponent implements OnInit {
|
||||
@Input() entryId: number = 0;
|
||||
@ViewChild(NotificationPopupComponent)
|
||||
notificationComponent!: NotificationPopupComponent;
|
||||
searchControl = new FormControl('');
|
||||
showAddButton: boolean = false;
|
||||
|
||||
lists: UserCollection[] = [];
|
||||
listsToShow: UserCollection[] = [];
|
||||
userCollections: UserCollection[] = [];
|
||||
userCollectionsToShow: UserCollection[] = [];
|
||||
|
||||
constructor(
|
||||
public dialogRef: MatDialogRef<ListSelectionModalComponent>,
|
||||
public dialogRef: MatDialogRef<UserCollectionsModalComponent>,
|
||||
@Inject(MAT_DIALOG_DATA) public data: any,
|
||||
private listService: ListService,
|
||||
private listService: UserCollectionService,
|
||||
private notificationService: NotificationService
|
||||
) {}
|
||||
|
||||
@@ -64,17 +64,19 @@ export class ListSelectionModalComponent implements OnInit {
|
||||
|
||||
getLists() {
|
||||
this.listService.getLists().subscribe({
|
||||
next: (l) => {
|
||||
l.forEach((list) => {
|
||||
next: (c) => {
|
||||
c.forEach((collection) => {
|
||||
if (
|
||||
list.listEntries.some((entry) => entry.entry_id == this.entryId)
|
||||
collection.userCollectionEntries.some(
|
||||
(entry) => entry.entry_id == this.entryId
|
||||
)
|
||||
) {
|
||||
list.isChecked = true;
|
||||
collection.isChecked = true;
|
||||
}
|
||||
});
|
||||
|
||||
this.lists = l;
|
||||
this.listsToShow = this.lists;
|
||||
this.userCollections = c;
|
||||
this.userCollectionsToShow = this.userCollections;
|
||||
this.applyFilter(this.searchControl.value);
|
||||
},
|
||||
error: (error) => {
|
||||
@@ -85,18 +87,18 @@ export class ListSelectionModalComponent implements OnInit {
|
||||
|
||||
applyFilter(filterValue: string | null) {
|
||||
if (filterValue == null) {
|
||||
this.listsToShow = [...this.lists]; // Show all lists if filter is cleared or null
|
||||
this.showAddButton = false; // Assuming you want to hide the button when there's no filter
|
||||
this.userCollectionsToShow = [...this.userCollections];
|
||||
this.showAddButton = false;
|
||||
return;
|
||||
}
|
||||
|
||||
const normalizedFilter = filterValue.toLowerCase().trim();
|
||||
|
||||
this.listsToShow = this.lists.filter((list) =>
|
||||
this.userCollectionsToShow = this.userCollections.filter((list) =>
|
||||
list.name.toLowerCase().trim().includes(normalizedFilter)
|
||||
);
|
||||
|
||||
this.showAddButton = this.listsToShow.length === 0;
|
||||
this.showAddButton = this.userCollectionsToShow.length === 0;
|
||||
}
|
||||
|
||||
createList() {
|
||||
@@ -113,17 +115,23 @@ export class ListSelectionModalComponent implements OnInit {
|
||||
return this.showAddButton;
|
||||
}
|
||||
|
||||
onSelectionChange(list: UserCollection, event: Event): void {
|
||||
onSelectionChange(userCollection: UserCollection, event: Event): void {
|
||||
const inputElement = event.target as HTMLInputElement;
|
||||
const isChecked = inputElement.checked;
|
||||
|
||||
if (isChecked || isChecked == null) {
|
||||
console.log(`Adding Entry ${this.entryId} to list: ${list.name}`);
|
||||
console.log(
|
||||
`Adding Entry ${this.entryId} to list: ${userCollection.name}`
|
||||
);
|
||||
this.listService
|
||||
.addEntryToList(list.id, this.entryId, list.listEntries.length + 1)
|
||||
.addEntryToList(
|
||||
userCollection.id,
|
||||
this.entryId,
|
||||
userCollection.userCollectionEntries.length + 1
|
||||
)
|
||||
.subscribe({
|
||||
next: (response) => {
|
||||
console.log('Success:', response);
|
||||
console.log('Successfuly added Entry To Collection:', response);
|
||||
this.getLists();
|
||||
this.showNotification(
|
||||
'Entry Added',
|
||||
@@ -137,9 +145,11 @@ export class ListSelectionModalComponent implements OnInit {
|
||||
},
|
||||
});
|
||||
} else {
|
||||
console.log(`Removing Entry ${this.entryId} from list: ${list.name}`);
|
||||
console.log(
|
||||
`Removing Entry ${this.entryId} from list: ${userCollection.name}`
|
||||
);
|
||||
this.listService
|
||||
.removeEntryFromList(list.id.toString(), this.entryId)
|
||||
.removeEntryFromList(userCollection.id.toString(), this.entryId)
|
||||
.subscribe({
|
||||
next: (_) => {
|
||||
this.showNotification(
|
||||
@@ -0,0 +1,11 @@
|
||||
export interface EpisodeSeen {
|
||||
id: number;
|
||||
|
||||
episode_id: number;
|
||||
|
||||
date_seen: Date;
|
||||
seen_with: string;
|
||||
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Entry } from './entry.model';
|
||||
import { ListEntry } from './listEntry.model';
|
||||
import { UserCollectionEntry } from './userCollectionEntry.model';
|
||||
|
||||
export interface UserCollection {
|
||||
id: number;
|
||||
@@ -10,7 +10,7 @@ export interface UserCollection {
|
||||
|
||||
poster_path: string;
|
||||
|
||||
listEntries: ListEntry[];
|
||||
userCollectionEntries: UserCollectionEntry[];
|
||||
entries: Entry[];
|
||||
changed: boolean;
|
||||
isChecked: boolean;
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
export interface ListEntry {
|
||||
list_id: number;
|
||||
export interface UserCollectionEntry {
|
||||
user_collection_id: number;
|
||||
entry_id: number;
|
||||
|
||||
order: number;
|
||||
@@ -4,7 +4,7 @@ import { NotificationPopupComponent } from './components/notification-popup/noti
|
||||
import { DateFormatPipe } from './pipes/date-format/date-format.pipe';
|
||||
import { MainCardComponent } from './components/cards/main-card/main-card.component';
|
||||
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
|
||||
import { ListSelectionModalComponent } from './components/modals/list-selection-modal/list-selection-modal.component';
|
||||
import { UserCollectionsModalComponent } from './components/modals/list-selection-modal/user-collections-modal.component';
|
||||
|
||||
@NgModule({
|
||||
declarations: [
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
const { spawn } = require('child_process');
|
||||
const { app, BrowserWindow } = require('electron');
|
||||
const path = require('path');
|
||||
const url = require('url');
|
||||
@@ -16,7 +17,7 @@ function createWindow() {
|
||||
|
||||
win.loadURL(
|
||||
url.format({
|
||||
pathname: path.join(__dirname, 'frontend\\dist\\show-z\\browser\\index.html'),
|
||||
pathname: path.join(__dirname, 'dist\\show-z\\browser\\index.html'),
|
||||
protocol: 'file:',
|
||||
slashes: true
|
||||
})
|
||||
@@ -27,7 +28,21 @@ function createWindow() {
|
||||
});
|
||||
}
|
||||
|
||||
app.on('ready', createWindow);
|
||||
// app.on('ready', createWindow);
|
||||
|
||||
app.on('ready', () => {
|
||||
// Start the Express server
|
||||
const expressProcess = spawn('node', ['backend/server.js']);
|
||||
expressProcess.stdout.on('data', (data) => {
|
||||
console.log(`Express stdout: ${data}`);
|
||||
});
|
||||
expressProcess.stderr.on('data', (data) => {
|
||||
console.error(`Express stderr: ${data}`);
|
||||
});
|
||||
|
||||
// Start the Electron app
|
||||
createWindow();
|
||||
});
|
||||
|
||||
app.on('window-all-closed', () => {
|
||||
if (process.platform !== 'darwin') {
|
||||
|
||||
Generated
+1999
-775
File diff suppressed because it is too large.
Load diff
+9
-5
@@ -6,11 +6,14 @@
|
||||
"ng": "ng",
|
||||
"start:backend": "nodemon backend/server.js",
|
||||
"start:frontend": "ng serve",
|
||||
"start": "concurrently \"npm run start:backend\" \"npm run start:frontend\"",
|
||||
"electron build": "ng build --configuration=production --base-href ./ && electron .",
|
||||
"electron build": "ng build --configuration=production --base-href ./ && copyfiles backend/**/* dist/show-z && electron .",
|
||||
"build": "ng build",
|
||||
"watch": "ng build --watch --configuration development",
|
||||
"test": "ng test"
|
||||
"test": "ng test",
|
||||
"electron-build": "npm-run-all -s electron-build:*",
|
||||
"electron-build:ng": "ng build --configuration=production --base-href ./",
|
||||
"electron-build:copy": "copyfiles backend/**/* dist",
|
||||
"electron-build:electron": "electron ."
|
||||
},
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
@@ -20,7 +23,7 @@
|
||||
"@angular/compiler": "^17.3.0",
|
||||
"@angular/core": "^17.3.0",
|
||||
"@angular/forms": "^17.3.0",
|
||||
"@angular/material": "^17.3.2",
|
||||
"@angular/material": "^17.3.3",
|
||||
"@angular/platform-browser": "^17.3.0",
|
||||
"@angular/platform-browser-dynamic": "^17.3.0",
|
||||
"@angular/router": "^17.3.0",
|
||||
@@ -34,11 +37,12 @@
|
||||
"zone.js": "~0.14.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@angular-devkit/build-angular": "^17.3.0",
|
||||
"@angular-devkit/build-angular": "^17.0.10",
|
||||
"@angular/cli": "^16",
|
||||
"@angular/compiler-cli": "^17.3.0",
|
||||
"@types/jasmine": "~5.1.0",
|
||||
"concurrently": "^8.2.2",
|
||||
"copyfiles": "^2.4.1",
|
||||
"electron": "^29.1.5",
|
||||
"electron-builder": "^24.13.3",
|
||||
"jasmine-core": "~5.1.0",
|
||||
|
||||
Reference in new issue
Block a user