Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PIG-64-Lofts #20

Merged
merged 1 commit into from
Nov 11, 2024
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
@@ -1,8 +1,12 @@
package ma.yc.PigeonSkyRace.piegon.application.dto.request;

import jakarta.validation.constraints.NotNull;
import ma.yc.PigeonSkyRace.common.application.validation.EntityExists;
import ma.yc.PigeonSkyRace.user.domain.model.aggregate.User;

public record LoftRequestDTO(
@NotNull CoordinateRequestDTO coordinate,

@EntityExists(entity = User.class, message = "The specified breeder does not exist")
@NotNull String userId) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ public record PigeonRequestDTO(

@NotBlank String color,

@EntityExists(entity = Loft.class , message = "The specified loft does not exist")
@EntityExists(entity = Loft.class, message = "The specified loft does not exist")
@NotBlank String loftId) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
import ma.yc.PigeonSkyRace.piegon.domain.service.LoftDomainService;
import ma.yc.PigeonSkyRace.piegon.domain.service.LoftNameGenerator;
import ma.yc.PigeonSkyRace.piegon.infrastructure.repository.LoftRepository;
import ma.yc.PigeonSkyRace.user.application.service.UserApplicationService;
import ma.yc.PigeonSkyRace.user.domain.exception.InvalidUserException;
import ma.yc.PigeonSkyRace.user.domain.model.valueobject.UserId;
import org.springframework.stereotype.Service;

import java.util.List;
Expand All @@ -28,7 +25,6 @@ public class DefaultLoftDomainService implements LoftDomainService, LoftApplicat
private final LoftRepository repository;
private final LoftMapper mapper;
private final LoftNameGenerator loftNameGenerator;
private final UserApplicationService userApplicationService;

@Override
public boolean existsById ( LoftId id ) {
Expand All @@ -47,11 +43,6 @@ public List<LoftResponseDTO> findAll () {

@Override
public LoftResponseDTO create ( LoftRequestDTO dto ) {
try {
userApplicationService.getById(UserId.fromString(dto.userId()));
} catch (NotFoundException e) {
throw new InvalidUserException("User with ID " + dto.userId() + " does not exist", e);
}

Loft loft = mapper.toEntity(dto);
String uniqueName = generateUniqueLoftName();
Expand All @@ -65,7 +56,6 @@ public Coordinate geLoftCoordinate ( LoftId loftId ) {
return repository.getCoordinateById(loftId);
}


private String generateUniqueLoftName () {
String uniqueName;
do {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
package ma.yc.PigeonSkyRace.user.application.service;

import ma.yc.PigeonSkyRace.user.application.dto.response.AuthResponseDTO;
import ma.yc.PigeonSkyRace.user.domain.model.valueobject.UserId;

public interface UserApplicationService {
AuthResponseDTO getById ( UserId id );
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
@Service
@RequiredArgsConstructor
@Slf4j
public class DefaultUserDomainService implements UserDomainService, UserApplicationService {
public class DefaultUserDomainService implements UserDomainService {

private final UserRepository repository;
private final UserMapper mapper;
Expand Down Expand Up @@ -79,8 +79,4 @@ private void validateNewUser ( RegisterRequestDTO registerRequest ) {
}
}

@Override
public AuthResponseDTO getById ( UserId id ) {
return mapper.toDto(repository.findById(id).orElseThrow(() -> new NotFoundException("User", id)));
}
}
Loading