mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-08 11:30:12 +08:00
Add quest to API spec
+ Remove timestamps + Add 404 error handling
This commit is contained in:
1 parent
247c75ff84
commit
5e8115be11
3 files changed
+71
-10
No files matched your search
@@ -15,5 +15,9 @@ export async function getQuests(req, res) {
|
|||||||
export async function getQuestDetail(req, res) {
|
export async function getQuestDetail(req, res) {
|
||||||
const { name } = req.params
|
const { name } = req.params
|
||||||
const quest = await Quest.findOne({ name })
|
const quest = await Quest.findOne({ name })
|
||||||
|
if (!quest) {
|
||||||
|
res.status(404).json({ message: 'Quest not found.' })
|
||||||
|
return
|
||||||
|
}
|
||||||
res.json(quest)
|
res.json(quest)
|
||||||
}
|
}
|
||||||
@@ -2,15 +2,12 @@ import { model, Schema } from 'mongoose'
|
|||||||
|
|
||||||
const Quest = model(
|
const Quest = model(
|
||||||
'Quest',
|
'Quest',
|
||||||
new Schema(
|
new Schema({
|
||||||
{
|
name: String,
|
||||||
name: String,
|
title: String,
|
||||||
title: String,
|
order: Number,
|
||||||
order: Number,
|
content: String,
|
||||||
content: String,
|
})
|
||||||
},
|
|
||||||
{ timestamps: true }
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
export default Quest
|
export default Quest
|
||||||
+61
-1
@@ -250,6 +250,45 @@ paths:
|
|||||||
schema:
|
schema:
|
||||||
$ref: '#/components/schemas/User'
|
$ref: '#/components/schemas/User'
|
||||||
|
|
||||||
|
/quests:
|
||||||
|
get:
|
||||||
|
summary: Get quests list
|
||||||
|
responses:
|
||||||
|
'200':
|
||||||
|
description: Quests summary list
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
$ref: '#/components/schemas/QuestSummary'
|
||||||
|
|
||||||
|
/quests/{quest_name}:
|
||||||
|
get:
|
||||||
|
summary: get a quest's detail by name
|
||||||
|
parameters:
|
||||||
|
- in: path
|
||||||
|
name: quest_name
|
||||||
|
description: name of the quest to retrieve
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
responses:
|
||||||
|
'200':
|
||||||
|
description: the quest
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: '#/components/schemas/Quest'
|
||||||
|
'404':
|
||||||
|
description: cannot find specific quest
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
message:
|
||||||
|
type: string
|
||||||
components:
|
components:
|
||||||
schemas:
|
schemas:
|
||||||
User:
|
User:
|
||||||
@@ -267,10 +306,31 @@ components:
|
|||||||
Quest:
|
Quest:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
|
id:
|
||||||
|
type: string
|
||||||
|
format: objectId
|
||||||
name:
|
name:
|
||||||
type: string
|
type: string
|
||||||
description:
|
title:
|
||||||
type: string
|
type: string
|
||||||
|
content:
|
||||||
|
type: string
|
||||||
|
format: html
|
||||||
|
order:
|
||||||
|
type: number
|
||||||
|
|
||||||
|
QuestSummary:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
id:
|
||||||
|
type: string
|
||||||
|
format: objectId
|
||||||
|
name:
|
||||||
|
type: string
|
||||||
|
title:
|
||||||
|
type: string
|
||||||
|
order:
|
||||||
|
type: number
|
||||||
|
|
||||||
Session:
|
Session:
|
||||||
type: object
|
type: object
|
||||||
|
|||||||
Reference in new issue
Block a user