-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
161 additions
and
12 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
src/main/java/com/srltas/runtogether/adapter/out/persistence/mybatis/MybatisUserMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.srltas.runtogether.adapter.out.persistence.mybatis; | ||
|
||
import org.apache.ibatis.annotations.Mapper; | ||
|
||
import com.srltas.runtogether.adapter.out.persistence.mybatis.dao.VerifiedUserNeighborhoodDAO; | ||
|
||
@Mapper | ||
public interface MybatisUserMapper { | ||
void updateVerifiedUserNeighborhood(VerifiedUserNeighborhoodDAO dao); | ||
} |
36 changes: 36 additions & 0 deletions
36
...in/java/com/srltas/runtogether/adapter/out/persistence/mybatis/MybatisUserRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.srltas.runtogether.adapter.out.persistence.mybatis; | ||
|
||
import static com.srltas.runtogether.adapter.out.persistence.mybatis.converter.UserConverter.*; | ||
|
||
import java.util.Optional; | ||
|
||
import org.springframework.stereotype.Repository; | ||
|
||
import com.srltas.runtogether.domain.model.user.User; | ||
import com.srltas.runtogether.domain.model.user.UserNeighborhood; | ||
import com.srltas.runtogether.domain.model.user.UserRepository; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@Repository | ||
@RequiredArgsConstructor | ||
public class MybatisUserRepository implements UserRepository { | ||
|
||
private final MybatisUserMapper mybatisUserMapper; | ||
|
||
@Override | ||
public Optional<User> findById(long id) { | ||
// TODO 사용자 조회 구현 | ||
return Optional.empty(); | ||
} | ||
|
||
@Override | ||
public void save(User user) { | ||
// TODO 사용자 저장 구현 | ||
} | ||
|
||
@Override | ||
public void updateVerifiedUserNeighborhood(long userId, UserNeighborhood userNeighborhood) { | ||
mybatisUserMapper.updateVerifiedUserNeighborhood(toVerifiedUserNeighborhoodDAO(userId, userNeighborhood)); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
.../java/com/srltas/runtogether/adapter/out/persistence/mybatis/converter/UserConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.srltas.runtogether.adapter.out.persistence.mybatis.converter; | ||
|
||
import com.srltas.runtogether.adapter.out.persistence.mybatis.dao.VerifiedUserNeighborhoodDAO; | ||
import com.srltas.runtogether.domain.model.user.UserNeighborhood; | ||
|
||
import lombok.experimental.UtilityClass; | ||
|
||
@UtilityClass | ||
public class UserConverter { | ||
|
||
public VerifiedUserNeighborhoodDAO toVerifiedUserNeighborhoodDAO(long userId, UserNeighborhood userNeighborhood) { | ||
return VerifiedUserNeighborhoodDAO.builder() | ||
.userId(userId) | ||
.neighborhoodId(userNeighborhood.getNeighborhood().getId()) | ||
.verified(userNeighborhood.isVerified()) | ||
.verifiedAt(userNeighborhood.getVerifiedAt()) | ||
.build(); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...m/srltas/runtogether/adapter/out/persistence/mybatis/dao/VerifiedUserNeighborhoodDAO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.srltas.runtogether.adapter.out.persistence.mybatis.dao; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
import lombok.Builder; | ||
|
||
@Builder | ||
public record VerifiedUserNeighborhoodDAO( | ||
long userId, | ||
int neighborhoodId, | ||
boolean verified, | ||
LocalDateTime verifiedAt | ||
) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/main/java/com/srltas/runtogether/application/port/out/VerifyUserNeighborhoodCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.srltas.runtogether.application.port.out; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
import lombok.Builder; | ||
|
||
@Builder | ||
public record VerifyUserNeighborhoodCommand( | ||
long userId, | ||
int neighborhoodId, | ||
boolean verified, | ||
LocalDateTime verifiedAt | ||
) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | ||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | ||
|
||
<mapper namespace="com.srltas.runtogether.adapter.out.persistence.mybatis.MybatisUserMapper"> | ||
|
||
<update id="updateVerifiedUserNeighborhood" parameterType="VerifiedUserNeighborhoodDAO"> | ||
UPDATE user_neighborhoods | ||
SET verified = #{verified}, verified_at = #{verifiedAt} | ||
WHERE user_id = #{userId} AND neighborhood_id = #{neighborhoodId} | ||
</update> | ||
</mapper> |
38 changes: 38 additions & 0 deletions
38
...ava/com/srltas/runtogether/adapter/out/persistence/mybatis/MybatisUserRepositoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.srltas.runtogether.adapter.out.persistence.mybatis; | ||
|
||
import static org.mockito.BDDMockito.*; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import com.srltas.runtogether.adapter.out.persistence.mybatis.dao.VerifiedUserNeighborhoodDAO; | ||
import com.srltas.runtogether.domain.model.neighborhood.Location; | ||
import com.srltas.runtogether.domain.model.neighborhood.Neighborhood; | ||
import com.srltas.runtogether.domain.model.user.UserNeighborhood; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class MybatisUserRepositoryTest { | ||
|
||
@Mock | ||
private MybatisUserMapper mybatisUserMapper; | ||
|
||
@InjectMocks | ||
private MybatisUserRepository mybatisUserRepository; | ||
|
||
@Test | ||
@DisplayName("동네 인증 정보 업데이트 SQL 실행 위임을 검증") | ||
void shouldCallMapperToUserRepository() { | ||
long userId = 1L; | ||
Neighborhood neighborhood = new Neighborhood(1, "Test Neighborhood", | ||
new Location(37.505858, 127.058319), 5.0); | ||
UserNeighborhood userNeighborhood = new UserNeighborhood(neighborhood); | ||
|
||
mybatisUserRepository.updateVerifiedUserNeighborhood(userId, userNeighborhood); | ||
|
||
verify(mybatisUserMapper).updateVerifiedUserNeighborhood(any(VerifiedUserNeighborhoodDAO.class)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters