Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 26 additions & 28 deletions application/endpoints/src/main/resources/openapi/documentation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -317,17 +317,16 @@ paths:
required: true
schema:
type: string
- name: friendId
in: query
required: true
schema:
type: string
delete:
summary: Delete friend
tags:
- friends
description: "Unsubscribing from a user, as a result of which he ceases to be your friend"
requestBody:
description: Creation token based on nickname
content:
application/json:
schema:
$ref: '#/components/schemas/AccessFriendRequest'
responses:
"200":
description: An example of a successful generated response with an token
Expand Down Expand Up @@ -627,17 +626,16 @@ paths:
required: true
schema:
type: string
- name: meetingId
in: query
required: true
schema:
type: string
delete:
summary: Deleting a meeting
tags:
- meetings
description: "Removing a meeting from the database"
requestBody:
description: response with an token
content:
application/json:
schema:
$ref: '#/components/schemas/AccessMeetingIdRequest'
responses:
"200":
description: An example of a successful generated response with an token
Expand Down Expand Up @@ -1299,7 +1297,7 @@ components:
example: "John"
required:
- "nickname"
additionalProperties: false
additionalProperties: true
GenerateIdentityResponse:
type: "object"
properties:
Expand All @@ -1312,7 +1310,7 @@ components:
required:
- "status"
- "result"
additionalProperties: false
additionalProperties: true
AccessMeetingIdRequest:
type: "object"
properties:
Expand All @@ -1322,7 +1320,7 @@ components:
required:
- "token"
- "meetingId"
additionalProperties: false
additionalProperties: true
ListMeetingParticipantsRequest:
type: "object"
properties:
Expand All @@ -1337,7 +1335,7 @@ components:
- "token"
- "meetingId"
- "amount"
additionalProperties: false
additionalProperties: true
ListMeetingParticipantsResponse:
type: "object"
properties:
Expand All @@ -1358,7 +1356,7 @@ components:
required:
- "result"
- "status"
additionalProperties: false
additionalProperties: true
ListMapMeetingsRequest:
type: object
properties:
Expand All @@ -1385,7 +1383,7 @@ components:
- "14:BtEpi2o77Uia9NvwQqbumtNggJzjlEVS5gTS1Z8SDs9BmXk7E8lGxji5MBHxcor0j9X1tMgTjiYwbVvuqjdhkdDTr4XtZY6lFhURbKYG17LlfgqPVi6xJpoAdwQyxLz6wILAaiJdBy3wK1PZ3t0Zg3oBGeyeKJtfestgJylmEMCBjH7eXkBP9Bi93xkV4u68kB4OBKPesxJrTpUHlQjwuP8bCpj8Q591BUdUm9t9dXR4xSksMKWWWe4t4Y4ZrAfA"
required:
- "accessIdentity"
additionalProperties: false
additionalProperties: true
IdentityRequest:
type: object
properties:
Expand All @@ -1399,7 +1397,7 @@ components:
- "14:BtEpi2o77Uia9NvwQqbumtNggJzjlEVS5gTS1Z8SDs9BmXk7E8lGxji5MBHxcor0j9X1tMgTjiYwbVvuqjdhkdDTr4XtZY6lFhURbKYG17LlfgqPVi6xJpoAdwQyxLz6wILAaiJdBy3wK1PZ3t0Zg3oBGeyeKJtfestgJylmEMCBjH7eXkBP9Bi93xkV4u68kB4OBKPesxJrTpUHlQjwuP8bCpj8Q591BUdUm9t9dXR4xSksMKWWWe4t4Y4ZrAfA"
required:
- "id"
additionalProperties: false
additionalProperties: true
AccessFriendRequest:
type: "object"
properties:
Expand All @@ -1408,7 +1406,7 @@ components:
example: "5:PjvgzvEu2YsHIm5OP4L0apfqtQV9Ck9I02ZuhJxDqJ4VeS9SwQJGpBRV0QhvbaDJjsTaMZRVRzsM3yn9uSvBffdY1ul9k3J7IDgWqgbQXHlI0quTL0ORJAUONHzzRfLHs6sOmTAf7AlRP4AmGu9aqwN6hALE9MeDITcY3LlNJR6HPE5z3SK1aE5OC2YKpjhX0xQLBQd6wlkdeoCPhyJRevx60u1T1kVIhpnjBLyXQZwbHYGPCIVJ5ryeVByQCQI8"
required:
- "friendId"
additionalProperties: false
additionalProperties: true
ListFriendsRequest:
type: "object"
properties:
Expand Down Expand Up @@ -1445,7 +1443,7 @@ components:
required:
- "email"
- "confirmHash"
additionalProperties: false
additionalProperties: true
EmailLinkRequest:
type: "object"
properties:
Expand All @@ -1455,7 +1453,7 @@ components:
required:
- "email"
- "token"
additionalProperties: false
additionalProperties: true
TelegramFinishRequest:
type: "object"
properties:
Expand Down Expand Up @@ -1489,7 +1487,7 @@ components:
required:
- "accessIdentity"
- "fileIdentityIdentity"
additionalProperties: false
additionalProperties: true
CreateMeetingRequest:
type: "object"
properties:
Expand Down Expand Up @@ -1521,7 +1519,7 @@ components:
- "date"
- "location"
- "visibility"
additionalProperties: false
additionalProperties: true
EditMeetingResponse:
type: object
properties:
Expand Down Expand Up @@ -1566,7 +1564,7 @@ components:
required:
- "token"
- "meetingId"
additionalProperties: false
additionalProperties: true
InvalidResponse:
type: object
properties:
Expand All @@ -1585,7 +1583,7 @@ components:
- "status"
- "errorCode"
- "errorMessage"
additionalProperties: false
additionalProperties: true
StatusTrueResponse:
type: object
properties:
Expand All @@ -1594,7 +1592,7 @@ components:
example: true
required:
- "status"
additionalProperties: false
additionalProperties: true
TelegramPreloginResponse:
type: object
properties:
Expand Down Expand Up @@ -1819,7 +1817,7 @@ components:
example: "8:bqLhYy1hjNTL0wXcN0dnmSeyZDMt2akkGYMDdaa81oc8fPhOHBWTuFWzMdWNqu7gTHHrfhvC64RE2ZEtngYD5YVpOAGz8Nx1ii7l6BxpBCfHgaL6hHzkEqsmuGlea2gijOEZFkDEhebZ9lwkav13DMTdWJUm4GMm0VQgXzX8s3B528XsMxkXiu5ps9JrRB4m2m4vnZHEaskq9SXEGfhxzeuVft4d2eHWlp5V06NPmfhuyehq9J3GwWxYSkN3Doun"
required:
- token
additionalProperties: false
additionalProperties: true
EditUserRequest:
type: object
properties:
Expand Down
14 changes: 14 additions & 0 deletions application/src/test/kotlin/TestFriends.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,20 @@ class TestFriends {
assertNull(user.relationship)
}

@Test
fun `test friend delete`() = runTestServer {
val self = generateTestAccount()
val friend = generateTestAccount()

self.friends.add(friend.id)
friend.friends.add(self.id)

require(self.friends.list(1.amount).data.first().id == friend.id)

self.friends.delete(friend.id)
require(self.friends.list(1.amount).data.isEmpty())
}

@Test
fun `test relationship property`() = runTestServer {
val self = generateTestAccount()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package app.meetacy.backend.core.endpoints

import app.meetacy.backend.types.serializable.serialization
import app.meetacy.backend.types.serializable.users.UserId
import io.ktor.http.*
import kotlinx.serialization.SerializationException


fun Parameters.friendIdOrNull(name: String = "friendId"): UserId? {
return this[name]?.let(::UserId)
}

fun Parameters.friendId(name: String = "friendId"): UserId = serialization {
val friendId = this[name] ?: throw SerializationException("Bad request. Illegal input: param 'friendId' is required for type with serial name, but it was missing at path: $name")
UserId(friendId)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package app.meetacy.backend.core.endpoints

import app.meetacy.backend.types.serializable.meetings.MeetingId
import app.meetacy.backend.types.serializable.serialization
import io.ktor.http.*
import kotlinx.serialization.SerializationException

fun Parameters.meetingIdOrNull(name: String = "meetingId"): MeetingId? {
return this[name]?.let(::MeetingId)
}

fun Parameters.meetingId(name: String = "meetingId"): MeetingId = serialization {
val meetingId = this[name] ?: throw SerializationException("Bad request. Illegal input: param 'meetingId' is required for type with serial name, but it was missing at path: $name")
MeetingId(meetingId)
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
package app.meetacy.backend.core.endpoints

import app.meetacy.backend.types.serializable.serialization
import app.meetacy.backend.types.serializable.users.UserId
import io.ktor.http.*
import io.ktor.server.application.*
import kotlinx.serialization.SerializationException

fun Parameters.userIdOrNull(name: String = "userId"): UserId? {
return this[name]?.let(::UserId)
}

fun Parameters.userId(name: String = "userId"): UserId = serialization {
val userId = this[name] ?: throw SerializationException("Bad request. Illegal input: param 'userId' is required for type with serial name, but it was missing at path: $name")
UserId(userId)
}
Original file line number Diff line number Diff line change
@@ -1,36 +1,30 @@
package app.meetacy.backend.feature.friends.endpoints.delete

import app.meetacy.backend.core.endpoints.accessIdentity
import app.meetacy.backend.core.endpoints.friendId
import app.meetacy.backend.endpoint.ktor.Failure
import app.meetacy.backend.endpoint.ktor.respondFailure
import app.meetacy.backend.endpoint.ktor.respondSuccess
import app.meetacy.backend.types.serializable.access.AccessIdentity
import app.meetacy.backend.types.serializable.users.UserId as UserIdentitySerializable
import io.ktor.server.application.*
import io.ktor.server.request.*
import io.ktor.server.routing.*
import kotlinx.serialization.Serializable
import app.meetacy.backend.types.serializable.users.UserId as UserIdentitySerializable

interface DeleteFriendRepository {
suspend fun deleteFriend(token: AccessIdentity, friendId: UserIdentitySerializable): DeleteFriendResult
}

@Serializable
data class DeleteFriendParam(
val friendId: UserIdentitySerializable
)

sealed interface DeleteFriendResult {
data object Success : DeleteFriendResult
data object InvalidIdentity : DeleteFriendResult
data object FriendNotFound : DeleteFriendResult
}

fun Route.deleteFriend(provider: DeleteFriendRepository) = delete("/delete") {
val param = call.receive<DeleteFriendParam>()
val param = call.parameters.friendId()
val token = call.accessIdentity()

when (provider.deleteFriend(token, param.friendId)) {
when (provider.deleteFriend(token, param)) {
DeleteFriendResult.FriendNotFound -> call.respondFailure(Failure.FriendNotFound)
DeleteFriendResult.InvalidIdentity -> call.respondFailure(Failure.InvalidToken)
DeleteFriendResult.Success -> call.respondSuccess()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
package app.meetacy.backend.feature.meetings.endpoints.delete

import app.meetacy.backend.core.endpoints.accessIdentity
import app.meetacy.backend.core.endpoints.meetingId
import app.meetacy.backend.endpoint.ktor.Failure
import app.meetacy.backend.endpoint.ktor.respondFailure
import app.meetacy.backend.endpoint.ktor.respondSuccess
import app.meetacy.backend.types.serializable.access.AccessIdentity
import app.meetacy.backend.types.serializable.meetings.MeetingId
import io.ktor.server.application.*
import io.ktor.server.request.*
import io.ktor.server.routing.*
import kotlinx.serialization.Serializable

@Serializable
data class DeleteMeetingParam(
val meetingId: MeetingId
)

sealed interface DeleteMeetingResult {
data object Success : DeleteMeetingResult
Expand All @@ -27,9 +21,9 @@ interface DeleteMeetingRepository {
}

fun Route.deleteMeeting(repository: DeleteMeetingRepository) = delete("/delete") {
val param = call.receive<DeleteMeetingParam>()
val param = call.parameters.meetingId()
val token = call.accessIdentity()
when (repository.deleteMeeting(token, param.meetingId)) {
when (repository.deleteMeeting(token, param)) {
is DeleteMeetingResult.Success -> call.respondSuccess()
is DeleteMeetingResult.InvalidIdentity -> call.respondFailure(Failure.InvalidToken)
is DeleteMeetingResult.MeetingNotFound -> call.respondFailure(Failure.InvalidMeetingIdentity)
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ ssh = "2.10.1"
shadow = "7.0.0"

wdater = "0.0.4"
meetacySdk = "0.0.71-builde09e00c"
meetacySdk = "0.0.71-build80f4055"
meetacyDi = "0.0.25"

[libraries]
Expand Down