-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8e4568f
commit e2fb0de
Showing
10 changed files
with
267 additions
and
67 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,27 @@ | ||
const Sequelize = require('sequelize'); | ||
const UserModel = require('./user'); | ||
const Sequelize = require("sequelize"); | ||
const UserModel = require("./user"); | ||
|
||
const sequelize = new Sequelize('mysql://root:123qweasd@localhost:3306/cs304_project'); | ||
sequelize.authenticate() | ||
.then(() => console.log('Connection has been established successfully.')) | ||
.catch(err => console.error('Unable to connect to the database:', err)); | ||
const sequelize = new Sequelize("cs304_project", "root", "123qweasd", { | ||
host: "localhost", | ||
dialect: "mysql", | ||
logging: (msg) => { | ||
if (msg.startsWith("Executing")) { | ||
console.log(msg); | ||
} | ||
}, | ||
}); | ||
sequelize | ||
.authenticate() | ||
.then(() => | ||
console.log("Connection to database has been established successfully.") | ||
) | ||
.catch((err) => console.error("Unable to connect to the database:", err)); | ||
const User = UserModel(sequelize, Sequelize); | ||
|
||
sequelize.sync({ force: false }) | ||
.then(() => { | ||
console.log(`Database & tables created!`) | ||
}); | ||
sequelize.sync({ force: false }).then(() => { | ||
console.log(`Database & tables created!`); | ||
}); | ||
|
||
module.exports = { | ||
User | ||
}; | ||
User, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,16 @@ | ||
const express = require("express"); | ||
const bodyParser = require("body-parser"); | ||
const routes = require("./routes"); | ||
const swaggerUi = require("swagger-ui-express"); | ||
const swaggerJsdoc = require("swagger-jsdoc"); | ||
const setupSwagger = require("./swagger"); | ||
|
||
const app = express(); | ||
app.use(bodyParser.json()); | ||
app.use("/api", routes); | ||
|
||
const options = { | ||
swaggerDefinition: { | ||
openapi: "3.0.0", | ||
info: { | ||
title: "Campus Events and Entertainment Center API", | ||
version: "1.0.0", | ||
description: "API for managing campus events and entertainment", | ||
}, | ||
servers: [ | ||
{ | ||
url: "http://localhost:5000/api", | ||
}, | ||
], | ||
}, | ||
apis: ["./src/routes/*.js"], | ||
}; | ||
setupSwagger(app); | ||
|
||
const specs = swaggerJsdoc(options); | ||
|
||
app.use( | ||
"/api-docs", | ||
swaggerUi.serve, | ||
swaggerUi.setup(specs, { explorer: true }) | ||
); | ||
app.use(express.json()); | ||
|
||
app.listen(5000, () => { | ||
console.log("Server is running on port 5000"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
const fs = require("fs"); | ||
const swaggerUi = require("swagger-ui-express"); | ||
const swaggerJsdoc = require("swagger-jsdoc"); | ||
const yaml = require("js-yaml"); | ||
|
||
const options = { | ||
swaggerDefinition: { | ||
openapi: "3.0.0", | ||
info: { | ||
title: "Campus Events and Entertainment Center API", | ||
version: "1.0.0", | ||
description: "API for managing campus events and entertainment", | ||
}, | ||
servers: [ | ||
{ | ||
url: "http://localhost:5000/api", | ||
}, | ||
], | ||
}, | ||
apis: ["./src/routes/*.js", "./src/models/*.js"], | ||
failOnErrors: true, | ||
}; | ||
|
||
const specs = swaggerJsdoc(options); | ||
|
||
const yamlString = yaml.dump(specs); | ||
|
||
fs.writeFile("swagger-auto-generated.yaml", yamlString, (err) => { | ||
if (err) { | ||
console.log(err); | ||
} else { | ||
console.log("YAML file has been saved."); | ||
} | ||
}); | ||
|
||
module.exports = (app) => { | ||
app.use( | ||
"/api-docs", | ||
swaggerUi.serve, | ||
swaggerUi.setup(specs, { explorer: true }) | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
openapi: 3.0.0 | ||
info: | ||
title: Campus Events and Entertainment Center API | ||
version: 1.0.0 | ||
description: API for managing campus events and entertainment | ||
servers: | ||
- url: http://localhost:5000/api | ||
paths: | ||
/users/register: | ||
post: | ||
summary: Register a user | ||
requestBody: | ||
required: true | ||
content: | ||
application/json: | ||
schema: | ||
type: object | ||
required: | ||
- username | ||
- password | ||
properties: | ||
username: | ||
type: string | ||
password: | ||
type: string | ||
responses: | ||
'200': | ||
description: User created successfully | ||
/users/login: | ||
post: | ||
summary: Login a user | ||
requestBody: | ||
required: true | ||
content: | ||
application/json: | ||
schema: | ||
type: object | ||
required: | ||
- username | ||
- password | ||
properties: | ||
username: | ||
type: string | ||
password: | ||
type: string | ||
responses: | ||
'200': | ||
description: User logged in successfully | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/User' | ||
'401': | ||
description: Invalid username or password | ||
components: | ||
schemas: | ||
User: | ||
type: object | ||
required: | ||
- username | ||
- password | ||
properties: | ||
id: | ||
type: integer | ||
description: The auto-generated id of the user | ||
readOnly: true | ||
username: | ||
type: string | ||
description: The username of the user | ||
password: | ||
type: string | ||
description: The password of the user | ||
example: | ||
id: 1 | ||
username: user1 | ||
password: pass1 | ||
tags: [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
openapi: 3.0.0 | ||
info: | ||
title: Campus Events and Entertainment Center API | ||
version: 1.0.0 | ||
description: API for managing campus events and entertainment | ||
servers: | ||
- url: http://localhost:5000/api | ||
paths: | ||
/users/register: | ||
post: | ||
summary: Register a user | ||
requestBody: | ||
required: true | ||
content: | ||
application/json: | ||
schema: | ||
type: object | ||
required: | ||
- username | ||
- password | ||
properties: | ||
username: | ||
type: string | ||
password: | ||
type: string | ||
responses: | ||
'200': | ||
description: User created successfully | ||
/users/login: | ||
post: | ||
summary: Login a user | ||
requestBody: | ||
required: true | ||
content: | ||
application/json: | ||
schema: | ||
type: object | ||
required: | ||
- username | ||
- password | ||
properties: | ||
username: | ||
type: string | ||
password: | ||
type: string | ||
responses: | ||
'200': | ||
description: User logged in successfully | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/User' | ||
'401': | ||
description: Invalid username or password | ||
components: | ||
schemas: | ||
User: | ||
type: object | ||
required: | ||
- username | ||
- password | ||
properties: | ||
id: | ||
type: integer | ||
description: The auto-generated id of the user | ||
readOnly: true | ||
username: | ||
type: string | ||
description: The username of the user | ||
password: | ||
type: string | ||
description: The password of the user | ||
example: | ||
id: 1 | ||
username: user1 | ||
password: pass1 | ||
tags: [] |