소스 검색

Create page for uploading currency data.

Lee Morgan 4 년 전
부모
커밋
032d551862
6개의 변경된 파일73개의 추가작업 그리고 0개의 파일을 삭제
  1. 14 0
      controllers/currency.js
  2. 11 0
      models/currency.js
  3. 6 0
      routes.js
  4. 0 0
      views/currency/currency.css
  5. 0 0
      views/currency/display.ejs
  6. 42 0
      views/currency/new.html

+ 14 - 0
controllers/currency.js

@@ -0,0 +1,14 @@
+const Currency = require("../models/currency.js");
+
+module.exports = {
+    currency: function(req, res){
+        Currency.find()
+            .then((currencies)=>{
+                return res.render("currency/display.ejs");
+            })
+            .catch((err)=>{
+                console.error(err);
+                return res.redirect("/");
+            });
+    }
+}

+ 11 - 0
models/currency.js

@@ -0,0 +1,11 @@
+const mongoose = require("mongoose");
+
+const CurrencySchema = new mongoose.Schema({
+    location: String,
+    frontImage: String,
+    backImage: String,
+    type: String,
+    year: Number
+});
+
+module.exports = mongoose.model("currency", CurrencySchema);

+ 6 - 0
routes.js

@@ -2,6 +2,7 @@ const gallery = require("./controllers/gallery.js");
 const learn = require("./controllers/learn.js");
 const blog = require("./controllers/blog.js");
 const covid = require("./controllers/covid.js");
+const currency = require("./controllers/currency.js");
 
 const visit = require("./middleware.js").visit;
 
@@ -87,6 +88,11 @@ module.exports = function(app){
     app.get("/covid/style", (req, res)=>{res.sendFile(`${views}/covid/covid.css`)});
     app.post("/covid", visit, covid.data);
 
+    //CURRENCY
+    app.get("/currency/style", (req, res)=>res.sendFile(`${views}/currency/currency.css`));
+    app.get("/currency", visit, currency.currency);
+    app.get("/currency/new", (req, res)=>{res.sendFile(`${views}/currency/new.html`)});
+
     //CONTENT
     app.get("/thumbNails/*", (req, res)=>{res.sendFile(`${__dirname}${req.url}`)});
     app.get("/documents/*", (req, res)=>{res.download(`${__dirname}${req.url}`)});

+ 0 - 0
views/currency/currency.css


+ 0 - 0
views/currency/display.ejs


+ 42 - 0
views/currency/new.html

@@ -0,0 +1,42 @@
+<!DOCTYPE html>
+<html lang="en">
+    <head>
+        <meta charset="utf-8">
+        <title>Lee Morgan</title>
+        <style>
+            form{
+                display: flex;
+                flex-direction: column;
+            }
+        </style>
+    </head>
+    <body>
+        <form action="/currency" method="post" ecntype="multipart/form-data">
+            <label>Location
+                <input name="location" type="text" placeholder="Location" required>
+            </label>
+
+            <label>Paper
+                <input name="type" type="radio" value="paper">
+            </label>
+
+            <label>Coin
+                <input name="type" type="radio" value="coin">
+            </label>
+
+            <label>Year
+                <input name="year" type="number" required>
+            </label>
+
+            <label>Front Image
+                <input name="frontImage" type="file" required>
+            </label>
+
+            <label>Back Image
+                <input name="backImage" type="file" required>
+            </label>
+
+            <input type="submit" value="Submit">
+        </form>
+    </body>
+</html>