Skip to content

Commit

Permalink
๐Ÿ‘”๏ธ ์ฑ„ํŒ…๋ฐฉ ์ƒ์„ฑ ์„œ๋น„์Šค ๋กœ์ง ์ถ”๊ฐ€(#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
jun108059 committed Jul 4, 2022
1 parent f3c7d33 commit 94c0890
Showing 1 changed file with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package hexagonal.api.room.application.service;

import hexagonal.api.room.application.port.in.CreateRoomCommand;
import hexagonal.api.room.application.port.in.CreateRoomUseCase;
import hexagonal.api.room.application.port.out.FindRoomPort;
import hexagonal.api.room.application.port.out.SaveRoomPort;
import hexagonal.core.domain.jpa.RoomJpaEntity;
import lombok.RequiredArgsConstructor;

import javax.persistence.EntityNotFoundException;

@RequiredArgsConstructor
public class CreateRoomService implements CreateRoomUseCase {

private final FindRoomPort findRoomPort;
private final SaveRoomPort saveRoomPort;

@Override
public Long createRoom(CreateRoomCommand command) {
// ์ค‘๋ณต ์ฑ„ํŒ…๋ฐฉ ๊ฒ€์‚ฌ
if (!checkRoomExists(command.getCompanyId())) {
RoomJpaEntity roomJpaEntity = command.toJpaEntity();
return saveRoomPort.saveRoom(roomJpaEntity);
}
return null;
}

private boolean checkRoomExists(Long companyId) {
try {
findRoomPort.findRoomByCompanyId(companyId);
} catch (EntityNotFoundException e) {
return false;
}

return true;
}
}

0 comments on commit 94c0890

Please sign in to comment.