Skip to content

Commit

Permalink
Merge pull request #89 from prgrms-web-devcourse-final-project/Feat/#24
Browse files Browse the repository at this point in the history
feat : 펫 등록시 User의 is_registered 컬럼을 0에서 1로 업데이트
  • Loading branch information
Cheol-Jin authored Dec 9, 2024
2 parents 1c0d977 + 4484d70 commit b26ae22
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/main/java/com/petmatz/domain/pet/PetServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,21 @@
import com.petmatz.domain.pet.dto.PetServiceDto;
import com.petmatz.domain.pet.dto.PetServiceDtoFactory;
import com.petmatz.domain.pet.dto.PetUpdateResponse;
import com.petmatz.domain.pet.exception.ImageErrorCode;
import com.petmatz.domain.pet.exception.ImageServiceException;
import com.petmatz.domain.pet.exception.PetErrorCode;
import com.petmatz.domain.pet.exception.PetServiceException;
import com.petmatz.domain.user.entity.User;
import com.petmatz.domain.user.repository.UserRepository;
import lombok.RequiredArgsConstructor;
import lombok.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.stream.Collectors;

import static com.petmatz.domain.pet.exception.PetErrorCode.PET_NOT_FOUND;
Expand All @@ -42,6 +34,7 @@ public class PetServiceImpl implements PetService{
private final AwsClient awsClient;

private final PetRepository repository;
private final UserRepository userRepository;
private final ObjectMapper objectMapper = new ObjectMapper();
private final String uploadDir = System.getProperty("user.dir") + "/uploads/";

Expand Down Expand Up @@ -104,6 +97,11 @@ public PetSaveResponse savePet(User user, PetServiceDto dto) throws MalformedURL
.build();

Long id = repository.save(pet).getId();

// User의 isRegistered 상태 업데이트
user.markAsRegistered();
userRepository.save(user);

return PetSaveResponse.of(id, resultImgURL);
}

Expand Down
7 changes: 7 additions & 0 deletions src/main/java/com/petmatz/domain/user/entity/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,11 @@ public void checkLatitudeLongitude() { // (희수 : 예외나 위도 경도 범
}
}
}

public void markAsRegistered() {
if (Boolean.TRUE.equals(this.isRegistered)) {
return; // 이미 등록된 경우 아무 작업도 하지 않음
}
this.isRegistered = true; // 등록 상태로 변경
}
}

0 comments on commit b26ae22

Please sign in to comment.