Skip to content

Commit

Permalink
feat(schema): schema.prisma updated to add Feed and Article models
Browse files Browse the repository at this point in the history
  • Loading branch information
= committed Nov 20, 2023
1 parent f148482 commit 94e6547
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 23 deletions.
5 changes: 5 additions & 0 deletions back/biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,10 @@
"formatter": {
"indentStyle": "tab",
"indentWidth": 2
},
"javascript": {
"formatter": {
"quoteStyle": "single"
}
}
}
16 changes: 8 additions & 8 deletions back/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion back/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@types/jest": "^29.5.8",
"@types/node": "20.9.0",
"jest": "^29.7.0",
"prisma": "5.5.2",
"prisma": "^5.6.0",
"ts-jest": "^29.1.1",
"tsx": "^4.1.1",
"typescript": "5.2.2"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
-- CreateTable
CREATE TABLE "Feed" (
"id" TEXT NOT NULL,
"url" TEXT NOT NULL,

CONSTRAINT "Feed_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "Article" (
"id" TEXT NOT NULL,
"title" TEXT NOT NULL,
"url" TEXT NOT NULL,
"image_url" TEXT,
"content" TEXT NOT NULL,
"published" TIMESTAMP(3) NOT NULL,
"source_feed_id" TEXT NOT NULL,

CONSTRAINT "Article_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE UNIQUE INDEX "Feed_id_key" ON "Feed"("id");

-- CreateIndex
CREATE UNIQUE INDEX "Feed_url_key" ON "Feed"("url");

-- CreateIndex
CREATE UNIQUE INDEX "Article_id_key" ON "Article"("id");

-- CreateIndex
CREATE UNIQUE INDEX "Article_url_key" ON "Article"("url");

-- CreateIndex
CREATE INDEX "Article_source_feed_id_idx" ON "Article"("source_feed_id");

-- AddForeignKey
ALTER TABLE "Article" ADD CONSTRAINT "Article_source_feed_id_fkey" FOREIGN KEY ("source_feed_id") REFERENCES "Feed"("id") ON DELETE CASCADE ON UPDATE CASCADE;
19 changes: 19 additions & 0 deletions back/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,22 @@ model Key {
@@index([user_id])
}

model Feed {
id String @id @unique
url String @unique
articles Article[]
}

model Article {
id String @id @unique
title String
url String @unique
image_url String?
content String
published DateTime
source_feed_id String
source_feed Feed @relation(references: [id], fields: [source_feed_id], onDelete: Cascade)
@@index([source_feed_id])
}
8 changes: 4 additions & 4 deletions back/src/apiErrors.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import APIError from "./types/APIError";
import HttpStatusCode from "./types/HttpStatusCode";
import APIError from './types/APIError';
import HttpStatusCode from './types/HttpStatusCode';

export const ResourceNotFound: APIError = {
id: "RESOURCE_NOT_FOUND",
id: 'RESOURCE_NOT_FOUND',
code: HttpStatusCode.NOT_FOUND_404,
};

export const InvalidCredentials: APIError = {
id: "INVALID_CREDENTIALS",
id: 'INVALID_CREDENTIALS',
code: HttpStatusCode.BAD_REQUEST_400,
};
4 changes: 2 additions & 2 deletions back/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import express from "express";
import express from 'express';

const app = express();

app.use(express.json());

app.get("/status", (req, res) => {
app.get('/status', (req, res) => {
res.send({ healthy: true });
});

Expand Down
10 changes: 5 additions & 5 deletions back/src/lucia.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { lucia } from "lucia";
import { prisma } from "@lucia-auth/adapter-prisma";
import { lucia } from 'lucia';
import { prisma } from '@lucia-auth/adapter-prisma';

import { PrismaClient } from "@prisma/client";
import { express } from "lucia/middleware";
import { PrismaClient } from '@prisma/client';
import { express } from 'lucia/middleware';

export const database = new PrismaClient();

export const auth = lucia({
// Set to 'PROD' to use HTTPS
env: "DEV",
env: 'DEV',

adapter: prisma(database),
middleware: express(),
Expand Down
4 changes: 2 additions & 2 deletions back/src/types/APIError.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import APIErrorId from "./APIErrorId";
import HttpStatusCode from "./HttpStatusCode";
import APIErrorId from './APIErrorId';
import HttpStatusCode from './HttpStatusCode';

type APIError = {
id: APIErrorId;
Expand Down
2 changes: 1 addition & 1 deletion back/src/types/APIErrorId.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
type APIErrorId = "INVALID_CREDENTIALS" | "RESOURCE_NOT_FOUND" | "UNAUTHORIZED";
type APIErrorId = 'INVALID_CREDENTIALS' | 'RESOURCE_NOT_FOUND' | 'UNAUTHORIZED';

export default APIErrorId;

0 comments on commit 94e6547

Please sign in to comment.