Skip to content

Commit 0006883

Browse files
committed
Merge branch 'main' into fetch/fix-track1099
2 parents 86969ab + 20281c4 commit 0006883

11 files changed

+216
-48
lines changed
Lines changed: 8 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 8 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 8 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/labrinth/.sqlx/query-d307116366d03315a8a01d1b62c5ca81624a42d01a43e1d5adf8881f8a71d495.json

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ALTER TABLE affiliate_codes
2+
ADD COLUMN source_name VARCHAR(255) NOT NULL DEFAULT '(unnamed)';

apps/labrinth/src/database/models/affiliate_code_item.rs

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ pub struct DBAffiliateCode {
99
pub created_at: DateTime<Utc>,
1010
pub created_by: DBUserId,
1111
pub affiliate: DBUserId,
12+
pub source_name: String,
1213
}
1314

1415
impl DBAffiliateCode {
@@ -17,7 +18,7 @@ impl DBAffiliateCode {
1718
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
1819
) -> Result<Option<DBAffiliateCode>, DatabaseError> {
1920
let record = sqlx::query!(
20-
"SELECT id, created_at, created_by, affiliate
21+
"SELECT id, created_at, created_by, affiliate, source_name
2122
FROM affiliate_codes WHERE id = $1",
2223
id as DBAffiliateCodeId
2324
)
@@ -29,6 +30,7 @@ impl DBAffiliateCode {
2930
created_at: record.created_at,
3031
created_by: DBUserId(record.created_by),
3132
affiliate: DBUserId(record.affiliate),
33+
source_name: record.source_name,
3234
}))
3335
}
3436

@@ -37,7 +39,7 @@ impl DBAffiliateCode {
3739
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
3840
) -> Result<Vec<DBAffiliateCode>, DatabaseError> {
3941
let records = sqlx::query!(
40-
"SELECT id, created_at, created_by, affiliate
42+
"SELECT id, created_at, created_by, affiliate, source_name
4143
FROM affiliate_codes WHERE affiliate = $1",
4244
affiliate as DBUserId
4345
)
@@ -49,6 +51,7 @@ impl DBAffiliateCode {
4951
created_at: record.created_at,
5052
created_by: DBUserId(record.created_by),
5153
affiliate: DBUserId(record.affiliate),
54+
source_name: record.source_name,
5255
})
5356
})
5457
.try_collect::<Vec<_>>()
@@ -62,12 +65,13 @@ impl DBAffiliateCode {
6265
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
6366
) -> Result<(), DatabaseError> {
6467
sqlx::query!(
65-
"INSERT INTO affiliate_codes (id, created_at, created_by, affiliate)
66-
VALUES ($1, $2, $3, $4)",
68+
"INSERT INTO affiliate_codes (id, created_at, created_by, affiliate, source_name)
69+
VALUES ($1, $2, $3, $4, $5)",
6770
self.id as DBAffiliateCodeId,
6871
self.created_at,
6972
self.created_by as DBUserId,
70-
self.affiliate as DBUserId
73+
self.affiliate as DBUserId,
74+
self.source_name
7175
)
7276
.execute(exec)
7377
.await?;
@@ -92,11 +96,27 @@ impl DBAffiliateCode {
9296
}
9397
}
9498

99+
pub async fn update_source_name(
100+
id: DBAffiliateCodeId,
101+
source_name: &str,
102+
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
103+
) -> Result<bool, DatabaseError> {
104+
let result = sqlx::query!(
105+
"UPDATE affiliate_codes SET source_name = $1 WHERE id = $2",
106+
source_name,
107+
id as DBAffiliateCodeId
108+
)
109+
.execute(exec)
110+
.await?;
111+
112+
Ok(result.rows_affected() > 0)
113+
}
114+
95115
pub async fn get_all(
96116
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
97117
) -> Result<Vec<DBAffiliateCode>, DatabaseError> {
98118
let records = sqlx::query!(
99-
"SELECT id, created_at, created_by, affiliate
119+
"SELECT id, created_at, created_by, affiliate, source_name
100120
FROM affiliate_codes ORDER BY created_at DESC"
101121
)
102122
.fetch(exec)
@@ -107,6 +127,7 @@ impl DBAffiliateCode {
107127
created_at: record.created_at,
108128
created_by: DBUserId(record.created_by),
109129
affiliate: DBUserId(record.affiliate),
130+
source_name: record.source_name,
110131
})
111132
})
112133
.try_collect::<Vec<_>>()

apps/labrinth/src/models/v3/users.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,15 @@ bitflags::bitflags! {
1717
const ALPHA_TESTER = 1 << 4;
1818
const CONTRIBUTOR = 1 << 5;
1919
const TRANSLATOR = 1 << 6;
20-
21-
const ALL = 0b1111111;
22-
const NONE = 0b0;
20+
const AFFILIATE = 1 << 7;
2321
}
2422
}
2523

2624
bitflags_serde_impl!(Badges, u64);
2725

2826
impl Default for Badges {
2927
fn default() -> Badges {
30-
Badges::NONE
28+
Badges::empty()
3129
}
3230
}
3331

0 commit comments

Comments
 (0)