Skip to content

Commit

Permalink
[fix] Room 입장 분기처리 추가
Browse files Browse the repository at this point in the history
[fix] Room 입장 분기처리 추가
  • Loading branch information
kmjenny committed Jun 6, 2024
2 parents 7bc12ad + a907b54 commit e2d1a71
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CD.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ jobs:
key: ${{ secrets.SERVER_KEY }}
script: |
cd ~
./deploy.sh
./deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public enum BusinessErrorCode implements DefaultErrorCode{
FCM_SERVER_ERROR(HttpStatus.SERVICE_UNAVAILABLE, "external", "FCM 서버 오류"),
NAVER_CLOUD_SERVER_ERROR(HttpStatus.SERVICE_UNAVAILABLE, "external", "네이버 클라우드 서버 오류"),
OPEN_AI_SERVER_ERROR(HttpStatus.SERVICE_UNAVAILABLE, "external", "OpenAI 서버 오류"),
REENTER_ERROR(HttpStatus.OK, "conflict", "이미 입장하신 방입니다."),
ROOM_FULL_ERROR(HttpStatus.OK, "conflict", "이미 매칭이 완료된 방입니다."),
;
@JsonIgnore
private final HttpStatus httpStatus;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ public interface ProfileRepository extends JpaRepository<Profile, Long> {
Optional<Profile> findByUserAndRoom(User user, Room room);
Optional<Profile> findByUserNotAndRoom(User user, Room room);
boolean existsByUserNotAndRoom(User user, Room room);

boolean existsByUserAndRoom(User user, Room room);
List<Profile> findAllByUserId(Long userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ public Profile findByUserNotAndRoom(final User user, final Room room) {
public boolean existsByUserNotAndRoom(final User user, final Room room) {
return profileRepository.existsByUserNotAndRoom(user, room);
}

public boolean existsByUserAndRoom(final User user, final Room room) {
return profileRepository.existsByUserAndRoom(user, room);
}

public List<Profile> findByUserId(final long userId) {
return profileRepository.findAllByUserId(userId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public ProfileInfoDto getProfileExtraInfo(final Long roomId, final Long userId)
Room room = roomRetriever.findById(roomId);
User user = userRetriever.findById(userId);
Profile profile = profileRetriever.findByUserAndRoom(user, room);

String gender = profile.getGender()!=null?profile.getGender().getContent():"-";
String ageRange = profile.getAgeRange()!=null?profile.getAgeRange().getContent():"-";
String relation = profile.getRelation()!=null?profile.getRelation().getContent():"-";
Expand All @@ -64,7 +65,7 @@ public Profile updateProfileInfo(
String keywords = "";
if(profileDto.keywords()!=null) {
keywords = String.join(",", profileDto.keywords());
};
}

profileUpdater.updateProfileInfo(
profile,
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/telepigeon/server/service/room/RoomService.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import com.telepigeon.server.dto.room.response.RoomInfoDto;
import com.telepigeon.server.dto.room.response.RoomListDto;
import com.telepigeon.server.dto.type.FcmContent;
import com.telepigeon.server.exception.BusinessException;
import com.telepigeon.server.exception.code.BusinessErrorCode;
import com.telepigeon.server.repository.RoomRepository;
import com.telepigeon.server.service.answer.AnswerRemover;
import com.telepigeon.server.service.answer.AnswerRetriever;
Expand Down Expand Up @@ -119,6 +121,14 @@ public Profile enterRoom(final RoomEnterDto roomEnterDto, final Long userId) {
User user = userRetriever.findById(userId);
Room room = roomRetriever.findByCode(roomEnterDto.code());

if (profileRetriever.existsByUserAndRoom(user, room)) {
throw new BusinessException(BusinessErrorCode.REENTER_ERROR);
}

if ((profileRetriever.findAll()).size()==2) {
throw new BusinessException(BusinessErrorCode.ROOM_FULL_ERROR);
}

Profile profile = profileSaver.save(Profile.create(user, room));
Profile receiver = profileRetriever.findByUserNotAndRoom(user, room);
sendQuestionFirst(receiver, profile);
Expand Down

0 comments on commit e2d1a71

Please sign in to comment.