diff --git a/docs/ai-usage.md b/docs/ai-usage.md index 7b75d5e..30889bc 100644 --- a/docs/ai-usage.md +++ b/docs/ai-usage.md @@ -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. | \ No newline at end of file +| 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. | \ No newline at end of file diff --git a/frontend/src/components/StarRating.tsx b/frontend/src/components/StarRating.tsx index 0e29a24..895444c 100644 --- a/frontend/src/components/StarRating.tsx +++ b/frontend/src/components/StarRating.tsx @@ -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 @@ -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"; @@ -40,6 +41,7 @@ function starValueFromPointer(clientX: number, rect: DOMRect): number { export default function StarRating({ score, onChange, + onDelete, disabled = false, size = 2, scorePosition = "bottom", @@ -71,54 +73,71 @@ export default function StarRating({ return (
-
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 ( - - ); - })} +
+
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 ( + + ); + })} +
+ {onDelete && score != null && ( + + )}

- {score == null ? "Not yet rated" : `${score/2}/5 stars`} + {score == null ? "Not yet rated" : `${Math.round((score / 2) * 100) / 100}/5 stars`}

); diff --git a/frontend/src/pages/GameDetails.tsx b/frontend/src/pages/GameDetails.tsx index f5c67ce..649ed16 100644 --- a/frontend/src/pages/GameDetails.tsx +++ b/frontend/src/pages/GameDetails.tsx @@ -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; @@ -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( + { 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 = @@ -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 = @@ -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 ( <>
@@ -223,7 +252,12 @@ export default function GameDetails() {

Your Rating

- +
diff --git a/server/src/resolvers/mutation.ts b/server/src/resolvers/mutation.ts index 7114705..dc20fc6 100644 --- a/server/src/resolvers/mutation.ts +++ b/server/src/resolvers/mutation.ts @@ -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), } diff --git a/server/src/schema/typeDefs.ts b/server/src/schema/typeDefs.ts index 20bbe5b..5058897 100644 --- a/server/src/schema/typeDefs.ts +++ b/server/src/schema/typeDefs.ts @@ -65,5 +65,6 @@ export const typeDefs = `#graphql type Mutation { rateGame(gameId: ID!, userId: String!, score: Int!): Game! + deleteRating(gameId: ID!, userId: String!): Game! } ` diff --git a/server/src/services/reviewService.ts b/server/src/services/reviewService.ts index a6d5d56..123b3b0 100644 --- a/server/src/services/reviewService.ts +++ b/server/src/services/reviewService.ts @@ -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) +}