def create_donation(self, data: Dict) -> int:
     """
     create donation records
     :param data:
     :return: created donation id
     """
     if not data:
         raise RequestDataEmpty("Donation data is empty")
     if not self.input_validate.validate_json(data, donation_schema):
         self.logger.error("All donation field input must be required.")
         raise ValidateFail("Donation validation fail")
     try:
         return DonationModel.create_donation(DonationModel(
             user_id=data["user_id"],
             attendance_id=data["attendance_id"],
             transfer_id=data["transfer_id"],
             year=data["year"],
             month=data["month"],
             mmk_amount=data["mmk_amount"],
             jpy_amount=data["jpy_amount"],
             paid_at=data["paid_at"]
             ))
     except SQLAlchemyError as error:
         self.logger.error("Donation create fail. error %s", error)
         raise SQLCustomError("Donation create fail")
 def update_donation_by_id(self, donation_id: int, data: Dict) -> bool:
     """
     put donation by id
     :param donation_id:
     :param data:
     :return:
     """
     if not data:
         raise RequestDataEmpty("Donation data is empty")
     if not self.input_validate.validate_json(data, donation_schema):
         self.logger.error("All donation field input must be required.")
         raise ValidateFail("Donation update validation fail")
     try:
         self.logger.info("Update donation info by donation_id:{}".format(donation_id))
         return DonationModel.update_donation(donation_id, DonationModel(
             user_id=data["user_id"],
             attendance_id=data["attendance_id"],
             transfer_id=data["transfer_id"],
             year=data["year"],
             month=data["month"],
             mmk_amount=data["mmk_amount"],
             jpy_amount=data["jpy_amount"],
             paid_at=data["paid_at"]))
     except SQLAlchemyError as error:
         self.logger.error("Error: {}".format(error))
         raise SQLCustomError(description="Update donation by ID SQL ERROR")
     except SQLCustomError as error:
         self.logger.error("Error: {}".format(error))
         raise SQLCustomError(description="No record for requested donation")
Esempio n. 3
0
 def get_donations_records_by_year_month(self, year: int,
                                         month: str) -> Dict[str, Any]:
     """
     get donations for a given year and month
     :params page
     :params per_page
     :return: donation list of dict
     """
     self.logger.debug("Get Donation list by year and month")
     donations = DonationModel.get_donations_by_year_month(
         year, month.lower())
     return {
         "donations": [
             donation.donation_dict(user, student)
             for donation, user, student in donations.items
         ],
         "total_count":
         donations.total,
         "current_page":
         donations.page,
         "next_page":
         donations.next_num,
         "prev_page":
         donations.prev_num,
         "pages":
         donations.pages
     }
Esempio n. 4
0
 def get_all_donator_donations_records(self,
                                       user_id: int,
                                       page: int = 1,
                                       per_page: int = 20) -> (List, Any):
     """
     get all donation
     :params page
     :params per_page
     :return: donation list of dict
     """
     try:
         self.logger.info("Get Donation list")
         donations = DonationModel.get_all_donator_donations(
             user_id, page, per_page)
         return {
             "donations": [
                 donation.donation_dict(user, student)
                 for donation, user, student in donations.items
             ],
             "total_count":
             donations.total,
             "current_page":
             donations.page,
             "next_page":
             donations.next_num,
             "prev_page":
             donations.prev_num,
             "pages":
             donations.pages
         }
     except SQLAlchemyError as error:
         self.logger.error("Error: {}".format(error))
         raise SQLCustomError(description="GET Donation SQL ERROR")
 def delete_donation_by_id(self, donation_id: int) -> bool:
     """
     delete donation by id
     :param donation_id:
     :return:
     """
     try:
         self.logger.info("Delete donation info by donation_id:{}".format(donation_id))
         return DonationModel.delete_donation_by_id(donation_id)
     except SQLAlchemyError as error:
         self.logger.error("Error: {}".format(error))
         raise SQLCustomError(description="Delete Donation by ID SQL ERROR")
Esempio n. 6
0
 def get_all_donations_records(self, page: int) -> (List, Any):
     """
     get all donation
     :return: donation list of dict
     """
     try:
         self.logger.info("Get Donation list")
         donations = DonationModel.get_all_donations(page)
         return [
             donation.donation_dict(user, student)
             for donation, user, student in donations.items
         ], donations.total
     except SQLAlchemyError as error:
         self.logger.error("Error: {}".format(error))
         raise SQLCustomError(description="GET Donation SQL ERROR")
Esempio n. 7
0
 def get_donation_by_id(self, donation_id: int) -> Optional[Dict]:
     """
     get donation info by id
     :param donation_id:
     :return: donation list of dict
     """
     try:
         self.logger.info(
             "Get donation info by donation_id:{}".format(donation_id))
         donations = [
             donation.donation_dict(user, student) for donation, user,
             student in DonationModel.get_donation_by_id(donation_id)
         ]
         return donations[0] if len(donations) > 0 else {}
     except SQLAlchemyError as error:
         self.logger.error("Error: {}".format(error))
         raise SQLCustomError(description="GET Donation by ID SQL ERROR")
 def get_donation_by_id(self, donation_id: int) -> Optional[Dict]:
     """
     get donation info by id
     :param donation_id:
     :return: donation list of dict
     """
     try:
         donation_record = DonationModel.get_donation_by_id(donation_id)
         if donation_record:
             donation, user, student = donation_record
             self.logger.info("Get donation info by donation_id:{}".format(donation_id))
             return donation.donation_dict(user, student)
         else:
             self.logger.error("Fail to get donation info by donation_id:{}".format(donation_id))
             raise ThingahaCustomError(description="No record for requested donation id: {}".format(donation_id))
     except SQLAlchemyError as error:
         self.logger.error("Error: {}".format(error))
         raise SQLCustomError(description="GET Donation by ID SQL ERROR")
Esempio n. 9
0
    def update_donation_status_by_id(self, donation_id: int,
                                     status: str) -> bool:
        """
        put donation by id
        :param donation_id:
        :param status:
        :return:
        """

        try:
            self.logger.info(
                "Update donation info by donation_id:{}".format(donation_id))
            paid_at = func.now() if status == "paid" else None
            return DonationModel.update_donation_status_by_id(
                donation_id, paid_at)

        except SQLAlchemyError as error:
            self.logger.error("Error: {}".format(error))
            raise SQLCustomError(description="Update donation by ID SQL ERROR")
        except SQLCustomError as error:
            self.logger.error("Error: {}".format(error))
            raise SQLCustomError(
                description="No record for requested donation")