TRM-coding | d1cbf67 | 2025-06-18 15:15:08 +0800 | [diff] [blame^] | 1 | # utils/serializers.py |
| 2 | from marshmallow import Schema, fields, validate, ValidationError |
| 3 | |
| 4 | class PostSchema(Schema): |
| 5 | user_id = fields.Int(required=True) |
| 6 | topic_id = fields.Int(required=False, allow_none=True) |
| 7 | type = fields.Str(validate=validate.OneOf(['text','image','video','document']), missing='text') |
| 8 | title = fields.Str(required=True, validate=validate.Length(min=1, max=255)) |
| 9 | content = fields.Str(required=True) |
| 10 | media_urls = fields.List(fields.Url(), required=False) |
| 11 | status = fields.Str(validate=validate.OneOf(['draft','pending','published','deleted','rejected']), missing='draft') |
| 12 | |
| 13 | class CommentSchema(Schema): |
| 14 | user_id = fields.Int(required=True) |
| 15 | content = fields.Str(required=True, validate=validate.Length(min=1)) |
| 16 | parent_id = fields.Int(required=False, allow_none=True) |