Skip to content

Commit

Permalink
Merge pull request #12 from gonta1026/feature/hello_api
Browse files Browse the repository at this point in the history
fix: hello api
  • Loading branch information
gonta1026 authored Jul 31, 2024
2 parents fdd29a9 + 0eae880 commit aeef118
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 19 deletions.
3 changes: 3 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
},
"complexity": {
"noExcessiveCognitiveComplexity": "off"
},
"correctness": {
"noUnusedImports": "info"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type Props = {
}

export const LatestUser: FC<Props> = ({ latestUser }) => {
// const { data: latestUser } = api.user.first.useQuery()
const [user] = api.user.hello.useSuspenseQuery({ text: 'hello', id: 5 })
const utils = api.useUtils()
const [name, setName] = useState('')
const [email, setEmail] = useState('')
Expand All @@ -28,8 +28,8 @@ export const LatestUser: FC<Props> = ({ latestUser }) => {

return (
<div className={styles.showcaseContainer}>
{latestUser ? (
<p className={styles.showcaseText}>Your most recent post: {latestUser.name}</p>
{user ? (
<p className={styles.showcaseText}>Your most recent post: {user.name} です</p>
) : (
<p className={styles.showcaseText}>You have no posts yet.</p>
)}
Expand Down
2 changes: 1 addition & 1 deletion src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { Metadata } from 'next'
import { Inter } from 'next/font/google'
import './globals.css'
import type { ReactNode } from 'react'
import { TRPCReactProvider } from '@/trpc/react'
import { HydrateClient } from '@/trpc/server'
import type { ReactNode } from 'react'

const inter = Inter({
subsets: ['latin'],
Expand Down
10 changes: 9 additions & 1 deletion src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
import Link from 'next/link'

import { LatestUser } from '@/app/components/user'
import { LatestUser } from '@/app/components/latestUser'
import styles from './index.module.css'
import { api } from '@/trpc/server'
// import { api as reactApi } from '@/trpc/react'

export const metadata = {
title: 'next template',
}

export default async function Home() {
const latestUser = await api.user.first()
// const user = await api.user.hello({ text: 'hello', id: 5 })
const user = await api.user.hello({ text: 'hello', id: 5 })

return (
<main className={styles.main}>
<h1>Hello World🚀</h1>
<p style={{ color: 'white' }}>
id: {user?.id}
name: {user?.name}
</p>
<div className={styles.container}>
<h2 className={styles.title}>
Create <span className={styles.pinkSpan}>T3</span> App
Expand Down
7 changes: 0 additions & 7 deletions src/server/api/routers/hello/hello.ts

This file was deleted.

5 changes: 0 additions & 5 deletions src/server/api/routers/hello/hello.usecase.ts

This file was deleted.

7 changes: 7 additions & 0 deletions src/server/api/routers/user/hello.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { helloSchema } from '@/server/api/routers/user/request/hello'
import { helloCallback } from '@/server/api/routers/user/usecase/hello'
import { publicProcedure } from '@/server/api/trpc'

export const hello = () => {
return publicProcedure.input(helloSchema).query(helloCallback)
}
2 changes: 1 addition & 1 deletion src/server/api/routers/user/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createTRPCRouter } from '@/server/api/trpc'
import { create } from './create'
import { hello } from '@/server/api/routers/hello/hello'
import { hello } from '@/server/api/routers/user/hello'
import { first } from '@/server/api/routers/user/first'

export const userRouter = createTRPCRouter({
Expand Down
2 changes: 1 addition & 1 deletion src/server/api/routers/user/request/create.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { z } from 'zod'

export type CreateSchemaInput = typeof createSchema._type
export type CreateSchemaInput = z.infer<typeof createSchema>

export const createSchema = z.object({
name: z
Expand Down
5 changes: 5 additions & 0 deletions src/server/api/routers/user/request/hello.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { z } from 'zod'

export type HelloSchemaInput = z.infer<typeof helloSchema>

export const helloSchema = z.object({ text: z.string(), id: z.number() })
6 changes: 6 additions & 0 deletions src/server/api/routers/user/usecase/hello.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type { MutationCallBackArg } from '@/server/api/routers/user/type'
import type { HelloSchemaInput } from '@/server/api/routers/user/request/hello'

export const helloCallback = async ({ ctx, input }: MutationCallBackArg<HelloSchemaInput>) => {
return await ctx.db.user.findFirst({ where: { id: input.id } })
}

0 comments on commit aeef118

Please sign in to comment.