> For the complete documentation index, see [llms.txt](https://geekyants-5.gitbook.io/flatandflatmates/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://geekyants-5.gitbook.io/flatandflatmates/api-server/routes/apartments.md).

# Apartments

**File Name** : apartments.js\
**File Path** : /server/routes/apartments.js\
This route is used to handle user's apartment related queries. For example: creating an apartment, updating apartment details, fetching apartments, fetching filtered apartments, delete apartment etc.

## Get Apartments

<mark style="color:blue;">`GET`</mark> `/api/apartments`

#### Headers

| Name          | Type   | Description          |
| ------------- | ------ | -------------------- |
| Authorization | string | Authentication token |

{% tabs %}
{% tab title="200 " %}

```javascript

{
    success: true,
    message: 'user apartments',
    data: apartmentObjArray : [
            {
            userId
            address
            gpsLoc
            availableFrom
            houseSize
            spaceFor
            monthlyRent
            oneTimeDeposit
            occupancyType
            amenities
            pictures
            description
            }
            . . . 
            . . .
            ]

}

or 

{
        success: true,
        message: 'no apartments available',
        data: []
}

```

{% endtab %}

{% tab title="404 " %}

```javascript
{
        success: false,
        message: 'error while finding apartments for the user',
}
```

{% endtab %}
{% endtabs %}

## Create Apartment (Flat)

<mark style="color:green;">`POST`</mark> `/api/apartments`

#### Headers

| Name          | Type   | Description          |
| ------------- | ------ | -------------------- |
| Authorization | string | Authentication Token |

#### Request Body

| Name           | Type   | Description                     |
| -------------- | ------ | ------------------------------- |
| userId         | string | User Id                         |
| address        | string | address of the locality of flat |
| gpsLoc         | array  | location array \[lat, lng]      |
| availableFrom  | string | date from flat is available     |
| houseSize      | string | size of the flat                |
| spaceFor       | number | space for how many members      |
| monthlyRent    | number | monthly rent                    |
| oneTimeDeposit | number | one time deposit                |
| occupancyType  | string | occupancy type                  |
| amenities      | array  | amenities array                 |
| pictures       | array  | pictures array                  |
| description    | string | Description                     |

{% tabs %}
{% tab title="200 " %}

```javascript
{
         success: true,
          message: 'apartment created successfully',
          data: {
            userId
            address
            gpsLoc
            availableFrom
            houseSize
            spaceFor
            monthlyRent
            oneTimeDeposit
            occupancyType
            amenities
            pictures
            description
            }
}
```

{% endtab %}
{% endtabs %}

## Update Apartment

<mark style="color:orange;">`PUT`</mark> `/api/apartments/?id=${_id}`

#### Headers

| Name          | Type   | Description                                                            |
| ------------- | ------ | ---------------------------------------------------------------------- |
| updateObj     | object | updateObj contains type of the details to be modified and details obj. |
| Authorization | string | Authentication Token                                                   |

{% tabs %}
{% tab title="200 " %}

```javascript
 {
            userId
            address
            gpsLoc
            availableFrom
            houseSize
            spaceFor
            monthlyRent
            oneTimeDeposit
            occupancyType
            amenities
            pictures
            description
}
```

{% endtab %}

{% tab title="304 " %}

```
Error occured while updating the apartment details
```

{% endtab %}

{% tab title="404 " %}

```
Error occured while searching for the Apartment
```

{% endtab %}
{% endtabs %}

## Get filtered Apartments

<mark style="color:blue;">`GET`</mark> `/api/apartments/filterdApartments`

#### Headers

| Name          | Type   | Description                 |
| ------------- | ------ | --------------------------- |
| filterObject  | object | Contains the filter details |
| Authorization | string | Authentication Token        |

{% tabs %}
{% tab title="200 " %}

```javascript
{
  success: true,
  message: 'filtered apartments',
  data: filteredApartments

}

or 

{
   success: true,
   message: 'no apartments with this filter options available',
   data: []

}
```

{% endtab %}
{% endtabs %}

## Delete Apartment

<mark style="color:blue;">`GET`</mark> `/api/apartments/deleteApartment/?id=${id}`

#### Headers

| Name          | Type   | Description          |
| ------------- | ------ | -------------------- |
| Authorization | string | Authentication Token |

{% tabs %}
{% tab title="200 " %}

```javascript
{
    success: true,
    message: Apartment deleted
}
or
{
     success: false,
     message: 'unable to delete  apartment ,id provided didnt match ',
}
```

{% endtab %}
{% endtabs %}
