-
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
17 changed files
with
245 additions
and
26 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
Api/src/main/java/allchive/server/api/block/controller/BlockController.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,26 @@ | ||
package allchive.server.api.block.controller; | ||
|
||
|
||
import allchive.server.api.block.model.dto.request.BlockRequest; | ||
import allchive.server.api.block.model.dto.response.BlockResponse; | ||
import allchive.server.api.block.service.CreateBlockUseCase; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@RequestMapping("/blocks") | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
@Tag(name = "8. [block]") | ||
public class BlockController { | ||
private final CreateBlockUseCase createBlockUseCase; | ||
|
||
@Operation(summary = "유저를 차단합니다") | ||
@PostMapping() | ||
public BlockResponse createBlock(@RequestBody BlockRequest blockRequest) { | ||
return createBlockUseCase.execute(blockRequest); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Api/src/main/java/allchive/server/api/block/model/dto/request/BlockRequest.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 allchive.server.api.block.model.dto.request; | ||
|
||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class BlockRequest { | ||
@Schema(defaultValue = "1", description = "차단할 유저의 id") | ||
private Long userId; | ||
} |
21 changes: 21 additions & 0 deletions
21
Api/src/main/java/allchive/server/api/block/model/dto/response/BlockResponse.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,21 @@ | ||
package allchive.server.api.block.model.dto.response; | ||
|
||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class BlockResponse { | ||
@Schema(defaultValue = "이름", description = "차단한 유저의 닉네임") | ||
private String nickname; | ||
|
||
@Builder | ||
private BlockResponse(String nickname) { | ||
this.nickname = nickname; | ||
} | ||
|
||
public static BlockResponse from(String nickname) { | ||
return BlockResponse.builder().nickname(nickname).build(); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
Api/src/main/java/allchive/server/api/block/model/mapper/BlockMapper.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 allchive.server.api.block.model.mapper; | ||
|
||
|
||
import allchive.server.core.annotation.Mapper; | ||
import allchive.server.domain.domains.block.domain.Block; | ||
|
||
@Mapper | ||
public class BlockMapper { | ||
public Block toEntity(Long blockFrom, Long blockUser) { | ||
return Block.of(blockFrom, blockUser); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
Api/src/main/java/allchive/server/api/block/service/CreateBlockUseCase.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,33 @@ | ||
package allchive.server.api.block.service; | ||
|
||
|
||
import allchive.server.api.block.model.dto.request.BlockRequest; | ||
import allchive.server.api.block.model.dto.response.BlockResponse; | ||
import allchive.server.api.block.model.mapper.BlockMapper; | ||
import allchive.server.api.config.security.SecurityUtil; | ||
import allchive.server.core.annotation.UseCase; | ||
import allchive.server.domain.domains.block.domain.Block; | ||
import allchive.server.domain.domains.block.service.BlockDomainService; | ||
import allchive.server.domain.domains.block.validator.BlockValidator; | ||
import allchive.server.domain.domains.user.adaptor.UserAdaptor; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@UseCase | ||
@RequiredArgsConstructor | ||
public class CreateBlockUseCase { | ||
private final BlockValidator blockValidator; | ||
private final BlockMapper blockMapper; | ||
private final BlockDomainService blockDomainService; | ||
private final UserAdaptor userAdaptor; | ||
|
||
@Transactional | ||
public BlockResponse execute(BlockRequest request) { | ||
Long userId = SecurityUtil.getCurrentUserId(); | ||
blockValidator.validateNotDuplicate(userId, request.getUserId()); | ||
blockValidator.validateNotMyself(userId, request.getUserId()); | ||
Block block = blockMapper.toEntity(userId, request.getUserId()); | ||
blockDomainService.save(block); | ||
return BlockResponse.from(userAdaptor.queryUserById(request.getUserId()).getNickname()); | ||
} | ||
} |
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
8 changes: 5 additions & 3 deletions
8
Domain/src/main/java/allchive/server/domain/domains/block/exception/BlockErrorCode.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 |
---|---|---|
@@ -1,22 +1,24 @@ | ||
package allchive.server.domain.domains.block.exception; | ||
|
||
import static allchive.server.core.consts.AllchiveConst.BAD_REQUEST; | ||
|
||
import allchive.server.core.dto.ErrorReason; | ||
import allchive.server.core.error.BaseErrorCode; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import org.springframework.http.HttpStatus; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public enum BlockErrorCode implements BaseErrorCode { | ||
DUPLICATED_BLOCK(BAD_REQUEST, "BLOCK_400_1", "이미 차단한 유저입니다."), | ||
CANNOT_BLOCK_MYSELF(BAD_REQUEST, "BLOCK_400_2", "본인을 차단할 수 없습니다."), | ||
; | ||
private HttpStatus status; | ||
private int status; | ||
private String code; | ||
private String reason; | ||
|
||
@Override | ||
public ErrorReason getErrorReason() { | ||
return ErrorReason.of(status.value(), code, reason); | ||
return ErrorReason.of(status, code, reason); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...allchive/server/domain/domains/block/exception/exceptions/CannotBlockMyselfException.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 allchive.server.domain.domains.block.exception.exceptions; | ||
|
||
|
||
import allchive.server.core.error.BaseErrorException; | ||
import allchive.server.domain.domains.block.exception.BlockErrorCode; | ||
|
||
public class CannotBlockMyselfException extends BaseErrorException { | ||
|
||
public static final BaseErrorException EXCEPTION = new CannotBlockMyselfException(); | ||
|
||
private CannotBlockMyselfException() { | ||
super(BlockErrorCode.CANNOT_BLOCK_MYSELF); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...a/allchive/server/domain/domains/block/exception/exceptions/DuplicatedBlockException.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 allchive.server.domain.domains.block.exception.exceptions; | ||
|
||
|
||
import allchive.server.core.error.BaseErrorException; | ||
import allchive.server.domain.domains.block.exception.BlockErrorCode; | ||
|
||
public class DuplicatedBlockException extends BaseErrorException { | ||
|
||
public static final BaseErrorException EXCEPTION = new DuplicatedBlockException(); | ||
|
||
private DuplicatedBlockException() { | ||
super(BlockErrorCode.DUPLICATED_BLOCK); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
.../src/main/java/allchive/server/domain/domains/block/repository/BlockCustomRepository.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,5 @@ | ||
package allchive.server.domain.domains.block.repository; | ||
|
||
public interface BlockCustomRepository { | ||
boolean queryBlockExistByBlockFromAndBlockUser(Long blockFrom, Long blockUser); | ||
} |
31 changes: 31 additions & 0 deletions
31
.../main/java/allchive/server/domain/domains/block/repository/BlockCustomRepositoryImpl.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,31 @@ | ||
package allchive.server.domain.domains.block.repository; | ||
|
||
import static allchive.server.domain.domains.block.domain.QBlock.block; | ||
|
||
import com.querydsl.core.types.dsl.BooleanExpression; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
public class BlockCustomRepositoryImpl implements BlockCustomRepository { | ||
private final JPAQueryFactory queryFactory; | ||
|
||
@Override | ||
public boolean queryBlockExistByBlockFromAndBlockUser(Long blockFrom, Long blockUser) { | ||
Integer fetchOne = | ||
queryFactory | ||
.selectOne() | ||
.from(block) | ||
.where(blockFromEq(blockFrom), blockUserEq(blockUser)) | ||
.fetchFirst(); // limit 1 | ||
return fetchOne != null; | ||
} | ||
|
||
private BooleanExpression blockFromEq(Long blockFrom) { | ||
return block.blockFrom.eq(blockFrom); | ||
} | ||
|
||
private BooleanExpression blockUserEq(Long blockUser) { | ||
return block.blockUser.eq(blockUser); | ||
} | ||
} |
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
17 changes: 17 additions & 0 deletions
17
Domain/src/main/java/allchive/server/domain/domains/block/service/BlockDomainService.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 allchive.server.domain.domains.block.service; | ||
|
||
|
||
import allchive.server.core.annotation.DomainService; | ||
import allchive.server.domain.domains.block.adaptor.BlockAdaptor; | ||
import allchive.server.domain.domains.block.domain.Block; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@DomainService | ||
@RequiredArgsConstructor | ||
public class BlockDomainService { | ||
private final BlockAdaptor blockAdaptor; | ||
|
||
public void save(Block block) { | ||
blockAdaptor.save(block); | ||
} | ||
} |
7 changes: 0 additions & 7 deletions
7
Domain/src/main/java/allchive/server/domain/domains/block/service/BlockService.java
This file was deleted.
Oops, something went wrong.
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