Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,25 @@ public void run(String... args) throws Exception {
new Document("_id", "admin-1")
.append("userName", System.getenv("ADMIN1_USERNAME"))
.append("password", passwordEncoder.encode(System.getenv("ADMIN1_PASSWORD")))
.append("email", System.getenv("ADMIN1_EMAIL"))
.append("roles", List.of(roleAdmin)),

new Document("_id", "admin-2")
.append("userName", System.getenv("ADMIN2_USERNAME"))
.append("password", passwordEncoder.encode(System.getenv("ADMIN2_PASSWORD")))
.append("email", System.getenv("ADMIN2_EMAIL"))
.append("roles", List.of(roleAdmin)),

new Document("_id", "admin-3")
.append("userName", System.getenv("ADMIN3_USERNAME"))
.append("password", passwordEncoder.encode(System.getenv("ADMIN3_PASSWORD")))
.append("email", System.getenv("ADMIN3_EMAIL"))
.append("roles", List.of(roleAdmin)),

new Document("_id", "admin-4")
.append("userName", System.getenv("ADMIN4_USERNAME"))
.append("password", passwordEncoder.encode(System.getenv("ADMIN4_PASSWORD")))
.append("email", System.getenv("ADMIN4_EMAIL"))
.append("roles", List.of(roleAdmin))
));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ public class UserDetailsServiceImpl implements UserDetailsService {
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
try {
var user = userRepository.findByUserName(username);
// O parâmetro 'username' agora contém o email
var user = userRepository.findUserByEmail(username);
var opt = user.orElseThrow(() -> new UsernameNotFoundException(USER_NOT_FOUND + username));
return UserDatailsImpl.build(opt);
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@
import java.util.List;

public record AccommodationDTO(
@Schema(example = "6804eaef24e9aa24141421a1")
String id,

@NotBlank
@Schema(example = "Apartamento moderno no centro")
@Schema(example = "Apartamento moderno no centro 2")
String title,

@Schema(example = "Centro Histórico")
Expand All @@ -27,7 +24,7 @@ public record AccommodationDTO(
String city,

@NotBlank
@Schema(example = "Apartamento bem iluminado, com 2 quartos e cozinha equipada.")
@Schema(example = "Apartamento bem iluminado, com 3 quartos e cozinha equipada.")
String description,

@Schema(example = "Rua dos Andradas")
Expand Down Expand Up @@ -56,6 +53,22 @@ public record AccommodationDTO(
@Schema(example = "4")
Integer maxOccupancy,

@Schema(example = "[\"https://img.com/1.jpg\", \"https://img.com/2.jpg\"]")
@NotNull
@Schema(example = "2")
Integer roomCount,

@NotNull
@Schema(example = "1")
Integer bathroomCount,

@NotNull
@Schema(example = "true")
Boolean allowsPets,

@NotNull
@Schema(example = "true")
Boolean isSharedHosting,

@Schema(example = "[]")
List<String> imagesUrls
) {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.unipampa.crud.dto;

import com.unipampa.crud.enums.AccommodationType;
import io.swagger.v3.oas.annotations.media.Schema;
import java.math.BigDecimal;

public record AccommodationFilterDTO(
@Schema(example = "Porto Alegre", description = "Cidade da acomodação")
String city,

@Schema(example = "RS", description = "Estado/UF da acomodação")
String state,

@Schema(example = "Centro Histórico", description = "Bairro da acomodação")
String neighborhood,

@Schema(example = "500.00", description = "Preço mínimo da acomodação")
BigDecimal priceMin,

@Schema(example = "5000.00", description = "Preço máximo da acomodação")
BigDecimal priceMax,

@Schema(example = "APARTMENT", description = "Tipo de acomodação")
AccommodationType accommodationType,

@Schema(example = "4", description = "Ocupância máxima mínima")
Integer maxOccupancyMin,

@Schema(example = "true", description = "Permite animais de estimação")
Boolean allowsPets,

@Schema(example = "true", description = "Permite crianças")
Boolean allowsChildren,

@Schema(example = "true", description = "É um alojamento compartilhado")
Boolean isSharedHosting
) {}

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.unipampa.crud.dto;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.unipampa.crud.enums.AccommodationType;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
Expand All @@ -10,7 +11,7 @@

public record AccommodationRequestDTO(
@NotBlank
@Schema(example = "Apartamento moderno no centro")
@Schema(example = "Apartamento moderno no centro 2")
String title,

@Schema(example = "Centro Histórico")
Expand All @@ -24,7 +25,7 @@ public record AccommodationRequestDTO(
String city,

@NotBlank
@Schema(example = "Apartamento bem iluminado, com 2 quartos e cozinha equipada.")
@Schema(example = "Apartamento bem iluminado, com 3 quartos e cozinha equipada.")
String description,

@Schema(example = "Rua dos Andradas")
Expand All @@ -46,16 +47,31 @@ public record AccommodationRequestDTO(
Integer imageQuantity,

@NotNull
@JsonProperty("accommodationType")
@Schema(example = "APARTMENT")
AccommodationType accommodationType,

@NotNull
@Schema(example = "4")
Integer maxOccupancy,

@Schema(example = "[\"https://img.com/1.jpg\", \"https://img.com/2.jpg\"]")
List<String> imagesUrls,
@NotNull
@Schema(example = "2")
Integer roomCount,

@NotNull
@Schema(example = "1")
Integer bathroomCount,

@NotNull
@Schema(example = "true")
Boolean allowsPets,

@NotNull
@Schema(example = "true")
Boolean isSharedHosting,

@Schema(example = "[]")
List<String> imagesUrls

@NotBlank
String hostId
) {}
4 changes: 3 additions & 1 deletion cadastral/src/main/java/com/unipampa/crud/dto/LoginDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

public record LoginDTO(

@NotBlank
String username,

@NotBlank
String email,

@NotBlank
String password

Expand Down
21 changes: 11 additions & 10 deletions cadastral/src/main/java/com/unipampa/crud/dto/UserDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
import jakarta.validation.constraints.NotBlank;

public record UserDTO(
@NotBlank String email,
@NotBlank String name,
@NotBlank String userName,
@NotBlank String cpf,
@NotBlank String phone,
@NotBlank String address,
@NotBlank String password,
@NotBlank String role,
@NotBlank UserType type
) {}
@NotBlank String email,
@NotBlank String name,
@NotBlank String userName,
@NotBlank String cpf,
@NotBlank String password,
@NotBlank String role,
@NotBlank UserType type,
String phone,
String address
) {
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.unipampa.crud.enums;

import com.fasterxml.jackson.annotation.JsonCreator;
import io.swagger.v3.oas.annotations.media.Schema;

public enum AccommodationType {
Expand All @@ -9,4 +10,12 @@ public enum AccommodationType {

@Schema(description = "Casa")
HOUSE;

@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
public static AccommodationType forValue(String value) {
if (value == null || value.trim().isEmpty()) {
return null;
}
return AccommodationType.valueOf(value.toUpperCase().trim());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,31 @@ public Accommodation toEntity(AccommodationDTO dto) {
}

public Accommodation toEntity(AccommodationRequestDTO requestDTO) {
return objectMapper.convertValue(requestDTO, Accommodation.class);
return Accommodation.builder()
.title(requestDTO.title())
.neighborhood(requestDTO.neighborhood())
.zipCode(requestDTO.codAddress())
.city(requestDTO.city())
.description(requestDTO.description())
.address(requestDTO.address())
.state(requestDTO.state())
.price(requestDTO.price())
.streetNumber(requestDTO.streetNumber())
.type(requestDTO.accommodationType()) // Mapeia accommodationType -> type
.maxOccupancy(requestDTO.maxOccupancy())
.roomCount(requestDTO.roomCount())
.bathroomCount(requestDTO.bathroomCount())
.allowsPets(requestDTO.allowsPets())
.isSharedHosting(requestDTO.isSharedHosting())
.imagesUrls(requestDTO.imagesUrls())
.build();
}

public AccommodationDTO toDTO(Accommodation entity) {
String urlBase = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort();
List<String> imageUrls = entity.getImagesUrls().stream()
.map(path -> {
Path p = Paths.get(path);
String id = p.getParent().getFileName().toString(); // exemplo: "6804eaef24e9aa24141421a1"
String filename = p.getFileName().toString();
return urlBase + "/accommodations/images/" + id + "/" + filename;
})
.collect(Collectors.toList());

List<String> imageUrls = entity.getImagesUrls();

return new AccommodationDTO(
entity.getId(),
entity.getTitle(),
entity.getNeighborhood(),
entity.getZipCode(),
Expand All @@ -57,12 +66,15 @@ public AccommodationDTO toDTO(Accommodation entity) {
entity.getState(),
entity.getPrice(),
entity.getStreetNumber(),
entity.getImagesUrls() != null ? entity.getImagesUrls().size() : 0,
imageUrls != null ? imageUrls.size() : 0,
entity.getType(),
entity.getMaxOccupancy(),
entity.getRoomCount(),
entity.getBathroomCount(),
entity.isAllowsPets(),
entity.isSharedHosting(),
imageUrls
);


}

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.unipampa.crud.repository;

import com.unipampa.crud.dto.AccommodationFilterDTO;
import com.unipampa.crud.entities.Accommodation;
import org.springframework.data.mongodb.repository.MongoRepository;

public interface AccommodationRepository extends MongoRepository<Accommodation, String> {
import java.util.List;

public interface AccommodationRepository extends MongoRepository<Accommodation, String>, AccommodationRepositoryCustom {

boolean existsByZipCodeAndStreetNumber(String codeAddress, int streetNumber);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.unipampa.crud.repository;

import com.unipampa.crud.dto.AccommodationFilterDTO;
import com.unipampa.crud.entities.Accommodation;

import java.util.List;


public interface AccommodationRepositoryCustom {

/**
* Busca acomodações com base em filtros opcionais usando Criteria do MongoDB
* Todos os filtros são opcionais - apenas campos não nulos serão utilizados
*
* @param filters DTO contendo os filtros opcionais
* @return Lista de acomodações que correspondem aos filtros
*/
List<Accommodation> findByFilters(AccommodationFilterDTO filters);

}

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

public interface UserRepository extends MongoRepository<User, String> {

@EntityGraph(attributePaths = {"roles"}, type = EntityGraph.EntityGraphType.FETCH)
Optional<User> findUserByEmail(String email);

boolean existsByUserName(String username);
Expand Down
Loading