GET /api/custom_domains
This commit is contained in:
parent
f6568aca6a
commit
9d24b1b88a
|
@ -1,6 +1,7 @@
|
|||
from .views import (
|
||||
alias_options,
|
||||
new_custom_alias,
|
||||
custom_domain,
|
||||
new_random_alias,
|
||||
user_info,
|
||||
auth,
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
from flask import g
|
||||
from flask import jsonify
|
||||
|
||||
from app.api.base import api_bp, require_api_auth
|
||||
from app.models import CustomDomain
|
||||
|
||||
|
||||
def custom_domain_to_dict(custom_domain: CustomDomain):
|
||||
return {
|
||||
"id": custom_domain.id,
|
||||
"domain": custom_domain.domain,
|
||||
"verified": custom_domain.verified,
|
||||
}
|
||||
|
||||
|
||||
@api_bp.route("/custom_domains", methods=["GET"])
|
||||
@require_api_auth
|
||||
def get_custom_domains():
|
||||
user = g.user
|
||||
custom_domains = CustomDomain.filter_by(user_id=user.id).all()
|
||||
|
||||
return jsonify(custom_domains=[custom_domain_to_dict(cd) for cd in custom_domains])
|
44
docs/api.md
44
docs/api.md
|
@ -1,18 +1,20 @@
|
|||
## API
|
||||
|
||||
[1. Account endpoints](#account-endpoints)
|
||||
[Account endpoints](#account-endpoints)
|
||||
|
||||
[2. Alias endpoints](#alias-endpoints)
|
||||
[Alias endpoints](#alias-endpoints)
|
||||
|
||||
[3. Mailbox endpoints](#mailbox-endpoints)
|
||||
[Mailbox endpoints](#mailbox-endpoints)
|
||||
|
||||
[4. Contact endpoints](#contact-endpoints)
|
||||
[Custom domain endpoints](#custom-domain-endpoints)
|
||||
|
||||
[5. Notification endpoints](#notification-endpoints)
|
||||
[Contact endpoints](#contact-endpoints)
|
||||
|
||||
[6. Settings endpoints](#settings-endpoints)
|
||||
[Notification endpoints](#notification-endpoints)
|
||||
|
||||
[7. MISC endpoints](#misc-endpoints)
|
||||
[Settings endpoints](#settings-endpoints)
|
||||
|
||||
[MISC endpoints](#misc-endpoints)
|
||||
|
||||
---
|
||||
|
||||
|
@ -619,6 +621,34 @@ Output:
|
|||
- 200 if updated successfully
|
||||
- 400 if error
|
||||
|
||||
### Custom domain endpoints
|
||||
|
||||
#### GET /api/custom_domains
|
||||
|
||||
Return user's custom domains
|
||||
|
||||
Input:
|
||||
- `Authentication` header that contains the api key
|
||||
|
||||
Output:
|
||||
List of custom domains.
|
||||
|
||||
```json
|
||||
{
|
||||
"custom_domains": [
|
||||
{
|
||||
"domain": "test1.org",
|
||||
"id": 1,
|
||||
"verified": true
|
||||
},
|
||||
{
|
||||
"domain": "test2.org",
|
||||
"id": 2,
|
||||
"verified": false
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
### Contact endpoints
|
||||
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
import json
|
||||
|
||||
from app.models import CustomDomain
|
||||
from tests.utils import login
|
||||
|
||||
|
||||
def test_get_custom_domains(flask_client):
|
||||
user = login(flask_client)
|
||||
|
||||
CustomDomain.create(user_id=user.id, domain="test1.org", verified=True, commit=True)
|
||||
CustomDomain.create(
|
||||
user_id=user.id, domain="test2.org", verified=False, commit=True
|
||||
)
|
||||
|
||||
r = flask_client.get(
|
||||
"/api/custom_domains",
|
||||
)
|
||||
|
||||
assert r.status_code == 200
|
||||
assert r.json == {
|
||||
"custom_domains": [
|
||||
{"domain": "test1.org", "id": 1, "verified": True},
|
||||
{"domain": "test2.org", "id": 2, "verified": False},
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue