프로젝트/PongGame

Relation API 명세

히포파타마스 2022. 5. 30. 17:06

Relation API 명세

Account 간의 관계를 나타내는 Relation entity를 생성하고 Relation을 사용하는 API에 대한 명세를 작성한다.

 

 

 

 

1. Relation

Account 간의 관계를 나타내는 entity.

관계는 세 가지로, [친구, 친구 요청, 차단] 상태가 존재한다.

 

[Relation]

@Entity
@Where(clause = "deleted = false")
@Getter
@Builder
@AllArgsConstructor
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Relation extends BaseTime {

    @Id @GeneratedValue
    @Column(name = "relation_id")
    private Long id;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "fromAccount_id")
    private Account fromAccount;   //[1]

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "toAccount_id")
    private Account toAccount;   //[2]

    @Enumerated(EnumType.STRING)
    private RelationState relationState;   //[3]

    public void acceptRequest() {   //[4]
        relationState = RelationState.FRIEND;
    }

    public void block() {   //[5]
        relationState = RelationState.BLOCK;
    }
}

Relation은 단방향 관계이다.

예를 들어 Account1는 Account2(Account1 -> Account2)가 친구 상태일 수 있지만, Account2는 Account1(Account2 -> Account1)이 친구가 아닐 수도 있다.

 

● [1] : 관계의 주체

● [2] : 관계의 객체

● [3] : 관계의 상태(친구, 친구 요청, 차단)

● [4] : 관계를 "친구" 상태로 변환해주는 메서드

● [5] : 관계를 "차단" 상태로 변환해주는 메서드

 

 

[RelationState]

public enum RelationState {
    REQUEST, FRIEND, BLOCK
}

 

 

 

 

2. Relation API 명세

친구 요청, 수락, 거절, 차단 등과 같은 기능을 수행하는 API를 작성한다.

또한 위의 API로 생성된 Relation에 관련된 Account를 조회할 수 있는 API를 작성한다.

 

 

 

■ 생성, 변경

□ requestFriend

로그인한 Account가 경로 변수의 Account에게 "친구 요청"을 한다.

 

[requestFriend]

@PostMapping("/relation/request/{accountId}")
public ResultMessage requestFriend(@LoginAccountId Long loginAccountId, @PathVariable Long accountId) {}

● 입력

○ accountId : 경로 변수, 관계의 객체

 

● 출력

○ ResultMessage : 성공 메시지를 담아서 반환

 

 

□ acceptFriend

로그인한 Account가 특정 Account로부터 받은 "친구 요청"을 수락한다.

이 경우 두 Account 모두 친구 관계가 된다.

 

[acceptFriend]

@PostMapping("/relation/request/accept/{accountId}")
public ResultMessage acceptFriend(@LoginAccountId Long loginAccountId, @PathVariable Long accountId) {}

● 입력

○ accountId : 경로 변수, "친구 요청" 상태인 Relation의 주체

 

● 출력

○ ResultMessage : 성공 메시지를 담아서 반환

 

 

□ rejectFriend

로그인한 Account가 경로 변수의 Account가 보낸 "친구 요청"을 거절한다.

 

[rejectFriend]

@PostMapping("/relation/request/reject/{accountId}")
public ResultMessage rejectFriend(@LoginAccountId Long loginAccountId, @PathVariable Long accountId) {}

● 입력

○ accountId : 경로 변수, "친구 요청" 상태인 Relation의 주체

 

● 출력

○ ResultMessage : 성공 메시지를 담아서 반환

 

 

□ block

로그인한 Account가 경로 변수의 Account를 "차단" 한다.

 

[block]

@PostMapping("/relation/block/{accountId}")
public ResultMessage block(@LoginAccountId Long loginAccountId, @PathVariable Long accountId) {}

● 입력

○ accountId : 경로 변수, 관계의 객체

 

● 출력

○ ResultMessage : 성공 메시지를 담아서 반환

 

 

□ unBlock

로그인한 Account가 경로 변수의 Account의 "차단"을 해제한다.

 

[unBlock]

@PostMapping("/relation/unBlock/{accountId}")
public ResultMessage unBlock(@LoginAccountId Long loginAccountId, @PathVariable Long accountId) {}

● 입력

○ accountId : 경로 변수, 관계의 객체

 

● 출력

○ ResultMessage : 성공 메시지를 담아서 반환

 

 

 

■ 조회

□ findAllRequest

로그인한 Account가 "친구 요청"한 모든 Account를 조회한다.

 

[findAllRequest]

@GetMapping("relation/request/all")
public Result<List<AccountDto>> findAllRequest(@LoginAccountId Long loginAccountId) {}

● 출력

○ Result<List<AccountDto>> : 로그인한 Account가 "친구 요청"한 모든 Account를 Dto에 담아서 List로 반환

 

 

□ findRequestsByPage

로그인한 Account가 "친구 요청"한 Account를 Page로 조회한다.

 

[findRequestsByPage]

@GetMapping("/relation/requests")
public Page<AccountDto> findRequestsByPage(@LoginAccountId Long loginAccountId, Pageable pageable) {}

● 입력

○ pageable : 값이 입력되지 않으면 기본값 적용(page = 1, size = 20)

◎ page

◎ size

◎ sort

 

● 출력

○ Page<AccountDto> : 입력받은 조건으로 페이징 한 AccountDto를 반환

 

 

□ findAllRequestFromOther

로그인한 Account로 "친구 요청"한 Account를 전부 조회한다.

 

[findAllRequestFromOther]

@GetMapping("/relation/requestFromOther/all")
public Result<List<AccountDto>> findAllRequestFromOther(@LoginAccountId Long loginAccountId) {}

● 출력

○ Result<List<AccountDto>> : 로그인한 Account로 "친구 요청"한 모든 Account를 Dto에 담아서 List로 반환

 

 

□ findRequestsFromOtherByPage

로그인한 Account로 "친구 요청"한 Account를 Page로 조회한다.

 

[findRequestsFromOtherByPage]

@GetMapping("/relation/requestsFromOther")
public Page<AccountDto> findRequestsFromOtherByPage(@LoginAccountId Long loginAccountId, Pageable pageable) {}

● 입력

○ pageable : 값이 입력되지 않으면 기본값 적용(page = 1, size = 20)

◎ page

◎ size

◎ sort

 

● 출력

○ Page<AccountDto> : 입력받은 조건으로 페이징 한 AccountDto를 반환

 

 

□ findAllFriend

로그인한 Account의 "친구" 상태의 Account를 전부 조회

 

[findAllFriend]

@GetMapping("/relation/friend/all")
public Result<List<AccountDto>> findAllFriend(@LoginAccountId Long loginAccountId, Pageable pageable) {}

● 출력

○ Result<List<AccountDto>> : 로그인한 Account의 "친구" 상태의 모든 Account를 Dto에 담아서 List로 반환

 

 

□ findFriends

로그인한 Account의 "친구" 상태의 Account를 Page로 조회

 

[findFriends]

@GetMapping("/relation/friends")
public Page<AccountDto> findFriends(@LoginAccountId Long loginAccountId, Pageable pageable) {}

● 입력

○ pageable : 값이 입력되지 않으면 기본값 적용(page = 1, size = 20)

◎ page

◎ size

◎ sort

 

● 출력

○ Page<AccountDto> : 입력받은 조건으로 페이징 한 AccountDto를 반환

 

 

□ findAllBlock

로그인한 Account가 "차단"한 모든 Account를 조회

 

[findAllBlock]

@GetMapping("/relation/block/all")
public Result<List<AccountDto>> findAllBlock(@LoginAccountId Long loginAccountId) {}

● 출력

○ Result<List<AccountDto>> : 로그인한 Account가 "차단"한 모든 Account를 Dto에 담아서 List로 반환

 

 

□ findBlockAccounts

로그인한 Account가 "차단"한 Account를 Page로 조회

 

[findBlockAccounts]

@GetMapping("/relation/blocks")
public Page<AccountDto> findBlockAccounts(@LoginAccountId Long loginAccountId, Pageable pageable) {}

● 입력

○ pageable : 값이 입력되지 않으면 기본값 적용(page = 1, size = 20)

◎ page

◎ size

◎ sort

 

● 출력

○ Page<AccountDto> : 입력받은 조건으로 페이징 한 AccountDto를 반환