-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
commit 01eb6e7 Author: Hayden <hayden.hhoang@gmail.com> Date: Wed Aug 7 18:26:08 2024 +0700 update README: add stopwords documentation commit ba8256b Author: Hayden <hayden.hhoang@gmail.com> Date: Wed Aug 7 18:23:22 2024 +0700 feat: add stopwords endpoint
- Loading branch information
1 parent
96b8eb6
commit 5e62e20
Showing
12 changed files
with
338 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import Foundation | ||
|
||
|
||
|
||
public struct StopwordsSetDeleteSchema: Codable { | ||
public var _id: String | ||
|
||
public init(_id: String) { | ||
self._id = _id | ||
} | ||
|
||
public enum CodingKeys: String, CodingKey { | ||
case _id = "id" | ||
} | ||
|
||
} |
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,21 @@ | ||
// | ||
// StopwordsSetRetrieveSchema.swift | ||
// | ||
// Generated by swagger-codegen | ||
// https://github.com/swagger-api/swagger-codegen | ||
// | ||
|
||
import Foundation | ||
|
||
|
||
|
||
public struct StopwordsSetRetrieveSchema: Codable { | ||
|
||
public var stopwords: StopwordsSetSchema | ||
|
||
public init(stopwords: StopwordsSetSchema) { | ||
self.stopwords = stopwords | ||
} | ||
|
||
|
||
} |
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,30 @@ | ||
// | ||
// StopwordsSetSchema.swift | ||
// | ||
// Generated by swagger-codegen | ||
// https://github.com/swagger-api/swagger-codegen | ||
// | ||
|
||
import Foundation | ||
|
||
|
||
|
||
public struct StopwordsSetSchema: Codable { | ||
|
||
public var _id: String | ||
public var stopwords: [String] | ||
public var locale: String? | ||
|
||
public init(_id: String, stopwords: [String], locale: String? = nil) { | ||
self._id = _id | ||
self.stopwords = stopwords | ||
self.locale = locale | ||
} | ||
|
||
public enum CodingKeys: String, CodingKey { | ||
case _id = "id" | ||
case stopwords | ||
case locale | ||
} | ||
|
||
} |
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,23 @@ | ||
// | ||
// StopwordsSetUpsertSchema.swift | ||
// | ||
// Generated by swagger-codegen | ||
// https://github.com/swagger-api/swagger-codegen | ||
// | ||
|
||
import Foundation | ||
|
||
|
||
|
||
public struct StopwordsSetUpsertSchema: Codable { | ||
|
||
public var stopwords: [String] | ||
public var locale: String? | ||
|
||
public init(stopwords: [String], locale: String? = nil) { | ||
self.stopwords = stopwords | ||
self.locale = locale | ||
} | ||
|
||
|
||
} |
21 changes: 21 additions & 0 deletions
21
Sources/Typesense/Models/StopwordsSetsRetrieveAllSchema.swift
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,21 @@ | ||
// | ||
// StopwordsSetsRetrieveAllSchema.swift | ||
// | ||
// Generated by swagger-codegen | ||
// https://github.com/swagger-api/swagger-codegen | ||
// | ||
|
||
import Foundation | ||
|
||
|
||
|
||
public struct StopwordsSetsRetrieveAllSchema: Codable { | ||
|
||
public var stopwords: [StopwordsSetSchema] | ||
|
||
public init(stopwords: [StopwordsSetSchema]) { | ||
self.stopwords = stopwords | ||
} | ||
|
||
|
||
} |
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,39 @@ | ||
import Foundation | ||
#if canImport(FoundationNetworking) | ||
import FoundationNetworking | ||
#endif | ||
|
||
public struct Stopword { | ||
private var apiCall: ApiCall | ||
private var stopwordsSetId: String | ||
|
||
|
||
init(apiCall: ApiCall, stopwordsSetId: String) { | ||
self.apiCall = apiCall | ||
self.stopwordsSetId = stopwordsSetId | ||
} | ||
|
||
public func retrieve() async throws -> (StopwordsSetSchema?, URLResponse?) { | ||
let (data, response) = try await apiCall.get(endPoint: endpointPath()) | ||
if let result = data { | ||
let decodedData = try decoder.decode(StopwordsSetRetrieveSchema.self, from: result) | ||
return (decodedData.stopwords, response) | ||
} | ||
return (nil, response) | ||
} | ||
|
||
public func delete() async throws -> (StopwordsSetDeleteSchema?, URLResponse?) { | ||
let (data, response) = try await apiCall.delete(endPoint: endpointPath()) | ||
if let result = data { | ||
let decodedData = try decoder.decode(StopwordsSetDeleteSchema.self, from: result) | ||
return (decodedData, response) | ||
} | ||
return (nil, response) | ||
} | ||
|
||
private func endpointPath() -> String { | ||
return "\(Stopwords.RESOURCEPATH)/\(stopwordsSetId)" | ||
} | ||
|
||
|
||
} |
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,44 @@ | ||
import Foundation | ||
#if canImport(FoundationNetworking) | ||
import FoundationNetworking | ||
#endif | ||
|
||
public struct Stopwords { | ||
static let RESOURCEPATH = "stopwords" | ||
private var apiCall: ApiCall | ||
|
||
|
||
init(apiCall: ApiCall) { | ||
self.apiCall = apiCall | ||
} | ||
|
||
public func upsert(stopwordsSetId: String, params: StopwordsSetUpsertSchema) async throws -> (StopwordsSetSchema?, URLResponse?) { | ||
let schemaData = try encoder.encode(params) | ||
let (data, response) = try await self.apiCall.put(endPoint: endpointPath(stopwordsSetId), body: schemaData) | ||
if let result = data { | ||
let decodedData = try decoder.decode(StopwordsSetSchema.self, from: result) | ||
return (decodedData, response) | ||
} | ||
return (nil, response) | ||
} | ||
|
||
public func retrieve() async throws -> ([StopwordsSetSchema]?, URLResponse?) { | ||
let (data, response) = try await self.apiCall.get(endPoint: endpointPath()) | ||
if let result = data { | ||
let decodedData = try decoder.decode(StopwordsSetsRetrieveAllSchema.self, from: result) | ||
return (decodedData.stopwords, response) | ||
} | ||
return (nil, response) | ||
} | ||
|
||
private func endpointPath(_ operation: String? = nil) -> String { | ||
let baseEndpoint = "\(Stopwords.RESOURCEPATH)" | ||
if let operation = operation { | ||
return "\(baseEndpoint)/\(operation)" | ||
} else { | ||
return baseEndpoint | ||
} | ||
} | ||
|
||
|
||
} |
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 @@ | ||
import XCTest | ||
@testable import Typesense | ||
|
||
final class StopwordTests: XCTestCase { | ||
override func tearDown() async throws { | ||
try! await tearDownStopwords() | ||
} | ||
|
||
func testStopwordRetrieve() async { | ||
try! await createStopwordSet() | ||
do { | ||
let (result, _) = try await client.stopword("test-id-stopword-set").retrieve() | ||
XCTAssertNotNil(result) | ||
guard let validResult = result else { | ||
throw DataError.dataNotFound | ||
} | ||
print(validResult) | ||
XCTAssertEqual("test-id-stopword-set", validResult._id) | ||
XCTAssertEqual(["states","united"], validResult.stopwords) | ||
XCTAssertEqual("en", validResult.locale) | ||
} catch (let error) { | ||
print(error.localizedDescription) | ||
XCTAssertTrue(false) | ||
} | ||
} | ||
|
||
func testStopwordDelete() async { | ||
try! await createStopwordSet() | ||
do { | ||
let (result, _) = try await client.stopword("test-id-stopword-set").delete() | ||
guard let validResult = result else { | ||
throw DataError.dataNotFound | ||
} | ||
print(validResult) | ||
XCTAssertEqual("test-id-stopword-set", validResult._id) | ||
} catch (let error) { | ||
print(error) | ||
XCTAssertTrue(false) | ||
} | ||
} | ||
|
||
} |
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,46 @@ | ||
import XCTest | ||
@testable import Typesense | ||
|
||
final class StopwordsTests: XCTestCase { | ||
override func tearDown() async throws { | ||
try! await tearDownStopwords() | ||
} | ||
|
||
func testStopwordsUpsert() async { | ||
let schema = StopwordsSetUpsertSchema( | ||
stopwords: ["states","united"], | ||
locale: "en" | ||
) | ||
do { | ||
let (result, _) = try await client.stopwords().upsert(stopwordsSetId: "test-id", params: schema) | ||
XCTAssertNotNil(result) | ||
guard let validResult = result else { | ||
throw DataError.dataNotFound | ||
} | ||
print(validResult) | ||
XCTAssertEqual("test-id", validResult._id) | ||
XCTAssertEqual(["states","united"], validResult.stopwords) | ||
XCTAssertEqual("en", validResult.locale) | ||
} catch (let error) { | ||
print(error.localizedDescription) | ||
XCTAssertTrue(false) | ||
} | ||
} | ||
|
||
func testStopwordsRetrieveAll() async { | ||
try! await createStopwordSet() | ||
do { | ||
let (result, _) = try await client.stopwords().retrieve() | ||
guard let validResult = result else { | ||
throw DataError.dataNotFound | ||
} | ||
print(validResult) | ||
XCTAssertEqual(1, validResult.count) | ||
XCTAssertEqual("test-id-stopword-set", validResult[0]._id) | ||
} catch (let error) { | ||
print(error) | ||
XCTAssertTrue(false) | ||
} | ||
} | ||
|
||
} |
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