Skip to content

Commit cb01094

Browse files
committed
feat(api): refactored REST API to create and update FAQs
1 parent c41599c commit cb01094

File tree

9 files changed

+542
-437
lines changed

9 files changed

+542
-437
lines changed

API.md

Lines changed: 0 additions & 68 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66

77
This is a log of major user-visible changes in each phpMyFAQ release.
88

9-
### phpMyFAQ v4.0.0-alpha - 2024-02-12
9+
### phpMyFAQ v4.0.0-alpha.2 - unreleased
1010

11-
- Happy 23rd Birthday, phpMyFAQ!
1211
- changed PHP requirement to PHP 8.2 or later (Thorsten)
1312
- changed rewrite rules for Apache and nginx as mandatory requirement (Thorsten)
1413
- changed folder structure (Thorsten, Jan Harms)
@@ -20,13 +19,14 @@ This is a log of major user-visible changes in each phpMyFAQ release.
2019
- added possibility to sort sticky FAQs (Jan Harms)
2120
- added possibility to enable/disable cookie consent (Thorsten)
2221
- added experimental online update feature (Jan Harms, Thorsten)
23-
- [WIP] added REST API v3.0 with OpenAPI specification (Thorsten)
22+
- added REST API v3 with OpenAPI specification (Thorsten)
2423
- added Kubernetes manifest samples (OWNDOMAINHOME SAS)
2524
- added experimental import of FAQs from CSV (Jan Harms)
2625
- added CSV export of user sessions (Jan Harms)
2726
- added experimental support for PHP 8.4 (Thorsten)
2827
- removed Twitter/X support (Thorsten)
2928
- removed support for adding own meta-content in templates (Thorsten)
29+
- removed REST API v2 (Thorsten)
3030
- migrated from Yarn to PNPM (Thorsten)
3131
- migrated from Fork Awesome to Bootstrap Icons (Thorsten, Jan Harms)
3232
- migrated codebase to use PHP 8.2 language features (Thorsten)

api-docs/faq/put.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Content-Type: application/json
4040
"faq-id": 1,
4141
"language": "de",
4242
"category-id": 1,
43-
"question": "Is this the world we created?",
43+
"question": "Is this the world we updated?",
4444
"answer": "What did we do it for, is this the world we invaded, against the law, so it seems in the end, is this what we're all living for today",
4545
"keywords": "phpMyFAQ, FAQ, Foo, Bar",
4646
"author": "Freddie Mercury",

api-docs/openapi.yaml

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,195 @@ paths:
442442
application/json:
443443
schema: {}
444444
example: []
445+
/api/v3.0/faq/create:
446+
post:
447+
tags:
448+
- 'Endpoints with Authentication'
449+
operationId: createFaq
450+
requestBody:
451+
description: 'The category ID is a required value, the category name is optional. If the category name is present and the ID can be mapped, the category ID from the name will be used. If the category name cannot be mapped, a 409 error is thrown.'
452+
required: true
453+
content:
454+
application/json:
455+
schema:
456+
required:
457+
- language
458+
- category-id
459+
- category-name
460+
- question
461+
- answer
462+
- keywords
463+
- author
464+
- email
465+
- is-active
466+
- is-sticky
467+
properties:
468+
language:
469+
type: string
470+
category-id:
471+
type: integer
472+
category-name:
473+
type: string
474+
question:
475+
type: string
476+
answer:
477+
type: string
478+
keywords:
479+
type: string
480+
author:
481+
type: string
482+
email:
483+
type: string
484+
is-active:
485+
type: boolean
486+
is-sticky:
487+
type: boolean
488+
type: object
489+
example: "{\n \"language\": \"de\",\n \"category-id\": 1,\n \"category-name\": \"Queen Songs\",\n \"question\": \"Is this the world we created?\",\n \"answer\": \"What did we do it for, is this the world we invaded, against the law, so it seems in the end, is this what we're all living for today\",\n \"keywords\": \"phpMyFAQ, FAQ, Foo, Bar\",\n \"author\": \"Freddie Mercury\",\n \"email\": \"[email protected]\",\n \"is-active\": \"true\",\n \"is-sticky\": \"false\"\n }"
490+
responses:
491+
'201':
492+
description: 'If all posted data is correct.'
493+
headers:
494+
Accept-Language:
495+
description: 'The language code for the login.'
496+
schema:
497+
type: string
498+
x-pmf-token:
499+
description: 'phpMyFAQ client API Token, generated in admin backend'
500+
schema:
501+
type: string
502+
content:
503+
application/json:
504+
schema: {}
505+
example: '{ "stored": true }'
506+
'400':
507+
description: "If something didn't worked out."
508+
headers:
509+
Accept-Language:
510+
description: 'The language code for the login.'
511+
schema:
512+
type: string
513+
x-pmf-token:
514+
description: 'phpMyFAQ client API Token, generated in admin backend'
515+
schema:
516+
type: string
517+
content:
518+
application/json:
519+
schema: {}
520+
example: '{ "stored": false, "error": "It is not allowed, that the question title contains a hash." }'
521+
'409':
522+
description: 'If the parent category name cannot be mapped.'
523+
headers:
524+
Accept-Language:
525+
description: 'The language code for the login.'
526+
schema:
527+
type: string
528+
x-pmf-token:
529+
description: 'phpMyFAQ client API Token, generated in admin backend'
530+
schema:
531+
type: string
532+
content:
533+
application/json:
534+
schema: {}
535+
example: '{ "stored": false, "error": "The given category name was not found" }'
536+
'401':
537+
description: 'If the user is not authenticated.'
538+
headers:
539+
Accept-Language:
540+
description: 'The language code for the login.'
541+
schema:
542+
type: string
543+
x-pmf-token:
544+
description: 'phpMyFAQ client API Token, generated in admin backend'
545+
schema:
546+
type: string
547+
/api/v3.0/faq/update:
548+
put:
549+
tags:
550+
- 'Endpoints with Authentication'
551+
description: 'Used to update a FAQ in one existing category.'
552+
operationId: updateFaq
553+
requestBody:
554+
required: true
555+
content:
556+
application/json:
557+
schema:
558+
required:
559+
- faq-id
560+
- language
561+
- category-id
562+
- question
563+
- answer
564+
- keywords
565+
- author
566+
- email
567+
- is-active
568+
- is-sticky
569+
properties:
570+
faq-id:
571+
type: integer
572+
language:
573+
type: string
574+
category-id:
575+
type: integer
576+
question:
577+
type: string
578+
answer:
579+
type: string
580+
keywords:
581+
type: string
582+
author:
583+
type: string
584+
email:
585+
type: string
586+
is-active:
587+
type: boolean
588+
is-sticky:
589+
type: boolean
590+
type: object
591+
example: "{\n \"faq-id\": 1,\n \"language\": \"de\",\n \"category-id\": 1,\n \"question\": \"Is this the world we updated?\",\n \"answer\": \"What did we do it for, is this the world we invaded, against the law, so it seems in the end, is this what we're all living for today\",\n \"keywords\": \"phpMyFAQ, FAQ, Foo, Bar\",\n \"author\": \"Freddie Mercury\",\n \"email\": \"[email protected]\",\n \"is-active\": \"true\",\n \"is-sticky\": \"false\"\n }"
592+
responses:
593+
'200':
594+
description: 'If all posted data is correct.'
595+
headers:
596+
Accept-Language:
597+
description: 'The language code for the login.'
598+
schema:
599+
type: string
600+
x-pmf-token:
601+
description: 'phpMyFAQ client API Token, generated in admin backend'
602+
schema:
603+
type: string
604+
content:
605+
application/json:
606+
schema: {}
607+
example: '{ "stored": true }'
608+
'400':
609+
description: "If something didn't worked out."
610+
headers:
611+
Accept-Language:
612+
description: 'The language code for the login.'
613+
schema:
614+
type: string
615+
x-pmf-token:
616+
description: 'phpMyFAQ client API Token, generated in admin backend'
617+
schema:
618+
type: string
619+
content:
620+
application/json:
621+
schema: {}
622+
example: '{ "stored": false, "error": "It is not allowed, that the question title contains a hash." }'
623+
'401':
624+
description: 'If the user is not authenticated.'
625+
headers:
626+
Accept-Language:
627+
description: 'The language code for the login.'
628+
schema:
629+
type: string
630+
x-pmf-token:
631+
description: 'phpMyFAQ client API Token, generated in admin backend'
632+
schema:
633+
type: string
445634
/api/v3.0/groups:
446635
get:
447636
tags:

nginx.conf

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -84,76 +84,6 @@ server {
8484
# Administration API
8585
rewrite admin/api/(.*) /admin/api/index.php last;
8686

87-
# REST API v2.0
88-
# * http://[...]/api/v2.0/<ACTION>
89-
rewrite api/v2.0/version /api/index.php last;
90-
rewrite api/v2.0/language /api/index.php last;
91-
rewrite api/v2.0/categories /api/index.php last;
92-
rewrite api/v2.0/searches/popular /api/index.php last;
93-
rewrite api/v2.0/search /api/index.php last;
94-
rewrite api/v2.0/tags /api/index.php last;
95-
rewrite api/v2.0/open-questions /api/index.php last;
96-
rewrite api/v2.0/comments/([0-9]+) /api/index.php last;
97-
rewrite api/v2.0/attachments/([0-9]+) /api/index.php last;
98-
rewrite api/v2.0/news /api/index.php last;
99-
rewrite api/v2.0/login /api/index.php last;
100-
rewrite api/v2.0/faqs/([0-9]+) /api/index.php last;
101-
rewrite api/v2.0/faqs/popular /api/index.php last;
102-
rewrite api/v2.0/faqs/latest /api/index.php last;
103-
rewrite api/v2.0/faqs/sticky /api/index.php last;
104-
rewrite api/v2.0/faqs/tags/([0-9]+) /api/index.php last;
105-
rewrite api/v2.0/faqs /api/index.php last;
106-
rewrite api/v2.0/faq/([0-9]+)/([0-9]+) /api/index.php last;
107-
108-
# REST API v2.1
109-
# * http://[...]/api/v2.1/<ACTION>
110-
rewrite api/v2.1/version /api/index.php last;
111-
rewrite api/v2.1/language /api/index.php last;
112-
rewrite api/v2.1/categories /api/index.php last;
113-
rewrite api/v2.1/searches/popular /api/index.php last;
114-
rewrite api/v2.1/search /api/index.php last;
115-
rewrite api/v2.1/tags /api/index.php last;
116-
rewrite api/v2.1/open-questions /api/index.php last;
117-
rewrite api/v2.1/comments/([0-9]+) /api/index.php last;
118-
rewrite api/v2.1/attachments/([0-9]+) /api/index.php last;
119-
rewrite api/v2.1/news /api/index.php last;
120-
rewrite api/v2.1/login /api/index.php last;
121-
rewrite api/v2.1/faqs/([0-9]+) /api/index.php last;
122-
rewrite api/v2.1/faqs/popular /api/index.php last;
123-
rewrite api/v2.1/faqs/latest /api/index.php last;
124-
rewrite api/v2.1/faqs/sticky /api/index.php last;
125-
rewrite api/v2.1/faqs/tags/([0-9]+) /api/index.php last;
126-
rewrite api/v2.1/faqs /api/index.php last;
127-
rewrite api/v2.1/faq/([0-9]+)/([0-9]+) /api/index.php last;
128-
rewrite api/v2.1/faq /api.php?action=faq last;
129-
rewrite api/v2.1/register /api/index.php last;
130-
131-
# REST API v2.2
132-
# * http://[...]/api/v2.2/<ACTION>
133-
rewrite api/v2.2/version /api/index.php last;
134-
rewrite api/v2.2/title /api/index.php last;
135-
rewrite api/v2.2/language /api/index.php last;
136-
rewrite api/v2.2/categories /api/index.php last;
137-
rewrite api/v2.2/category /api/index.php last;
138-
rewrite api/v2.2/groups /api/index.php last;
139-
rewrite api/v2.2/searches/popular /api/index.php last;
140-
rewrite api/v2.2/search /api/index.php last;
141-
rewrite api/v2.2/tags /api/index.php last;
142-
rewrite api/v2.2/open-questions /api/index.php last;
143-
rewrite api/v2.2/comments/([0-9]+) /api/index.php last;
144-
rewrite api/v2.2/attachments/([0-9]+) /api/index.php last;
145-
rewrite api/v2.2/news /api/index.php last;
146-
rewrite api/v2.2/login /api/index.php last;
147-
rewrite api/v2.2/faqs/([0-9]+) /api/index.php last;
148-
rewrite api/v2.2/faqs/popular /api/index.php last;
149-
rewrite api/v2.2/faqs/latest /api/index.php last;
150-
rewrite api/v2.2/faqs/sticky /api/index.php last;
151-
rewrite api/v2.2/faqs/tags/([0-9]+) /api/index.php last;
152-
rewrite api/v2.2/faqs /api/index.php last;
153-
rewrite api/v2.2/faq/([0-9]+)/([0-9]+) /api/index.php last;
154-
rewrite api/v2.1/faq /api.php?action=faq last;
155-
rewrite api/v2.2/register /api/index.php last;
156-
15787
# REST API v3.0
15888
rewrite api/v3.0/(.*) /api/index.php last;
15989

0 commit comments

Comments
 (0)