Skip to content

Commit

Permalink
pagination, gitlab
Browse files Browse the repository at this point in the history
  • Loading branch information
DCRepublic committed Nov 12, 2024
1 parent c323951 commit 06d2885
Show file tree
Hide file tree
Showing 15 changed files with 401 additions and 126 deletions.
31 changes: 31 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
variables:
GIT_STRATEGY: clone
GIT_SUBMODULE_STRATEGY: recursive
DOCKER_TLS_CERTDIR: ""

default:
image: docker:24.0.9
services:
- name: docker:24.0.9-dind
before_script:
- apk add bash curl
- curl --silent "https://gitlab.com/gitlab-org/incubation-engineering/mobile-devops/download-secure-files/-/raw/main/installer" | bash
- mv .secure_files/.env .env
- mv .secure_files/scraper.env scraper.env
- docker info
- docker login -u $SCCS_REGISTRY_USER -p $SCCS_REGISTRY_TOKEN $SCCS_REGISTRY
- git submodule update --init --recursive
- git submodule sync --recursive

build:
stage: build
script:
- docker compose -f docker-compose.yml build
- docker push $SCCS_REGISTRY/sccs/scheduler/scheduler:latest

deploy_docker_stage:
stage: deploy
variables:
DOCKER_HOST: "tcp://130.58.218.21:2376"
script:
- docker stack deploy --with-registry-auth -c ./docker-compose.yml scheduler
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "swatscraper"]
path = swatscraper
url = git@github.com:swat-sccs/swatscraper.git
url = https://github.com/swat-sccs/swatscraper.git
File renamed without changes.
142 changes: 142 additions & 0 deletions app/actions/getCourses.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
"use server";

import { cookies } from "next/headers";
import prisma from "../../lib/prisma";
import { Prisma } from "@prisma/client";
export async function setPlanCookie(plan: string) {
//@ts-ignore
(await cookies()).set("plan", plan);
}

export async function getInitialCourses() {
return await prisma.course.findMany({
relationLoadStrategy: "join", // or 'query'
take: 10,

include: {
sectionAttributes: true,
facultyMeet: {
include: {
meetingTimes: true,
},
},
instructor: true,
},
});
}

export async function getCourses(
take: any,
cursor: any,
query: any,
term: any,
dotw: any,
stime: any
) {
const startTime = stime.toString().split(",").filter(Number);
return await prisma.course.findMany({
relationLoadStrategy: "join", // or 'query'
take: take,

include: {
sectionAttributes: true,
facultyMeet: {
include: {
meetingTimes: true,
},
},
instructor: true,
},

orderBy: [
{
_relevance: {
fields: ["courseTitle", "subject", "courseNumber"],
search: query.trim().split(" ").join(" & "),
sort: "desc",
},
},
],
where: {
...(term
? {
year: term,
}
: {}),
//year: term,

...(query
? {
OR: [
{
courseTitle: {
search: query.trim().split(" ").join(" | "),
mode: "insensitive",
},
},
{
sectionAttributes: {
some: {
code: {
search: query.trim().split(" ").join(" | "),
mode: "insensitive",
},
},
},
},
{
subject: {
search: query.trim().split(" ").join(" | "),
mode: "insensitive",
},
},
{
courseNumber: {
search: query.trim().split(" ").join(" | "),
mode: "insensitive",
},
},
{
instructor: {
displayName: {
search: query.trim().split(" ").join(" | "),
mode: "insensitive",
},
},
},
],
}
: {}),

...(startTime.length > 0
? {
facultyMeet: {
meetingTimes: {
beginTime: {
in: startTime,
},
},
},
}
: {}),

...(dotw.length > 0
? {
facultyMeet: {
meetingTimes: {
is: {
monday: dotw.includes("monday") ? true : Prisma.skip,
tuesday: dotw.includes("tuesday") ? true : Prisma.skip,
wednesday: dotw.includes("wednesday") ? true : Prisma.skip,
thursday: dotw.includes("thursday") ? true : Prisma.skip,
friday: dotw.includes("friday") ? true : Prisma.skip,
saturday: dotw.includes("saturday") ? true : Prisma.skip,
sunday: dotw.includes("sunday") ? true : Prisma.skip,
},
},
},
}
: {}),
},
});
}
2 changes: 2 additions & 0 deletions app/api/deleteRating/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import { NextResponse, NextRequest } from "next/server";

import prisma from "../../../lib/prisma";
import { auth } from "../../../lib/auth";
import { getPlanCookie } from "../../actions/actions";

export async function POST(request: NextRequest) {
const data = await request.json();
Expand Down
2 changes: 1 addition & 1 deletion app/api/getplancourses/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { NextResponse, NextRequest } from "next/server";

import prisma from "../../../lib/prisma";
import { auth } from "../../../lib/auth";
import { getPlanCookie } from "../../../app/actions";
import { getPlanCookie } from "../../actions/actions";

export async function GET(request: NextRequest) {
const planCookie: any = await getPlanCookie();
Expand Down
2 changes: 1 addition & 1 deletion app/api/updatePlan/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { NextResponse, NextRequest } from "next/server";

import prisma from "../../../lib/prisma";
import { auth } from "../../../lib/auth";
import { getPlanCookie } from "../../../app/actions";
import { getPlanCookie } from "../../actions/actions";

export async function POST(request: NextRequest) {
const course = await request.json();
Expand Down
2 changes: 1 addition & 1 deletion app/calendar/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import CreatePlan from "../../components/CreatePlan";
import Calendar from "../../components/Calendar";
import prisma from "../../lib/prisma";
import { getPlanCookie } from "../actions";
import { getPlanCookie } from "../actions/actions";
import { generateColorFromName } from "../../components/primitives";
export default async function CalendarPage() {
async function getEvents() {
Expand Down
10 changes: 9 additions & 1 deletion app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Search from "../components/Search";
import { FullCourseList } from "../components/FullCourseList";
import CreatePlan from "../components/CreatePlan";
import prisma from "../lib/prisma";
import { getInitialCourses } from "../app/actions/getCourses";

async function getCourses() {
const courses = await prisma.course.findMany();
Expand Down Expand Up @@ -74,6 +75,7 @@ export default async function Page(props: {
const dotw = searchParams?.dotw || [];
const stime = searchParams?.stime || [];
const homePageProps: any = {};
const initalCourses = await getInitialCourses();

homePageProps["fullCourseList"] = (
<Suspense
Expand All @@ -85,7 +87,13 @@ export default async function Page(props: {
</div>
}
>
<FullCourseList dotw={dotw} query={query} stime={stime} term={term} />
<FullCourseList
init={initalCourses}
dotw={dotw}
query={query}
stime={stime}
term={term}
/>
</Suspense>
);

Expand Down
2 changes: 1 addition & 1 deletion components/CourseCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export default function CourseCard(props: any) {
{props.course.facultyMeet.meetingTimes ? (
<div className="mt-1">
<div className="font-normal">
{" "}
{}
{props.course.facultyMeet.meetingTimes.beginTime.slice(
0,
2
Expand Down
2 changes: 1 addition & 1 deletion components/CreatePlan.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { useEffect, useRef, useState } from "react";
import useSWR from "swr";
import { useCookies } from "next-client-cookies";

import { setPlanCookie } from "../app/actions";
import { setPlanCookie } from "../app/actions/actions";
import { generateColorFromName } from "../components/primitives";

export default function CreatePlan(props: any) {
Expand Down
Loading

0 comments on commit 06d2885

Please sign in to comment.