mirror of https://github.com/usbharu/Hideout.git
feat: Mastodon APIからフォロー解除・ブロック解除ができるように
This commit is contained in:
parent
c57ba6d434
commit
539c65ada2
|
@ -197,7 +197,9 @@ class SecurityConfig {
|
|||
authorize(GET, "/api/v1/accounts/*", permitAll)
|
||||
authorize(GET, "/api/v1/accounts/*/statuses", permitAll)
|
||||
authorize(POST, "/api/v1/accounts/*/follow", hasAnyScope("write", "write:follows"))
|
||||
authorize(POST, "/api/v1/accounts/*/unfollow", hasAnyScope("write", "write:follows"))
|
||||
authorize(POST, "/api/v1/accounts/*/block", hasAnyScope("write", "write:blocks"))
|
||||
authorize(POST, "/api/v1/accounts/*/unblock", hasAnyScope("write", "write:blocks"))
|
||||
|
||||
authorize(POST, "/api/v1/media", hasAnyScope("write", "write:media"))
|
||||
authorize(POST, "/api/v1/statuses", hasAnyScope("write", "write:statuses"))
|
||||
|
|
|
@ -167,7 +167,7 @@ class RelationshipServiceImpl(
|
|||
return
|
||||
}
|
||||
|
||||
if (relationship.followRequest.not()) {
|
||||
if (relationship.followRequest.not() && relationship.following.not()) {
|
||||
logger.warn("FAILED Follow Request Not Found. (Follow Request) userId: {} targetId: {}", userId, targetId)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -113,4 +113,24 @@ class MastodonAccountApiController(
|
|||
|
||||
return ResponseEntity.ok(block)
|
||||
}
|
||||
|
||||
override suspend fun apiV1AccountsIdUnblockPost(id: String): ResponseEntity<Relationship> {
|
||||
val principal = SecurityContextHolder.getContext().getAuthentication().principal as Jwt
|
||||
|
||||
val userid = principal.getClaim<String>("uid").toLong()
|
||||
|
||||
val unblock = accountApiService.unblock(userid, id.toLong())
|
||||
|
||||
return ResponseEntity.ok(unblock)
|
||||
}
|
||||
|
||||
override suspend fun apiV1AccountsIdUnfollowPost(id: String): ResponseEntity<Relationship> {
|
||||
val principal = SecurityContextHolder.getContext().getAuthentication().principal as Jwt
|
||||
|
||||
val userid = principal.getClaim<String>("uid").toLong()
|
||||
|
||||
val unfollow = accountApiService.unfollow(userid, id.toLong())
|
||||
|
||||
return ResponseEntity.ok(unfollow)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,6 +42,8 @@ interface AccountApiService {
|
|||
* @return ブロック後のブロック対象ユーザーとの[Relationship]
|
||||
*/
|
||||
suspend fun block(userid: Long, target: Long): Relationship
|
||||
suspend fun unblock(userid: Long, target: Long): Relationship
|
||||
suspend fun unfollow(userid: Long, target: Long): Relationship
|
||||
}
|
||||
|
||||
@Service
|
||||
|
@ -101,10 +103,10 @@ class AccountApiServiceImpl(
|
|||
userService.createLocalUser(UserCreateDto(userCreateDto.name, userCreateDto.name, "", userCreateDto.password))
|
||||
}
|
||||
|
||||
override suspend fun follow(loginUser: Long, followTargetUserId: Long): Relationship {
|
||||
override suspend fun follow(loginUser: Long, followTargetUserId: Long): Relationship = transaction.transaction {
|
||||
relationshipService.followRequest(loginUser, followTargetUserId)
|
||||
|
||||
return fetchRelationship(loginUser, followTargetUserId)
|
||||
return@transaction fetchRelationship(loginUser, followTargetUserId)
|
||||
}
|
||||
|
||||
override suspend fun account(id: Long): Account = transaction.transaction {
|
||||
|
@ -132,6 +134,18 @@ class AccountApiServiceImpl(
|
|||
fetchRelationship(userid, target)
|
||||
}
|
||||
|
||||
override suspend fun unblock(userid: Long, target: Long): Relationship = transaction.transaction {
|
||||
relationshipService.unblock(userid, target)
|
||||
|
||||
return@transaction fetchRelationship(userid, target)
|
||||
}
|
||||
|
||||
override suspend fun unfollow(userid: Long, target: Long): Relationship = transaction.transaction {
|
||||
relationshipService.unfollow(userid, target)
|
||||
|
||||
return@transaction fetchRelationship(userid, target)
|
||||
}
|
||||
|
||||
private fun from(account: Account): CredentialAccount {
|
||||
return CredentialAccount(
|
||||
id = account.id,
|
||||
|
|
|
@ -308,6 +308,49 @@ paths:
|
|||
schema:
|
||||
$ref: "#/components/schemas/Relationship"
|
||||
|
||||
/api/v1/accounts/{id}/unfollow:
|
||||
post:
|
||||
tags:
|
||||
- account
|
||||
security:
|
||||
- OAuth2:
|
||||
- "write:follows"
|
||||
parameters:
|
||||
- in: path
|
||||
name: id
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
responses:
|
||||
200:
|
||||
description: 成功
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Relationship"
|
||||
|
||||
/api/v1/accounts/{id}/unblock:
|
||||
post:
|
||||
tags:
|
||||
- account
|
||||
security:
|
||||
- OAuth2:
|
||||
- "write:blocks"
|
||||
parameters:
|
||||
- in: path
|
||||
name: id
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
responses:
|
||||
200:
|
||||
description: 成功
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Relationship"
|
||||
|
||||
|
||||
/api/v1/accounts/{id}/statuses:
|
||||
get:
|
||||
tags:
|
||||
|
|
Loading…
Reference in New Issue