File size: 1,634 Bytes
94ed9e1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from http import HTTPStatus
from fastapi.responses import JSONResponse
from restful.services import cryptocurrency_svc
from restful.schemas import CryptocurrencyPredictionSchema


# Cryptocurrency Controller
class cryptocurrency_controller:
    # Cryptocurrency Service
    __SERVICE = cryptocurrency_svc()

    # Cryptocurrency Controller
    def prediction(self, payload: CryptocurrencyPredictionSchema) -> JSONResponse:
        try: 
            prediction: list = self.__SERVICE.prediction(
                payload = payload
            )

            if not prediction :
                return JSONResponse(
                    content = {
                        'message': 'Request Failed',
                        'status_code': HTTPStatus.BAD_REQUEST,
                        'data': None
                    },
                    status_code = HTTPStatus.BAD_REQUEST
                )

            return JSONResponse(
                content = {
                    'message': 'Prediction Success',
                    'status_code': HTTPStatus.OK,
                    'data': {
						'currency': payload.currency,
						'predictions': prediction
					}
                },
                status_code = HTTPStatus.OK
            )

        except Exception as error_message:
            print(error_message)
            return JSONResponse(
                content = {
                    'message': 'Internal Server Error',
                    'status_code': HTTPStatus.INTERNAL_SERVER_ERROR,
                    'data': None
                },
                status_code = HTTPStatus.INTERNAL_SERVER_ERROR
            )