-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #218 from swm-nodriversomabus/BUS-222-mypage-1-mvp
Bus 222 mypage 1 mvp
- Loading branch information
Showing
18 changed files
with
394 additions
and
0 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
src/main/java/com/example/api/blocklist/adapter/in/rest/BlockListController.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,71 @@ | ||
package com.example.api.blocklist.adapter.in.rest; | ||
|
||
|
||
import com.example.api.auth.domain.SecurityUser; | ||
import com.example.api.blocklist.application.port.in.AddBlockUseccase; | ||
import com.example.api.blocklist.application.port.in.ReleaseBlockUsecase; | ||
import com.example.api.blocklist.application.port.in.GetListUsecase; | ||
import com.example.api.blocklist.domain.BlockList; | ||
import com.example.api.blocklist.dto.AddBlockDto; | ||
import com.example.api.blocklist.dto.DeleteBlockDto; | ||
import com.example.api.common.exception.CustomException; | ||
import com.example.api.common.type.ErrorCodeEnum; | ||
import com.example.api.common.utils.AuthenticationUtils; | ||
import com.example.api.user.domain.BlockUser; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.domain.Sort; | ||
import org.springframework.data.web.PageableDefault; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
@Tag(name = "BlockList", description = "Blocklist API") | ||
public class BlockListController { | ||
private final AddBlockUseccase addBlockUseccase; | ||
private final ReleaseBlockUsecase releaseBlockUsecase; | ||
private final GetListUsecase getListUsecase; | ||
|
||
@Operation(summary = "add Block User", description = "차단할 유저 추가") | ||
@PostMapping("/block") | ||
public void addBlockUser(@Valid @RequestBody AddBlockDto addBlockDto){ | ||
SecurityUser securityUser = AuthenticationUtils.getCurrentUserAuthentication(); | ||
if (securityUser == null) { | ||
log.error("BlockListController::addBlockUser: Login is needed"); | ||
throw new CustomException(ErrorCodeEnum.LOGIN_IS_NOT_DONE); | ||
} | ||
addBlockUseccase.addBlockUser(addBlockDto, securityUser.getUserId()); | ||
} | ||
|
||
@Operation(summary = "get List block User", description = "차단한 유저 리스트제공") | ||
@GetMapping("/block") | ||
public List<BlockUser> getBlockList(@PageableDefault(sort = "createdAt", direction = Sort.Direction.DESC, size = 30) Pageable pageable){ | ||
SecurityUser securityUser = AuthenticationUtils.getCurrentUserAuthentication(); | ||
if (securityUser == null) { | ||
log.error("BlockListController::getBlockList: Login is needed"); | ||
throw new CustomException(ErrorCodeEnum.LOGIN_IS_NOT_DONE); | ||
} | ||
return getListUsecase.getBlockList(pageable, securityUser.getUserId()); | ||
} | ||
|
||
@Operation(summary = "release block user", description = "차단한 유저 해제") | ||
@DeleteMapping("/block") | ||
public void releaseBlockUser(@Valid @RequestBody DeleteBlockDto deleteBlockDto){ | ||
SecurityUser securityUser = AuthenticationUtils.getCurrentUserAuthentication(); | ||
if (securityUser == null) { | ||
log.error("BlockListController::releaseBlockUser: Login is needed"); | ||
throw new CustomException(ErrorCodeEnum.LOGIN_IS_NOT_DONE); | ||
} | ||
releaseBlockUsecase.releaseBlockUser(deleteBlockDto, securityUser.getUserId()); | ||
|
||
} | ||
|
||
|
||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/com/example/api/blocklist/adapter/out/persistence/BlockListEntity.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,30 @@ | ||
package com.example.api.blocklist.adapter.out.persistence; | ||
|
||
import com.example.api.common.entity.BaseEntity; | ||
import com.example.api.user.adapter.out.persistence.UserEntity; | ||
import jakarta.persistence.*; | ||
import lombok.*; | ||
import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
|
||
import java.util.UUID; | ||
|
||
|
||
@Entity | ||
@EntityListeners(AuditingEntityListener.class) | ||
@Getter | ||
@Setter | ||
@Builder | ||
@ToString | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@IdClass(BlockListPK.class) | ||
@Table(name="blocklist") | ||
public class BlockListEntity extends BaseEntity { | ||
@Id | ||
private UUID userId; | ||
@ManyToOne(fetch = FetchType.LAZY, optional = false) | ||
@JoinColumn(nullable = false, name="blocklist_userid", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) | ||
@ToString.Exclude | ||
@Id | ||
private UserEntity blocklistUserId; | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/example/api/blocklist/adapter/out/persistence/BlockListPK.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,11 @@ | ||
package com.example.api.blocklist.adapter.out.persistence; | ||
|
||
import com.example.api.user.adapter.out.persistence.UserEntity; | ||
|
||
import java.io.Serializable; | ||
import java.util.UUID; | ||
|
||
public class BlockListPK implements Serializable { | ||
private UUID userId; | ||
private UserEntity blocklistUserId; | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/com/example/api/blocklist/adapter/out/persistence/BlockMapperInterface.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,29 @@ | ||
package com.example.api.blocklist.adapter.out.persistence; | ||
|
||
|
||
import com.example.api.blocklist.domain.BlockList; | ||
import com.example.api.blocklist.dto.AddBlockDto; | ||
import com.example.api.user.domain.BlockUser; | ||
import org.mapstruct.InjectionStrategy; | ||
import org.mapstruct.Mapper; | ||
import org.mapstruct.Mapping; | ||
import org.mapstruct.ReportingPolicy; | ||
|
||
import java.util.List; | ||
|
||
@Mapper(componentModel = "spring", | ||
injectionStrategy = InjectionStrategy.CONSTRUCTOR, | ||
unmappedTargetPolicy = ReportingPolicy.IGNORE) | ||
public interface BlockMapperInterface { | ||
@Mapping(source = "blocklistUserId", target = "blocklistUserId.userId") | ||
BlockList toDomain(AddBlockDto addBlockDto); | ||
@Mapping(source = "blocklistUserId.userId", target = "blocklistUserId.userId") | ||
List<BlockList> toDomainList(List<BlockListEntity> blockListEntities); | ||
@Mapping(source = "blocklistUserId.userId", target = "blocklistUserId.userId") | ||
BlockListEntity toEntity(BlockList blockList); | ||
@Mapping(source = "blocklistUserId.userId", target = "userId") | ||
@Mapping(source = "blocklistUserId.username", target = "username") | ||
List<BlockUser> toDomainBlockUserList(List<BlockList> blockLists); | ||
// @Mapping(source = "blocklistUserId.userId", target = "userId") | ||
// List<BlockUser> toDomainList(List<BlockListEntity> blockListEntities); | ||
} |
48 changes: 48 additions & 0 deletions
48
...in/java/com/example/api/blocklist/adapter/out/persistence/BlockUserPersistentAdapter.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,48 @@ | ||
package com.example.api.blocklist.adapter.out.persistence; | ||
|
||
import com.example.api.blocklist.application.port.out.AddBlockUserPort; | ||
import com.example.api.blocklist.application.port.out.GetBlockListPort; | ||
import com.example.api.blocklist.application.port.out.ReleaseBlockPort; | ||
import com.example.api.blocklist.domain.BlockList; | ||
import com.example.api.blocklist.repositorty.BlockListRepository; | ||
import com.example.api.chat.adapter.out.persistence.ChatEntity; | ||
import com.example.api.user.domain.BlockUser; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.cglib.core.Block; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
|
||
|
||
@Repository | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class BlockUserPersistentAdapter implements AddBlockUserPort, GetBlockListPort, ReleaseBlockPort { | ||
private final BlockListRepository blockListRepository; | ||
private final BlockMapperInterface blockMapperInterface; | ||
|
||
@Override | ||
public void addBlockUser(BlockList blockList) { | ||
blockListRepository.save(blockMapperInterface.toEntity(blockList)); | ||
} | ||
|
||
@Override | ||
public List<BlockList> getBlockUserList(UUID userId, Pageable pageable) { | ||
Page<BlockListEntity> ret = blockListRepository.findAllByUserId(userId, pageable); | ||
if (ret != null && ret.hasContent()){ | ||
return blockMapperInterface.toDomainList(ret.getContent()); | ||
} | ||
return new ArrayList<>(); | ||
} | ||
|
||
@Override | ||
public void deleteBlockUser(UUID userId, UUID blockUserId) { | ||
blockListRepository.deleteByUserIdAndBlocklistUserId_UserId(userId, blockUserId); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/example/api/blocklist/application/port/in/AddBlockUseccase.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,9 @@ | ||
package com.example.api.blocklist.application.port.in; | ||
|
||
import com.example.api.blocklist.dto.AddBlockDto; | ||
|
||
import java.util.UUID; | ||
|
||
public interface AddBlockUseccase { | ||
void addBlockUser(AddBlockDto addBlockDto, UUID userId); | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/example/api/blocklist/application/port/in/GetListUsecase.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,12 @@ | ||
package com.example.api.blocklist.application.port.in; | ||
|
||
import com.example.api.blocklist.domain.BlockList; | ||
import com.example.api.user.domain.BlockUser; | ||
import org.springframework.data.domain.Pageable; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
public interface GetListUsecase { | ||
List<BlockUser> getBlockList(Pageable pageable, UUID userId); | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/example/api/blocklist/application/port/in/ReleaseBlockUsecase.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.example.api.blocklist.application.port.in; | ||
|
||
import com.example.api.blocklist.dto.AddBlockDto; | ||
import com.example.api.blocklist.dto.DeleteBlockDto; | ||
|
||
import java.util.UUID; | ||
|
||
public interface ReleaseBlockUsecase { | ||
void releaseBlockUser(DeleteBlockDto addBlockDto, UUID userId); | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/example/api/blocklist/application/port/out/AddBlockUserPort.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,9 @@ | ||
package com.example.api.blocklist.application.port.out; | ||
|
||
import com.example.api.blocklist.domain.BlockList; | ||
|
||
import java.util.UUID; | ||
|
||
public interface AddBlockUserPort { | ||
void addBlockUser(BlockList blockList); | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/example/api/blocklist/application/port/out/GetBlockListPort.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,11 @@ | ||
package com.example.api.blocklist.application.port.out; | ||
|
||
import com.example.api.blocklist.domain.BlockList; | ||
import org.springframework.data.domain.Pageable; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
public interface GetBlockListPort { | ||
List<BlockList> getBlockUserList(UUID userId, Pageable pageable); | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/example/api/blocklist/application/port/out/ReleaseBlockPort.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.example.api.blocklist.application.port.out; | ||
|
||
import com.example.api.blocklist.domain.BlockList; | ||
|
||
import java.util.UUID; | ||
|
||
public interface ReleaseBlockPort { | ||
void deleteBlockUser(UUID userId, UUID blockUserId); | ||
} | ||
|
15 changes: 15 additions & 0 deletions
15
src/main/java/com/example/api/blocklist/domain/BlockList.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,15 @@ | ||
package com.example.api.blocklist.domain; | ||
|
||
import com.example.api.user.domain.BlockUser; | ||
import lombok.*; | ||
|
||
import java.util.UUID; | ||
|
||
@Getter | ||
@Builder | ||
@AllArgsConstructor | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class BlockList { | ||
private UUID userId; | ||
private BlockUser blocklistUserId; | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/com/example/api/blocklist/dto/AddBlockDto.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,17 @@ | ||
package com.example.api.blocklist.dto; | ||
|
||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.NotNull; | ||
import jakarta.validation.constraints.Pattern; | ||
import lombok.Data; | ||
|
||
import java.util.UUID; | ||
|
||
@Data | ||
public class AddBlockDto { | ||
@NotNull | ||
// @Pattern(regexp = "[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}") | ||
private UUID blocklistUserId; | ||
|
||
private UUID userId; | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/example/api/blocklist/dto/DeleteBlockDto.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,13 @@ | ||
package com.example.api.blocklist.dto; | ||
|
||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.NotNull; | ||
import lombok.Data; | ||
|
||
import java.util.UUID; | ||
|
||
@Data | ||
public class DeleteBlockDto { | ||
@NotNull | ||
private UUID blocklistUserId; | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/com/example/api/blocklist/repositorty/BlockListRepository.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,18 @@ | ||
package com.example.api.blocklist.repositorty; | ||
|
||
import com.example.api.blocklist.adapter.out.persistence.BlockListEntity; | ||
import com.example.api.blocklist.adapter.out.persistence.BlockListPK; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.jpa.repository.EntityGraph; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.repository.query.Param; | ||
|
||
import java.util.UUID; | ||
|
||
public interface BlockListRepository extends JpaRepository<BlockListEntity, BlockListPK> { | ||
void deleteByUserIdAndBlocklistUserId_UserId(UUID userId, UUID blockListUserId); | ||
|
||
@EntityGraph(attributePaths = {"blocklistUserId"}) | ||
Page<BlockListEntity> findAllByUserId(@Param("userId") UUID userId, Pageable pageable); | ||
} |
54 changes: 54 additions & 0 deletions
54
src/main/java/com/example/api/blocklist/service/BlockListService.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,54 @@ | ||
package com.example.api.blocklist.service; | ||
|
||
|
||
import com.example.api.blocklist.adapter.out.persistence.BlockMapperInterface; | ||
import com.example.api.blocklist.application.port.in.AddBlockUseccase; | ||
import com.example.api.blocklist.application.port.in.GetListUsecase; | ||
import com.example.api.blocklist.application.port.in.ReleaseBlockUsecase; | ||
import com.example.api.blocklist.application.port.out.AddBlockUserPort; | ||
import com.example.api.blocklist.application.port.out.GetBlockListPort; | ||
import com.example.api.blocklist.application.port.out.ReleaseBlockPort; | ||
import com.example.api.blocklist.domain.BlockList; | ||
import com.example.api.blocklist.dto.AddBlockDto; | ||
import com.example.api.blocklist.dto.DeleteBlockDto; | ||
import com.example.api.user.domain.BlockUser; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
import java.util.stream.Collectors; | ||
|
||
@Service | ||
@Slf4j | ||
@Transactional(readOnly = true) | ||
@RequiredArgsConstructor | ||
public class BlockListService implements AddBlockUseccase, GetListUsecase, ReleaseBlockUsecase { | ||
private final AddBlockUserPort addBlockUserPort; | ||
private final GetBlockListPort getBlockListPort; | ||
private final ReleaseBlockPort releaseBlockPort; | ||
private final BlockMapperInterface blockMapperInterface; | ||
|
||
@Override | ||
@Transactional | ||
public void addBlockUser(AddBlockDto addBlockDto, UUID userId) { | ||
addBlockDto.setUserId(userId); | ||
BlockList blockList = blockMapperInterface.toDomain(addBlockDto); | ||
addBlockUserPort.addBlockUser(blockList); | ||
} | ||
|
||
@Override | ||
public List<BlockUser> getBlockList(Pageable pageable, UUID userId) { | ||
List<BlockList> blockList = getBlockListPort.getBlockUserList(userId, pageable); | ||
return blockList.stream().map(BlockList::getBlocklistUserId).toList(); | ||
} | ||
|
||
@Override | ||
@Transactional | ||
public void releaseBlockUser(DeleteBlockDto addBlockDto, UUID userId) { | ||
releaseBlockPort.deleteBlockUser(userId, addBlockDto.getBlocklistUserId()); | ||
} | ||
} |
Oops, something went wrong.