├── .gitignore ├── assets └── sakura.jpg ├── src ├── routes │ └── card_routes.js ├── config │ └── db.js ├── models │ └── card.js ├── index.js └── controller │ └── card_controller.js ├── package.json └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .env 3 | -------------------------------------------------------------------------------- /assets/sakura.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JessVel/sakura-card-captor-api/HEAD/assets/sakura.jpg -------------------------------------------------------------------------------- /src/routes/card_routes.js: -------------------------------------------------------------------------------- 1 | const express = require("express"); 2 | const router = express.Router(); 3 | const cardController = require("../controller/card_controller"); 4 | 5 | router.get("/", cardController.getCards); 6 | 7 | router.get("/:id", cardController.getCard); 8 | 9 | router.post("/", cardController.createCard); 10 | 11 | module.exports = router; 12 | -------------------------------------------------------------------------------- /src/config/db.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | require("dotenv").config(); 3 | 4 | const connectDB = async () => { 5 | try { 6 | await mongoose.connect(process.env.DB_MONGO, { 7 | useNewUrlParser: true, 8 | useUnifiedTopology: true, 9 | useFindAndModify: false, 10 | useCreateIndex: true, 11 | }); 12 | console.log("Data base connected"); 13 | } catch (err) { 14 | console.log(`Error: ${err.message}`); 15 | process.exit(1); 16 | } 17 | }; 18 | 19 | module.exports = connectDB; 20 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "sakura-api", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "src/index.js", 6 | "scripts": { 7 | "start": "node src/index.js", 8 | "dev": "nodemon --watch src src/index.js" 9 | }, 10 | "repository": { 11 | "type": "git", 12 | "url": "git+https://github.com/JessVel/sakura-card-capture-api.git" 13 | }, 14 | "keywords": [], 15 | "author": "", 16 | "license": "ISC", 17 | "bugs": { 18 | "url": "https://github.com/JessVel/sakura-card-capture-api/issues" 19 | }, 20 | "homepage": "https://github.com/JessVel/sakura-card-capture-api#readme", 21 | "dependencies": { 22 | "cors": "^2.8.5", 23 | "dotenv": "^8.2.0", 24 | "express": "^4.17.1", 25 | "mongoose": "^5.11.18" 26 | }, 27 | "devDependencies": { 28 | "consola": "^2.15.3", 29 | "nodemon": "^2.0.7" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/models/card.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const CardSchema = mongoose.Schema({ 4 | cardNumber: { 5 | type: Number, 6 | require: true, 7 | trim: true, 8 | }, 9 | spanishName: { 10 | type: String, 11 | require: true, 12 | trim: true, 13 | }, 14 | englishName: { 15 | type: String, 16 | require: true, 17 | trim: true, 18 | }, 19 | kanji: { 20 | type: String, 21 | trim: true, 22 | }, 23 | Rōmaji: { 24 | type: String, 25 | trim: true, 26 | }, 27 | appeardManga: { 28 | type: String, 29 | trim: true, 30 | }, 31 | appeardAnime: { 32 | type: String, 33 | trim: true, 34 | }, 35 | clowCard: { 36 | type: String, 37 | trim: true, 38 | require: true, 39 | }, 40 | sakuraCard: { 41 | type: String, 42 | trim: true, 43 | require: true, 44 | }, 45 | }); 46 | 47 | module.exports = mongoose.model("Card", CardSchema); 48 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | const express = require("express"); 2 | 3 | const connectDB = require("./config/db"); 4 | 5 | const cors = require("cors"); 6 | 7 | require("dotenv").config(); 8 | 9 | const app = express(); 10 | 11 | connectDB(); 12 | 13 | app.use( 14 | cors({ 15 | origin: "*", 16 | optionsSuccessStatus: 200, 17 | credentials: true, 18 | }) 19 | ); 20 | app.options("*", cors()); 21 | 22 | app.use(express.json({ extended: true })); 23 | 24 | const PORT = process.env.PORT || 4000; 25 | 26 | app.use(function (req, res, next) { 27 | res.header("Access-Control-Allow-Origin", "*"); 28 | res.header("Access-Control-Allow-Credentials", true); 29 | res.header("Access-Control-Allow-Methods", "GET,PUT,POST,DELETE,OPTIONS"); 30 | res.header("Access-Control-Allow-Headers", "Content-Type, Authorization, Content-Length, X-Requested-With, Accept"); 31 | next(); 32 | }); 33 | 34 | app.use("/api/card", require("./routes/card_routes")); 35 | 36 | app.listen(PORT, () => { 37 | console.log(`Server running in ${PORT}`); 38 | }); 39 | -------------------------------------------------------------------------------- /src/controller/card_controller.js: -------------------------------------------------------------------------------- 1 | const cardModel = require("../models/card"); 2 | 3 | exports.getCards = async (req, res) => { 4 | try { 5 | const DEFAULT_PAGE = 1, DEFAULT_PAGE_SIZE = 60; 6 | 7 | let {page = DEFAULT_PAGE, pageSize = DEFAULT_PAGE_SIZE} = req.query; 8 | page = +page; pageSize = +pageSize; 9 | 10 | if(!page || !pageSize) 11 | throw new Error("Invalid page or pageSize format") 12 | 13 | const cards = await cardModel.find(); 14 | 15 | pageSize = (pageSize > DEFAULT_PAGE_SIZE)? DEFAULT_PAGE_SIZE: pageSize; 16 | const start = (page - 1) * pageSize; 17 | const end = (start + pageSize > cards.length)? cards.length: start + pageSize; 18 | 19 | const data = cards.slice(start, end); 20 | 21 | res.json({ 22 | data: data, 23 | page: page, 24 | pageSize: pageSize, 25 | count: data.length, 26 | totalCount: cards.length 27 | }); 28 | 29 | console.log(cards); 30 | } catch (error) { 31 | console.log(error); 32 | res.status(400).json({ msg: "Hubo un error" }); 33 | } 34 | }; 35 | 36 | exports.getCard = async (req, res) => { 37 | try { 38 | { 39 | const card = await cardModel.findById(req.params.id); 40 | res.json(card); 41 | console.log(card); 42 | } 43 | } catch (error) { 44 | console.log(error); 45 | res.status(400).json({ msg: "Hubo un error" }); 46 | } 47 | }; 48 | 49 | exports.createCard = async (req, res) => { 50 | try { 51 | const card = new cardModel(req.body); 52 | card.save(); 53 | res.json({ card }); 54 | } catch (error) { 55 | console.log(error); 56 | res.status(400).json({ msg: "Hubo un error" }); 57 | } 58 | }; 59 | 60 | exports.editCard = async (req, res) =>{ 61 | try{ 62 | 63 | }catch(error){ 64 | console.log(error); 65 | res.status(400).json({ msg: "Hubo un error" }); 66 | } 67 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Sakura CardCaptor API ✨ 2 | 3 | 4 | ![ScreenShot](https://raw.github.com/JessVel/sakura-card-capture-api/main/assets/sakura.jpg) 5 | 6 | 7 | https://protected-taiga-89091.herokuapp.com/ 8 | 9 | |HTTP METHOD | GET | 10 | |----------------|----------------| 11 | |api/card | gets all cards | 12 | |api/card/:id | gets card by id| 13 | 14 | ## api/card 15 | 16 | This call will return a maximum of 60 cards. The default is 60. 17 | 18 | * Example of object: 19 | 20 | ```json 21 | { 22 | "data": [ 23 | { 24 | "_id":"6039396a68347a4a842920cf", 25 | "cardNumber":1, 26 | "spanishName":"Viento", 27 | "englishName":"The Windy", 28 | "kanji":"風", 29 | "Rōmaji":"Kaze", 30 | "appeardManga":"1", 31 | "appeardAnime":"1", 32 | "clowCard":"https://static.wikia.nocookie.net/sakuracardcaptors/images/6/6d/Viento.jpg/revision/latest/scale-to-width-down/210?cb=20181225230616&path-prefix=es", 33 | "sakuraCard":"https://static.wikia.nocookie.net/sakuracardcaptors/images/7/7e/Viento_Sakura.jpg/revision/latest/scale-to-width-down/210?cb=20201116174455&path-prefix=es", 34 | "__v":0 35 | }, 36 | { ... }, 37 | { ... } 38 | ] 39 | } 40 | ``` 41 | 42 | These are the supported query string parameters: 43 | 44 | 45 | |Parameters | Description | 46 | |----------------|----------------| 47 | |page | The page of data to access. Defaults to 1. | 48 | |pageSize | The maximum amount of cards to return. Defaults to 60 (max is also 60).| 49 | 50 | Simple usage: 51 | 52 | ```bash 53 | # Get all Cards 54 | curl "https://protected-taiga-89091.herokuapp.com/api/card" 55 | 56 | # Get page 3 of data with a page size of 10 Cards 57 | curl "https://protected-taiga-89091.herokuapp.com/api/card?pageSize=10&page=3" 58 | ``` 59 | 60 | 61 | 62 | ### There are currently nine available resources: 63 | 64 | `_id`: Card id.
65 | `cardNumber`: This is the card number, not the id.
66 | `spanishName`: Card name in spanish language.
67 | `englishName`: Card name in english language.
68 | `kanji`: Card name in logographic Japanese characters.
69 | `Rōmaji`: Card name in western alphabet transcription.
70 | `appeardManga`: Number of manga in which the card first appeard.
71 | `appeardAnime` : Number of episode in which the card first appeard.
72 | `clowCard`: Image of the Clow Card.
73 | `sakuraCard`: Image of the Sakura Card
74 | 75 | 76 | ### Start proyect 🚀 77 | 78 | `npm install` 79 | 80 | `npm run dev` 81 | 82 | # Clow cards and Sakura cards API made with a lot of love for the community 🌈 83 | 84 | Contributions are welcome 💕 85 | --------------------------------------------------------------------------------