From b8423f4d05c75094b7b9d09c6f0bb353acc9be1c Mon Sep 17 00:00:00 2001 From: ckonstanski Date: Sat, 25 May 2024 18:03:25 -0600 Subject: initial commit --- sql/functions/contact.mark_contact_us_post.sql | 38 ++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 sql/functions/contact.mark_contact_us_post.sql (limited to 'sql/functions/contact.mark_contact_us_post.sql') diff --git a/sql/functions/contact.mark_contact_us_post.sql b/sql/functions/contact.mark_contact_us_post.sql new file mode 100644 index 0000000..7bcc001 --- /dev/null +++ b/sql/functions/contact.mark_contact_us_post.sql @@ -0,0 +1,38 @@ +drop function contact.mark_contact_us_post ( + p_contact_us_post_id int, + p_user_id int, + p_read_p bool +); + +create or replace function contact.mark_contact_us_post ( + p_contact_us_post_id int, + p_user_id int, + p_read_p bool +) +returns void +as $$ +declare + l_id bigint; +begin + if(p_read_p) then + select id into l_id + from contact.contact_us_posts_read + where contact_us_post_id = p_contact_us_post_id + and user_id = p_user_id; + + if(l_id is null) then + insert into contact.contact_us_posts_read ( + contact_us_post_id, + user_id + ) values ( + p_contact_us_post_id, + p_user_id + ); + end if; + else + delete from contact.contact_us_posts_read + where contact_us_post_id = p_contact_us_post_id + and user_id = p_user_id; + end if; +end; +$$ language plpgsql; -- cgit v1.3