-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from aulasoftwarelibre/feat-read-reviews
Add reviews and stats
- Loading branch information
Showing
32 changed files
with
767 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
prisma/migrations/20240418141956_book_rating/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
-- CreateTable | ||
CREATE TABLE "Review" ( | ||
"id" TEXT NOT NULL, | ||
"version" INTEGER NOT NULL DEFAULT 0, | ||
"bookId" TEXT NOT NULL, | ||
"userId" TEXT NOT NULL, | ||
"createdAt" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"score" INTEGER NOT NULL, | ||
|
||
CONSTRAINT "Review_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "Review_userId_bookId_key" ON "Review"("userId", "bookId"); | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "Review" ADD CONSTRAINT "Review_bookId_fkey" FOREIGN KEY ("bookId") REFERENCES "Book"("id") ON DELETE CASCADE ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "Review" ADD CONSTRAINT "Review_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
-- AlterTable | ||
ALTER TABLE "Review" ADD COLUMN "description" TEXT NOT NULL DEFAULT '', | ||
ADD COLUMN "title" TEXT NOT NULL DEFAULT ''; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
'use client' | ||
|
||
import { Tab, Tabs } from '@nextui-org/tabs' | ||
import NextLink from 'next/link' | ||
import { usePathname } from 'next/navigation' | ||
import { ReactNode } from 'react' | ||
|
||
const TABS = [ | ||
{ | ||
target: 'reviews', | ||
title: 'Reseñas', | ||
}, | ||
{ | ||
target: 'loans', | ||
title: 'Préstamos', | ||
}, | ||
] as ViewTab[] | ||
|
||
interface ViewTab { | ||
target: string | ||
title: string | ||
} | ||
|
||
interface ViewTabsProperties { | ||
children: ReactNode | ||
id: string | ||
} | ||
|
||
export function BookViewTabs({ children, id }: ViewTabsProperties) { | ||
const pathname = usePathname() | ||
|
||
return ( | ||
<> | ||
<Tabs | ||
aria-label="Opciones" | ||
classNames={{ | ||
tab: 'max-w-fit', | ||
tabList: 'w-full', | ||
}} | ||
items={TABS} | ||
selectedKey={pathname} | ||
> | ||
{({ target, title }) => ( | ||
<Tab | ||
as={NextLink} | ||
href={`/books/${id}/${target}`} | ||
key={`/books/${id}/${target}`} | ||
title={title} | ||
/> | ||
)} | ||
</Tabs> | ||
<div className="mt-4">{children}</div> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { Divider } from '@nextui-org/divider' | ||
import { notFound } from 'next/navigation' | ||
import { ReactNode } from 'react' | ||
|
||
import { BookView } from '@/app/books/[id]/(view)/components/book-view' | ||
import { BookViewTabs } from '@/app/books/[id]/(view)/components/book-view-tabs' | ||
import { findBook } from '@/core/book/infrastructure/actions/find-book' | ||
import { UserResponse } from '@/core/user/dto/responses/user.response' | ||
import { me } from '@/core/user/infrastructure/actions/me' | ||
|
||
interface PageParameters { | ||
id: string | ||
} | ||
|
||
export default async function Page({ | ||
children, | ||
params, | ||
}: { | ||
children: ReactNode | ||
params: PageParameters | ||
}) { | ||
const book = await findBook(params.id) | ||
const user = (await me()) as UserResponse | ||
|
||
if (!book) { | ||
return notFound() | ||
} | ||
|
||
return ( | ||
<> | ||
<div className="flex flex-col gap-4"> | ||
<BookView book={book} user={user} /> | ||
<Divider /> | ||
<BookViewTabs id={params.id}>{children}</BookViewTabs> | ||
</div> | ||
</> | ||
) | ||
} |
50 changes: 50 additions & 0 deletions
50
src/app/books/[id]/(view)/loans/components/book-view-tab-loans.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
'use client' | ||
|
||
import { | ||
Table, | ||
TableBody, | ||
TableCell, | ||
TableColumn, | ||
TableHeader, | ||
TableRow, | ||
} from '@nextui-org/table' | ||
import { format } from 'date-fns' | ||
import { es } from 'date-fns/locale' | ||
|
||
import { HistoricalLoansResponse } from '@/core/loan/dto/responses/historical-loans.response' | ||
|
||
interface BookViewTabLoansProperties { | ||
historicalLoans: HistoricalLoansResponse[] | ||
} | ||
|
||
export function BookViewTabLoans({ | ||
historicalLoans, | ||
}: BookViewTabLoansProperties) { | ||
return ( | ||
<> | ||
<h2 className="mt-4 text-3xl font-bold">Histórico de préstamos</h2> | ||
<Table aria-label="Listado historico" isStriped> | ||
<TableHeader> | ||
<TableColumn>Usuario</TableColumn> | ||
<TableColumn>Fecha de préstamo</TableColumn> | ||
<TableColumn>Fecha de devolución</TableColumn> | ||
</TableHeader> | ||
<TableBody items={historicalLoans}> | ||
{(historicalLoan) => ( | ||
<TableRow key={historicalLoan.id}> | ||
<TableCell>{historicalLoan.user.name}</TableCell> | ||
<TableCell>{shortDate(historicalLoan.startsAt)}</TableCell> | ||
<TableCell>{shortDate(historicalLoan.finishedAt)}</TableCell> | ||
</TableRow> | ||
)} | ||
</TableBody> | ||
</Table> | ||
</> | ||
) | ||
} | ||
|
||
function shortDate(date: string | Date) { | ||
return format(new Date(date), 'dd/MM/yyyy', { | ||
locale: es, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { BookViewTabLoans } from '@/app/books/[id]/(view)/loans/components/book-view-tab-loans' | ||
import { getHistoricalLoans } from '@/core/loan/infrastructure/actions/get-historical-loans' | ||
|
||
interface PageParameters { | ||
id: string | ||
} | ||
|
||
export default async function Page({ params }: { params: PageParameters }) { | ||
const historicalLoans = await getHistoricalLoans(params.id) | ||
|
||
return <BookViewTabLoans historicalLoans={historicalLoans} /> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { redirect } from 'next/navigation' | ||
|
||
interface PageParameters { | ||
id: string | ||
} | ||
|
||
export default async function Page({ | ||
params: { id }, | ||
}: { | ||
params: PageParameters | ||
}) { | ||
return redirect(`/books/${id}/reviews`) | ||
} |
Oops, something went wrong.