Skip to content

Commit afd084f

Browse files
authored
Merge pull request #98 from Eason0729/master
fix(backend)!: fix API, see #94
2 parents f4ee034 + 162f761 commit afd084f

File tree

8 files changed

+25
-41
lines changed

8 files changed

+25
-41
lines changed

backend/src/endpoint/announcement.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ impl<'a> From<WithAuth<'a, Model>> for AnnouncementFullInfo {
1717
id: model.id,
1818
title: model.title,
1919
update_date: into_prost(model.update_at),
20+
create_date: into_prost(model.create_at),
2021
},
2122
author_id: model.user_id,
2223
content: model.content,
@@ -34,6 +35,7 @@ impl From<Model> for AnnouncementInfo {
3435
id: value.id,
3536
title: value.title,
3637
update_date: into_prost(value.update_at),
38+
create_date: into_prost(value.create_at),
3739
}
3840
}
3941
}
@@ -44,6 +46,7 @@ impl From<PartialModel> for AnnouncementInfo {
4446
id: value.id,
4547
title: value.title,
4648
update_date: into_prost(value.update_at),
49+
create_date: into_prost(value.create_at),
4750
}
4851
}
4952
}

backend/src/endpoint/contest.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,6 @@ impl<'a> From<WithAuth<'a, Model>> for ContestFullInfo {
2424

2525
impl WithAuthTrait for Model {}
2626

27-
impl From<user_contest::Model> for UserRank {
28-
fn from(value: user_contest::Model) -> Self {
29-
UserRank {
30-
user_id: value.user_id,
31-
score: value.score,
32-
}
33-
}
34-
}
35-
3627
impl From<Model> for ContestInfo {
3728
fn from(value: Model) -> Self {
3829
ContestInfo {
@@ -41,6 +32,7 @@ impl From<Model> for ContestInfo {
4132
begin: value.begin.map(into_prost),
4233
end: value.end.map(into_prost),
4334
need_password: value.password.is_some(),
35+
public: value.public,
4436
}
4537
}
4638
}
@@ -53,6 +45,7 @@ impl From<PartialModel> for ContestInfo {
5345
begin: value.begin.map(into_prost),
5446
end: value.end.map(into_prost),
5547
need_password: value.password.is_some(),
48+
public: value.public,
5649
}
5750
}
5851
}

backend/src/endpoint/problem.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ impl<'a> From<WithAuth<'a, Model>> for ProblemFullInfo {
2121
submit_count: model.submit_count,
2222
ac_rate: model.ac_rate,
2323
difficulty: model.difficulty,
24+
create_at: into_prost(model.create_at),
25+
update_at: into_prost(model.update_at),
26+
public: model.public,
2427
},
2528
author: model.user_id,
2629
writable,
@@ -38,6 +41,9 @@ impl From<PartialModel> for ProblemInfo {
3841
submit_count: value.submit_count,
3942
ac_rate: value.ac_rate,
4043
difficulty: value.difficulty,
44+
create_at: into_prost(value.create_at),
45+
update_at: into_prost(value.update_at),
46+
public: value.public,
4147
}
4248
}
4349
}

backend/src/endpoint/user.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,19 @@ impl<'a> From<WithAuth<'a, Model>> for UserFullInfo {
1919
}
2020
}
2121

22-
impl WithAuthTrait for Model {}
23-
2422
impl From<Model> for UserInfo {
2523
fn from(value: Model) -> Self {
26-
UserInfo {
24+
Self {
2725
username: value.username,
28-
// FIXME: capture Error(database corruption?) instead!
29-
score: value.score.try_into().unwrap_or_default(),
26+
score: value.score as u64,
3027
id: value.id,
28+
create_at: into_prost(value.create_at),
3129
}
3230
}
3331
}
3432

33+
impl WithAuthTrait for Model {}
34+
3535
#[async_trait]
3636
impl User for ArcServer {
3737
#[instrument(

backend/src/entity/announcement.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,6 @@ impl SortSource<PartialModel> for ColPagerTrait {
211211
match data.0 {
212212
Sort::UpdateDate => Column::UpdateAt,
213213
Sort::CreateDate => Column::CreateAt,
214-
Sort::Public => Column::Public,
215214
}
216215
}
217216
fn get_val(data: &Self::Data) -> impl Into<Value> + Clone + Send {
@@ -221,7 +220,6 @@ impl SortSource<PartialModel> for ColPagerTrait {
221220
data.1 = match data.0 {
222221
Sort::UpdateDate => model.update_at.to_string(),
223222
Sort::CreateDate => model.create_at.to_string(),
224-
Sort::Public => model.public.to_string(),
225223
}
226224
}
227225
}

backend/src/entity/contest.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -252,23 +252,17 @@ impl Source for ColPagerTrait {
252252
impl SortSource<PartialModel> for ColPagerTrait {
253253
fn sort_col(data: &Self::Data) -> impl ColumnTrait {
254254
match data.0 {
255-
Sort::UpdateDate => Column::UpdateAt,
256-
Sort::CreateDate => Column::CreateAt,
257255
Sort::Begin => Column::Begin,
258256
Sort::End => Column::End,
259-
Sort::Public => Column::Public,
260257
}
261258
}
262259
fn get_val(data: &Self::Data) -> impl Into<sea_orm::Value> + Clone + Send {
263260
&data.1
264261
}
265262
fn save_val(data: &mut Self::Data, model: &PartialModel) {
266263
data.1 = match data.0 {
267-
Sort::UpdateDate => model.update_at.to_string(),
268-
Sort::CreateDate => model.create_at.to_string(),
269264
Sort::Begin => model.begin.unwrap().to_string(),
270265
Sort::End => model.end.unwrap().to_string(),
271-
Sort::Public => model.public.to_string(),
272266
}
273267
}
274268
}
@@ -294,7 +288,7 @@ impl Paginator {
294288
))
295289
}
296290
pub fn new(start_from_end: bool) -> Self {
297-
Self::new_sort(Sort::CreateDate, start_from_end)
291+
Self::new_sort(Sort::Begin, start_from_end)
298292
}
299293
}
300294

backend/src/entity/problem.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,6 @@ impl SortSource<PartialModel> for ColPagerTrait {
403403
Sort::SubmitCount => Column::SubmitCount,
404404
Sort::Difficulty => Column::Difficulty,
405405
Sort::Order => Column::Order,
406-
Sort::Public => Column::Public,
407406
}
408407
}
409408
fn get_val(data: &Self::Data) -> impl Into<sea_orm::Value> + Clone + Send {
@@ -417,7 +416,6 @@ impl SortSource<PartialModel> for ColPagerTrait {
417416
Sort::SubmitCount => model.submit_count.to_string(),
418417
Sort::Difficulty => model.difficulty.to_string(),
419418
Sort::Order => model.order.to_string(),
420-
Sort::Public => model.public.to_string(),
421419
}
422420
}
423421
}

grpc/proto/backend.proto

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ message ProblemInfo {
147147
// 3000 - inf geek
148148
required uint32 difficulty = 5;
149149
required float ac_rate = 4;
150+
required google.protobuf.Timestamp update_at = 6;
151+
required google.protobuf.Timestamp create_at = 7;
152+
required bool public = 8;
150153
}
151154

152155
message ProblemFullInfo {
@@ -177,7 +180,7 @@ message ListProblemRequest {
177180
SORT_SUBMIT_COUNT = 3;
178181
SORT_DIFFICULTY = 4;
179182
SORT_ORDER = 5;
180-
SORT_PUBLIC = 6;
183+
// 6 is used
181184
}
182185
message Query {
183186
optional int32 contest_id = 1;
@@ -299,6 +302,7 @@ message AnnouncementInfo {
299302
required int32 id = 1;
300303
required string title = 2;
301304
required google.protobuf.Timestamp update_date = 3;
305+
required google.protobuf.Timestamp create_date = 4;
302306
}
303307

304308
message AnnouncementFullInfo {
@@ -358,7 +362,6 @@ message ListAnnouncementRequest {
358362
enum Sort {
359363
SORT_UPDATE_DATE = 0;
360364
SORT_CREATE_DATE = 1;
361-
SORT_PUBLIC = 2;
362365
}
363366
message Query {
364367
optional Sort sort_by = 1;
@@ -591,6 +594,7 @@ message ContestInfo {
591594
optional google.protobuf.Timestamp begin = 4;
592595
optional google.protobuf.Timestamp end = 5;
593596
required bool need_password = 6;
597+
required bool public = 7;
594598
}
595599

596600
message ContestFullInfo {
@@ -645,17 +649,6 @@ message UpdateContestRequest {
645649
optional string request_id = 3;
646650
}
647651

648-
message UserRank {
649-
required int32 user_id = 1;
650-
required uint32 score = 2;
651-
}
652-
653-
message ListRankResponse {
654-
repeated UserRank list = 1;
655-
required string paginator = 2;
656-
required uint64 remain = 3;
657-
}
658-
659652
message JoinContestRequest {
660653
required int32 id = 1;
661654
optional string password = 2;
@@ -667,11 +660,9 @@ message JoinContestRequest {
667660

668661
message ListContestRequest {
669662
enum Sort {
670-
SORT_CREATE_DATE = 0;
671-
SORT_UPDATE_DATE = 1;
672663
SORT_BEGIN = 2;
673664
SORT_END = 3;
674-
SORT_PUBLIC = 4;
665+
// leave 4, it's used
675666
}
676667
message Query {
677668
optional Sort sort_by = 1;
@@ -720,6 +711,7 @@ message UserInfo {
720711
required string username = 1;
721712
required uint64 score = 4;
722713
required int32 id = 3;
714+
required google.protobuf.Timestamp create_at = 5;
723715
}
724716

725717
message UserFullInfo {

0 commit comments

Comments
 (0)