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 authored May 30, 2023
2 parents d625fc8 + d9cfac0 commit 3f5953d
Show file tree
Hide file tree
Showing 21 changed files with 97 additions and 68 deletions.
10 changes: 3 additions & 7 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 Down Expand Up @@ -76,7 +70,9 @@ jobs:
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ DOCKER_FILES := frontend/Dockerfile backend/Dockerfile db/Dockerfile
DOCKER_BUILD_TXT := .docker_build

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

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
6 changes: 5 additions & 1 deletion backend/src/post-message/post-message.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@ export class PostMessageService {
constructor(private prisma: PrismaService) {}

async postMessage(dto: MessageDto): Promise<Message> {
// TODO 消す。roomIdをベタ打ちしてたけど、idがランダムになるから,部屋名で検索してidを取得する
const room = await this.prisma.chatRoom.findUnique({
where: { roomName: 'hogeRoom' },
});
const msg = await this.prisma.message.create({
data: {
userId: dto.authorId,
content: dto.content,
chatRoomId: 1,
chatRoomId: room?.id || '',
},
});
return msg;
Expand Down
2 changes: 1 addition & 1 deletion backend/src/user/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { loginDto, signUpDto } from './dto/user.dto';
import { UserService } from './user.service';
// TODO front直したら消す
type User = {
id: number;
id: string;
createdAt: Date;
updatedAt: Date;
email: string;
Expand Down
Binary file modified frontend/src/app/__image_snapshots__/app-page--login.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/src/app/__image_snapshots__/app-page--select-channel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/src/app/__image_snapshots__/app-page--send-msg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/src/app/__image_snapshots__/app-page--send-some-msg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion frontend/src/features/chat/api/postMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { MessageDto } from '../types/MessageDto';

import { BACKEND } from '../../../constants';

export const postMessage = (authorId: number, msg: string) => {
export const postMessage = (authorId: string, msg: string) => {
const url = BACKEND + '/post-message';

const msgDto: MessageDto = { content: msg, authorId: authorId };
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion frontend/src/features/chat/types/MessageDto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

export type MessageDto = {
content: string;
authorId: number;
authorId: string;
};

export type handleMessageDto = {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/features/user/components/User.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const User = ({ children }: { children: ReactNode }) => {
botton
</button>
<p>
id : {userInfo?.id}, name : {userInfo?.nickname}
name : {userInfo?.nickname}
</p>
<UserDetailsModal
userInfo={userInfo}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/features/user/types/UserDto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ export type LoginDto = {
};

export type UserInfo = {
id: number;
id: string;
nickname: string;
};

0 comments on commit 3f5953d

Please sign in to comment.