Skip to main content

Overview

As a Trippins administrator, you have complete control over the housing catalog. This includes reviewing and approving new property submissions, editing existing listings, managing tags and categorization, and removing properties that violate platform policies.
Admin privileges are required to access housing management features. Only users with the ADMIN role can perform these operations.

Housing Entity Structure

The Housing entity is the core data model for all property listings in Trippins. Understanding its structure is essential for effective management.
@Entity
public class Housing {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int code;

    @Column(name = "location", nullable = false)
    private String location;

    @Column(name = "name", nullable = false, unique = true, length = 100)
    private String name;

    @Lob
    @Column(name = "image", columnDefinition = "LONGBLOB")
    private Blob image;

    @Column(name = "price", nullable = false)
    private Integer price;

    @Column(name = "description", nullable = false, length = 200)
    private String description;

    @Column(name = "stars", nullable = false)
    private Integer stars;

    @Column(name = "acepted", nullable = false)
    protected Boolean acepted;

    @ManyToMany
    @JoinTable(
        name = "housing_tags",
        joinColumns = @JoinColumn(name = "housing_id"),
        inverseJoinColumns = @JoinColumn(name = "tag_id")
    )
    private Set<Tag> tags;
}

Key Fields

code
int
Auto-generated unique identifier for the housing listing
acepted
Boolean
Approval status. Only approved listings (acepted = true) are visible to regular users
image
Blob
Property image stored as LONGBLOB, converted to Base64 for API responses
tags
Set<Tag>
Many-to-many relationship with tags (e.g., “Beach”, “City”, “River”) for categorization

Admin Workflows

Viewing All Housing Listings

Administrators can retrieve all housing listings, including both approved and pending properties.
curl -X GET "https://api.trippins.com/v1/api/houses" \
  -H "Authorization: Bearer YOUR_JWT_TOKEN"
Response
array
Returns an array of all housing listings with complete details including approval status

Filtering by Approval Status

The service layer provides methods to filter housing by approval status using pagination.
HousingService.java
public Page<HousingDTO> findByAceptedTrue(Pageable pageable) {
    Page<Housing> houses = housingRepository.findByAceptedTrue(pageable);
    
    return houses.map(housing -> {
        HousingDTO dto = new HousingDTO();
        dto.setCode(housing.getCode());
        dto.setLocation(housing.getLocation());
        dto.setName(housing.getName());
        dto.setPrice(housing.getPrice());
        dto.setDescription(housing.getDescription());
        dto.setStars(housing.getStars());
        dto.setAcepted(housing.getAcepted());
        dto.setImageBase64(housing.getImageBase64());
        dto.setTags(housing.getTags());
        return dto;
    });
}

Approving a Housing Listing

When a new property is submitted, it starts with acepted = false. Administrators must review and approve it before it becomes visible to users.
public void acceptHouse(int code) {
    Housing house = housingRepository.findByCode(code).get();
    house.setAcepted(true);
    housingRepository.save(house);
}
After approval, the listing immediately becomes visible in search results and the main catalog

Creating a New Housing Listing

Administrators can create housing listings directly through the API.
1

Prepare the Housing Data

Collect all required fields including location, name, price, description, star rating, and tags.
2

Submit via API

curl -X POST "https://api.trippins.com/v1/api/houses" \
  -H "Authorization: Bearer ADMIN_JWT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "location": "Maldives",
    "name": "Paradise Resort",
    "price": 350,
    "description": "Luxury beachfront resort with overwater bungalows",
    "stars": 5,
    "acepted": true,
    "tags": [{"id": "Beach"}]
  }'
3

Verify Creation

The API returns the created housing with its auto-generated code:
{
  "code": 21,
  "location": "Maldives",
  "name": "Paradise Resort",
  "price": 350,
  "description": "Luxury beachfront resort with overwater bungalows",
  "stars": 5,
  "acepted": true
}

Updating Housing Details

Administrators can update any aspect of a housing listing using the update endpoint.
@PutMapping("/{id}")
public ResponseEntity<HousingDTO> updateHouse(
    @PathVariable int id,
    @RequestBody HousingDTO house) {
    HousingDTO updatedHouse = housingService.updateHouse(id, house);
    return ResponseEntity.ok(updatedHouse);
}
Updating the name field requires caution as it must remain unique across all listings

Deleting a Housing Listing

Remove properties that violate policies or are no longer available.
curl -X DELETE "https://api.trippins.com/v1/api/houses/21" \
  -H "Authorization: Bearer ADMIN_JWT_TOKEN"
Returns 204 No Content on successful deletion. This operation is permanent and cannot be undone.

Managing Tags and Categories

Viewing Tags for a Housing

Tags help users discover properties through filtered search. Each housing can have multiple tags.
curl -X GET "https://api.trippins.com/v1/api/houses/1/tags" \
  -H "Authorization: Bearer YOUR_JWT_TOKEN"
Response Example:
[
  {"id": "Beach"},
  {"id": "City"}
]

Available Tag Types

The platform supports the following tag categories:

Beach

Properties located near beaches or coastal areas

City

Urban properties in city centers

River

Properties with river views or riverside locations

Security and Permissions

Role-Based Access Control

Housing management endpoints require the ADMIN role. This is enforced at the security configuration level:
SecurityConfiguration.java
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
    http.authorizeHttpRequests(auth -> auth
        .requestMatchers(HttpMethod.POST, "/addHotel").hasAnyRole("USER", "ADMIN")
        .requestMatchers("/v1/api/users/**","/v1/api/reviews/**","/v1/api/admin/**")
            .hasRole("ADMIN")
        .requestMatchers("/admin/**", "/admin").hasRole("ADMIN")
        // ...
    );
    return http.build();
}

JWT Authentication

All admin operations require a valid JWT token with admin privileges:
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
Attempting to access admin endpoints without the ADMIN role returns 403 Forbidden

API Reference

Housing Management Endpoints

GET /v1/api/houses
GET
Retrieve all housing listings (both approved and pending)Security: Requires JWT authenticationResponse: 200 OK with array of HousingDTO objects
GET /v1/api/houses/{id}
GET
Get a specific housing listing by codeParameters:
  • id (path) - Housing code (e.g., 1)
Response: 200 OK with HousingDTO object
POST /v1/api/houses
POST
Create a new housing listingSecurity: Requires ADMIN roleBody: HousingDTO object (code is auto-generated)Response: 201 Created with created HousingDTO
PUT /v1/api/houses/{id}
PUT
Update an existing housing listingSecurity: Requires ADMIN roleParameters:
  • id (path) - Housing code to update
Body: Complete HousingDTO objectResponse: 200 OK with updated HousingDTO
DELETE /v1/api/houses/{id}
DELETE
Delete a housing listingSecurity: Requires ADMIN roleParameters:
  • id (path) - Housing code to delete
Response: 204 No Content
GET /v1/api/houses/{id}/tags
GET
Get all tags associated with a housingParameters:
  • id (path) - Housing code
Response: 200 OK with Set of TagDTO objects

Best Practices

Always review property descriptions, images, and pricing for accuracy before setting acepted = true. Ensure the listing meets platform quality standards.
Apply tags consistently across similar properties. A beach resort should always have the “Beach” tag for accurate filtering.
Images are stored as BLOBs in the database and converted to Base64 for API responses. Ensure images are optimized before upload to prevent database bloat.
The name field must be unique. Check for duplicates before creating or updating housing listings to avoid constraint violations.
Consider setting acepted = false instead of deleting listings to maintain reservation history and data integrity.

Troubleshooting

Cause: Missing or invalid admin role in JWT tokenSolution: Verify that the authenticated user has admin = true in the User entity and the JWT contains ROLE_ADMIN
Cause: Attempting to create/update housing with a name that already existsSolution: Choose a unique name or modify the existing listing instead
Cause: Improper Base64 encoding or BLOB conversionSolution: Ensure images are properly converted using the getImageBase64() method from the Housing entity

Build docs developers (and LLMs) love