| | 1 | = Погледи |
| | 2 | == Детали за договори за изнајмување |
| | 3 | |
| | 4 | {{{ |
| | 5 | CREATE OR REPLACE VIEW domify.LeaseDetailsView AS |
| | 6 | SELECT |
| | 7 | L.id AS lease_id, |
| | 8 | L.start_date, |
| | 9 | L.end_date, |
| | 10 | L.rent_amount, |
| | 11 | L.deposit_amount, |
| | 12 | |
| | 13 | Li.id AS listing_id, |
| | 14 | Li.title AS listing_title, |
| | 15 | Li.description AS listing_description, |
| | 16 | Li.status AS listing_status, |
| | 17 | |
| | 18 | U.id AS unit_id, |
| | 19 | U.unit_number, |
| | 20 | U.floor, |
| | 21 | U.area_sq_m, |
| | 22 | |
| | 23 | P.id AS property_id, |
| | 24 | P.title AS property_title, |
| | 25 | PT.name AS property_type, |
| | 26 | |
| | 27 | A.street, |
| | 28 | A.number, |
| | 29 | A.municipality, |
| | 30 | A.city, |
| | 31 | A.country, |
| | 32 | |
| | 33 | T.id AS tenant_id, |
| | 34 | TU.first_name AS tenant_first_name, |
| | 35 | TU.last_name AS tenant_last_name, |
| | 36 | TU.rating AS tenant_rating, |
| | 37 | |
| | 38 | LL.id AS landlord_id, |
| | 39 | LU.first_name AS landlord_first_name, |
| | 40 | LU.last_name AS landlord_last_name, |
| | 41 | LU.rating AS landlord_rating, |
| | 42 | |
| | 43 | (SELECT ARRAY_AGG(image) FROM domify.UnitImage WHERE unit_id = U.id) AS unit_images, |
| | 44 | |
| | 45 | CASE |
| | 46 | WHEN CURRENT_DATE BETWEEN L.start_date AND L.end_date |
| | 47 | THEN (L.end_date - CURRENT_DATE) |
| | 48 | ELSE NULL |
| | 49 | END AS days_remaining |
| | 50 | |
| | 51 | FROM domify.Lease L |
| | 52 | JOIN domify.Listing Li ON L.listing_id = Li.id |
| | 53 | JOIN domify.Unit U ON Li.unit_id = U.id |
| | 54 | JOIN domify.Property P ON U.property_id = P.id |
| | 55 | JOIN domify.PropertyType PT ON P.property_type_id = PT.id |
| | 56 | JOIN domify.Address A ON P.address_id = A.id |
| | 57 | JOIN domify.TenantProfile T ON L.tenant_id = T.id |
| | 58 | JOIN domify.UserD TU ON T.id = TU.id |
| | 59 | JOIN domify.LandlordProfile LL ON L.landlord_id = LL.id |
| | 60 | JOIN domify.UserD LU ON LL.id = LU.id; |
| | 61 | }}} |
| | 62 | |
| | 63 | |
| | 64 | * Прикажува целосни информации за изнајмување: детали за изнајмувањето, станарот, сопственикот, имотот, листингот, адресата и останатите слики. Пресметува и колку денови остануваат до крај на договорот. |
| | 65 | * Корисен е кога сакаме да имаме централизиран приказ на сите потребни податоци за еден договор. |
| | 66 | ---- |
| | 67 | |
| | 68 | == Активни слободни огласи |
| | 69 | |
| | 70 | {{{ |
| | 71 | CREATE OR REPLACE VIEW domify.ActiveListingsView AS |
| | 72 | SELECT |
| | 73 | L.id AS listing_id, |
| | 74 | L.title, |
| | 75 | U.rent_amount, |
| | 76 | A.city, |
| | 77 | A.municipality, |
| | 78 | CONCAT(A.street, ' ', A.number, ', ', A.municipality, ', ', A.city) AS display_address, |
| | 79 | PT.name AS property_type, |
| | 80 | UI.image AS unit_image |
| | 81 | FROM domify.Listing L |
| | 82 | JOIN domify.Unit U ON L.unit_id = U.id |
| | 83 | JOIN domify.Property P ON U.property_id = P.id |
| | 84 | JOIN domify.PropertyType PT ON P.property_type_id = PT.id |
| | 85 | JOIN domify.Address A ON P.address_id = A.id |
| | 86 | LEFT JOIN domify.UnitImage UI ON U.id = UI.unit_id |
| | 87 | WHERE L.status = 'слободно'; |
| | 88 | }}} |
| | 89 | |
| | 90 | |
| | 91 | * Прикажува тековни активни/слободни огласи со клучни информации: наслов, кирија, адреса, тип на имот и слика. |
| | 92 | * Корисен за брзо пребарување и прикажување на слободни огласи за изнајмување. |
| | 93 | |
| | 94 | |
| | 95 | ---- |
| | 96 | |
| | 97 | == Заинтересирани станари за оглас |
| | 98 | |
| | 99 | {{{ |
| | 100 | CREATE OR REPLACE VIEW domify.InterestedTenantsView AS |
| | 101 | SELECT |
| | 102 | I.listing_id, |
| | 103 | L.title AS listing_title, |
| | 104 | TP.id AS tenant_id, |
| | 105 | UT.first_name, |
| | 106 | UT.last_name, |
| | 107 | UT.email, |
| | 108 | UT.rating, |
| | 109 | UT.bio, |
| | 110 | AT.city AS tenant_city, |
| | 111 | AT.municipality AS tenant_municipality |
| | 112 | FROM domify.Interested I |
| | 113 | JOIN domify.Listing L ON I.listing_id = L.id |
| | 114 | JOIN domify.TenantProfile TP ON I.tenant_profile_id = TP.id |
| | 115 | JOIN domify.UserD UT ON TP.id = UT.id |
| | 116 | JOIN domify.Address AT ON UT.address_id = AT.id; |
| | 117 | }}} |
| | 118 | |
| | 119 | * Прикажува кои станари се заинтересирале за одреден оглас, заедно со нивните лични податоци, рејтинг и адреса. |
| | 120 | * Сопствениците можат да ги видат потенцијалните станари и полесно да изберат кому да изнајмат. |
| | 121 | |
| | 122 | ---- |
| | 123 | |
| | 124 | == Детали за огласи за изнајмување |
| | 125 | |
| | 126 | {{{ |
| | 127 | CREATE OR REPLACE VIEW domify.ListingDetailsView AS |
| | 128 | SELECT |
| | 129 | L.id AS listing_id, |
| | 130 | L.title, |
| | 131 | L.description, |
| | 132 | L.available_from, |
| | 133 | L.available_to, |
| | 134 | L.status, |
| | 135 | U.id AS unit_id, |
| | 136 | U.unit_number, |
| | 137 | U.floor, |
| | 138 | U.bedrooms, |
| | 139 | U.bathrooms, |
| | 140 | U.area_sq_m, |
| | 141 | U.rent_amount, |
| | 142 | P.id AS property_id, |
| | 143 | P.title AS property_title, |
| | 144 | P.description AS property_description, |
| | 145 | PT.name AS property_type, |
| | 146 | OU.first_name, |
| | 147 | OU.last_name, |
| | 148 | A.street, |
| | 149 | A.number, |
| | 150 | A.municipality, |
| | 151 | A.city, |
| | 152 | A.country, |
| | 153 | U.rent_amount * 2 AS deposit_amount, |
| | 154 | COALESCE(interest_count.count, 0) AS interested_count, |
| | 155 | ARRAY_AGG(UI.image) FILTER (WHERE UI.image IS NOT NULL) AS unit_images |
| | 156 | FROM domify.Listing L |
| | 157 | JOIN domify.Unit U ON L.unit_id = U.id |
| | 158 | JOIN domify.Property P ON U.property_id = P.id |
| | 159 | JOIN domify.PropertyType PT ON P.property_type_id = PT.id |
| | 160 | JOIN domify.Address A ON P.address_id = A.id |
| | 161 | JOIN domify.UserD OU ON P.owner_id = OU.id |
| | 162 | LEFT JOIN domify.UnitImage UI ON U.id = UI.unit_id |
| | 163 | LEFT JOIN ( |
| | 164 | SELECT listing_id, COUNT(*) as count |
| | 165 | FROM domify.Interested |
| | 166 | GROUP BY listing_id |
| | 167 | ) interest_count ON L.id = interest_count.listing_id |
| | 168 | GROUP BY L.id, L.title, L.description, L.available_from, L.available_to, L.status, |
| | 169 | U.id, U.unit_number, U.floor, U.bedrooms, U.bathrooms, U.area_sq_m, U.rent_amount, |
| | 170 | P.id, P.title, P.description, PT.name, OU.first_name, OU.last_name, |
| | 171 | A.street, A.number, A.municipality, A.city, A.country, |
| | 172 | interest_count.count; |
| | 173 | }}} |
| | 174 | |
| | 175 | |
| | 176 | * Прикажува детални информации за огласите: единицата, имотот, сопственикот, адресата, депозитот, број на заинтересирани станари и сите слики. |
| | 177 | * Дава целосна слика за огласот на едно место, со што станарите и сопствениците добиваат комплетни информации. |