Skip to content

Commit

Permalink
add note search count endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
geekdinazor committed Jun 21, 2022
1 parent c64398d commit 13318ce
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
22 changes: 17 additions & 5 deletions src/note_service/modules/rest/business.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@
import requests as requests
from flask import current_app
from flask_smorest import abort
from sqlalchemy import func, column
from sqlalchemy.orm.exc import NoResultFound


from note_service.database import db
from note_service.modules.rest.models import Notes
from note_service.modules.rest.utils import ResponseObject, PaginationObject
from sqlalchemy import func, column
from sqlalchemy.orm.exc import NoResultFound


def create_note(files, args, username):
Expand Down Expand Up @@ -46,14 +44,28 @@ def search_notes(args, pagination_parameters):
_response = _response.select_from(func.unnest(func.string_to_array(Notes.tag, ',')).alias("tags")).filter(column("tags").like(tag))
if note_info:
_response = _response.filter(Notes.note_info.ilike("%" + note_info + "%"))
_response = _response.distinct().order_by(Notes.created_date.desc()).paginate(pagination_parameters.page, pagination_parameters.page_size)
_response = _response.distinct().order_by(Notes.created_date.desc()).paginate(pagination_parameters.page,
pagination_parameters.page_size)
pagination_parameters.item_count = _response.total
return ResponseObject(data=_response.items,
page=PaginationObject(page=_response.page, total_pages=_response.pages,
total=_response.total),
status=HTTPStatus.OK)


def search_item_count(args):
tag = args.get("tag")
note_info = args.get("note_info")
_response = Notes.query
_response = _response.select_from(func.unnest(func.string_to_array(Notes.tag, ',')).alias("tags")).filter(
column("tags").like(tag))
if note_info:
_response = _response.filter(Notes.note_info.ilike("%" + note_info + "%"))
_response = _response.distinct()

return ResponseObject(data={"count": str(_response.count())}, status=HTTPStatus.OK)


def fetch_note(note_id):
try:
_response = Notes.query.filter(Notes.id == note_id).one()
Expand Down
13 changes: 11 additions & 2 deletions src/note_service/modules/rest/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from flask_smorest import Blueprint

from note_service.modules.rest.business import search_notes, create_note, fetch_note, update_note, delete_note, \
get_pdf_key
get_pdf_key, search_item_count
from note_service.modules.rest.decorators import token_required
from note_service.modules.rest.schemas import Note, NoteFile, NotesResponse, NoteResponse, BaseResponse, NoteSearch

Expand Down Expand Up @@ -35,6 +35,16 @@ def get(self, args, pagination_parameters, **kwargs):
return search_notes(args, pagination_parameters)


@notes.route("/search/count")
class NoteSearchCountCollection(MethodView):
@token_required
@notes.arguments(NoteSearch, location="query")
@notes.response(HTTPStatus.OK, BaseResponse)
def get(self, args, **kwargs):
"""Verilen tag bilgisine göre not aramak için kullanılır"""
return search_item_count(args)


@notes.route("/<uuid:note_id>")
class NoteItemCollection(MethodView):
@token_required
Expand Down Expand Up @@ -69,4 +79,3 @@ class NoteItemCollection(MethodView):
def get(self, note_id, **kwargs):
"""Not'un ekini görüntülenmek için pdf anahtarı oluşturur """
return get_pdf_key(note_id)

0 comments on commit 13318ce

Please sign in to comment.