Tried to add MirageJS but failed

sections-backend
Jef Roosens 2021-09-23 15:30:39 +02:00
parent 6d83c18036
commit 548dd0d022
Signed by: Jef Roosens
GPG Key ID: 955C0660072F691F
8 changed files with 681 additions and 373 deletions

View File

@ -1,5 +1,3 @@
//! Handles all posts-related database operations.
use chrono::NaiveDate;
use diesel::{insert_into, prelude::*, Insertable, PgConnection, Queryable};
use uuid::Uuid;
@ -9,7 +7,6 @@ use crate::{
schema::{posts, posts::dsl::*},
};
/// Represents a post contained within the database.
#[derive(Queryable)]
pub struct Post
{
@ -20,7 +17,6 @@ pub struct Post
pub content: String,
}
/// Represents a new post to be added to the database.
#[derive(Insertable)]
#[table_name = "posts"]
pub struct NewPost

View File

@ -23,7 +23,7 @@ pub struct Section
/// A new section to be added into the database.
#[derive(Deserialize, Insertable)]
#[table_name = "sections"]
// #[serde(rename_all = "camelCase")]
#[serde(rename_all = "camelCase")]
pub struct NewSection
{
title: String,

View File

@ -7,7 +7,9 @@
"build": "astro build"
},
"devDependencies": {
"@astrojs/renderer-svelte": "^0.1.1",
"astro": "0.19.0-next.2",
"@astrojs/renderer-svelte": "^0.1.1"
"miragejs": "^0.1.41",
"typescript": "^4.4.3"
}
}

View File

@ -0,0 +1,19 @@
<script lang="ts">
console.log("sup");
let movies = [];
fetch("/api/movies").then(res => res.json()).then(res => {
movies = res;
console.log(movies);
});
</script>
<ul>
{#each movies as { id, name, year }, i}
<li><a target="_blank" href="https://www.youtube.com/watch?v={id}">
{i + 1}: {name} - {year}
</a></li>
{/each}
</ul>

View File

@ -1,4 +1,4 @@
<script>
<script lang="ts">
let count = 0;
function add() {

View File

@ -1,7 +1,11 @@
---
---
<html>
<body>
<h1>huh</h1>
<p>lol</p>
<MirageTest />
<slot />
</body>
</html>

View File

@ -1,3 +1,24 @@
---
import { createServer } from "miragejs"
import MirageTest from "../components/MirageTest"
createServer({
routes() {
this.namespace = "api"
this.get("/movies", () => {
return {
movies: [
{ id: 1, name: "Inception", year: 2010 },
{ id: 2, name: "Interstellar", year: 2014 },
{ id: 3, name: "Dunkirk", year: 2017 },
],
}
})
},
})
---
<html>
<body>
@ -7,6 +28,8 @@
<li class="nav-bar-item"><a href="/microblog">Microblog</a></li>
<li class="nav-bar-item"><a href="/devlogs">Devlogs</a></li>
</ul>
<MirageTest client:load />
</body>
</html>

File diff suppressed because it is too large Load Diff