SoldHistory.value()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1.037

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 10
ccs 2
cts 3
cp 0.6667
rs 10
c 0
b 0
f 0
cc 1
nop 1
crap 1.037
1
#!/usr/bin/python
2
# -*- coding: utf-8 -*-
3
4 1
from typing import List
5
6 1
from kuon.watcher.adapters.models import AbstractEntity
7 1
from kuon.watcher.adapters.models.sold_item import SoldItem
8
9
10 1
class SoldHistory(AbstractEntity):
11
    """General Sold History Response from the APIs"""
12
13 1
    def __init__(self, success: bool, sold_items: List[SoldItem] = None) -> None:
14
        """Initializing function
15
16
        :type success: bool
17
        :type sold_items: List[SoldItem]
18
        """
19
        self._success = success
20
21
        if sold_items:
22
            self._sold_items = sold_items
23
        else:
24
            self._sold_items = []
25
26 1
    @property
27 1
    def value(self) -> dict:
28
        """Return all important information from the API response like success and sold items
29
30
        :return:
31
        """
32
        return {
33
            'data': {
34
                'success': self._success,
35
                'sales': self.sold_items
36
            }
37
        }
38
39 1
    @property
40 1
    def sold_items(self) -> list:
41
        """Property for sold items which returns __dict__ of the sold item objects
42
        to allow JSON dump the search response without custom JSONEncoder objects
43
44
        :return:
45
        """
46
        return [i.__dict__ for i in self._sold_items]
47
48 1
    @sold_items.setter
49 1
    def sold_items(self, sold_items: List[SoldItem]) -> None:
50
        """Setter for sold items
51
52
        :type sold_items: List[SoldItem]
53
        :return:
54
        """
55
        self._sold_items = sold_items
56
57 1
    def add_sale(self, sold_item: SoldItem) -> None:
58
        """Adder for sold items
59
60
        :type sold_item: SoldItem
61
        :return:
62
        """
63
        if sold_item not in self._sold_items:
64
            self._sold_items.append(sold_item)
65