mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-06 03:20:13 +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) {
|
||||
const { name } = req.params
|
||||
const quest = await Quest.findOne({ name })
|
||||
if (!quest) {
|
||||
res.status(404).json({ message: 'Quest not found.' })
|
||||
return
|
||||
}
|
||||
res.json(quest)
|
||||
}
|
||||
@@ -2,15 +2,12 @@ import { model, Schema } from 'mongoose'
|
||||
|
||||
const Quest = model(
|
||||
'Quest',
|
||||
new Schema(
|
||||
{
|
||||
name: String,
|
||||
title: String,
|
||||
order: Number,
|
||||
content: String,
|
||||
},
|
||||
{ timestamps: true }
|
||||
)
|
||||
new Schema({
|
||||
name: String,
|
||||
title: String,
|
||||
order: Number,
|
||||
content: String,
|
||||
})
|
||||
)
|
||||
|
||||
export default Quest
|
||||
+61
-1
@@ -250,6 +250,45 @@ paths:
|
||||
schema:
|
||||
$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:
|
||||
schemas:
|
||||
User:
|
||||
@@ -267,10 +306,31 @@ components:
|
||||
Quest:
|
||||
type: object
|
||||
properties:
|
||||
id:
|
||||
type: string
|
||||
format: objectId
|
||||
name:
|
||||
type: string
|
||||
description:
|
||||
title:
|
||||
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:
|
||||
type: object
|
||||
|
||||
Reference in new issue
Block a user