to: bill repository

This commit is contained in:
clz 2023-05-08 21:48:34 +08:00
parent 832780ce54
commit efe6160521
7 changed files with 170 additions and 2 deletions

12
.idea/dataSources.xml Normal file
View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
<data-source source="LOCAL" name="fadinglight" uuid="e8915c47-28a5-42b5-91b6-83b100f9c018">
<driver-ref>mariadb</driver-ref>
<synchronize>true</synchronize>
<jdbc-driver>org.mariadb.jdbc.Driver</jdbc-driver>
<jdbc-url>jdbc:mariadb://fadinglight.cn:3306</jdbc-url>
<working-dir>$ProjectFileDir$</working-dir>
</data-source>
</component>
</project>

7
.idea/sqldialects.xml Normal file
View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="SqlDialectMappings">
<file url="file://$PROJECT_DIR$/internal/bill/repository.go" dialect="GenericSQL" />
<file url="file://$PROJECT_DIR$/scripts/billMigrations.sql" dialect="MariaDB" />
</component>
</project>

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

View File

@ -21,7 +21,7 @@ type BDate struct {
type BillRepository interface { type BillRepository interface {
GetBills(ctx context.Context) (*[]Bill, error) 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) GetBillByMonth(ctx context.Context, year int, month int) (*[]Bill, error)
GetBillByYear(ctx context.Context, year int) (*[]Bill, error) GetBillByYear(ctx context.Context, year int) (*[]Bill, error)
GetBillByID(ctx context.Context, id int) (*Bill, error) GetBillByID(ctx context.Context, id int) (*Bill, error)

View File

@ -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")
}

View File

@ -34,7 +34,7 @@ func (b *billService) FetchBills(ctx context.Context, date BDate) (*[]Bill, erro
case date.Day == 0: case date.Day == 0:
return b.billRepository.GetBillByMonth(ctx, date.Year, date.Month) return b.billRepository.GetBillByMonth(ctx, date.Year, date.Month)
default: default:
return b.billRepository.GetBillByDate(ctx, date.Year, date.Month, date.Day) return b.billRepository.GetBillByDay(ctx, date.Year, date.Month, date.Day)
} }
} }

View File

@ -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', '餐饮', '晚餐', '');