Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
f jt
进阶项目
Commits
19c7c301
Commit
19c7c301
authored
Sep 06, 2025
by
f jt
Browse files
revised
parent
590f1c60
Changes
4
Hide whitespace changes
Inline
Side-by-side
prisma/schema.prisma
View file @
19c7c301
...
@@ -20,6 +20,7 @@ model Room {
...
@@ -20,6 +20,7 @@ model Room {
roomName
String
roomName
String
createdAt
DateTime
@
default
(
now
())
createdAt
DateTime
@
default
(
now
())
messages
Message
[]
messages
Message
[]
roomcreatorId
Int
}
}
model
Message
{
model
Message
{
...
...
src/app/api/room/add/route.ts
View file @
19c7c301
...
@@ -9,7 +9,7 @@ export async function POST(request: NextRequest) {
...
@@ -9,7 +9,7 @@ export async function POST(request: NextRequest) {
return
NextResponse
.
json
({
message
:
'
Unauthorized
'
},
{
status
:
401
});
return
NextResponse
.
json
({
message
:
'
Unauthorized
'
},
{
status
:
401
});
}
}
const
{
roomName
}
=
await
request
.
json
();
const
{
roomName
,
userId
}
=
await
request
.
json
();
if
(
!
roomName
||
typeof
roomName
!==
'
string
'
||
roomName
.
trim
()
===
''
)
{
if
(
!
roomName
||
typeof
roomName
!==
'
string
'
||
roomName
.
trim
()
===
''
)
{
return
NextResponse
.
json
({
message
:
'
有效的房间名称是必需的
'
},
{
status
:
400
});
return
NextResponse
.
json
({
message
:
'
有效的房间名称是必需的
'
},
{
status
:
400
});
...
@@ -18,6 +18,7 @@ export async function POST(request: NextRequest) {
...
@@ -18,6 +18,7 @@ export async function POST(request: NextRequest) {
const
newRoom
=
await
prisma
.
room
.
create
({
const
newRoom
=
await
prisma
.
room
.
create
({
data
:
{
data
:
{
roomName
:
roomName
.
trim
(),
roomName
:
roomName
.
trim
(),
roomcreatorId
:
userId
,
},
},
});
});
...
...
src/app/api/room/delete/route.ts
View file @
19c7c301
...
@@ -15,6 +15,16 @@ export async function POST(request: NextRequest) {
...
@@ -15,6 +15,16 @@ export async function POST(request: NextRequest) {
return
NextResponse
.
json
({
message
:
'
有效的 Room ID 是必需的
'
},
{
status
:
400
});
return
NextResponse
.
json
({
message
:
'
有效的 Room ID 是必需的
'
},
{
status
:
400
});
}
}
const
room
=
await
prisma
.
room
.
findUnique
({
where
:
{
roomId
},
});
if
(
!
room
)
{
return
NextResponse
.
json
({
message
:
'
房间未找到
'
},
{
status
:
404
});
}
if
(
user
.
userId
!==
room
.
roomcreatorId
){
return
NextResponse
.
json
({
message
:
'
Unauthorized
'
},
{
status
:
401
});
}
await
prisma
.
$transaction
([
await
prisma
.
$transaction
([
prisma
.
message
.
deleteMany
({
prisma
.
message
.
deleteMany
({
where
:
{
roomId
:
roomId
},
where
:
{
roomId
:
roomId
},
...
...
src/app/page.tsx
View file @
19c7c301
...
@@ -27,6 +27,7 @@ interface Room {
...
@@ -27,6 +27,7 @@ interface Room {
roomId
:
number
;
roomId
:
number
;
roomName
:
string
;
roomName
:
string
;
lastMessage
:
Message
|
null
;
lastMessage
:
Message
|
null
;
roomcreatorId
:
number
;
}
}
type
RoomListRes
=
{
rooms
:
Room
[]
};
type
RoomListRes
=
{
rooms
:
Room
[]
};
...
@@ -130,7 +131,7 @@ const ChatRoomPage = ({ user, onLogout }: { user: User, onLogout: () => void })
...
@@ -130,7 +131,7 @@ const ChatRoomPage = ({ user, onLogout }: { user: User, onLogout: () => void })
const
handleAddRoom
=
async
()
=>
{
const
handleAddRoom
=
async
()
=>
{
if
(
!
newRoomName
.
trim
())
return
;
if
(
!
newRoomName
.
trim
())
return
;
try
{
try
{
await
addRoomTrigger
({
roomName
:
newRoomName
});
await
addRoomTrigger
({
roomName
:
newRoomName
,
userId
:
user
.
id
});
setNewRoomName
(
''
);
setNewRoomName
(
''
);
mutateRooms
();
mutateRooms
();
}
catch
(
e
)
{
}
catch
(
e
)
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment