示例#1
0
class NoteListResource(MethodResource):
    @auth.login_required
    @marshal_with(NoteResponseSchema(many=True))
    @doc(summary="Get all notes")
    def get(self):
        """
        Возвращает все заметки пользователя.
        Фильтры поиска не применяются.
        Требуется аутентификация.
        :return: все заметки
        """
        author = g.user
        notes = NoteModel.get_all_notes(author, archive="all")
        if not notes:
            abort(404, error=f"You have no notes yet")
        return notes, 200

    @auth.login_required
    @use_kwargs(NotePostRequestSchema, location='json')
    @marshal_with(NoteResponseSchema)
    @doc(summary="Create note")
    def post(self, **kwargs):
        """
        Создает заметку пользователя.
        Требуется аутентификация.
        :param kwargs: параметры для создания заметки
        :return: заметку
        """
        author = g.user
        note = NoteModel(author_id=author.id, **kwargs)
        note.save()
        return note, 201
示例#2
0
文件: note.py 项目: MyGodIsHe/Blog
class NotesPublicResource(MethodResource):
    @marshal_with(NoteResponseSchema(many=True))
    @doc(summary="Get all public notes")
    def get(self):
        notes = NoteModel.get_all_public_notes()
        if not notes:
            abort(404, error=f"Public notes not found")
        return notes, 200
示例#3
0
文件: note.py 项目: MyGodIsHe/Blog
class NoteListArchiveResource(MethodResource):
    @auth.login_required
    @marshal_with(NoteResponseSchema(many=True))
    @doc(summary="Get all archive notes")
    def get(self):
        author = g.user
        notes = NoteModel.get_all_notes(author, archive="archive")
        if not notes:
            abort(404, error=f"You have no notes yet")
        return notes, 200
示例#4
0
class NotesPublicResource(MethodResource):
    @marshal_with(NoteResponseSchema(many=True))
    @doc(summary="Get all public notes")
    def get(self):
        """
        Возвращает все публичные заметки пользователя
        :return: заметки
        """
        notes = NoteModel.get_all_public_notes()
        if not notes:
            abort(404, error=f"Public notes not found")
        return notes, 200
示例#5
0
文件: note.py 项目: MyGodIsHe/Blog
class NoteFilterResource(MethodResource):
    @doc(summary="Get notes. Filter by tags")
    @use_kwargs(NoteFilterSchema, location='query')
    @marshal_with(NoteResponseSchema(many=True))
    def get(self, **kwargs):
        notes_lst = []
        for tag_name in kwargs["tags"]:
            #pdb.set_trace()
            notes = NoteModel.get_notes_filtered_by_tags(tag_name)
            if not notes:
                abort(404, error=f"Note with tag_name={tag_name} not found")
            for note in notes:
                if note not in notes_lst:
                    notes_lst.append(note)
        return notes_lst, 200
示例#6
0
class NoteListArchiveResource(MethodResource):
    @auth.login_required
    @marshal_with(NoteResponseSchema(many=True))
    @doc(summary="Get all archive notes")
    def get(self):
        """
        Возвращает все архивные заметки пользователя.
        Используется фильтр - "архивные".
        Требуется аутентификация.
        :return:
        """
        author = g.user
        notes = NoteModel.get_all_notes(author, archive="archive")
        if not notes:
            abort(404, error=f"You have no notes yet")
        return notes, 200
示例#7
0
class NoteFilterResource(MethodResource):
    @doc(summary="Get notes. Filter by tags")
    @use_kwargs(NoteFilterSchema, location='query')
    @marshal_with(NoteResponseSchema(many=True))
    def get(self, **kwargs):
        """
        Возвращает заметки, фильтруя по привязанным тегам.
        :param kwargs: теги в формате списка
        :return: заметки
        """
        notes_lst = []
        for tag_name in kwargs["tags"]:
            #pdb.set_trace()
            notes = NoteModel.get_notes_filtered_by_tags(tag_name)
            if not notes:
                abort(404, error=f"Note with tag_name={tag_name} not found")
            for note in notes:
                if note not in notes_lst:
                    notes_lst.append(note)
        return notes_lst, 200
示例#8
0
文件: note.py 项目: MyGodIsHe/Blog
class NoteListResource(MethodResource):
    @auth.login_required
    @marshal_with(NoteResponseSchema(many=True))
    @doc(summary="Get all notes")
    def get(self):
        author = g.user
        notes = NoteModel.get_all_notes(author, archive="all")
        if not notes:
            abort(404, error=f"You have no notes yet")
        return notes, 200

    @auth.login_required
    @use_kwargs(NotePostRequestSchema, location='json')
    @marshal_with(NoteResponseSchema)
    @doc(summary="Create note")
    def post(self, **kwargs):
        author = g.user
        note = NoteModel(author_id=author.id, **kwargs)
        note.save()
        return note, 201