Skip to content

Commit

Permalink
Merge pull request #45 from FAC29A/delete-function2
Browse files Browse the repository at this point in the history
Delete function
  • Loading branch information
lucfercas authored Feb 6, 2024
2 parents 88a8d76 + 23db909 commit 9f9327e
Show file tree
Hide file tree
Showing 7 changed files with 442 additions and 102 deletions.
57 changes: 32 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,32 @@
# blogging-website
Welcome to our no-fuss, intuitive-focused blog posting website! Here, you can post everything you want with ease.

The site is powered by Fly.io, ensuring seamless deployment and optimal performance.
[Link here](https://post-anything.fly.dev)


## Home: (Route: /)
Navigate to the home page, where you'll find a user-friendly form to input your name and blog content.
<img width="659" alt="Screenshot 2024-01-29 at 21 23 49" src="https://github.com/FAC29A/blogging-website/assets/128807685/ac1e7428-5e8e-4cb1-afc0-3644d58ad579">

Our validation function will check for any missing information and prompt you accordingly.
<img width="659" alt="Screenshot 2024-01-29 at 21 26 26" src="https://github.com/FAC29A/blogging-website/assets/128807685/acc87ec1-aaad-4da6-bad8-a22a47dc6d29">

## Post: (Route: /posts)
Discover a collection of posts where you can read and even delete your own contributions.
<img width="661" alt="Screenshot 2024-01-29 at 21 25 38" src="https://github.com/FAC29A/blogging-website/assets/128807685/0ee0f579-1ae5-44ef-b191-89da7ec1a2ec">


## Error: (404)
In case of an incorrect route, you'll be directed to our 404 page, ensuring a smooth browsing experience.
<img width="662" alt="Screenshot 2024-01-29 at 21 26 41" src="https://github.com/FAC29A/blogging-website/assets/128807685/9fad34ad-332d-419d-9712-6f6c7254fa3b">



# SQL schema

Your project this week is to build a web app that stores data in a SQLite database.
## Spike
Before you start writing features you need to design the schema for your data. Think about what different things your app needs to store, how they relate to each other, and how you can avoid duplicating information. Record your schema in your README.md using Markdown tables. Consider embedding a diagram to help visualise the relationships.
## Questions to consider
What kinds of data relationships are there?
What’s a foreign key? How can they help us design schemas with relational data?
Useful resources
## Database Relationships
A beginner’s guide to many-to-many relationships
## User stories
### Core
As a user, I want to: submit information to your site for anyone to see
As a user, I want to: come back to your site later and see what I posted is still there
Since this project is open-ended you’ll need to write your own more specific user stories once you know what you want to build.
## Example project ideas
Founders & Coders book sharing system
Food / coffee recommendations around Founders & Coders
Founders & Coders events calendar
## Acceptance Criteria
- [ ] A form for users to submit data
- [ ] A page showing all the data
- [ ] Semantic form elements with correctly associated labels
- [ ] A SQLite database, deployed to fly.io as a persistent volume
- [ ] A schema describing your database in your README
- [ ] Tests for server routes and database access
- [ ] Not process user input as SQL commands
- [ ] Hidden environment variables (i.e. not on GitHub)
## Stretch criteria
- [ ] A way to view filtered/sorted data, instead of just all of it
- [ ] GitHub Actions CI setup to run your tests when you push
6 changes: 3 additions & 3 deletions database/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ BEGIN;

CREATE TABLE IF NOT EXISTS blog_posts (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT,
blogpost TEXT,
created_at DATETIME,
name TEXT NOT NULL,
blogpost TEXT NOT NULL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
likes INTEGER DEFAULT 0
);

Expand Down
28 changes: 17 additions & 11 deletions model/blogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ function createBlog (blog) {

//read functions here:
const read_blogs = db.prepare(/*sql*/ `
SELECT name, blogpost, created_at, likes
SELECT
id,
name,
blogpost,
DATE(created_at) AS created_at,
likes
FROM blog_posts
`)

Expand All @@ -24,7 +29,7 @@ function displayBlogs () {
//update functions here:
const update_blog = db.prepare(/*sql*/`
UPDATE blog_posts
SET blog_post = $blog_post
SET blogpost = $blogpost
WHERE id = $id
`)
Expand All @@ -34,23 +39,24 @@ function editTask(task) {
return update_blog.get(task)
}




//delete functions here:

const delete_blog = db.prepare(/*sql*/`
DELETE FROM blog_posts
WHERE id = ?
`)






function deleteTask(id) {
return delete_blog.run(id)
}

//EXPORT YOUR FUNCTIONS!!

module.exports = {
createBlog,
displayBlogs
displayBlogs,
editTask,
deleteTask
}


Expand Down
Loading

0 comments on commit 9f9327e

Please sign in to comment.