Ejemplo n.º 1
0
    def get_address(self, user_id, connection):
        """ [서비스] 배송지 목록 가져오기
        Author:
            Ji Yoon Lee
        Args:
            user_id(str): 로그인한 user id
        Returns:
            {'data': get_address} ; 해당 사용자의 과거 배송지를 'data'라는 키값에 넣어서 반환
        """
        order_dao = OrderDao()
        get_address = order_dao.get_address(user_id, connection)

        return {'data': get_address}
Ejemplo n.º 2
0
    def post_address(self, address_info, connection):
        """ [서비스] 신규 배송지 추가
        Author:
            Ji Yoon Lee
        Args:
            address_info(dict)
        Returns:
            {'data': address_id}; 추가된 배송지의 id값을 'data'라는 키값에 넣어서 반환
        """
        order_dao = OrderDao()
        user_id = address_info['user_id']
        address_all = order_dao.get_address(user_id, connection)
        default_address = None

        # 해당 유저가 이미 등록한 배송지인지 검사
        for address in address_all:
            if address['address'] == address_info[
                    'recipient_address'] and address[
                        'addressDetail'] == address_info[
                            'recipient_address_detail']:
                raise ApiException(400, ADDRESS_ALREADY_EXISTS)

            if address_info['is_default'] in ['1', 1]:
                default_address = address['id']

        # 기본배송지가 이미 존재하는데, 새로추가된 배송지를 기본배송지로 등록할 때 - 기존 배송지 기본배송지 해제
        if address_info['is_default'] in ['1', 1]:
            if order_dao.reset_address_default(address_info,
                                               connection) == False:
                raise ApiException(400, REQUEST_FAILED)
            address_info['shipping_info_id'] = default_address
            reset_log = order_dao.post_address_log(address_info, connection)

        # 신규 배송지 등록
        address_id = order_dao.post_address(address_info, connection)
        address_info['shipping_info_id'] = address_id
        address_log = order_dao.post_address_log(address_info, connection)

        return {'data': address_id}