Changes between Initial Version and Version 1 of UseCase02


Ignore:
Timestamp:
01/23/26 21:37:15 (2 weeks ago)
Author:
231035
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • UseCase02

    v1 v1  
     1= UseCase02- Manages Clients
     2** Initiating actor: Admin **
     3== Description
     4The Admin moderates Petify by blocking a client account when the client posts disrespectful/abusive reviews, or when the client receives extremely bad reviews that indicate harmful or unacceptable behavior. The Admin reviews evidence (review comments, ratings) and then blocks the client. The system records the decision (who/when/why), marks the user as blocked, and creates a notification for the blocked user.
     5== Scenario
     61. Admin goes to the reviews page that are grouped by client.
     7{{{
     8SELECT
     9  u.user_id,
     10  u.username,
     11  u.email,
     12  u.is_blocked,
     13  u.blocked_reason,
     14  u.blocked_at,
     15  u.blocked_by,
     16
     17  COUNT(ur.review_id) AS received_review_count,
     18  COALESCE(AVG(r.rating), 0)::numeric(10,2) AS avg_received_rating,
     19
     20  (SELECT COUNT(*)
     21   FROM reviews rw
     22   WHERE rw.reviewer_id = u.user_id) AS written_review_count
     23
     24FROM users u
     25JOIN clients c ON c.user_id = u.user_id
     26LEFT JOIN user_reviews ur ON ur.target_user_id = u.user_id
     27LEFT JOIN reviews r ON r.review_id = ur.review_id
     28GROUP BY
     29  u.user_id, u.username, u.email,
     30  u.is_blocked, u.blocked_reason, u.blocked_at, u.blocked_by
     31ORDER BY
     32  (COUNT(ur.review_id) = 0) ASC,
     33  avg_received_rating ASC,
     34  received_review_count DESC,
     35  u.username;
     36
     37}}}
     382. Admin clicks on a client so he can see all the reviews for them.
     39{{{
     40SELECT
     41  r.review_id,
     42  r.reviewer_id,
     43  ru.username AS reviewer_username,
     44  r.rating,
     45  r.comment,
     46  r.created_at
     47FROM user_reviews ur
     48JOIN reviews r ON r.review_id = ur.review_id
     49JOIN users ru ON ru.user_id = r.reviewer_id
     50WHERE ur.target_user_id = $1       
     51ORDER BY r.created_at DESC;
     52}}}
     533. Admin clicks "Block client" and enters the reason.
     54{{{
     55BEGIN;
     56
     57SELECT u.user_id, u.email, u.is_blocked
     58FROM users u
     59JOIN clients c ON c.user_id = u.user_id
     60WHERE u.user_id = $1
     61FOR UPDATE;
     62
     63UPDATE users
     64SET
     65  is_blocked = TRUE,
     66  blocked_reason = $2,       
     67  blocked_by     = $4,     
     68  blocked_at     = NOW()
     69WHERE user_id = $1;
     70
     71INSERT INTO notifications (user_id, type, message, is_read, created_at)
     72VALUES (
     73  $1,
     74  'ACCOUNT_BLOCKED',
     75  CONCAT('Your account has been blocked. Reason: ', $2, '. ', COALESCE($3, '')),
     76  FALSE,
     77  NOW()
     78);
     79
     80COMMIT;
     81}}}
     824. The system sends and email to the client.
     83{{{
     84SELECT
     85  email,
     86  username,
     87  blocked_reason,
     88  blocked_at
     89FROM users
     90WHERE user_id = $1;
     91}}}
     92
     93
     94