ํ”„๋กœ์ ํŠธ/๐Ÿ ๊ธˆ์œต ์ปค๋ฎค๋‹ˆํ‹ฐ

[๊ฐœ๋ฐœ] ๊ธˆ์œต ์ปค๋ฎค๋‹ˆํ‹ฐ - ๋ฆฌ์น˜์—์ด๋ธ” ๊ฐœ๋ฐœ์ผ์ง€ #5(๋‹ต๊ธ€๊ธฐ๋Šฅ) - v1.0

TwoIceFish 2024. 7. 6. 20:26

ํ›„๊ธฐ

๋ฆฌ์น˜์—์ด๋ธ” v1.0์ด ์™„์„ฑ๋˜์—ˆ๋‹ค.

 

๊ฒŒ์‹œ๊ธ€ ์ž‘์„ฑ ๋ฐ ๋‹ต๊ธ€ ์ž‘์„ฑ ๊ทธ๋ฆฌ๊ณ  ํŒ”๋กœ์šฐ ๊ธฐ๋Šฅ ๊นŒ์ง€ ๋„ฃ์—ˆ๋‹ค.

 

๊ธฐ๋ณธ ๊ตฌ์กฐ๋ฅผ ์žก๋Š”๋ฐ๋งŒ ๊ฑฐ์˜ 3์ฃผ๊ฐ€ ๊ฑธ๋ฆฐ ๋“ฏ ํ•˜๋‹ค ์ด ๊ณผ์ •์—์„œ ์‚ฌ์šฉ์ž ์š”๊ตฌ์‚ฌํ•ญ์— ๋”ฐ๋ฅธ ๋ฐ์ด๋”๋ฒ ์ด์Šค ์„ค๊ณ„ ๋ฐ ๊ธฐ๋Šฅ ๊ตฌํ˜„์— ์žˆ์–ด์„œ ์ข‹์€ ๊ฒฝํ—˜์„ ์–ป์„ ์ˆ˜ ์žˆ๊ฒŒ ๋˜์—ˆ๋‹ค. ํŠนํžˆ ๋ฐ์ดํ„ฐ ๋ฒ ์ด์Šค ๋ถ€๋ถ„์˜ ๊ฒฝ์šฐ ํ…Œ์ด๋ธ” ๊ฐ„ ์ƒ๊ด€๊ด€๊ณ„๊ฐ€ ์•„์ฃผ ์ค‘์š”ํ•œ ๊ฒƒ์„ ๋Š๊ผˆ๋‹ค.

model Thread {
  id         String       @id @default(cuid())
  content    String
  User       User         @relation(fields: [userId], references: [id], onDelete: Cascade)
  createdAt  DateTime     @default(now())
  updatedAt  DateTime     @updatedAt
  userId     String
  ThreadLike ThreadLike[]

  Origin Reply[] @relation("origin")
  Reply  Reply[] @relation("reply")
}

model Reply {
  id        String   @id @default(cuid())
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt

  originThread String // The user who is following
  replyThread  String // The user being followed
  origin       Thread @relation("origin", fields: [originThread], references: [id], onDelete: Cascade)
  reply        Thread @relation("reply", fields: [replyThread], references: [id], onDelete: Cascade)

  @@index([originThread, replyThread], name: "idx_follower_following")
  @@unique([originThread, replyThread])
}

๊ทธ๋ฆฌ๊ณ  ํ”„๋ก ํŠธ์—”๋“œ ๋ถ€๋ถ„์—์„œ์˜ ๋ฐ์ดํ„ฐ API ๊ทœ๊ฒฉ ์„ค์ • ๋“ฑ ๊ธฐ์ดˆ๋ถ€ํ„ฐ ์ž˜ ํ•˜์ง€ ์•Š์œผ๋ฉด ํ›„๋ฐ˜์—๋Š” ๊ผฌ์ด๋Š” ๊ฒƒ์„ ๋Š๊ผˆ๋‹ค. ๊ทธ๋ž˜์„œ ๊ณตํ†ต์ ์œผ๋กœ ๋ฆฌํ„ดํ•˜๋Š” ํ•จ์ˆ˜๋ฅผ ๊ตฌํ˜„ํ•˜๊ณ  ๊ธฐ๋ณธ Type์— ์ œ๋„ค๋ฆญ์„ ํ†ตํ•˜์—ฌ ์ผ๊ด€๋œ ๋ฐ์ดํ„ฐ๋ฅผ ๋ฐ›์•„ ์˜ค๋„๋ก ๊ตฌ์„ฑํ•˜์˜€๋‹ค.

export async function ResponseData<T>(data: T, result: boolean) {
  const response: BasicType<T> = {
    result: result,
    createdAt: new Date(),
    data: data,
  };

  return response;
}
export type BasicType<T> = {
  result: boolean;
  createdAt: Date;
  data?: T;
};
 

์ด์ œ๋Š” ๋‚˜์˜ ๋ณธ์—…์œผ๋กœ ๋Œ์•„๊ฐ„๋‹ค.

 

์ด์Šˆ

zod๋กœ ๋„˜๊ธธ ๋•Œ ๊ตฌ๊ธ€๋กœ๊ทธ์ธ ์‚ฌ์šฉ์ž์˜ ๊ฒฝ์šฐ ์ด๋ฉ”์ผ๊ณผ ๋น„๋ฐ€๋ฒˆํ˜ธ๋Š” ์„ ํƒ์ ์œผ๋กœํ•˜๊ณ  "" ๋กœ ๋Œ€์ฒดํ•ด์„œ ๋„˜๊ฒจ์ค˜์„œ ๋™์ž‘์ด ๊ฐ€๋Šฅํ–ˆ๋‹ค. ๋ฌด๋ฐ˜์‘ ํ˜„์ƒ ์‹œ ์˜ต์…”๋„์— "" ์ถ”๊ฐ€ํ•˜๋Š” ๊ฒƒ์„ ๊ณ ๋ คํ•ด๋ณด์ž

export const userUpdateSchema = z.object({
  email: z.optional(z.string().email()).or(z.literal("")),
  name: z.string().min(2).max(8, {
    message: "์ตœ๋Œ€ 8์ž ์ด๋‚ด๋กœ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”.",
  }),
  password: z
    .optional(z.string().regex(passwordValidation).min(8).max(16))
    .or(z.literal("")),
  image: z.optional(z.string().url().nullable()),
  content: z.string().min(0).nullable(),
});

 

์‚ฌ์ดํŠธ

https://richable.cyber-luna.com

 

๋ฆฌ์น˜์—์ด๋ธ” - ๋กœ๊ทธ์ธ

๋” ๋†’์€ ์„ฑ์žฅ์„ ์œ„ํ•œ ์ปค๋ฎค๋‹ˆํ‹ฐ

richable.cyber-luna.com

์†Œ์Šค์ฝ”๋“œ

https://github.com/TwoIceFIsh/richable-web-server

 

GitHub - TwoIceFIsh/richable-web-server: richable-web-server

richable-web-server. Contribute to TwoIceFIsh/richable-web-server development by creating an account on GitHub.

github.com