Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion docs/ai-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,17 @@ This file documents how we use AI tools in the project.
| Tool | Used for | How we checked the output |
| --- | --- | --- |
| Claude (Anthropic) / Opus 5.5 (medium)| Refactoring our written specification into a structured README format. | The group wrote the content and made all decisions: app idea, dataset, data model, functionality and tech stack. We reviewed the result against our own notes and the project requirements, and corrected inconsistencies before committing. |
| Claude (Anthropic) / Sonnet 5 | Scaffolding the backend (`server/`): project setup, Mongoose schema/index design, the `averageScore`/`reviewCount` recompute strategy for ratings, the CSV ingestion script, GraphQL resolvers, and integration tests. Database choice (MongoDB) was decided by the group. | We reviewed the generated code against the README's data model and functionality requirements, checked proposed package versions for compatibility, and verified behavior by running the backend locally against Apollo Sandbox and the automated test suite before committing. |
| Claude (Anthropic) / Sonnet 5 | Scaffolding the backend (`server/`): project setup, Mongoose schema/index design, the `averageScore`/`reviewCount` recompute strategy for ratings, the CSV ingestion script, GraphQL resolvers, and integration tests. Database choice (MongoDB) was decided by the group. | We reviewed the generated code against the README's data model and functionality requirements, checked proposed package versions for compatibility, and verified behavior by running the backend locally against Apollo Sandbox and the automated test suite before committing. |

## Delivery 2

| Tool | Used for | How we checked the output |
| --- | --- | --- |
| Claude (Anthropic) / Sonnet 5 | Writing tests, keeping documentation in sync with new features and decisions, and assisting with debugging and error handling. | We reviewed and ran the tests locally, read through the documentation changes for accuracy, and verified fixes by reproducing the original issues before committing. |

## Delivery 3

| Tool | Used for | How we checked the output |
| --- | --- | --- |
| Claude (Anthropic) / Sonnet 5 | Same as Delivery 2: writing tests, keeping documentation in sync with new features and decisions, and assisting with debugging and error handling. | We reviewed and ran the tests locally, read through the documentation changes for accuracy, and verified fixes by reproducing the original issues before committing. |
| Claude (Anthropic) / Opus 5.5 | Assisting with error handling during deployment to the VM. | We tested the deployment on the VM and confirmed the errors were resolved before committing. |
113 changes: 66 additions & 47 deletions frontend/src/components/StarRating.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useRef, useState } from "react";
import type { KeyboardEvent, MouseEvent } from "react";
import { Star, StarFill, StarHalf } from "react-bootstrap-icons";
import { Star, StarFill, StarHalf, XCircle } from "react-bootstrap-icons";

const STAR_COUNT = 5;
// Ratings are out of 10 server-side, so each star covers two points and a
Expand All @@ -10,6 +10,7 @@ const POINTS_PER_STAR = 2;
interface StarRatingProps {
score: number | null; // 0-10, null when no rating exists yet
onChange?: (score: number) => void;
onDelete?: () => void;
disabled?: boolean;
size?: number;
scorePosition?: "bottom" | "right";
Expand Down Expand Up @@ -40,6 +41,7 @@ function starValueFromPointer(clientX: number, rect: DOMRect): number {
export default function StarRating({
score,
onChange,
onDelete,
disabled = false,
size = 2,
scorePosition = "bottom",
Expand Down Expand Up @@ -71,54 +73,71 @@ export default function StarRating({

return (
<div className={`d-flex flex-${scorePosition === 'bottom' ? 'column' : 'row'} align-items-start gap-1`}>
<div
ref={rowRef}
className="d-inline-flex gap-1"
style={{ cursor: canInteract ? "pointer" : "default" }}
role={canInteract ? "slider" : undefined}
aria-label={canInteract ? "Your rating" : undefined}
aria-valuemin={canInteract ? 0 : undefined}
aria-valuemax={canInteract ? 10 : undefined}
aria-valuenow={canInteract ? score ?? 0 : undefined}
aria-valuetext={
canInteract
? score == null
? "Not yet rated"
: `${score.toFixed(1)} out of 10`
: undefined
}
tabIndex={canInteract ? 0 : undefined}
onMouseMove={
canInteract ? (event) => setHovered(scoreFromPointer(event)) : undefined
}
onMouseLeave={canInteract ? () => setHovered(null) : undefined}
onClick={
canInteract
? (event) => {
const value = scoreFromPointer(event);
if (value != null) onChange?.(value);
}
: undefined
}
onKeyDown={canInteract ? handleKeyDown : undefined}
>
{Array.from({ length: STAR_COUNT }, (_, i) => i + 1).map((starIndex) => {
const fill = fillFor(displayed, starIndex);
return (
<span key={starIndex}
className={`d-inline-flex fs-${size} lh-1`}
style={{ color: "var(--color-brand)" }}
aria-hidden="true"
>
{fill === "full" && <StarFill />}
{fill === "half" && <StarHalf />}
{fill === "empty" && <Star />}
</span>
);
})}
<div className="d-inline-flex align-items-center gap-2">
<div
ref={rowRef}
className="d-inline-flex gap-1"
style={{ cursor: canInteract ? "pointer" : "default" }}
role={canInteract ? "slider" : undefined}
aria-label={canInteract ? "Your rating" : undefined}
aria-valuemin={canInteract ? 0 : undefined}
aria-valuemax={canInteract ? 10 : undefined}
aria-valuenow={canInteract ? score ?? 0 : undefined}
aria-valuetext={
canInteract
? score == null
? "Not yet rated"
: `${score.toFixed(1)} out of 10`
: undefined
}
tabIndex={canInteract ? 0 : undefined}
onMouseMove={
canInteract ? (event) => setHovered(scoreFromPointer(event)) : undefined
}
onMouseLeave={canInteract ? () => setHovered(null) : undefined}
onClick={
canInteract
? (event) => {
const value = scoreFromPointer(event);
if (value != null) onChange?.(value);
}
: undefined
}
onKeyDown={canInteract ? handleKeyDown : undefined}
>
{Array.from({ length: STAR_COUNT }, (_, i) => i + 1).map((starIndex) => {
const fill = fillFor(displayed, starIndex);
return (
<span key={starIndex}
className={`d-inline-flex fs-${size} lh-1`}
style={{ color: "var(--color-brand)" }}
aria-hidden="true"
>
{fill === "full" && <StarFill />}
{fill === "half" && <StarHalf />}
{fill === "empty" && <Star />}
</span>
);
})}
</div>
{onDelete && score != null && (
<button
type="button"
className="btn btn-link p-0 border-0 d-inline-flex text-muted"
style={{ lineHeight: 1 }}
aria-label="Remove your rating"
title="Remove your rating"
onClick={(event) => {
event.stopPropagation();
onDelete();
}}
>
<XCircle size={size >= 3 ? 18 : 14} />
</button>
)}
</div>
<p className={`m-0 text-muted fst-italic ${scorePosition === 'right' ? 'ms-1' : ''}`} style={{ fontSize: "0.875rem" }}>
{score == null ? "Not yet rated" : `${score/2}/5 stars`}
{score == null ? "Not yet rated" : `${Math.round((score / 2) * 100) / 100}/5 stars`}
</p>
</div>
);
Expand Down
38 changes: 36 additions & 2 deletions frontend/src/pages/GameDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ const RATE_GAME = gql`
}
`;

const DELETE_RATING = gql`
mutation DeleteRating($gameId: ID!, $userId: String!) {
deleteRating(gameId: $gameId, userId: $userId) {
id
averageScore
reviewCount
}
}
`;

interface GameData {
game: {
id: string;
Expand Down Expand Up @@ -126,6 +136,19 @@ export default function GameDetails() {
variables: { userId },
});
const [rateGame] = useMutation(RATE_GAME);
const [deleteRating] = useMutation(DELETE_RATING, {
update(cache, _result, { variables }) {
cache.updateQuery<MyReviewData>(
{ query: GET_MY_REVIEW, variables: { userId: variables?.userId } },
(data) =>
data && {
myReviews: data.myReviews.filter(
(review) => review.gameId !== variables?.gameId,
),
},
);
},
});

const game = data?.game;
const savedScore =
Expand All @@ -138,7 +161,7 @@ export default function GameDetails() {
// is only sent once they leave this page (see the effect below). Scoped
// to the current game id so switching games falls back to that game's
// own saved score instead of carrying the previous game's override.
const [override, setOverride] = useState<{ id: string; score: number } | null>(
const [override, setOverride] = useState<{ id: string; score: number | null } | null>(
null,
);
const draftScore =
Expand Down Expand Up @@ -188,6 +211,12 @@ export default function GameDetails() {
setOverride({ id, score });
}

function handleDeleteRating() {
if (!id) return;
setOverride({ id, score: null });
deleteRating({ variables: { gameId: id, userId } });
}

return (
<>
<Header />
Expand Down Expand Up @@ -223,7 +252,12 @@ export default function GameDetails() {
</div>
<div>
<p className="m-0 fw-bold">Your Rating</p>
<StarRating score={draftScore} onChange={handleRate} size={isMobile ? 1 : 2}/>
<StarRating
score={draftScore}
onChange={handleRate}
onDelete={handleDeleteRating}
size={isMobile ? 1 : 2}
/>
</div>
</Stack>
</Stack>
Expand Down
6 changes: 5 additions & 1 deletion server/src/resolvers/mutation.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { rateGame } from '../services/reviewService.js'
import { rateGame, deleteRating } from '../services/reviewService.js'

export const Mutation = {
rateGame: (
_parent: unknown,
args: { gameId: string; userId: string; score: number },
) => rateGame(args.gameId, args.userId, args.score),
deleteRating: (
_parent: unknown,
args: { gameId: string; userId: string },
) => deleteRating(args.gameId, args.userId),
}
1 change: 1 addition & 0 deletions server/src/schema/typeDefs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,6 @@ export const typeDefs = `#graphql
type Mutation {
rateGame(gameId: ID!, userId: String!, score: Int!): Game!
deleteRating(gameId: ID!, userId: String!): Game!
}
`
13 changes: 13 additions & 0 deletions server/src/services/reviewService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,16 @@ export async function rateGame(gameId: string, userId: string, score: number) {

return recomputeGameAggregates(gameObjectId)
}

export async function deleteRating(gameId: string, userId: string) {
const game = await Game.findById(gameId)
if (!game) {
throw new GraphQLError('Game not found', { extensions: { code: 'BAD_USER_INPUT' } })
}

const gameObjectId = new Types.ObjectId(gameId)

await Review.deleteOne({ gameId: gameObjectId, userId })

return recomputeGameAggregates(gameObjectId)
}