Skip to content

Commit

Permalink
fix: 같은 동네 인증 시 verified date에 추가 (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
gahyuun committed Jan 23, 2025
1 parent 8a348a4 commit 7e4776b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
import com.acon.server.member.application.mapper.GuidedSpotMapper;
import com.acon.server.member.application.mapper.MemberMapper;
import com.acon.server.member.application.mapper.PreferenceMapper;
import com.acon.server.member.application.mapper.VerifiedAreaMapper;
import com.acon.server.member.domain.entity.GuidedSpot;
import com.acon.server.member.domain.entity.Member;
import com.acon.server.member.domain.entity.Preference;
import com.acon.server.member.domain.entity.VerifiedArea;
import com.acon.server.member.domain.enums.Cuisine;
import com.acon.server.member.domain.enums.DislikeFood;
import com.acon.server.member.domain.enums.FavoriteSpot;
Expand Down Expand Up @@ -52,6 +54,7 @@ public class MemberService {
private final GuidedSpotMapper guidedSpotMapper;
private final MemberMapper memberMapper;
private final PreferenceMapper preferenceMapper;
private final VerifiedAreaMapper verifiedAreaMapper;

private final JwtTokenProvider jwtTokenProvider;
private final PrincipalHandler principalHandler;
Expand Down Expand Up @@ -124,13 +127,24 @@ public String createMemberArea(
) {
MemberEntity memberEntity = memberRepository.findByIdOrElseThrow(principalHandler.getUserIdFromPrincipal());
String legalDong = naverMapsAdapter.getReverseGeoCodingResult(latitude, longitude);

verifiedAreaRepository.save(
VerifiedAreaEntity.builder()
.name(legalDong)
.memberId(memberEntity.getId())
.verifiedDate(Collections.singletonList(LocalDate.now()))
.build()
Optional<VerifiedAreaEntity> optionalVerifiedAreaEntity = verifiedAreaRepository.findByMemberIdAndName(
memberEntity.getId(), legalDong);

optionalVerifiedAreaEntity.ifPresentOrElse(
verifiedAreaEntity -> {
VerifiedArea verifiedArea = verifiedAreaMapper.toDomain(verifiedAreaEntity);
List<LocalDate> dates = verifiedArea.getVerifiedDate();
dates.add(LocalDate.now());
verifiedArea.setVerifiedDate(dates);
verifiedAreaRepository.save(verifiedAreaMapper.toEntity(verifiedArea));
},
() -> verifiedAreaRepository.save(
VerifiedAreaEntity.builder()
.name(legalDong)
.memberId(memberEntity.getId())
.verifiedDate(Collections.singletonList(LocalDate.now()))
.build()
)
);

return legalDong;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
import java.util.List;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

@Getter
@Setter
@ToString
public class VerifiedArea {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.acon.server.member.infra.repository;

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

public interface VerifiedAreaRepository extends JpaRepository<VerifiedAreaEntity, Long> {

boolean existsByMemberIdAndName(Long memberId, String name);

Optional<VerifiedAreaEntity> findByMemberIdAndName(Long memberId, String name);
}

0 comments on commit 7e4776b

Please sign in to comment.