File tree Expand file tree Collapse file tree 3 files changed +54
-32
lines changed Expand file tree Collapse file tree 3 files changed +54
-32
lines changed Original file line number Diff line number Diff line change 1+ import { prisma } from "@/lib/prisma"
2+
3+ export async function getAuthorByUsername ( username : string ) {
4+ return await prisma . user . findUnique ( {
5+ where : { username } ,
6+ select : {
7+ id : true ,
8+ name : true ,
9+ username : true ,
10+ image : true ,
11+ bio : true ,
12+ _count : {
13+ select : { authoredArticles : true }
14+ }
15+ }
16+ } )
17+ }
18+
19+ export async function getAuthors ( ) {
20+ return await prisma . user . findMany ( {
21+ where : {
22+ authoredArticles : {
23+ some : { }
24+ }
25+ } ,
26+ select : {
27+ id : true ,
28+ name : true ,
29+ username : true ,
30+ image : true ,
31+ bio : true ,
32+ _count : {
33+ select : { authoredArticles : true }
34+ }
35+ } ,
36+ orderBy : {
37+ name : 'asc'
38+ }
39+ } )
40+ }
41+
42+ export async function getAuthorForMetadata ( username : string ) {
43+ return await prisma . user . findUnique ( {
44+ where : { username } ,
45+ select : {
46+ name : true ,
47+ username : true
48+ }
49+ } )
50+ }
Original file line number Diff line number Diff line change 1- import { prisma } from "@/lib/prisma"
21import { notFound } from "next/navigation"
32import { Avatar , AvatarFallback , AvatarImage } from "@/components/ui/avatar"
43import ArticleSearchAndGrid from "@/components/article/ArticleSearchAndGrid"
4+ import { getAuthorByUsername , getAuthorForMetadata } from "../../articleActions"
55
66export async function generateMetadata ( { params } : { params : { username : string } } ) {
7- const author = await prisma . user . findUnique ( {
8- where : { username : params . username }
9- } )
7+ const author = await getAuthorForMetadata ( params . username )
108
119 if ( ! author ) {
1210 return {
@@ -21,14 +19,7 @@ export async function generateMetadata({ params }: { params: { username: string
2119}
2220
2321export default async function AuthorPage ( { params } : { params : { username : string } } ) {
24- const author = await prisma . user . findUnique ( {
25- where : { username : params . username } ,
26- include : {
27- _count : {
28- select : { authoredArticles : true }
29- }
30- }
31- } )
22+ const author = await getAuthorByUsername ( params . username )
3223
3324 if ( ! author ) {
3425 notFound ( )
Original file line number Diff line number Diff line change 1- import { prisma } from "@/lib/prisma"
21import AuthorsList from "@/components/authors/AuthorsList"
2+ import { getAuthors } from "../articleActions"
33
44export const metadata = {
55 title : 'Article Authors' ,
66 description : 'Browse all article authors'
77}
88
9- async function getAuthors ( ) {
10- const authors = await prisma . user . findMany ( {
11- where : {
12- authoredArticles : {
13- some : { }
14- }
15- } ,
16- include : {
17- _count : {
18- select : { authoredArticles : true }
19- }
20- } ,
21- orderBy : {
22- name : 'asc'
23- }
24- } )
25- return authors
26- }
27-
289export default async function AuthorsPage ( ) {
2910 const authors = await getAuthors ( )
3011
You can’t perform that action at this time.
0 commit comments