Reworking actions
All checks were successful
Music Collection CI Workflow / test (./backend) (push) Successful in 22s
Music Collection CI Workflow / test (./frontend) (push) Successful in 27s
Music Collection CI Workflow / build-and-push-images (./backend/Dockerfile, git.anatid.net/tabris/msuic-collection-backend, ./backend) (push) Successful in 49s
Music Collection CI Workflow / build-and-push-images (./frontend/Dockerfile, git.anatid.net/tabris/music-collection-frontend, ./frontend) (push) Successful in 1m45s
Music Collection CI Workflow / deploy (push) Successful in 23s
All checks were successful
Music Collection CI Workflow / test (./backend) (push) Successful in 22s
Music Collection CI Workflow / test (./frontend) (push) Successful in 27s
Music Collection CI Workflow / build-and-push-images (./backend/Dockerfile, git.anatid.net/tabris/msuic-collection-backend, ./backend) (push) Successful in 49s
Music Collection CI Workflow / build-and-push-images (./frontend/Dockerfile, git.anatid.net/tabris/music-collection-frontend, ./frontend) (push) Successful in 1m45s
Music Collection CI Workflow / deploy (push) Successful in 23s
This commit is contained in:
parent
7259fda77c
commit
b078afc2af
@ -1,11 +1,11 @@
|
||||
'use server'
|
||||
|
||||
export async function getAlbums() {
|
||||
return await fetch('https://api.anatid.net/album');
|
||||
return fetch('https://api.anatid.net/album');
|
||||
}
|
||||
|
||||
export async function getAlbum(id: number) {
|
||||
return await fetch(`https://api.anatid.net/album/${id}`, {
|
||||
return fetch(`https://api.anatid.net/album/${id}`, {
|
||||
method: "GET",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
});
|
||||
@ -15,7 +15,7 @@ export async function createAlbum(formData: FormData) {
|
||||
const title = formData.get('title');
|
||||
const artist = formData.get('artist');
|
||||
const genre = formData.get('genre');
|
||||
return await fetch("https://api.anatid.net/album", {
|
||||
return fetch("https://api.anatid.net/album", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
@ -31,7 +31,7 @@ export async function updateAlbum(formData: FormData) {
|
||||
const title = formData.get('title');
|
||||
const artist = formData.get('artist');
|
||||
const genre = formData.get('genre');
|
||||
return await fetch("https://api.anatid.net/album", {
|
||||
return fetch("https://api.anatid.net/album", {
|
||||
method: "PUT",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
@ -45,7 +45,7 @@ export async function updateAlbum(formData: FormData) {
|
||||
|
||||
export async function deleteAlbum(formData: FormData) {
|
||||
const id = formData.get('id');
|
||||
return await fetch("https://api.anatid.net/album", {
|
||||
return fetch("https://api.anatid.net/album", {
|
||||
method: "DELETE",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
@ -55,11 +55,11 @@ export async function deleteAlbum(formData: FormData) {
|
||||
}
|
||||
|
||||
export async function getSongs() {
|
||||
return await fetch("https://api.anatid.net/song/");
|
||||
return fetch("https://api.anatid.net/song/");
|
||||
}
|
||||
|
||||
export async function getSong(id: number) {
|
||||
return await fetch(`https://api.anatid.net/song/${id}`, {
|
||||
return fetch(`https://api.anatid.net/song/${id}`, {
|
||||
method: "GET",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
});
|
||||
@ -69,7 +69,7 @@ export async function createSong(formData: FormData) {
|
||||
const albumId = formData.get('album-id');
|
||||
const title = formData.get('title');
|
||||
const duration = formData.get('duration');
|
||||
return await fetch("https://api.anatid.net/song", {
|
||||
return fetch("https://api.anatid.net/song", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
@ -85,7 +85,7 @@ export async function updateSong(formData: FormData) {
|
||||
const albumId = formData.get('album-id');
|
||||
const title = formData.get('title');
|
||||
const duration = formData.get('duration');
|
||||
return await fetch("https://api.anatid.net/song", {
|
||||
return fetch("https://api.anatid.net/song", {
|
||||
method: "PUT",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
@ -99,7 +99,7 @@ export async function updateSong(formData: FormData) {
|
||||
|
||||
export async function deleteSong(formData: FormData) {
|
||||
const id = formData.get('id');
|
||||
return await fetch("https://api.anatid.net/song", {
|
||||
return fetch("https://api.anatid.net/song", {
|
||||
method: "DELETE",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
|
@ -3,7 +3,7 @@
|
||||
import { FormEvent, MouseEvent, useState, useEffect } from 'react';
|
||||
import Link from 'next/link';
|
||||
import { Album } from '@/entities/album.entity';
|
||||
import { createAlbum, getAlbum, updateAlbum } from '@/app/actions';
|
||||
import { createAlbum, getAlbum, getAlbums, updateAlbum } from '@/app/actions';
|
||||
import Button from 'react-bootstrap/Button';
|
||||
import Modal from 'react-bootstrap/Modal';
|
||||
import { IconButton } from '@mui/material';
|
||||
@ -18,11 +18,12 @@ export default function Page() {
|
||||
const [formAlbumTitle, setFormAlbumTitle] = useState("");
|
||||
const [formAlbumArtist, setFormAlbumArtist] = useState("");
|
||||
const [formAlbumGenre, setFormAlbumGenre] = useState("");
|
||||
const [formModalTitle, setFormModalTitle] = useState("Add Album");
|
||||
|
||||
useEffect(() => {
|
||||
async function fetchAlbums() {
|
||||
try {
|
||||
const response = await fetch('https://api.anatid.net/album');
|
||||
const response = await getAlbums();
|
||||
const data = await response.json();
|
||||
setAlbums(data);
|
||||
} catch (error) {
|
||||
@ -53,6 +54,7 @@ export default function Page() {
|
||||
}
|
||||
|
||||
const handleCreate = async () => {
|
||||
setFormModalTitle("Add Album");
|
||||
setFormAlbumId("");
|
||||
setFormAlbumTitle("");
|
||||
setFormAlbumArtist("");
|
||||
@ -61,11 +63,12 @@ export default function Page() {
|
||||
}
|
||||
|
||||
const handleEdit = async (event: MouseEvent<HTMLElement>) => {
|
||||
const id = event.currentTarget.getAttribute('id');
|
||||
const id = event.currentTarget.getAttribute('album-id');
|
||||
if (id) {
|
||||
try {
|
||||
const response = await getAlbum(parseInt(id));
|
||||
const data = await response.json();
|
||||
setFormModalTitle("Edit Album");
|
||||
setFormAlbumId(data.id)
|
||||
setFormAlbumTitle(data.title);
|
||||
setFormAlbumArtist(data.artist);
|
||||
@ -113,10 +116,10 @@ export default function Page() {
|
||||
{album.genre}
|
||||
</td>
|
||||
<td>
|
||||
<IconButton aria-label="Edit Album" size="small" id={album.id.toString()} onClick={handleEdit}>
|
||||
<IconButton aria-label="Edit Album" size="small" album-id={album.id.toString()} onClick={handleEdit}>
|
||||
<Edit fontSize="inherit" color="success"/>
|
||||
</IconButton>
|
||||
<IconButton aria-label="Delete Album" size="small" id={album.id.toString()} onClick={handleEdit}>
|
||||
<IconButton aria-label="Delete Album" size="small" album-id={album.id.toString()} onClick={handleEdit}>
|
||||
<Delete fontSize="inherit" color="success"/>
|
||||
</IconButton>
|
||||
</td>
|
||||
@ -134,7 +137,7 @@ export default function Page() {
|
||||
keyboard={false}
|
||||
>
|
||||
<Modal.Header closeButton>
|
||||
<Modal.Title>Create Album</Modal.Title>
|
||||
<Modal.Title>{formModalTitle}</Modal.Title>
|
||||
</Modal.Header>
|
||||
<Modal.Body>
|
||||
<div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user