-
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.
Merge pull request #77 from YogitTeam/feat/report
Feat/report (보드, 클립보드, 코멘트 신고 구현)
- Loading branch information
Showing
39 changed files
with
838 additions
and
42 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
server/src/main/java/com/yogit/server/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,42 @@ | ||
package com.yogit.server.block.controller; | ||
|
||
import com.yogit.server.block.dto.req.CreateBlockReq; | ||
import com.yogit.server.block.dto.res.BlockRes; | ||
import com.yogit.server.block.service.BlockService; | ||
import com.yogit.server.global.dto.ApplicationResponse; | ||
import io.swagger.annotations.ApiOperation; | ||
import io.swagger.annotations.ApiResponse; | ||
import io.swagger.annotations.ApiResponses; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.validation.annotation.Validated; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import javax.validation.Valid; | ||
|
||
@Slf4j | ||
@RestController | ||
@RequiredArgsConstructor // private final DI의존주입 | ||
@RequestMapping("/blocks") | ||
public class BlockController { | ||
|
||
private final BlockService blockService; | ||
|
||
/** | ||
* 유저 차단 생성 | ||
* @author 토마스 | ||
*/ | ||
@ApiOperation(value = "유저 차단 생성", notes = "유저 차단 생성 요청.") | ||
@ApiResponses({ | ||
@ApiResponse(code= 201, message = "요청에 성공하였습니다."), | ||
@ApiResponse(code= 404, message = "존재하지 않는 유저입니다."), | ||
@ApiResponse(code = 4000 , message = "서버 오류입니다.") | ||
}) | ||
@PostMapping | ||
public ApplicationResponse<BlockRes> createBlock(@RequestBody @Validated CreateBlockReq dto){ | ||
return blockService.createBlock(dto); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
server/src/main/java/com/yogit/server/block/dto/req/CreateBlockReq.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.yogit.server.block.dto.req; | ||
|
||
import io.swagger.annotations.ApiModelProperty; | ||
import io.swagger.annotations.ApiParam; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
public class CreateBlockReq { | ||
|
||
@ApiModelProperty(example = "1") | ||
@ApiParam(value = "차단 생성하는 유저 ID", required = true) | ||
private Long blockingUserId; | ||
|
||
@ApiModelProperty(example = "2") | ||
@ApiParam(value = "차단 받는 유저 ID", required = true) | ||
private Long blockedUserId; | ||
} |
43 changes: 43 additions & 0 deletions
43
server/src/main/java/com/yogit/server/block/dto/res/BlockRes.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,43 @@ | ||
package com.yogit.server.block.dto.res; | ||
|
||
import com.yogit.server.block.entity.Block; | ||
import io.swagger.annotations.ApiModelProperty; | ||
import io.swagger.annotations.ApiParam; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
public class BlockRes { | ||
|
||
@ApiModelProperty(example = "1") | ||
@ApiParam(value = "차단 객체 ID") | ||
private Long blockId; | ||
|
||
@ApiModelProperty(example = "1") | ||
@ApiParam(value = "차단 생성하는 유저 ID") | ||
private Long blockingUserId; | ||
|
||
@ApiModelProperty(example = "2") | ||
@ApiParam(value = "차단 받는 유저 ID") | ||
private Long blockedUserId; | ||
|
||
/* | ||
연관관계 편의 메서드 | ||
*/ | ||
@Builder | ||
public BlockRes(Long blockId, Long blockingUserId, Long blockedUserId) { | ||
this.blockId = blockId; | ||
this.blockingUserId = blockingUserId; | ||
this.blockedUserId = blockedUserId; | ||
} | ||
|
||
public static BlockRes toDto(Block block){ | ||
return BlockRes.builder() | ||
.blockId(block.getId()) | ||
.blockingUserId(block.getBlockingUser().getId()) | ||
.blockedUserId(block.getBlockedUser().getId()) | ||
.build(); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
server/src/main/java/com/yogit/server/block/entity/Block.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 com.yogit.server.block.entity; | ||
|
||
import com.yogit.server.config.domain.BaseEntity; | ||
import com.yogit.server.user.entity.User; | ||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import javax.persistence.*; | ||
|
||
@Entity | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Getter | ||
public class Block extends BaseEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "block_id") | ||
private Long id; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "blocking_user_id") | ||
private User blockingUser; // 차단을 생성하는 유저 | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "blocked_user_id") | ||
private User blockedUser; // 차단을 받는 상대 유저 | ||
|
||
public Block(User blockingUser, User blockedUser) { | ||
this.blockingUser = blockingUser; | ||
this.blockedUser = blockedUser; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
server/src/main/java/com/yogit/server/block/exception/AlreadyBlockingException.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.yogit.server.block.exception; | ||
|
||
import static com.yogit.server.block.exception.BlockExceptionList.*; | ||
|
||
public class AlreadyBlockingException extends BlockException{ | ||
|
||
public AlreadyBlockingException(){ | ||
super(ALREADY_BLOCKING.getCODE(), ALREADY_BLOCKING.getHTTPSTATUS(), ALREADY_BLOCKING.getMESSAGE()); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
server/src/main/java/com/yogit/server/block/exception/BlockException.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.yogit.server.block.exception; | ||
|
||
import com.yogit.server.global.exception.ApplicationException; | ||
import org.springframework.http.HttpStatus; | ||
|
||
public class BlockException extends ApplicationException { | ||
|
||
protected BlockException(String errorCode, HttpStatus httpStatus, String message) { | ||
super(errorCode, httpStatus, message); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
server/src/main/java/com/yogit/server/block/exception/BlockExceptionList.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,16 @@ | ||
package com.yogit.server.block.exception; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public enum BlockExceptionList { | ||
|
||
ALREADY_BLOCKING("BL0001", HttpStatus.BAD_REQUEST, "이미 차단하였습니다."); | ||
|
||
private final String CODE; | ||
private final HttpStatus HTTPSTATUS; | ||
private final String MESSAGE; | ||
} |
16 changes: 16 additions & 0 deletions
16
server/src/main/java/com/yogit/server/block/repository/BlockRepository.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,16 @@ | ||
package com.yogit.server.block.repository; | ||
|
||
import com.yogit.server.block.entity.Block; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.List; | ||
|
||
@Repository | ||
public interface BlockRepository extends JpaRepository<Block, Long> { | ||
|
||
@Query("select bl from Block bl where bl.blockingUser.id = :blockingUserId and bl.blockedUser.id = :blockedUserId and bl.status = 'ACTIVE'") | ||
List<Block> findByBlockingUserIdAndBlockedUserId(@Param("blockingUserId") Long blockingUserId, @Param("blockedUserId") Long blockedUserId); | ||
} |
10 changes: 10 additions & 0 deletions
10
server/src/main/java/com/yogit/server/block/service/BlockService.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.yogit.server.block.service; | ||
|
||
import com.yogit.server.block.dto.req.CreateBlockReq; | ||
import com.yogit.server.block.dto.res.BlockRes; | ||
import com.yogit.server.global.dto.ApplicationResponse; | ||
|
||
public interface BlockService { | ||
|
||
ApplicationResponse<BlockRes> createBlock(CreateBlockReq createBlockReq); | ||
} |
48 changes: 48 additions & 0 deletions
48
server/src/main/java/com/yogit/server/block/service/BlockServiceImpl.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.yogit.server.block.service; | ||
|
||
import com.yogit.server.block.dto.req.CreateBlockReq; | ||
import com.yogit.server.block.dto.res.BlockRes; | ||
import com.yogit.server.block.entity.Block; | ||
import com.yogit.server.block.exception.AlreadyBlockingException; | ||
import com.yogit.server.block.repository.BlockRepository; | ||
import com.yogit.server.global.dto.ApplicationResponse; | ||
import com.yogit.server.user.entity.User; | ||
import com.yogit.server.user.exception.NotFoundUserException; | ||
import com.yogit.server.user.repository.UserRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@Transactional(readOnly = true) | ||
@RequiredArgsConstructor | ||
public class BlockServiceImpl implements BlockService{ | ||
|
||
private final BlockRepository blockRepository; | ||
private final UserRepository userRepository; | ||
|
||
@Override | ||
@Transactional(readOnly = false) | ||
public ApplicationResponse<BlockRes> createBlock(CreateBlockReq dto){ | ||
|
||
// 차단 생성하는 유저 조회 | ||
User blockingUser = userRepository.findById(dto.getBlockingUserId()) | ||
.orElseThrow(() -> new NotFoundUserException()); | ||
// 차단 받는 유저 조회 | ||
User blockedUser = userRepository.findById(dto.getBlockedUserId()) | ||
.orElseThrow(() -> new NotFoundUserException()); | ||
|
||
//Validation: 중복 차단(이미 차단했는지 검증) | ||
//TODO: 1.차단 리파지토리로 조회 or 2.유저의 차단 리스트 참조 조회 중 좋은 방법 선택해야 됨. | ||
if (!blockRepository.findByBlockingUserIdAndBlockedUserId(dto.getBlockingUserId(), dto.getBlockedUserId()).isEmpty()) { | ||
throw new AlreadyBlockingException(); | ||
} | ||
|
||
// 차단 엔티티 새성, 저장 | ||
Block block = new Block(blockingUser, blockedUser); | ||
blockRepository.save(block); | ||
|
||
BlockRes res = BlockRes.toDto(block); | ||
return ApplicationResponse.create("자단하였습니다.", res); | ||
} | ||
} |
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
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
Oops, something went wrong.