Skip to content

Commit

Permalink
fix: 장소 안내 조회 업데이트 오류 해결 (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
gahyuun committed Jan 20, 2025
1 parent ae081dc commit c08b881
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

import com.acon.server.global.exception.BusinessException;
import com.acon.server.global.exception.ErrorType;
import com.acon.server.member.application.mapper.RecentGuidedSpotMapper;
import com.acon.server.member.domain.entity.RecentGuidedSpot;
import com.acon.server.member.infra.entity.RecentGuidedSpotEntity;
import com.acon.server.member.infra.repository.RecentGuidedSpotRepository;
import com.acon.server.spot.infra.repository.SpotRepository;
import java.time.LocalDateTime;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

Expand All @@ -13,17 +17,29 @@
public class MemberService {

private final RecentGuidedSpotRepository recentGuidedSpotRepository;
private final RecentGuidedSpotMapper recentGuidedSpotMapper;
private final SpotRepository spotRepository;

public void createGuidedSpot(final Long spotId, final Long memberId) {
if (!spotRepository.existsById(spotId)) {
throw new BusinessException(ErrorType.NOT_FOUND_SPOT_ERROR);
}
Optional<RecentGuidedSpotEntity> optionalRecentGuidedSpotEntity = recentGuidedSpotRepository.findByMemberIdAndSpotId(
memberId, spotId);

if (optionalRecentGuidedSpotEntity.isPresent()) {
RecentGuidedSpotEntity recentGuidedSpotEntity = optionalRecentGuidedSpotEntity.get();
RecentGuidedSpot recentGuidedSpot = recentGuidedSpotMapper.toDomain(recentGuidedSpotEntity);
recentGuidedSpot.setUpdatedAt(LocalDateTime.now());
RecentGuidedSpotEntity updatedRecentGuidedSpotEntity = recentGuidedSpotMapper.toEntity(recentGuidedSpot);
recentGuidedSpotRepository.save(updatedRecentGuidedSpotEntity);
} else {
RecentGuidedSpotEntity entity = RecentGuidedSpotEntity.builder()
.memberId(memberId)
.spotId(spotId)
.build();
recentGuidedSpotRepository.save(entity);
}

RecentGuidedSpotEntity recentGuidedSpotEntity = RecentGuidedSpotEntity.builder()
.memberId(memberId)
.spotId(spotId)
.build();
recentGuidedSpotRepository.save(recentGuidedSpotEntity);
}
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,34 @@
package com.acon.server.member.domain.entity;

import java.time.LocalDateTime;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

@Getter
@ToString
@Setter
public class RecentGuidedSpot {

private final Long id;
private final Long memberId;
private final Long spotId;
private LocalDateTime createdAt;
private LocalDateTime updatedAt;

@Builder
public RecentGuidedSpot(
Long id,
Long memberId,
Long spotId
Long spotId,
LocalDateTime createdAt,
LocalDateTime updatedAt
) {
this.id = id;
this.memberId = memberId;
this.spotId = spotId;
this.createdAt = createdAt;
this.updatedAt = updatedAt;
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.acon.server.member.infra.repository;

import com.acon.server.member.infra.entity.RecentGuidedSpotEntity;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;

public interface RecentGuidedSpotRepository extends JpaRepository<RecentGuidedSpotEntity, Long> {

Optional<RecentGuidedSpotEntity> findByMemberIdAndSpotId(Long memberId, Long spotId);

}

0 comments on commit c08b881

Please sign in to comment.