From efe6160521c3aba51f7736d930f838f01a903871 Mon Sep 17 00:00:00 2001 From: clz Date: Mon, 8 May 2023 21:48:34 +0800 Subject: [PATCH] to: bill repository --- .idea/dataSources.xml | 12 ++++++ .idea/sqldialects.xml | 7 ++++ .idea/vcs.xml | 6 +++ internal/bill/domain.go | 2 +- internal/bill/repository.go | 64 ++++++++++++++++++++++++++++++ internal/bill/service.go | 2 +- scripts/billMigrations.sql | 79 +++++++++++++++++++++++++++++++++++++ 7 files changed, 170 insertions(+), 2 deletions(-) create mode 100644 .idea/dataSources.xml create mode 100644 .idea/sqldialects.xml create mode 100644 .idea/vcs.xml create mode 100644 internal/bill/repository.go create mode 100644 scripts/billMigrations.sql diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml new file mode 100644 index 0000000..362c030 --- /dev/null +++ b/.idea/dataSources.xml @@ -0,0 +1,12 @@ + + + + + mariadb + true + org.mariadb.jdbc.Driver + jdbc:mariadb://fadinglight.cn:3306 + $ProjectFileDir$ + + + \ No newline at end of file diff --git a/.idea/sqldialects.xml b/.idea/sqldialects.xml new file mode 100644 index 0000000..aa51b62 --- /dev/null +++ b/.idea/sqldialects.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..c8397c9 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/internal/bill/domain.go b/internal/bill/domain.go index 7681d35..4d702a2 100644 --- a/internal/bill/domain.go +++ b/internal/bill/domain.go @@ -21,7 +21,7 @@ type BDate struct { type BillRepository interface { GetBills(ctx context.Context) (*[]Bill, error) - GetBillByDate(ctx context.Context, year int, month int, day int) (*[]Bill, error) + GetBillByDay(ctx context.Context, year int, month int, day int) (*[]Bill, error) GetBillByMonth(ctx context.Context, year int, month int) (*[]Bill, error) GetBillByYear(ctx context.Context, year int) (*[]Bill, error) GetBillByID(ctx context.Context, id int) (*Bill, error) diff --git a/internal/bill/repository.go b/internal/bill/repository.go new file mode 100644 index 0000000..6ed5116 --- /dev/null +++ b/internal/bill/repository.go @@ -0,0 +1,64 @@ +package bill + +import ( + "context" + "database/sql" +) + +const ( + QUERY_GET_BILLS = "SELECT * FROM Bills" + QUERY_GET_BILLS_BY_DAY = "" + QUERY_GET_BILLS_BY_MONTH = "" + QUERY_GET_BILLS_BY_YEAR = "" + QUERY_GET_BILL_BY_ID = "" +) + +type mariaDBRepository struct { + mariadb *sql.DB +} + +func newMariaDBRepository(mariadb *sql.DB) BillRepository { + return &mariaDBRepository{ + mariadb: mariadb, + } +} + +func (m *mariaDBRepository) GetBills(ctx context.Context) (*[]Bill, error) { + //TODO implement me + panic("implement me") +} + +func (m *mariaDBRepository) GetBillByDay(ctx context.Context, year int, month int, day int) (*[]Bill, error) { + //TODO implement me + panic("implement me") +} + +func (m *mariaDBRepository) GetBillByMonth(ctx context.Context, year int, month int) (*[]Bill, error) { + //TODO implement me + panic("implement me") +} + +func (m *mariaDBRepository) GetBillByYear(ctx context.Context, year int) (*[]Bill, error) { + //TODO implement me + panic("implement me") +} + +func (m *mariaDBRepository) GetBillByID(ctx context.Context, id int) (*Bill, error) { + //TODO implement me + panic("implement me") +} + +func (m *mariaDBRepository) CreateBill(ctx context.Context, bill *Bill) error { + //TODO implement me + panic("implement me") +} + +func (m *mariaDBRepository) UpdateBill(ctx context.Context, bill *Bill) error { + //TODO implement me + panic("implement me") +} + +func (m *mariaDBRepository) DeleteBill(ctx context.Context, id int) error { + //TODO implement me + panic("implement me") +} diff --git a/internal/bill/service.go b/internal/bill/service.go index 92976b9..cdd9b72 100644 --- a/internal/bill/service.go +++ b/internal/bill/service.go @@ -34,7 +34,7 @@ func (b *billService) FetchBills(ctx context.Context, date BDate) (*[]Bill, erro case date.Day == 0: return b.billRepository.GetBillByMonth(ctx, date.Year, date.Month) default: - return b.billRepository.GetBillByDate(ctx, date.Year, date.Month, date.Day) + return b.billRepository.GetBillByDay(ctx, date.Year, date.Month, date.Day) } } diff --git a/scripts/billMigrations.sql b/scripts/billMigrations.sql new file mode 100644 index 0000000..94f63d6 --- /dev/null +++ b/scripts/billMigrations.sql @@ -0,0 +1,79 @@ +DROP DATABASE IF EXISTS bill; +CREATE DATABASE IF NOT EXISTS bill; +USE bill; + +create table Bills +( + id int auto_increment + primary key, + type varchar(15) not null, + date varchar(15) not null, + money varchar(900) null, + cls varchar(900) null, + label varchar(900) null, + options varchar(900) null +) + charset = utf8mb4; + +INSERT INTO bill.Bills (id, type, date, money, cls, label, options) +VALUES (3341, 'INCOME', '2022-09-01', '8.5', '交通', '打的', ''); +INSERT INTO bill.Bills (id, type, date, money, cls, label, options) +VALUES (3342, 'INCOME', '2022-09-01', '2.0', '交通', '公交', ''); +INSERT INTO bill.Bills (id, type, date, money, cls, label, options) +VALUES (3343, 'INCOME', '2022-09-01', '43.0', '交通', '其他', '巴士 回房县'); +INSERT INTO bill.Bills (id, type, date, money, cls, label, options) +VALUES (3344, 'INCOME', '2022-09-01', '5.0', '餐饮', '饮料', ''); +INSERT INTO bill.Bills (id, type, date, money, cls, label, options) +VALUES (3345, 'INCOME', '2022-09-01', '4.0', '交通', '公交', ''); +INSERT INTO bill.Bills (id, type, date, money, cls, label, options) +VALUES (3346, 'INCOME', '2022-09-04', '168.0', '餐饮', '聚餐', '胖嫂烧烤'); +INSERT INTO bill.Bills (id, type, date, money, cls, label, options) +VALUES (3347, 'INCOME', '2022-09-03', '27.0', '餐饮', '零食', ''); +INSERT INTO bill.Bills (id, type, date, money, cls, label, options) +VALUES (3348, 'INCOME', '2022-09-06', '186.0', '交通', '高铁', '回武汉的高铁票'); +INSERT INTO bill.Bills (id, type, date, money, cls, label, options) +VALUES (3349, 'INCOME', '2022-09-06', '4.0', '餐饮', '饮料', ''); +INSERT INTO bill.Bills (id, type, date, money, cls, label, options) +VALUES (3350, 'INCOME', '2022-09-06', '5.0', '餐饮', '早餐', ''); +INSERT INTO bill.Bills (id, type, date, money, cls, label, options) +VALUES (3351, 'INCOME', '2022-07-04', '17.9', '餐饮', '晚餐', ''); +INSERT INTO bill.Bills (id, type, date, money, cls, label, options) +VALUES (3352, 'INCOME', '2022-07-04', '18.5', '餐饮', '午餐', ''); +INSERT INTO bill.Bills (id, type, date, money, cls, label, options) +VALUES (3353, 'INCOME', '2022-07-04', '9.0', '餐饮', '饮料', ''); +INSERT INTO bill.Bills (id, type, date, money, cls, label, options) +VALUES (3354, 'INCOME', '2022-07-04', '17.0', '餐饮', '早餐', ''); +INSERT INTO bill.Bills (id, type, date, money, cls, label, options) +VALUES (3355, 'INCOME', '2022-07-04', '10.3', '餐饮', '零食', ''); +INSERT INTO bill.Bills (id, type, date, money, cls, label, options) +VALUES (3356, 'INCOME', '2022-07-05', '9.5', '餐饮', '早餐', ''); +INSERT INTO bill.Bills (id, type, date, money, cls, label, options) +VALUES (3357, 'INCOME', '2022-07-05', '22.0', '餐饮', '午餐', ''); +INSERT INTO bill.Bills (id, type, date, money, cls, label, options) +VALUES (3358, 'INCOME', '2022-07-05', '16.0', '餐饮', '晚餐', ''); +INSERT INTO bill.Bills (id, type, date, money, cls, label, options) +VALUES (3359, 'INCOME', '2022-07-05', '1.6', '交通', '公交', ''); +INSERT INTO bill.Bills (id, type, date, money, cls, label, options) +VALUES (3360, 'INCOME', '2022-07-06', '7.0', '餐饮', '早餐', ''); +INSERT INTO bill.Bills (id, type, date, money, cls, label, options) +VALUES (3361, 'INCOME', '2022-07-06', '19.0', '餐饮', '午餐', ''); +INSERT INTO bill.Bills (id, type, date, money, cls, label, options) +VALUES (3362, 'INCOME', '2022-07-06', '6.0', '餐饮', '饮料', ''); +INSERT INTO bill.Bills (id, type, date, money, cls, label, options) +VALUES (3363, 'INCOME', '2022-07-06', '14.0', '餐饮', '晚餐', ''); +INSERT INTO bill.Bills (id, type, date, money, cls, label, options) +VALUES (3364, 'INCOME', '2022-07-06', '1.6', '交通', '公交', ''); +INSERT INTO bill.Bills (id, type, date, money, cls, label, options) +VALUES (3365, 'INCOME', '2022-07-06', '1.6', '交通', '公交', ''); +INSERT INTO bill.Bills (id, type, date, money, cls, label, options) +VALUES (3366, 'INCOME', '2022-07-06', '16.0', '餐饮', '奶茶', ''); +INSERT INTO bill.Bills (id, type, date, money, cls, label, options) +VALUES (3367, 'INCOME', '2022-07-07', '9.0', '餐饮', '早餐', ''); +INSERT INTO bill.Bills (id, type, date, money, cls, label, options) +VALUES (3368, 'INCOME', '2022-07-07', '14.4', '餐饮', '午餐', ''); +INSERT INTO bill.Bills (id, type, date, money, cls, label, options) +VALUES (3369, 'INCOME', '2022-07-07', '1.6', '交通', '公交', ''); +INSERT INTO bill.Bills (id, type, date, money, cls, label, options) +VALUES (3370, 'INCOME', '2022-07-07', '9.0', '餐饮', '晚餐', ''); +INSERT INTO bill.Bills (id, type, date, money, cls, label, options) +VALUES (3371, 'INCOME', '2022-07-07', '5.5', '餐饮', '晚餐', ''); \ No newline at end of file