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 @@ -23,12 +23,12 @@ public void saveCarPhoto(@RequestBody CarPhotoRequestDto carPhotoRequestDto) {
carPhotoService.saveCarPhoto(carPhotoRequestDto);
}

@GetMapping("/selectList")
@GetMapping
public List<CarPhotoResponseDto> getCarPhotoList(@RequestParam Long memberId) {
return carPhotoService.getCarPhotoList(memberId);
}

@DeleteMapping("/remove/{photoId}")
@DeleteMapping("/{photoId}")
public void deleteCarPhoto(@PathVariable Long photoId) {
carPhotoService.deleteCarPhoto(photoId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import org.example.qpin.global.common.repository.CarPhotoRepository;
import org.example.qpin.domain.member.entity.Member;
import org.example.qpin.global.common.repository.MemberRepository;
import org.example.qpin.global.exception.BadRequestException;
import org.example.qpin.global.exception.ExceptionCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

Expand All @@ -18,16 +20,26 @@ public class CarPhotoServiceImpl implements CarPhotoService {
private final CarPhotoRepository carPhotoRepository;
private final MemberRepository memberRepository;

public Member findMemberById(Long memberId) {
return memberRepository.findById(memberId).orElseThrow(() -> new BadRequestException(ExceptionCode.NOT_FOUND_MEMBER_ID));
}

public CarPhoto findCarPhotoById(Long photoId) {
return carPhotoRepository.findById(photoId).orElseThrow(() -> new BadRequestException(ExceptionCode.NOT_FOUND_PHOTO));
}

// μ˜μ‘΄μ„± μ£Όμž…
@Autowired
public CarPhotoServiceImpl(CarPhotoRepository carPhotoRepository, MemberRepository memberRepository) {
this.carPhotoRepository = carPhotoRepository;
this.memberRepository = memberRepository;
}

// 사진 μ €μž₯
@Override
public void saveCarPhoto(CarPhotoRequestDto carPhotoRequestDto) {
Member member = memberRepository.findById(carPhotoRequestDto.getUserId())
.orElseThrow(() -> new RuntimeException("Member Not Found for id"));
Member member = findMemberById(carPhotoRequestDto.getUserId());

CarPhoto carPhoto = CarPhoto.builder()
.carPhotoUrl(carPhotoRequestDto.getCarPhotoUrl())
.parkingArea(carPhotoRequestDto.getParkingArea())
Expand All @@ -37,8 +49,10 @@ public void saveCarPhoto(CarPhotoRequestDto carPhotoRequestDto) {
carPhotoRepository.save(carPhoto);
}

// λͺ¨λ“  사진 쑰회
@Override
public List<CarPhotoResponseDto> getCarPhotoList(Long memberId) {
findMemberById(memberId);
List<CarPhoto> carPhotos = carPhotoRepository.findByMember_MemberId(memberId);

return carPhotos.stream()
Expand All @@ -50,8 +64,11 @@ public List<CarPhotoResponseDto> getCarPhotoList(Long memberId) {
.collect(Collectors.toList());
}

// 사진 μ‚­μ œ
@Override
public void deleteCarPhoto(Long photoId) {
findCarPhotoById(photoId);

carPhotoRepository.deleteById(photoId);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public enum ExceptionCode {
INVALID_IMAGE_PATH(5101, "이미지λ₯Ό μ €μž₯ν•  κ²½λ‘œκ°€ μ˜¬λ°”λ₯΄μ§€ μ•ŠμŠ΅λ‹ˆλ‹€."),
FAIL_IMAGE_NAME_HASH(5102, "이미지 이름을 ν•΄μ‹±ν•˜λŠ” 데 μ‹€νŒ¨ν–ˆμŠ΅λ‹ˆλ‹€."),
INVALID_IMAGE(5103, "μ˜¬λ°”λ₯΄μ§€ μ•Šμ€ 이미지 νŒŒμΌμž…λ‹ˆλ‹€."),
NOT_FOUND_PHOTO(5104, "사진을 찾을 수 μ—†μŠ΅λ‹ˆλ‹€."),

// μ£Όμ°¨ μ—λŸ¬
NOT_FOUND_PARKING(6001, "μš”μ²­ν•œ μ£Όμ°¨ID와 멀버ID에 ν•΄λ‹Ήν•˜λŠ” 정보가 μ‘΄μž¬ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€."),
Expand Down
Loading