From 57dc1fed925e5c2da3dae93e436b424a1b852508 Mon Sep 17 00:00:00 2001 From: PARK BYUNG JUN Date: Thu, 11 Aug 2022 06:43:56 +0000 Subject: [PATCH] last_signined_ip is modified --- migrations/202206171200_initialize/down.sql | 1 - migrations/202206171200_initialize/up.sql | 13 ------------- migrations/202206201240_member/down.sql | 1 - migrations/202206201240_member/up.sql | 7 ------- src/repositories/member/models.rs | 2 ++ src/services/member/service.rs | 3 +++ 6 files changed, 5 insertions(+), 22 deletions(-) diff --git a/migrations/202206171200_initialize/down.sql b/migrations/202206171200_initialize/down.sql index 8071988..4aba7c6 100644 --- a/migrations/202206171200_initialize/down.sql +++ b/migrations/202206171200_initialize/down.sql @@ -2,4 +2,3 @@ DROP EXTENSION "uuid-ossp"; DROP FUNCTION update_updated_at_column; DROP FUNCTION update_state_changed_at_column; DROP FUNCTION update_active_changed_at_column; -DROP FUNCTION update_last_signined_at_column; diff --git a/migrations/202206171200_initialize/up.sql b/migrations/202206171200_initialize/up.sql index 6850b4f..015f368 100644 --- a/migrations/202206171200_initialize/up.sql +++ b/migrations/202206171200_initialize/up.sql @@ -33,16 +33,3 @@ BEGIN RETURN NEW; END; $$ language 'plpgsql'; - -CREATE OR REPLACE FUNCTION update_last_signined_at_column() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.last_signined_ip != NEW.last_signined_ip THEN - NEW.last_signined_at = (extract(epoch from now()) * 1000); - ELSE - NEW.last_signined_at = NEW.last_signined_at; - END IF; - RETURN NEW; -END; -$$ language 'plpgsql'; - diff --git a/migrations/202206201240_member/down.sql b/migrations/202206201240_member/down.sql index 2e1b056..e2694fb 100644 --- a/migrations/202206201240_member/down.sql +++ b/migrations/202206201240_member/down.sql @@ -1,5 +1,4 @@ DROP INDEX idx_members_username; -DROP TRIGGER tg_members_last_signined_at; DROP TRIGGER tg_members_state_changed_at; DROP TRIGGER tg_members_updated_at; DROP TABLE members; diff --git a/migrations/202206201240_member/up.sql b/migrations/202206201240_member/up.sql index b9ec044..c1dddf0 100644 --- a/migrations/202206201240_member/up.sql +++ b/migrations/202206201240_member/up.sql @@ -51,10 +51,3 @@ CREATE TRIGGER tg_members_state_changed_at ON members FOR EACH ROW EXECUTE PROCEDURE update_state_changed_at_column(); - --- trigger (state_changed_at) -CREATE TRIGGER tg_members_last_signined_at - BEFORE UPDATE - ON members - FOR EACH ROW - EXECUTE PROCEDURE update_last_signined_at_column(); diff --git a/src/repositories/member/models.rs b/src/repositories/member/models.rs index 027ad2d..98187d6 100644 --- a/src/repositories/member/models.rs +++ b/src/repositories/member/models.rs @@ -85,6 +85,8 @@ pub struct ModifyMember { pub struct ModifyMember4LastSignined { /// pub last_signined_ip: String, + // + pub last_signined_at: i64, } /// diff --git a/src/services/member/service.rs b/src/services/member/service.rs index 17f0606..78b64f2 100644 --- a/src/services/member/service.rs +++ b/src/services/member/service.rs @@ -496,6 +496,8 @@ impl Service { }) })?; + let last_signined_at = chrono::Utc::now().timestamp(); + self .member_repository .update_last_signined_ip( @@ -503,6 +505,7 @@ impl Service { id, &repositories::member::models::ModifyMember4LastSignined { last_signined_ip: client.client_ip, + last_signined_at, }, ) .map_err(|e| {