No-57 / orange-frontstage-api

0 stars 2 forks source link

Frontstage - API /distributors Fake Data #24

Open Vince-Ku opened 7 months ago

Vince-Ku commented 7 months ago
create function get_distributor_data(p_code character varying, p_row_num integer)
    returns TABLE(distributor_id bigint, name character varying, description character varying, brand_image character varying, product_id bigint, path character varying)
    language plpgsql
as
$$
BEGIN
  RETURN QUERY
  WITH RankedData AS (
    SELECT
      d.id AS distributor_id, d.name, d.description, d.brand_image,
      pp.product_id AS product_id, pi.path,
      ROW_NUMBER() OVER (PARTITION BY pp.distributor_id ORDER BY pp.product_id) AS row_num
    FROM
      orange.public.product_priorities pp
      INNER JOIN orange.public.distributors d ON pp.distributor_id = d.id AND pp.code = p_code
      LEFT JOIN orange.public.product_imgs pi ON pp.product_id = pi.product_id
  )
  SELECT
    distributor_id,
    name, description, brand_image,
    product_id, path
  FROM RankedData
  WHERE row_num <= p_row_num;
END;
$$;

alter function get_distributor_data(varchar, integer) owner to dev;
Vince-Ku commented 7 months ago

@Vince-Ku Insert fake data into those tables.

  1. product_priorities
  2. distributors
  3. product_imgs

cc @KaoWeiCheng

Vince-Ku commented 6 months ago

@KaoWeiCheng

Following the Chinese New Year, we've encountered a connectivity issue with our Oracle database, Let's plan to address and resolve this problem during tonight's meeting.

cc @shadow3x3x3

KaoWeiCheng commented 6 months ago

Database is PostgreSQL !?