Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeepMemo #444

Merged
merged 14 commits into from
Dec 2, 2024
18 changes: 18 additions & 0 deletions server/src/database/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,21 @@ export async function getMatchedUser(userId: UserID): Promise<Result<User[]>> {
return Err(e);
}
}

export async function autoMatch(userId: UserID) {
try {
const result = await prisma.relationship.create({
data: {
status: "MATCHED",
sendingUserId: userId,
receivingUserId: 0, //Keepメモ
},
});

console.log("New relationship record created:", result);
return result;
} catch (error) {
console.error("Error creating new relationship:", error);
throw new Error("Failed to create a new match.");
}
}
15 changes: 15 additions & 0 deletions server/src/router/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { UserID } from "../common/types";
import { safeParseInt } from "../common/lib/result/safeParseInt";
import {
approveRequest,
autoMatch,
cancelRequest,
rejectRequest,
sendRequest,
Expand Down Expand Up @@ -84,4 +85,18 @@ router.put("/reject/:opponentId", async (req: Request, res: Response) => {
}
});

//オートマッチ(メモ帳、運営等に使用)
router.post("/autoMatch", async (req: Request, res: Response) => {
const requesterId = await safeGetUserId(req);
if (!requesterId.ok) return res.status(401).send("auth error");

try {
await autoMatch(requesterId.value as UserID);
res.status(204).send();
} catch (error) {
console.error("Error rejecting match request:", error);
res.status(500).json({ error: "Failed to reject match request" });
}
});

export default router;
5 changes: 5 additions & 0 deletions web/src/api/internal/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,10 @@ export const rejectRequest = (opponentId: UserID) => {
return `${origin}/requests/reject/${opponentId}`;
};

export const autoMatch = () => {
return `${origin}/requests/autoMatch/`;
};

/**
* []実装済み
* GET -> get personalized room overviews.
Expand Down Expand Up @@ -381,6 +385,7 @@ export default {
sendRequest,
acceptRequest,
rejectRequest,
autoMatch,
cancelRequest,
coursesUserId,
coursesDayPeriod,
Expand Down
7 changes: 7 additions & 0 deletions web/src/api/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,15 @@ export async function accept(senderId: UserID) {
return data;
}

export async function autoMatch() {
const res = await credFetch("POST", endpoints.autoMatch());
const data = await res.text();
return data;
}

export default {
send,
reject,
accept,
autoMatch,
};
21 changes: 21 additions & 0 deletions web/src/components/chat/RoomList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,27 @@ export function RoomList(props: RoomListProps) {
</p>
{roomsData?.map((room) => {
if (room.isDM) {
if (room.friendId === 0) {
//Keepメモ
return (
<Box
key={room.friendId}
onClick={() => {
// `state`を使って`room`データを渡す
navigate("./memo", { state: { room } });
}}
>
<HumanListItem
key={room.friendId}
id={room.friendId}
name={room.name}
pictureUrl={room.thumbnail}
rollUpName={true}
lastMessage={room.lastMsg?.content}
/>
</Box>
);
}
return (
<Box
key={room.friendId}
Expand Down
29 changes: 18 additions & 11 deletions web/src/components/match/matching.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,24 @@ export default function Matchings() {
<p>Error: {error.message}</p>
) : (
<List>
{data?.map((matchedUser) => (
<HumanListItem
key={matchedUser.id}
id={matchedUser.id}
name={matchedUser.name}
pictureUrl={matchedUser.pictureUrl}
onOpen={() => openModal(matchedUser)}
onDelete={() => deleteMatch(matchedUser.id).then(() => reload())}
hasDots
/>
))}
{data?.map((matchedUser) =>
matchedUser.id === 0 ? (
//メモ帳
<div key={0} />
) : (
<HumanListItem
key={matchedUser.id}
id={matchedUser.id}
name={matchedUser.name}
pictureUrl={matchedUser.pictureUrl}
onOpen={() => openModal(matchedUser)}
onDelete={() =>
deleteMatch(matchedUser.id).then(() => reload())
}
hasDots
/>
),
)}
</List>
)}
</Box>
Expand Down
6 changes: 6 additions & 0 deletions web/src/routes/registration/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Box } from "@mui/material";
import { useSnackbar } from "notistack";
import { useState } from "react";
import { useNavigate } from "react-router-dom";
import request from "../../api/request";
import type { Step1User } from "../../common/zod/types";
import Header from "../../components/Header";
import { register } from "./functions";
Expand All @@ -10,6 +11,10 @@ import Step2, { type Step2Data } from "./steps/step2_img";
import Confirmation from "./steps/step3_confirmation";
import Step4 from "./steps/step4_course";

function matchWithMemo() {
request.autoMatch();
}

function Registration() {
const { enqueueSnackbar } = useSnackbar();
const navigate = useNavigate();
Expand Down Expand Up @@ -55,6 +60,7 @@ function Registration() {
};
try {
await register(concat, { enqueueSnackbar, navigate });
matchWithMemo();
setStep(4);
} catch (error) {
enqueueSnackbar("サインアップに失敗しました", {
Expand Down
Loading