提交 101abe5d 编写于 作者: J jinhai

Before add real logic code

上级 7d18b6b0
......@@ -25,3 +25,23 @@
- `python` # enter python3 interaction environment
- `from engine import db`
- `db.create_all()`
- table desc
group_table
+-------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| group_name | varchar(100) | YES | | NULL | |
| file_number | int(11) | YES | | NULL | |
+-------------+--------------+------+-----+---------+----------------+
file_table
+------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| group_name | varchar(100) | YES | | NULL | |
| filename | varchar(100) | YES | | NULL | |
| row_number | int(11) | YES | | NULL | |
+------------+--------------+------+-----+---------+----------------+
from flask import Flask
from flask import Flask, jsonify, request
from flask_restful import Resource, Api
from engine import app, db
from engine.model.GroupTable import GroupTable
# app = Flask(__name__)
api = Api(app)
from flask_restful import reqparse
from flask_restful import request
class Vector(Resource):
def __init__(self):
self.__parser = reqparse.RequestParser()
self.__parser.add_argument('groupid', type=str)
self.__parser.add_argument('vec', type=str)
self.__parser.add_argument('vector', type=float, action='append', location=['json'])
def post(self):
# args = self.__parser.parse_args()
# vec = args['vec']
# groupid = args['groupid']
def post(self, groupid):
args = self.__parser.parse_args()
vector = args['vector']
# add vector into file
print("vector: ", vector)
return "vector post"
class VectorSearch(Resource):
def __init__(self):
self.__parser = reqparse.RequestParser()
self.__parser.add_argument('groupid', type=str)
self.__parser.add_argument('vector', type=float, action='append', location=['json'])
def post(self):
def post(self, groupid):
args = self.__parser.parse_args()
print('vector: ', args['vector'])
# go to search every thing
return "vectorSearch post"
......@@ -35,6 +40,7 @@ class Index(Resource):
self.__parser.add_argument('groupid', type=str)
def post(self):
# go to create index for specific group
return "index post"
......@@ -44,25 +50,56 @@ class Group(Resource):
self.__parser.add_argument('groupid', type=str)
def post(self, groupid):
return "group post"
args = self.__parser.parse_args()
group = GroupTable.query.filter(GroupTable.group_name==groupid).first()
if(group):
return jsonify({'code': 1, 'group_name': groupid, 'file_number': group.file_number})
else:
new_group = GroupTable(groupid)
db.session.add(new_group)
db.session.commit()
return jsonify({'code': 0, 'group_name': groupid, 'file_number': 0})
def get(self, groupid):
return "group get"
args = self.__parser.parse_args()
group = GroupTable.query.filter(GroupTable.group_name==groupid).first()
if(group):
return jsonify({'code': 0, 'group_name': groupid, 'file_number': group.file_number})
else:
return jsonify({'code': 1, 'group_name': groupid, 'file_number': 0}) # not found
def delete(self, groupid):
return "group delete"
args = self.__parser.parse_args()
group = GroupTable.query.filter(GroupTable.group_name==groupid).first()
if(group):
# old_group = GroupTable(groupid)
db.session.delete(group)
db.session.commit()
return jsonify({'code': 0, 'group_name': groupid, 'file_number': group.file_number})
else:
return jsonify({'code': 0, 'group_name': groupid, 'file_number': 0})
class GroupList(Resource):
def get(self):
return "grouplist get"
group = GroupTable.query.all()
group_list = []
for group_tuple in group:
group_item = {}
group_item['group_name'] = group_tuple.group_name
group_item['file_number'] = group_tuple.file_number
group_list.append(group_item)
print(group_list)
return jsonify(results = group_list)
api.add_resource(Vector, '/vector')
api.add_resource(Vector, '/vector/add/<groupid>')
api.add_resource(Group, '/vector/group/<groupid>')
api.add_resource(GroupList, '/vector/group')
api.add_resource(Index, '/vector/index')
api.add_resource(VectorSearch, '/vector/search')
api.add_resource(VectorSearch, '/vector/search/<groupid>')
# if __name__ == '__main__':
......
......@@ -11,4 +11,4 @@ class GroupTable(db.Model):
self.file_number = 0
def __repr__(self):
return '<GroupTable $r>' % self.group_name
\ No newline at end of file
return '<GroupTable $s>' % self.group_name
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册