Skip to content
This repository was archived by the owner on Jan 25, 2022. It is now read-only.

Commit c5ef0cd

Browse files
authored
Fontaneria (#82)
* Fontaneria * Cosas que hacen cosas * Allow other users to edit posts * Cosas
1 parent b083bd8 commit c5ef0cd

File tree

5 files changed

+28
-14
lines changed

5 files changed

+28
-14
lines changed

release/docker-compose.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ services:
9797
depends_on:
9898
- kafka
9999

100-
texttospeech:
100+
texttospeechservice:
101101
build: ../src/texttospeechservice/
102102
container_name: texttospeechservice
103103
ports:
@@ -106,6 +106,8 @@ services:
106106
- kafka
107107
environment:
108108
KAFKA_ENDPOINT: "kafka:9092"
109+
KAFKA_ENDPOINT: "kafka:9092"
110+
STATISTICS_SERVICE_ENDPOINT: "http://statisticsservice:5000/soapws/statistics?wsdl"
109111

110112
usersservice:
111113
build: ../src/usersservice/
@@ -179,6 +181,8 @@ services:
179181
POSTS_SERVICE_HOST: postsservice
180182
POSTS_SERVICE_PORT: 5000
181183
STATS_SERVICE_WDSL: "http://statisticsservice:5000/soapws/statistics?wsdl"
184+
TTS_SERVICE_HOST: texttospeechservice
185+
TTS_SERVICE_PORT: 5000
182186

183187
############# Web Client ################
184188
# webclient:

src/postsservice/Service/BasicPostsService.cs

100755100644
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,19 @@ public Task<List<Post>> GetPosts(PaginationFilter paginationFilter, PostsFilter
6161
.Where(p => postsFilter.User == null ? true : p.AuthorId == postsFilter.User)
6262
.Where(p => postsFilter.Language == null ? true : languages.Contains(p.Language));
6363

64-
// now pagination
65-
postsQueryable = postsQueryable
66-
.Skip(paginationFilter.Offset)
67-
.Take(paginationFilter.Limit);
68-
6964
// sorting...
7065
// at this point the name of the property has been validated to exist
7166
if (sortingInfo.Order.Equals("asc"))
7267
postsQueryable = postsQueryable.OrderBy(p => EF.Property<object>(p, sortingInfo.SortBy));
7368
else
7469
postsQueryable = postsQueryable.OrderByDescending(p => EF.Property<object>(p, sortingInfo.SortBy));
7570

71+
// now pagination
72+
postsQueryable = postsQueryable
73+
.Skip(paginationFilter.Offset)
74+
.Take(paginationFilter.Limit);
75+
76+
7677
// and get the posts!!
7778
return postsQueryable.ToListAsync();
7879
}

src/texttospeechservice/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class BaseConfig():
2121
SERVICE_KEY = _try_get_config_from_env('SERVICE_KEY', 'tts_service')
2222
LOCALE_MAPPINGS_FILE = _try_get_config_from_env('MAPPINGS_FILE', 'lang2locale.csv')
2323
DEPLOY_PORT = int(_try_get_config_from_env('DEPLOY_PORT', '5000'))
24+
STATISTICS_SERVICE_ENDPOINT = _try_get_config_from_env('STATISTICS_SERVICE_ENDPOINT', 'http://localhost:5000/soapws/statistics?wsdl')
2425

2526
class DevelopmentConfig(BaseConfig):
2627
DEBUG = True

src/texttospeechservice/src/clients/soap_client.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def __init__(self, successful, result=None):
1414
self.result = result
1515

1616

17-
class SoapClient:
17+
class SoapClient(object):
1818
""" Allows making request to a given SOAP endpoint.
1919
2020
This class uses the ZEEP Python library (https://docs.python-zeep.org/en/master/index.html#)
@@ -35,14 +35,15 @@ def __init__(self, wsdl_endpoint):
3535
settings = zeep.Settings(strict=False, xml_huge_tree=True)
3636
self.client = zeep.Client(wsdl=wsdl_endpoint, settings=settings)
3737

38-
def __getattribute__(self, attr_name, *args, **kwargs):
39-
logger.debug(f"Calling method of SOAP Client: {attr_name}")
38+
def call_method(self, method_name, *args, **kwargs):
39+
logger.debug(f"Calling method of SOAP Client: {method_name}")
4040
logger.debug(f"Args: {args} - Kwargs: {kwargs}")
4141
try:
42-
res = getattr(client.service, attr_name)(*args, **kwargs)
42+
res = getattr(self.client.service, method_name)(*args, **kwargs)
4343
logger.info(f"SOAP request was successful. Result: {res}")
4444
return SoapResult(True, res)
4545
except Exception as e:
4646
logger.error(f"There was an error calling the SOAP client: {e}")
4747
logger.debug("Returning unsuccessful SOAP result")
4848
return SoapResult(False)
49+

src/texttospeechservice/src/controller.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"""
33

44
import base64
5+
import json
56
import logging
67

78
from flask import current_app as app
@@ -16,7 +17,7 @@
1617
logger.setLevel(logging.DEBUG)
1718

1819
gcloud_tts_client = GCloudTTSClient()
19-
#statistics_client = SoapClient()
20+
statistics_client = SoapClient(app.config['STATISTICS_SERVICE_ENDPOINT'])
2021
locale_manager = LocaleManager(app.config['LOCALE_MAPPINGS_FILE'])
2122

2223

@@ -35,6 +36,14 @@ def tts():
3536
"""
3637
logger.debug("POST to TextsToSpeechs received")
3738
body_data = request.get_json()
39+
if 'passport' in request.headers:
40+
logger.debug("Passport found")
41+
passport = json.loads(request.headers.get('passport'))
42+
logger.debug(f"Passport: {passport}")
43+
user_id = passport['userId_']
44+
else:
45+
user_id = "1"
46+
logger.debug(f"User ID: {user_id}")
3847
logger.debug(f"Data: {body_data}")
3948

4049
if 'language' not in body_data or 'text' not in body_data:
@@ -61,9 +70,7 @@ def tts():
6170
# A user can then use it with base64.b64decode(audio_str)
6271
logger.debug("Encoding audio file to base64 and decoding to string...")
6372
audio_str = base64.b64encode(audio).decode()
64-
65-
# TODO: call statistics service to update number of tts of user
66-
#statistics_client.update_
73+
statistics_client.call_method('registerTextToSpeechCreatedEvent', user_id)
6774

6875
return jsonify({
6976
'locale': locale,

0 commit comments

Comments
 (0)