Skip to content

Commit

Permalink
Merge branch 'main' into 221-ユーザーをクリックらそのユーザーの情報をモーダルウィンドウ的なので表示させるます
Browse files Browse the repository at this point in the history
  • Loading branch information
wyoheiii committed May 30, 2023
2 parents 0211a4c + 8cd1926 commit b433d3f
Show file tree
Hide file tree
Showing 36 changed files with 486 additions and 90 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/backend-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ jobs:
- name: backend npm install
run: cd backend && npm install
- name: set up prisma
run: cd backend && npx prisma db push --preview-feature && npx prisma generate
run: cd backend && npx prisma db push && npx prisma generate
- name: backend test
run: cd backend && timeout 300 make test
44 changes: 35 additions & 9 deletions .github/workflows/storybook-test.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
# storybook test

# cache-playwright の key が `frontend/package-lock.json` になっているが
# playwright の version とかで 見た方がいいかもだが、
# 現状 プルリクごとに playwright の install が走るので とりあえずこれで 問題なしとする。
# 下記記事だと `package-lock.json` の 依存バージョン を 拾ってきているが この辺でもいいのか?
# - https://playwrightsolutions.com/playwright-github-action-to-cache-the-browser-binaries/
#
# ref
# - https://github.com/microsoft/playwright-github-action
# - `~/.cache/ms-playwright`
Expand All @@ -20,10 +14,23 @@ on:
pull_request:
workflow_dispatch:

env:
DATABASE_URL: postgresql://test:test@localhost:5432/test?schema=public

jobs:
storybook-test:
timeout-minutes: 5
timeout-minutes: 10
runs-on: ubuntu-latest
services:
postgres:
image: postgres:latest
env:
POSTGRES_USER: test
POSTGRES_PASSWORD: test
POSTGRES_DB: test
ports:
- 5432:5432

steps:
- name: checkout git repository
uses: actions/checkout@v3
Expand All @@ -35,18 +42,37 @@ jobs:
path: frontend/node_modules
key: cache-frontend-node-modules-${{ hashFiles('frontend/package-lock.json') }}

- name: playwright version
run: npx playwright -V > playwright-version.txt && cat playwright-version.txt

- name: cache playwright
id: cache-playwright
uses: actions/cache@v3
with:
path: ~/.cache/ms-playwright
key: cache-playwright-${{ hashFiles('frontend/package-lock.json') }}
key: cache-playwright-${{ hashFiles('frontend/package-lock.json') }}-${{ hashFiles('playwright-version.txt') }}

- name: cache backend node-modules
id: cache-backend-node-modules
uses: actions/cache@v3
with:
path: backend/node_modules
key: cache-backend-node-modules-${{ hashFiles('backend/package-lock.json') }}

- name: backend npm install
run: cd backend && npm install
- name: set up prisma
run: cd backend && npx prisma db push && npx prisma generate && npx prisma db seed
- name: run backend
run: cd backend && npm run start:dev &

- name: frontend npm install
run: cd frontend && npm install
- if: ${{ steps.cache-playwright.outputs.cache-hit != 'true' }}
name: install playwright
run: cd frontend && npx playwright install --with-deps
run: cd frontend && npx playwright install
- name: install playwright deps
run: cd frontend && npx playwright install-deps
- name: is storybook file exists
run: cd frontend && make sb-ck-file
- name: run storybook test
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.docker_build
26 changes: 22 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,27 @@

# MAKE
# ------------------------------------------------------------------------------------------
DOCKER_FILES := frontend/Dockerfile backend/Dockerfile db/Dockerfile
DOCKER_BUILD_TXT := .docker_build

PHONY := all
all:
docker compose up --build
all: $(DOCKER_BUILD_TXT)
$(MAKE) local-npm-i
$(MAKE) local-prisma-generate
docker compose up

$(DOCKER_BUILD_TXT): $(DOCKER_FILES)
date > $(DOCKER_BUILD_TXT)
docker compose build

PHONY += local-npm-i
local-npm-i:
cd frontend && npm i
cd backend && npm i

PHONY += local-prisma-generate
local-prisma-generate:
cd backend && npx prisma generate

PHONY += down
down:
Expand Down Expand Up @@ -46,11 +64,11 @@ lint-fix:

PHONY += sb-test
sb-test:
docker exec -t frontend make sb-test
docker compose run --rm frontend make sb-test

PHONY += sb-update
sb-update:
docker exec -t frontend make sb-update
docker compose run --rm frontend make sb-update

# etc...
# ------------------------------------------------------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"license": "UNLICENSED",
"scripts": {
"build": "nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\" .",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\" . && npx prisma format",
"format-ck": "prettier --check \"src/**/*.ts\" \"test/**/*.ts\" .",
"start": "nest start",
"start:dev": "nest start --watch --preserveWatchOutput",
Expand Down
102 changes: 64 additions & 38 deletions backend/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -9,71 +9,97 @@ datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}

// userの情報
model User {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
username String @unique
email String @unique
hashedPassword String
messages Message[]
roomMembers RoomMember[]
userChatState UserChatState[]
id String @id @default(cuid())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
username String @unique
email String @unique
hashedPassword String
messages Message[]
roomMembers RoomMember[]
userChatState UserChatState[]
friendship1 Friendship[] @relation("src")
friendship2 Friendship[] @relation("dest")
}

// userが所属しているchatRoomの集合を取得
model ChatRoom {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
roomName String @unique
id String @id @default(cuid())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
roomName String @unique
password String?
isPrivate Boolean @default(false)
isDM Boolean @default(false)
isPrivate Boolean @default(false)
isDM Boolean @default(false)
messages Message[]
roomMembers RoomMember[]
userChatState UserChatState[]
}

// チャットルームの管理者からbanされた時にこのテーブルに追加、時間が経ったら削除
// ルームに入る際やチャットを送信するときに
// このテーブルを都度チェックしてbanされてなかったらchatroomに入れる的な使い方
// endedAtに終了時間を渡す感じで使う予定

model UserChatState {
chatRoomId String
userId String
userState UserChatStateCode
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
endedAt DateTime
user User @relation(fields: [userId], references: [id])
chatRoom ChatRoom @relation(fields: [chatRoomId], references: [id], onDelete: Cascade)
@@id([chatRoomId, userId, userState])
chatRoomId Int
userId Int
userState UserChatStateCode
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
endedAt DateTime
user User @relation(fields: [userId],references: [id])
chatRoom ChatRoom @relation(fields: [chatRoomId],references: [id], onDelete: Cascade)
}

// chatRoomに参加するときはこのテーブルに追加する
// 抜けたときは削除する
// UserMutedInChatRoom,UserBannedInChatRoomの情報をこのテーブルに持たせれば良くねって思ってるそこのあなた
// このテーブルにban,muteの情報を持たせると、部屋から抜けた際に
// その情報を持っているレコードが削除されてしまってもう一度入るみたいなことができてしまう
model RoomMember {
joinedAt DateTime @default(now())
role UserRole @default(USER)
userId String
chatRoomId String
user User @relation(fields: [userId], references: [id])
chatRoom ChatRoom @relation(fields: [chatRoomId], references: [id], onDelete: Cascade)
@@id([userId, chatRoomId])
joinedAt DateTime @default(now())
role UserRole @default(USER)
userId Int
chatRoomId Int
user User @relation(fields: [userId],references: [id])
chatRoom ChatRoom @relation(fields: [chatRoomId],references: [id], onDelete: Cascade)
}

// chatRoomIdからそのchatRoomのmsg集合を取得したりする
model Message {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
content String
userId Int
chatRoomId Int
user User @relation(fields: [userId],references: [id])
chatRoom ChatRoom @relation(fields: [chatRoomId],references: [id], onDelete: Cascade)
id String @id @default(cuid())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
content String
userId String
chatRoomId String
user User @relation(fields: [userId], references: [id])
chatRoom ChatRoom @relation(fields: [chatRoomId], references: [id], onDelete: Cascade)
}

model Friendship {
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
srcUserId String
destUserId String
status FriendshipStatus
user1 User @relation("src", fields: [srcUserId], references: [id])
user2 User @relation("dest", fields: [destUserId], references: [id])
@@id([srcUserId, destUserId])
}

enum FriendshipStatus {
Requested
Accepted
Blocked
}

enum UserRole {
Expand Down
16 changes: 8 additions & 8 deletions backend/prisma/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,28 +37,28 @@ async function main() {
const roomMember1 = await prisma.roomMember.upsert({
where: {
userId_chatRoomId: {
userId: 1,
chatRoomId: 1,
userId: user1.id,
chatRoomId: room.id,
},
},
update: {},
create: {
userId: 1,
chatRoomId: 1,
userId: user1.id,
chatRoomId: room.id,
role: UserRole.OWNER,
},
});
const roomMember2 = await prisma.roomMember.upsert({
where: {
userId_chatRoomId: {
userId: 2,
chatRoomId: 1,
userId: user2.id,
chatRoomId: room.id,
},
},
update: {},
create: {
userId: 2,
chatRoomId: 1,
userId: user2.id,
chatRoomId: room.id,
},
});
console.log(user1, user2);
Expand Down
4 changes: 2 additions & 2 deletions backend/src/events/events.gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ export class EventsGateway {
}

@SubscribeMessage('getPastMessages')
async handleGetPastMessages(client: Socket, authorId: number) {
async handleGetPastMessages(client: Socket, authorId: string) {
console.log('getPastMessages');
// Userテーブルのidでそのuserのmsgデータを全て取得
const pastMessages = await this.prisma.message.findMany({
where: {
userId: 1,
userId: authorId,
},
});
console.log('mid', authorId);
Expand Down
4 changes: 2 additions & 2 deletions backend/src/post-message/dto/message.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import { ApiProperty } from '@nestjs/swagger';
export class MessageDto {
@ApiProperty({ example: 'test Message', description: 'test' })
content: string;
@ApiProperty({ example: 1, description: 'test' })
authorId: number;
@ApiProperty({ example: 'id', description: 'test' })
authorId: string;
}
11 changes: 7 additions & 4 deletions backend/src/post-message/post-message.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,28 @@ import { PrismaService } from '../prisma/prisma.service';
import { PostMessageService } from './post-message.service';

type Message = {
id: number;
id: string;
createdAt: Date;
updatedAt: Date;
content: string;
authorId: number;
authorId: string;
};
const mockMsg: Message = {
id: 12,
id: '1',
createdAt: new Date(),
updatedAt: new Date(),
content: 'nori',
authorId: 1,
authorId: '2',
};

const mockPrismaService = {
message: {
// PrismaService.createをmockMsgを返すだけの関数にした
create: jest.fn().mockReturnValue(mockMsg),
},
chatRoom: {
findUnique: jest.fn().mockReturnValue({ id: '1' }),
},
};

describe('PostMessageService', () => {
Expand Down
Loading

0 comments on commit b433d3f

Please sign in to comment.