Skip to content

Commit

Permalink
feat(#79-support-search): support search was added
Browse files Browse the repository at this point in the history
  • Loading branch information
y9Kap committed Nov 2, 2023
1 parent a468dab commit 6ab68a7
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import app.meetacy.sdk.friends.AuthorizedFriendsApi
import app.meetacy.sdk.invitations.AuthorizedInvitationsApi
import app.meetacy.sdk.meetings.AuthorizedMeetingsApi
import app.meetacy.sdk.notifications.AuthorizedNotificationsApi
import app.meetacy.sdk.search.AuthorizedSearchItemRepository
import app.meetacy.sdk.types.annotation.UnsafeConstructor
import app.meetacy.sdk.types.auth.Token
import app.meetacy.sdk.types.location.Location
import app.meetacy.sdk.updates.AuthorizedUpdatesApi
import app.meetacy.sdk.users.AuthorizedSelfUserRepository
import app.meetacy.sdk.users.AuthorizedUsersApi
Expand Down Expand Up @@ -38,4 +40,7 @@ public class AuthorizedMeetacyApi @UnsafeConstructor constructor(
data = base.getMe(token),
api = this
)

This comment has been minimized.

Copy link
@y9san9

y9san9 Nov 3, 2023

Member

Нет отступа

public suspend fun search(location: Location, prompt: String): List<AuthorizedSearchItemRepository> =
base.search(token, location, prompt).map { AuthorizedSearchItemRepository.of(it.data, api = this) }

}
19 changes: 19 additions & 0 deletions api/src/commonMain/kotlin/app/meetacy/sdk/MeetacyApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ package app.meetacy.sdk
import app.meetacy.sdk.auth.AuthApi
import app.meetacy.sdk.engine.MeetacyRequestsEngine
import app.meetacy.sdk.engine.requests.GetMeRequest
import app.meetacy.sdk.engine.requests.SearchRequest
import app.meetacy.sdk.files.FilesApi
import app.meetacy.sdk.friends.FriendsApi
import app.meetacy.sdk.invitations.InvitationsApi
import app.meetacy.sdk.meetings.MeetingsApi
import app.meetacy.sdk.notifications.NotificationsApi
import app.meetacy.sdk.search.SearchItemRepository
import app.meetacy.sdk.types.annotation.UnsafeConstructor
import app.meetacy.sdk.types.auth.Token
import app.meetacy.sdk.types.location.Location
import app.meetacy.sdk.types.user.SelfUser
import app.meetacy.sdk.updates.UpdatesApi
import app.meetacy.sdk.users.UsersApi
Expand All @@ -30,10 +33,26 @@ public class MeetacyApi(
return engine.execute(GetMeRequest(token)).me
}

public suspend fun search(
token: Token,
location: Location,
prompt: String
): List<SearchItemRepository> {
return engine.execute(
request = SearchRequest(
token, location, prompt
)
).items.map { searchItem ->
SearchItemRepository.of(searchItem, api = this)
}
}

@OptIn(UnsafeConstructor::class)
public fun authorized(token: Token): AuthorizedMeetacyApi {
return AuthorizedMeetacyApi(token, base = this)
}



This comment has been minimized.

Copy link
@y9san9

y9san9 Nov 3, 2023

Member

Пустое пространство

public companion object
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package app.meetacy.sdk.search

import app.meetacy.sdk.AuthorizedMeetacyApi
import app.meetacy.sdk.meetings.AuthorizedMeetingRepository
import app.meetacy.sdk.types.auth.Token
import app.meetacy.sdk.types.search.SearchItem
import app.meetacy.sdk.users.AuthorizedUserRepository
import app.meetacy.sdk.types.place.Place as PlaceData

public sealed class AuthorizedSearchItemRepository {
protected abstract val api: AuthorizedMeetacyApi

This comment has been minimized.

Copy link
@y9san9

y9san9 Nov 3, 2023

Member

Также как и в SearchItemRepository тут api не нужен

public abstract val data: SearchItem
public abstract val base: SearchItemRepository

public val token: Token get() = api.token

public class Meeting(
override val data: SearchItem.Meeting,
override val api: AuthorizedMeetacyApi
) : AuthorizedSearchItemRepository() {
override val base: SearchItemRepository
get() = SearchItemRepository.Meeting(data, api.base)
public val meeting: AuthorizedMeetingRepository
get() = AuthorizedMeetingRepository(data.meeting, api)
}

public class Place(
override val data: SearchItem.Place,
override val api: AuthorizedMeetacyApi
) : AuthorizedSearchItemRepository() {
override val base: SearchItemRepository
get() = SearchItemRepository.Place(data)

public val place: PlaceData
get() = data.place
}

public class User(
override val data: SearchItem.User,
override val api: AuthorizedMeetacyApi
) : AuthorizedSearchItemRepository() {

override val base: SearchItemRepository
get() = SearchItemRepository.User(data, api.base)
public val user: AuthorizedUserRepository
get() = AuthorizedUserRepository.of(data.user, api)
}

public companion object {
public fun of(data: SearchItem, api: AuthorizedMeetacyApi): AuthorizedSearchItemRepository =
when (data) {
is SearchItem.Meeting -> Meeting(data, api)
is SearchItem.Place -> Place(data, api)
is SearchItem.User -> User(data, api)
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package app.meetacy.sdk.search

import app.meetacy.sdk.MeetacyApi
import app.meetacy.sdk.meetings.AuthorizedMeetingRepository
import app.meetacy.sdk.meetings.MeetingRepository
import app.meetacy.sdk.types.place.Place as PlaceData
import app.meetacy.sdk.types.search.SearchItem
import app.meetacy.sdk.users.UserRepository

/**
* When modifying this class, corresponding classes should be altered:
* - [AuthorizedMeetingRepository]
*/

This comment has been minimized.

Copy link
@y9san9

y9san9 Nov 3, 2023

Member

Лишняя новая линия

public sealed class SearchItemRepository {
public abstract val data: SearchItem

public class Meeting(
override val data: SearchItem.Meeting,
private val api: MeetacyApi
) : SearchItemRepository() {
public val meeting: MeetingRepository
get() = MeetingRepository(data.meeting, api)
}

public class Place(
override val data: SearchItem.Place
) : SearchItemRepository() {
public val place: PlaceData
get() = data.place
}

public class User(
override val data: SearchItem.User,
private val api: MeetacyApi
) : SearchItemRepository() {
public val user: UserRepository
get() = UserRepository.of(data.user, api)
}

public companion object {
public fun of(data: SearchItem, api: MeetacyApi): SearchItemRepository {
return when (data) {
is SearchItem.Meeting -> Meeting(data, api)
is SearchItem.Place -> Place(data)
is SearchItem.User -> User(data, api)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ import app.meetacy.sdk.types.meeting.Meeting as MeetingView
import app.meetacy.sdk.types.place.Place as PlaceView
import app.meetacy.sdk.types.user.User as UserView

/**
* When modifying this class, corresponding classes should be altered:
* - [app.meetacy.sdk.search.SearchItemRepository]
* - [app.meetacy.sdk.search.AuthorizedSearchItemRepository]
*/

This comment has been minimized.

Copy link
@y9san9

y9san9 Nov 3, 2023

Member

Лишняя новая линия

public sealed interface SearchItem {
public class Meeting(public val meeting: MeetingView) : SearchItem
public class User(public val user: UserView) : SearchItem
Expand Down

0 comments on commit 6ab68a7

Please sign in to comment.