Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

completed #7

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion README-FE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
# Tuner Front-End
## Tuner Front-End

- [Tuner-front-end](https://seed-read-songs-front-end.netlify.app/)

## Tuner Back-End

- [Tuner-back-end](https://songs-api-1ej6.onrender.com/songs)

## Front-End-Repo

- [Tuner-front-end-repo](https://github.com/Jameel914/seed-read-front-end)

---

## Getting Started

Expand Down
21 changes: 21 additions & 0 deletions back-end/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const express = require("express");
const app = express();
const cors = require("cors");

//const songController = require("./controllers/songController.js");
const albumController = require("./controllers/albumController.js");

app.use(cors());
app.use(express.json());
//app.use("/songs", songController);
app.use("/albums", albumController);

app.get("/", (req, res) => {
res.status(200).send("Welcome to Tuner");
});

app.get("*", (req, res) => {
res.status(404).send("Page not found");
});

module.exports = app;
63 changes: 63 additions & 0 deletions back-end/controllers/albumController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
const express = require("express");
const albums = express.Router();

const songController = require("./songController.js");
albums.use("/:albums_id/songs", songController);

const {
getAllAlbums,
getAlbum,
createAlbum,
deleteAlbum,
updateAlbum,
} = require("../queries/album.js");
const { checkName, checkBoolean } = require("../validations/checkAlbums.js");

albums.get("/", async (req, res) => {
const allAlbums = await getAllAlbums();
console.log(allAlbums);
if (allAlbums[0]) {
res.status(200).json(allAlbums);
} else {
res.status(500).json({ error: "server error" });
}
});

albums.get("/:id", async (req, res) => {
const { id } = req.params;
const oneAlbum = await getAlbum(id);
if (oneAlbum) {
res.status(200).json(oneAlbum);
} else {
res.status(404).json({ error: "Not Found" });
}
});

albums.post("/", checkName, checkBoolean, async (req, res) => {
const body = req.body;
const album = await createAlbum(body);
res.status(200).json(album);
});

albums.delete("/:id", async (req, res) => {
const { id } = req.params;
const deletedAlbum = await deleteAlbum(id);
if (deletedAlbum.id) {
res.status(200).json(deletedAlbum);
} else {
res.status(404).json({ error: "Song Not Found" });
}
});

albums.put("/:id", checkName, checkBoolean, async (req, res) => {
const { id } = req.params;
const body = req.body;
const updatedAlbum = await updateAlbum(id, body);
if (updatedAlbum.id) {
res.status(200).json(updatedAlbum);
} else {
res.status(404).json({ error: "Song Not Found" });
}
});

module.exports = albums;
64 changes: 64 additions & 0 deletions back-end/controllers/songController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
const express = require("express");
const songs = express.Router({ mergeParams: true });

const { getAlbum } = require("../queries/album.js");

const {
getAllSongs,
getSong,
createSong,
deleteSong,
updateSong,
} = require("../queries/song.js");

songs.get("/", async (req, res) => {
const { albums_id } = req.params;
const allSongs = await getAllSongs(albums_id);
const albumIndex = await getAlbum(albums_id);

if (albumIndex.id) {
res.status(200).json({ ...albumIndex, allSongs });
} else {
res.status(500).json({ error: "server error" });
}
});

songs.get("/:id", async (req, res) => {
const { albums_id, id } = req.params;
const oneSong = await getSong(id);
const albumIndex = await getAlbum(albums_id);
if (oneSong) {
res.status(200).json({ ...albumIndex, oneSong });
} else {
res.status(404).json({ error: "Not Found" });
}
});

songs.post("/", async (req, res) => {
const { albums_id } = req.params;
const song = await createSong({ albums_id, ...req.body });
res.status(200).json(song);
});

songs.delete("/:id", async (req, res) => {
const { id } = req.params;
const deletedSong = await deleteSong(id);
if (deletedSong.id) {
res.status(200).json(deletedSong);
} else {
res.status(404).json({ error: "Song Not Found" });
}
});

songs.put("/:id", async (req, res) => {
const { id, albums_id } = req.params;
//const body = req.body;
const updatedSong = await updateSong({ albums_id, id, ...req.body });
if (updatedSong.id) {
res.status(200).json(updatedSong);
} else {
res.status(404).json({ error: "Song Not Found" });
}
});

module.exports = songs;
Loading