Skip to content

Commit

Permalink
Dev (#53)
Browse files Browse the repository at this point in the history
* fix: error messages in sepc

* User Update Profile

* Answer insert function (#40)

* Answer insert function
* Comments added

* feat: create question w/ tags (#41)

* add schema definition for questions

* Daniel (#43)

* User Update Profile

* add schema definition for questions

* add error logger

* Daniel (#44)

* User Update Profile

* add schema definition for questions

* add error logger

* error logger

* Daniel (#45)

* User Update Profile

* add schema definition for questions

* add error logger

* error logger

* Daniel (#47)

* interactor merge error

* question spec v2

* Daniel (#48)

* interactor merge error

* question spec v2

* fix: pagination

* Daniel (#49)

* interactor merge error

* question spec v2

* fix: pagination

* fix: duplication on quesions data

* Daniel (#50)


* fix: newest filter
add: create questions spec

* Daniel (#51)

* add: new swagger docs

* Daniel (#52)


* fix: schema forums

* fix: Questions response schema

---------

Co-authored-by: Xaalf104 <147465274+Xaalf104@users.noreply.github.com>
Co-authored-by: Jeffrey Brian Jonelas <107722564+Jepwyy@users.noreply.github.com>
  • Loading branch information
3 people authored Nov 12, 2023
1 parent b510184 commit 9d5ec71
Show file tree
Hide file tree
Showing 24 changed files with 1,401 additions and 12 deletions.
6 changes: 6 additions & 0 deletions data.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@

-- add bio
-- add users
CREATE TABLE users(
id SERIAL PRIMARY KEY,
username TEXT,
Expand All @@ -12,6 +15,7 @@ CREATE TABLE users(
district TEXT,
municipality TEXT,
verification_level INT,
bio TEXT,
role TEXT DEFAULT 'user',
createdAt timestamp DEFAULT CURRENT_TIMESTAMP,
updatedAt timestamp DEFAULT CURRENT_TIMESTAMP,
Expand All @@ -23,8 +27,10 @@ ON users (email);
CREATE INDEX username_index
ON users (username);

-- add details
CREATE TABLE tags (
id SERIAL PRIMARY KEY,
details TEXT,
tag_name TEXT
);

Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"redis": "^4.6.10",
"remove": "^0.1.5",
"socket.io": "^4.7.2",
"swagger-jsdoc": "^6.2.8",
"swagger-ui-express": "^5.0.0",
"ts-node": "^10.9.1"
},
Expand All @@ -39,6 +40,7 @@
"@types/express-session": "^1.17.8",
"@types/multer": "^1.4.8",
"@types/pg": "^8.10.4",
"@types/swagger-jsdoc": "^6.0.3",
"@types/swagger-ui-express": "^4.1.5",
"@types/yamljs": "^0.2.33",
"dotenv": "^16.3.1",
Expand Down
236 changes: 236 additions & 0 deletions spec/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,111 @@ paths:
application/json:
schema:
$ref: "#/components/schemas/ServerError"
/api/user/profile/{id}:
put:
tags:
- "User"
summary: Update user profile
parameters:
- name: id
in: path
required: true
schema:
type: string
description: User ID
requestBody:
required: true
content:
multipart/form-data:
schema:
$ref: "#/components/schemas/UserUpdateProfile"
responses:
"200":
description: Success
content:
application/json:
schema:
$ref: "#/components/schemas/TagsSchema"
"401":
description: Unauthorized
content:
application/json:
schema:
$ref: "#/components/schemas/ErrorResponse"
"500":
description: Server Error
content:
application/json:
schema:
$ref: "#/components/schemas/ServerError"
/api/forums:
get:
tags:
- Forums
summary: Get Questions Data
parameters:
- in: query
name: search
schema:
type: string
description: Search term for forums (optional)
- in: query
name: page
schema:
type: string
description: Page number (optional)
- in: query
name: perpage
schema:
type: string
description: Number of items per page (optional, default 10)
- in: query
name: filter
schema:
type: string
description: Filter criteria (optional, default newest)
responses:
"200":
description: Success
content:
application/json:
schema:
$ref: "#/components/schemas/QuestionsResponse"
"400":
description: Validation Error
content:
application/json:
schema:
$ref: "#/components/schemas/ErrorResponse"
"500":
description: Server Error
content:
application/json:
schema:
$ref: "#/components/schemas/ServerError"
post:
tags:
- Forums
description: Create Questions
requestBody:
required: true
content:
multipart/form-data:
schema:
$ref: "#/components/schemas/QuestionSchema"
responses:
"201":
description: Success
content:
application/json:
schema:
$ref: "#/components/schemas/NewQuestionSchema"
"500":
description: Server Error
content:
application/json:
schema:
$ref: "#/components/schemas/ServerError"

# components
components:
Expand All @@ -312,6 +417,61 @@ components:
password:
type: string
default: qweR123$
QuestionsResponse:
type: object
properties:
questions:
type: array
items:
type: object
properties:
id:
type: string
user:
type: object
properties:
avatar:
type: string # Adjust if it has a specific type
id:
type: string
username:
type: string # Adjust if it has a specific type
tags:
type: array
items:
type: object
properties:
tag:
type: string
title:
type: string
question:
type: string
imagesrc:
type: array
items:
type: string
createdat:
type: string
format: date-time
updatedat:
type: string
format: date-time
answer_count:
type: string
vote_count:
type: string
pagination:
type: object
properties:
page:
type: integer
per_page:
type: integer
total_pages:
type: integer
total_records:
type: integer
UserRegisterSchema:
type: object
required:
Expand Down Expand Up @@ -393,6 +553,82 @@ components:
type: array
items:
type: string
UserUpdateProfile:
type: object
properties:
avatar:
type: string
format: binary
username:
type: string
email:
type: string
firstname:
type: string
lastname:
type: string
birthdate:
type: string
format: date
present_address:
type: string
zipcode:
type: string
district:
type: string
municipality:
type: string
verification_level:
type: string
bio:
type: string
QuestionSchema:
type: object
required:
- title
- question
- imagesrc
properties:
title:
type: string
description: The title of the forum entry
question:
type: string
description: The question in the forum entry
imagesrc:
type: array
items:
type: string
format: binary
description: One or more images associated with the forum
NewQuestionSchema:
type: object
properties:
id:
type: string
description: The unique identifier for the new question
userid:
type: string
description: The user ID associated with the question
title:
type: string
description: The title of the new question
question:
type: string
description: The content of the new question
imagesrc:
type: array
items:
type: string
description: Array of image URLs associated with the question
createdat:
type: string
format: date-time
description: The timestamp when the question was created
updatedat:
type: string
format: date-time
description: The timestamp when the question was last updated
TagsSchema:
type: array
items:
Expand Down
4 changes: 2 additions & 2 deletions src/config/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import RedisStore from 'connect-redis'
import * as dotenv from 'dotenv'
import { SessionOptions } from 'express-session'
import { MemoryStore, SessionOptions } from 'express-session'
dotenv.config()
import { createClient } from 'redis'

Expand All @@ -14,7 +14,7 @@ let redisStore = new RedisStore({

export const sessionConfig: SessionOptions = {
name: 'sessionToken',
store: redisStore,
store: process.env.NODE_ENV === 'production' ? redisStore : null,
secret: process.env.SESSION_SECRET_KEY,
resave: false,
saveUninitialized: false,
Expand Down
Loading

0 comments on commit 9d5ec71

Please sign in to comment.