Skip to content

Commit

Permalink
Merge pull request #97 from icssc/get-menu
Browse files Browse the repository at this point in the history
Schema updates/menu.get
  • Loading branch information
anmho authored Feb 5, 2024
2 parents 65abd01 + 5335282 commit 158309a
Show file tree
Hide file tree
Showing 59 changed files with 11,592 additions and 5,026 deletions.
10 changes: 7 additions & 3 deletions .github/renovate.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": ["config:base"],
"extends": [
"config:base"
],
"packageRules": [
{
"matchPackagePatterns": ["^@acme/"],
"matchPackagePatterns": [
"^@zotmeal/"
],
"enabled": false
}
],
"updateInternalDeps": true,
"rangeStrategy": "bump",
"automerge": true
}
}
Empty file added .turbo/cookies/0.cookie
Empty file.
Empty file added .turbo/cookies/1.cookie
Empty file.
Empty file added .turbo/cookies/2.cookie
Empty file.
Empty file added .turbo/cookies/3.cookie
Empty file.
Empty file added .turbo/cookies/4.cookie
Empty file.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,5 @@ A summary of the libraries we use are listed below.
5. View the local website at http://localhost:19006 and/or with the [Expo Go mobile app](https://expo.dev/client).
As you make changes to the Expo application, those changes will be automatically
reflected on the local website as well as the mobile app.
6. To add a new package run `turbo gen workspace` and follow the prompts

18 changes: 9 additions & 9 deletions apps/expo/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@acme/expo_",
"name": "@zotmeal/expo_",
"version": "0.1.0",
"private": true,
"main": "expo-router/entry",
Expand Down Expand Up @@ -39,10 +39,10 @@
"superjson": "2.2.1"
},
"devDependencies": {
"@acme/eslint-config": "workspace:^0.2.0",
"@acme/prettier-config": "workspace:^0.1.0",
"@acme/tailwind-config": "workspace:^0.1.0",
"@acme/tsconfig": "workspace:^0.1.0",
"@zotmeal/eslint-config": "workspace:^0.2.0",
"@zotmeal/prettier-config": "workspace:^0.1.0",
"@zotmeal/tailwind-config": "workspace:^0.1.0",
"@zotmeal/tsconfig": "workspace:^0.1.0",
"@babel/core": "^7.23.9",
"@babel/preset-env": "^7.23.9",
"@babel/runtime": "^7.23.9",
Expand All @@ -54,12 +54,12 @@
"eslintConfig": {
"root": true,
"extends": [
"@acme/eslint-config/base",
"@acme/eslint-config/react"
"@zotmeal/eslint-config/base",
"@zotmeal/eslint-config/react"
],
"ignorePatterns": [
"expo-plugins/**"
]
},
"prettier": "@acme/prettier-config"
}
"prettier": "@zotmeal/prettier-config"
}
4 changes: 2 additions & 2 deletions apps/expo/src/utils/api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import { httpBatchLink, loggerLink } from "@trpc/client";
import { createTRPCReact } from "@trpc/react-query";
import superjson from "superjson";

import type { AppRouter } from "@acme/api";
import type { AppRouter } from "@zotmeal/api";

/**
* A set of typesafe hooks for consuming your API.
*/
export const api = createTRPCReact<AppRouter>();
export { type RouterInputs, type RouterOutputs } from "@acme/api";
export { type RouterInputs, type RouterOutputs } from "@zotmeal/api";

/**
* Extend this function when going to production by
Expand Down
2 changes: 1 addition & 1 deletion apps/expo/tailwind.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Config } from "tailwindcss";
// @ts-expect-error - no types
import nativewind from "nativewind/preset";

import baseConfig from "@acme/tailwind-config/native";
import baseConfig from "@zotmeal/tailwind-config/native";

export default {
content: ["./src/**/*.{ts,tsx}"],
Expand Down
24 changes: 18 additions & 6 deletions apps/expo/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
{
"extends": "@acme/tsconfig/base.json",
"extends": "@zotmeal/tsconfig/base.json",
"compilerOptions": {
"baseUrl": ".",
"paths": {
"~/*": ["./src/*"]
"~/*": [
"./src/*"
]
},
"jsx": "react-native",
"tsBuildInfoFile": "node_modules/.cache/tsbuildinfo.json",
"types": ["nativewind/types"]
"types": [
"nativewind/types"
]
},
"include": ["src", "*.ts", "*.js", ".expo/types/**/*.ts", "expo-env.d.ts"],
"exclude": ["node_modules"]
}
"include": [
"src",
"*.ts",
"*.js",
".expo/types/**/*.ts",
"expo-env.d.ts"
],
"exclude": [
"node_modules"
]
}
8 changes: 4 additions & 4 deletions apps/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
"main": "serverless.ts",
"scripts": {
"dev": "sls offline --noPrependStageInUrl",
"test": "echo \"Error: no test specified\" && exit 1"
"test": "npx jest"
},
"engines": {
"node": ">=14.15.0"
},
"author": "The serverless webpack authors (https://github.com/elastic-coders/serverless-webpack)",
"license": "MIT",
"dependencies": {
"@acme/api": "workspace:^",
"@acme/db": "workspace:^",
"@acme/eslint-config": "workspace:^",
"@zotmeal/api": "workspace:^",
"@zotmeal/db": "workspace:^",
"@zotmeal/eslint-config": "workspace:^",
"@serverless/typescript": "^3.38.0",
"@types/aws-lambda": "^8.10.133",
"@types/node": "^20.11.11",
Expand Down
7 changes: 0 additions & 7 deletions apps/server/src/functions/hello/schema.ts

This file was deleted.

2 changes: 1 addition & 1 deletion apps/server/src/functions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { AWS } from "@serverless/typescript";

export const functions: AWS["functions"] = {
hello: {
handler: "src/functions/hello/handler.main",
handler: "src/functions/trpc/handler.main",
description: "Lambda function to say hello",
memorySize: 256,
events: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import {
awsLambdaRequestHandler,
CreateAWSLambdaContextOptions,
} from "@trpc/server/adapters/aws-lambda";
import { appRouter, createTRPCContext } from "@acme/api";
import { APIGatewayProxyEventV2 } from "aws-lambda";

import { appRouter, createTRPCContext } from "@zotmeal/api";

const createContext = ({
event,
context,
Expand All @@ -20,15 +21,4 @@ export const handler = awsLambdaRequestHandler({
createContext,
});

// const handler = async (event) => {
// const res = await axios.get("https://jsonplaceholder.typicode.com/todos/1");
// return {
// statusCode: 200,
// body: JSON.stringify({
// message: `Hello ${"hello"} !`,
// data: res.data,
// }),
// };
// };

export const main = handler;
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"clean:workspaces": "turbo clean",
"db:push": "pnpm -F db push",
"db:studio": "pnpm -F db studio",
"dev": "turbo dev --parallel",
"dev": "turbo dev --parallel ",
"format": "turbo format --continue -- --cache --cache-location node_modules/.cache/.prettiercache",
"format:fix": "turbo format --continue -- --write --cache --cache-location node_modules/.cache/.prettiercache",
"lint": "turbo lint --continue -- --cache --cache-location node_modules/.cache/.eslintcache",
Expand All @@ -22,13 +22,13 @@
"typecheck": "turbo typecheck"
},
"devDependencies": {
"@acme/prettier-config": "workspace:^0.1.0",
"@zotmeal/prettier-config": "workspace:^0.1.0",
"@turbo/gen": "^1.11.3",
"prettier": "^3.1.1",
"turbo": "^1.11.3",
"typescript": "^5.3.3"
},
"prettier": "@acme/prettier-config",
"prettier": "@zotmeal/prettier-config",
"pnpm": {
"overrides": {
"@auth/core": "0.20.0"
Expand Down
20 changes: 12 additions & 8 deletions packages/api/package.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
{
"name": "@acme/api",
"name": "@zotmeal/api",
"version": "0.0.0",
"private": true,
"scripts": {
"dev": "echo 'Add dev script here'",
"build": "echo 'Add build script here'",
"test": "echo 'Add test script here'",
"test": "vitest",
"lint": "echo 'Add lint script here'"
},
"dependencies": {
"@acme/db": "workspace:^",
"@acme/eslint-config": "workspace:^",
"@acme/tsconfig": "workspace:^",
"@acme/validators": "workspace:^",
"@trpc/server": "11.0.0-next-beta.236",
"@zotmeal/db": "workspace:^",
"@zotmeal/eslint-config": "workspace:^",
"@zotmeal/prettier-config": "workspace:^",
"@zotmeal/tsconfig": "workspace:^",
"@zotmeal/utils": "workspace:^",
"@zotmeal/validators": "workspace:^",
"date-fns": "^3.3.1",
"superjson": "2.2.1",
"vitest": "^1.2.2",
"zod": "^3.22.4"
},
"eslintConfig": {
"root": true,
"extends": [
"@acme/eslint-config/base"
"@zotmeal/eslint-config/base"
]
},
"prettier": "@acme/prettier-config"
"prettier": "@zotmeal/prettier-config"
}
2 changes: 0 additions & 2 deletions packages/api/src/root.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { menuRouter } from "./router/menu";
import { postRouter } from "./router/post";
import { createTRPCRouter } from "./trpc";

export const appRouter = createTRPCRouter({
post: postRouter,
menu: menuRouter,
});

Expand Down
20 changes: 0 additions & 20 deletions packages/api/src/router/menu.ts

This file was deleted.

File renamed without changes.
7 changes: 7 additions & 0 deletions packages/api/src/router/menu/get.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { describe, it } from "vitest";

describe("", () => {
it("", () => {
console.log("");
});
});
61 changes: 61 additions & 0 deletions packages/api/src/router/menu/get.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { TRPCError } from "@trpc/server";
import { parse } from "date-fns";
import { z } from "zod";

import { MenuPeriod, RestaurantName } from "@zotmeal/db";

import { publicProcedure } from "../../trpc";

export const GetMenuSchema = z.object({
date: z.string().regex(RegExp("/^d{2}/d{2}/d{4}$/")),
period: z.nativeEnum(MenuPeriod),
restaurant: z.nativeEnum(RestaurantName),
});

export const getMenuProcedure = publicProcedure
.input(GetMenuSchema)
.query(async ({ ctx, input }) => {
// get a menu
const { date: dateString, period, restaurant: restaurantName } = input;
const { db } = ctx;
const restaurant = await db.restaurant.findFirst({
where: {
name: restaurantName,
},
include: {
stations: false,
menu: false,
},
});

// should 404
if (restaurant === null) {
throw new TRPCError({
message: "restaurant not found",
code: "NOT_FOUND",
});
}

const date = parse(dateString, "MM/dd/yyyy", new Date());
if (!date) {
throw new TRPCError({
message: `invalid date string ${dateString}`,
code: "BAD_REQUEST",
});
}
const menu = await db.menu.findFirst({
where: {
restaurantId: restaurant.id,
date: date,
period: period,
},
});
if (!menu) {
throw new TRPCError({
message: `menu not found`,
code: "NOT_FOUND",
});
}

return menu;
});
38 changes: 38 additions & 0 deletions packages/api/src/router/menu/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import axios from "axios";

import { createTRPCRouter, publicProcedure } from "../../trpc";
import { getMenuProcedure } from "./get";
import { parseMenuProcedure } from "./parse";

// import { createTRPCRouter, publicProcedure } from "../trpc";
// import { parseCampusDish } from "./parse";

const helloProcedure = publicProcedure.query(async (opts) => {
const res = await axios.get("https://jsonplaceholder.typicode.com/todos/1");
const _ = opts;
console.log(res.data);
console.log("hello");
return "hello";
});

export const menuRouter = createTRPCRouter({
get: getMenuProcedure,
hello: helloProcedure,
parse: parseMenuProcedure,
// parse: publicProcedure.query(async ({ ctx }) => {
// const res = await axios.get(
// "https://uci-campusdish-com.translate.goog/api/menu/GetMenus?locationId=3314&periodId=49&date=1/19/2024",
// );
// try {
// const validated = CampusDishResponseSchema.parse(res.data);
// const parsed = ParsedResponseSchema.parse(parseCampusDish(validated));
// const _ = ctx;
// return parsed;
// } catch (error) {
// if (error instanceof z.ZodError) {
// console.log(error.issues);
// }
// throw error;
// }
// }),
});
Loading

0 comments on commit 158309a

Please sign in to comment.