mudancas camera
This commit is contained in:
parent
adc299959d
commit
6a1e1eaf17
2
app.py
2
app.py
@ -142,4 +142,4 @@ if __name__ == "__main__":
|
|||||||
with app.app_context():
|
with app.app_context():
|
||||||
db.create_all() # Cria as tabelas
|
db.create_all() # Cria as tabelas
|
||||||
run_all_seeds()
|
run_all_seeds()
|
||||||
app.run(debug=True, host="0.0.0.0")
|
app.run(debug=True, host="0.0.0.0", port=5001)
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
tags:
|
tags:
|
||||||
- Ambiente
|
- Ambiente
|
||||||
summary: Cria um novo ambiente
|
summary: Cria um novo ambiente
|
||||||
security:
|
description:
|
||||||
- bearerAuth: []
|
Essa rota permite criar um ambiente associado ao um serviceRole
|
||||||
parameters:
|
parameters:
|
||||||
- in: body
|
- in: body
|
||||||
name: body
|
name: body
|
||||||
|
|||||||
@ -2,11 +2,14 @@ tags:
|
|||||||
- Ambiente
|
- Ambiente
|
||||||
summary: "Deleta um ambiente"
|
summary: "Deleta um ambiente"
|
||||||
description: "Remove um ambiente do sistema."
|
description: "Remove um ambiente do sistema."
|
||||||
|
security:
|
||||||
|
- bearerAuth: []
|
||||||
parameters:
|
parameters:
|
||||||
- name: "ambiente_id"
|
- in: "path"
|
||||||
in: "path"
|
name: "ambiente_id"
|
||||||
required: true
|
required: true
|
||||||
type: "integer"
|
schema:
|
||||||
|
type: integer
|
||||||
description: "ID do ambiente."
|
description: "ID do ambiente."
|
||||||
responses:
|
responses:
|
||||||
200:
|
200:
|
||||||
|
|||||||
@ -19,6 +19,14 @@ parameters:
|
|||||||
type: string
|
type: string
|
||||||
description: Descrição da localização ou modelo da camera
|
description: Descrição da localização ou modelo da camera
|
||||||
example: "camera entrada modelo xxx."
|
example: "camera entrada modelo xxx."
|
||||||
|
url:
|
||||||
|
type: string
|
||||||
|
description: url para acessar a camera
|
||||||
|
example: "http://exemplo."
|
||||||
|
status:
|
||||||
|
type: string
|
||||||
|
description: Estado da camera
|
||||||
|
example: "Ativo."
|
||||||
service_id:
|
service_id:
|
||||||
type: integer
|
type: integer
|
||||||
description: ID do serviço associado
|
description: ID do serviço associado
|
||||||
@ -48,6 +56,12 @@ responses:
|
|||||||
description:
|
description:
|
||||||
type: string
|
type: string
|
||||||
description: Descrição da camera
|
description: Descrição da camera
|
||||||
|
status:
|
||||||
|
type: string
|
||||||
|
description: Status da camera
|
||||||
|
url:
|
||||||
|
type: string
|
||||||
|
description: url para acessar a camera
|
||||||
service_id:
|
service_id:
|
||||||
type: integer
|
type: integer
|
||||||
description: ID do serviço associado
|
description: ID do serviço associado
|
||||||
@ -62,6 +76,8 @@ responses:
|
|||||||
id: 1
|
id: 1
|
||||||
name: "camera entrada"
|
name: "camera entrada"
|
||||||
description: "camera sony entrada."
|
description: "camera sony entrada."
|
||||||
|
status: "Ativo"
|
||||||
|
url: "http://exemplo.com"
|
||||||
service_id: 3
|
service_id: 3
|
||||||
ambiente_id: 1
|
ambiente_id: 1
|
||||||
service_role_id: 5
|
service_role_id: 5
|
||||||
|
|||||||
@ -19,6 +19,12 @@ responses:
|
|||||||
description:
|
description:
|
||||||
type: "string"
|
type: "string"
|
||||||
example: "camera hall principal, modelo xxx."
|
example: "camera hall principal, modelo xxx."
|
||||||
|
Status:
|
||||||
|
type: "string"
|
||||||
|
example: "status da camera."
|
||||||
|
url:
|
||||||
|
type: string
|
||||||
|
description: url para acessar a camera
|
||||||
service_id:
|
service_id:
|
||||||
type: "integer"
|
type: "integer"
|
||||||
example: 1
|
example: 1
|
||||||
|
|||||||
@ -11,6 +11,7 @@ parameters:
|
|||||||
type: integer
|
type: integer
|
||||||
default: 1
|
default: 1
|
||||||
description: Número da página a ser retornada
|
description: Número da página a ser retornada
|
||||||
|
status: Status da camera
|
||||||
- in: query
|
- in: query
|
||||||
name: per_page
|
name: per_page
|
||||||
required: false
|
required: false
|
||||||
@ -52,6 +53,12 @@ responses:
|
|||||||
description:
|
description:
|
||||||
type: string
|
type: string
|
||||||
description: Descrição da camera
|
description: Descrição da camera
|
||||||
|
status:
|
||||||
|
type: string
|
||||||
|
description: Status da camera
|
||||||
|
url:
|
||||||
|
type: string
|
||||||
|
description: url para acessar a camera
|
||||||
service_id:
|
service_id:
|
||||||
type: integer
|
type: integer
|
||||||
description: ID do serviço associado
|
description: ID do serviço associado
|
||||||
@ -71,12 +78,17 @@ responses:
|
|||||||
- id: 1
|
- id: 1
|
||||||
name: "camera 1"
|
name: "camera 1"
|
||||||
description: "camera hall de entrada."
|
description: "camera hall de entrada."
|
||||||
|
status: "Ativa"
|
||||||
|
url: "http://exemplo.com"
|
||||||
service_id: 1
|
service_id: 1
|
||||||
ambiente_id: 1
|
ambiente_id: 1
|
||||||
service_role_id: 1
|
service_role_id: 1
|
||||||
|
|
||||||
- id: 2
|
- id: 2
|
||||||
name: "camera 1"
|
name: "camera 1"
|
||||||
description: "camera estoque."
|
description: "camera estoque."
|
||||||
|
status: "Inativa"
|
||||||
|
url: "http://exemplo.com"
|
||||||
service_id: 1
|
service_id: 1
|
||||||
ambiente_id: 1
|
ambiente_id: 1
|
||||||
service_role_id: 1
|
service_role_id: 1
|
||||||
|
|||||||
@ -20,6 +20,18 @@ parameters:
|
|||||||
schema:
|
schema:
|
||||||
type: "string"
|
type: "string"
|
||||||
description: "Descrição da camera."
|
description: "Descrição da camera."
|
||||||
|
- name: "status"
|
||||||
|
in: "body"
|
||||||
|
required: false
|
||||||
|
schema:
|
||||||
|
type: "string"
|
||||||
|
description: "Status da camera."
|
||||||
|
- name: "url"
|
||||||
|
in: "body"
|
||||||
|
required: false
|
||||||
|
schema:
|
||||||
|
type: "string"
|
||||||
|
description: "url da camera."
|
||||||
responses:
|
responses:
|
||||||
200:
|
200:
|
||||||
description: "Camera atualizada com sucesso"
|
description: "Camera atualizada com sucesso"
|
||||||
|
|||||||
@ -6,7 +6,6 @@ Criar usuário ou subordinado
|
|||||||
description: >
|
description: >
|
||||||
Este endpoint permite criar um usuário ou subordinado vinculado a um usuário responsável.
|
Este endpoint permite criar um usuário ou subordinado vinculado a um usuário responsável.
|
||||||
parameters:
|
parameters:
|
||||||
|
|
||||||
- in: body
|
- in: body
|
||||||
name: body
|
name: body
|
||||||
required: true
|
required: true
|
||||||
|
|||||||
@ -9,6 +9,8 @@ class Cameras(db.Model):
|
|||||||
service_role_id = db.Column(db.Integer, db.ForeignKey('service_roles.id'), nullable=False)
|
service_role_id = db.Column(db.Integer, db.ForeignKey('service_roles.id'), nullable=False)
|
||||||
name = db.Column(db.String(255), nullable=False)
|
name = db.Column(db.String(255), nullable=False)
|
||||||
description = db.Column(db.Text, nullable=True)
|
description = db.Column(db.Text, nullable=True)
|
||||||
|
status = db.Column(db.Text, nullable=True)
|
||||||
|
url = db.Column(db.Text, nullable=True)
|
||||||
created_at = db.Column(db.DateTime, default=db.func.current_timestamp())
|
created_at = db.Column(db.DateTime, default=db.func.current_timestamp())
|
||||||
updated_at = db.Column(db.DateTime, default=db.func.current_timestamp(), onupdate=db.func.current_timestamp())
|
updated_at = db.Column(db.DateTime, default=db.func.current_timestamp(), onupdate=db.func.current_timestamp())
|
||||||
|
|
||||||
|
|||||||
@ -41,3 +41,79 @@ def create_ambiente():
|
|||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
return jsonify({'message': 'ambiente criado com sucesso', 'ambiente_id': ambiente.id}), 201
|
return jsonify({'message': 'ambiente criado com sucesso', 'ambiente_id': ambiente.id}), 201
|
||||||
|
|
||||||
|
@ambiente_bp.route('/', methods=['GET'])
|
||||||
|
@jwt_required()
|
||||||
|
@swag_from('../docs/ambiente/list.yml')
|
||||||
|
def list_ambiente():
|
||||||
|
page = request.args.get('page', 1, type=int)
|
||||||
|
per_page = request.args.get('per_page', 10, type=int)
|
||||||
|
|
||||||
|
pagination = Ambiente.query.paginate(page=page, per_page=per_page, error_out=False)
|
||||||
|
ambientes = pagination.items
|
||||||
|
|
||||||
|
return jsonify({
|
||||||
|
'ambiente': [
|
||||||
|
{
|
||||||
|
'id': ambiente.id,
|
||||||
|
'name': ambiente.name,
|
||||||
|
'description': ambiente.description,
|
||||||
|
'service_id': ambiente.service_id,
|
||||||
|
'service_role_id': ambiente.service_role_id
|
||||||
|
} for ambiente in ambientes
|
||||||
|
],
|
||||||
|
'total': pagination.total,
|
||||||
|
'page': pagination.page,
|
||||||
|
'per_page': pagination.per_page
|
||||||
|
}), 200
|
||||||
|
|
||||||
|
@ambiente_bp.route('/<int:ambiente_id>', methods=['GET'])
|
||||||
|
@jwt_required()
|
||||||
|
@swag_from('../docs/ambiente/get.yml')
|
||||||
|
def get_ambiente(ambiente_id):
|
||||||
|
ambiente = Ambiente.query.get(ambiente_id)
|
||||||
|
if not ambiente:
|
||||||
|
return jsonify({'error': 'Camera não encontrada'}), 404
|
||||||
|
|
||||||
|
return jsonify({
|
||||||
|
'id': ambiente.id,
|
||||||
|
'name': ambiente.name,
|
||||||
|
'description': ambiente.description,
|
||||||
|
'service_id': ambiente.service_id,
|
||||||
|
'service_role_id': ambiente.service_role_id
|
||||||
|
}), 200
|
||||||
|
|
||||||
|
@ambiente_bp.route('/<int:ambiente_id>', methods=['PUT'])
|
||||||
|
@jwt_required()
|
||||||
|
@swag_from('../docs/ambiente/update.yml')
|
||||||
|
def update_camera(ambiente_id):
|
||||||
|
data = request.get_json()
|
||||||
|
name = data.get('name')
|
||||||
|
description = data.get('description')
|
||||||
|
|
||||||
|
ambiente = Ambiente.query.get(ambiente_id)
|
||||||
|
if not ambiente:
|
||||||
|
return jsonify({'error': 'Camera não encontrada'}), 404
|
||||||
|
|
||||||
|
# Atualiza os campos fornecidos
|
||||||
|
if name:
|
||||||
|
ambiente.name = name
|
||||||
|
if description:
|
||||||
|
ambiente.description = description
|
||||||
|
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
return jsonify({'message': 'Ambiente atualizada com sucesso', 'ambiente_id': ambiente.id}), 200
|
||||||
|
|
||||||
|
@ambiente_bp.route('/<int:ambiente_id>', methods=['DELETE'])
|
||||||
|
@jwt_required()
|
||||||
|
@swag_from('../docs/ambiente/delete.yml')
|
||||||
|
def delete_ambiente(ambiente_id):
|
||||||
|
ambiente = Ambiente.query.get(ambiente_id)
|
||||||
|
if not ambiente:
|
||||||
|
return jsonify({'error': 'Ambiente não encontrada'}), 404
|
||||||
|
|
||||||
|
db.session.delete(ambiente)
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
return jsonify({'message': 'Ambiente deletada com sucesso'}), 200
|
||||||
|
|||||||
@ -17,7 +17,9 @@ def create_camera():
|
|||||||
ambiente_id = data.get('ambiente_id')
|
ambiente_id = data.get('ambiente_id')
|
||||||
service_role_id = data.get('service_role_id')
|
service_role_id = data.get('service_role_id')
|
||||||
name = data.get('name')
|
name = data.get('name')
|
||||||
|
status = data.get('status')
|
||||||
description = data.get('description')
|
description = data.get('description')
|
||||||
|
url = data.get('url')
|
||||||
|
|
||||||
# Verifica se o serviço existe
|
# Verifica se o serviço existe
|
||||||
service = Service.query.get(service_id)
|
service = Service.query.get(service_id)
|
||||||
@ -29,13 +31,16 @@ def create_camera():
|
|||||||
if existing_role:
|
if existing_role:
|
||||||
return jsonify({'error': 'Camera já existe para este serviço'}), 400
|
return jsonify({'error': 'Camera já existe para este serviço'}), 400
|
||||||
|
|
||||||
# Cria um novo ServiceRole
|
# Cria um nova camera
|
||||||
camera = Cameras(
|
camera = Cameras(
|
||||||
service_id=service_id,
|
service_id=service_id,
|
||||||
ambiente_id=ambiente_id,
|
ambiente_id=ambiente_id,
|
||||||
service_role_id = service_role_id,
|
service_role_id = service_role_id,
|
||||||
name=name,
|
name=name,
|
||||||
description=description
|
description=description,
|
||||||
|
status=status,
|
||||||
|
url=url,
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Adiciona e comita no banco de dados
|
# Adiciona e comita no banco de dados
|
||||||
@ -62,7 +67,9 @@ def list_service_roles():
|
|||||||
'description': camera.description,
|
'description': camera.description,
|
||||||
'service_id': camera.service_id,
|
'service_id': camera.service_id,
|
||||||
'ambiente_id': camera.ambiente_id,
|
'ambiente_id': camera.ambiente_id,
|
||||||
'service_role_id': camera.service_role_id
|
'service_role_id': camera.service_role_id,
|
||||||
|
'status': camera.status,
|
||||||
|
'url':camera.url,
|
||||||
} for camera in cameras
|
} for camera in cameras
|
||||||
],
|
],
|
||||||
'total': pagination.total,
|
'total': pagination.total,
|
||||||
@ -84,7 +91,9 @@ def get_service_role(camera_id):
|
|||||||
'description': camera.description,
|
'description': camera.description,
|
||||||
'service_id': camera.service_id,
|
'service_id': camera.service_id,
|
||||||
'ambiente_id': camera.ambiente_id,
|
'ambiente_id': camera.ambiente_id,
|
||||||
'service_role_id': camera.service_role_id
|
'service_role_id': camera.service_role_id,
|
||||||
|
'status': camera.status,
|
||||||
|
'url':camera.url,
|
||||||
}), 200
|
}), 200
|
||||||
|
|
||||||
@camera_bp.route('/<int:camera_id>', methods=['PUT'])
|
@camera_bp.route('/<int:camera_id>', methods=['PUT'])
|
||||||
@ -94,6 +103,9 @@ def update_camera(camera_id):
|
|||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
name = data.get('name')
|
name = data.get('name')
|
||||||
description = data.get('description')
|
description = data.get('description')
|
||||||
|
status=data.get('status')
|
||||||
|
url = data.get('url')
|
||||||
|
ambiente_id = data.get('ambiente_id')
|
||||||
|
|
||||||
camera = Cameras.query.get(camera_id)
|
camera = Cameras.query.get(camera_id)
|
||||||
if not camera:
|
if not camera:
|
||||||
@ -104,6 +116,12 @@ def update_camera(camera_id):
|
|||||||
camera.name = name
|
camera.name = name
|
||||||
if description:
|
if description:
|
||||||
camera.description = description
|
camera.description = description
|
||||||
|
if status:
|
||||||
|
camera.status = status
|
||||||
|
if url :
|
||||||
|
camera.url = url
|
||||||
|
if ambiente_id :
|
||||||
|
camera.ambiente_id = ambiente_id
|
||||||
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
@ -112,7 +130,7 @@ def update_camera(camera_id):
|
|||||||
@camera_bp.route('/<int:camera_id>', methods=['DELETE'])
|
@camera_bp.route('/<int:camera_id>', methods=['DELETE'])
|
||||||
@jwt_required()
|
@jwt_required()
|
||||||
@swag_from('../docs/camera/delete.yml')
|
@swag_from('../docs/camera/delete.yml')
|
||||||
def delete_service_role(camera_id):
|
def delete_camera(camera_id):
|
||||||
camera = Cameras.query.get(camera_id)
|
camera = Cameras.query.get(camera_id)
|
||||||
if not camera:
|
if not camera:
|
||||||
return jsonify({'error': 'Camera não encontrada'}), 404
|
return jsonify({'error': 'Camera não encontrada'}), 404
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user