fix
This commit is contained in:
parent
a6669b9b2d
commit
d72e7ab1db
@ -15,4 +15,8 @@ public struct URLS {
|
||||
static let login = "users/auth-with-password"
|
||||
static let getIdToken = "_authOrigins/records"
|
||||
static let deleteUser = "_authOrigins/records/"
|
||||
static let news = "news/records"
|
||||
static let infoProduct = "products/records/"
|
||||
static let products = "products/records"
|
||||
static let projects = "project/records"
|
||||
}
|
||||
|
43
Sources/NetworkApi/Models/ServerNewsResponse.swift
Normal file
43
Sources/NetworkApi/Models/ServerNewsResponse.swift
Normal file
@ -0,0 +1,43 @@
|
||||
//
|
||||
// File.swift
|
||||
// NetworkApi
|
||||
//
|
||||
// Created by User on 27.05.2025.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
//{
|
||||
// "items": [
|
||||
// {
|
||||
// "collectionId": "pbc_2599178718",
|
||||
// "collectionName": "News",
|
||||
// "created": "2025-05-26 14:21:46.284Z",
|
||||
// "id": "yxe08bp4woz996w",
|
||||
// "newsImage": "banner_u9uqsy4sf9.png",
|
||||
// "updated": "2025-05-26 15:29:41.083Z"
|
||||
// },
|
||||
// {
|
||||
// "collectionId": "pbc_2599178718",
|
||||
// "collectionName": "News",
|
||||
// "created": "2025-05-26 15:29:50.831Z",
|
||||
// "id": "lqg3hpgn46efgmz",
|
||||
// "newsImage": "banner_2_10pjar2fq7.png",
|
||||
// "updated": "2025-05-26 15:29:50.831Z"
|
||||
// }
|
||||
// ],
|
||||
// "page": 1,
|
||||
// "perPage": 30,
|
||||
// "totalItems": 2,
|
||||
// "totalPages": 1
|
||||
//}
|
||||
|
||||
public struct ServerNewsResponse: Decodable {
|
||||
public let items: [News]
|
||||
|
||||
public struct News: Decodable {
|
||||
public let newsImage: String
|
||||
}
|
||||
}
|
||||
|
||||
|
34
Sources/NetworkApi/Models/ServerProductInfoResponse.swift
Normal file
34
Sources/NetworkApi/Models/ServerProductInfoResponse.swift
Normal file
@ -0,0 +1,34 @@
|
||||
//
|
||||
// File.swift
|
||||
// NetworkApi
|
||||
//
|
||||
// Created by User on 27.05.2025.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
//{
|
||||
// "approximate_cost": "10-50",
|
||||
// "collectionId": "pbc_4092854851",
|
||||
// "collectionName": "products",
|
||||
// "created": "2025-05-26 15:43:11.113Z",
|
||||
// "description": "Пряжу 1400-1500м в 100г в 4 сложения, пряжу 700м в 2 сложения. Ориентир для конечной толщины – 300-350м в 100г.\r\nАртикулы, из которых мы вязали эту модель: Zermatt Zegna Baruffa, Cashfive, Baby Cashmere Loro Piana, Soft Donegal и другие.\r\nПримерный расход на шапку с подгибом 70-90г.",
|
||||
// "id": "411s42fl33008kt",
|
||||
// "price": 300,
|
||||
// "title": "Шорты вторник для машинного \r\nвязания",
|
||||
// "type": "Мужская одежда",
|
||||
// "typeCloses": "Мужчинам",
|
||||
// "updated": "2025-05-26 15:44:26.525Z"
|
||||
//}
|
||||
|
||||
|
||||
public struct ServerProductInfoResponse: Decodable {
|
||||
public let approximate_cost: String
|
||||
public let collectionName: String
|
||||
public let description: String
|
||||
public let id: String
|
||||
public let title: String
|
||||
public let price: String
|
||||
public let type: String
|
||||
public let typeCloses: String
|
||||
}
|
27
Sources/NetworkApi/Models/ServerProductsResponse.swift
Normal file
27
Sources/NetworkApi/Models/ServerProductsResponse.swift
Normal file
@ -0,0 +1,27 @@
|
||||
//
|
||||
// File.swift
|
||||
// NetworkApi
|
||||
//
|
||||
// Created by User on 27.05.2025.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
//{
|
||||
// "approximate_cost": "10-50",
|
||||
// "collectionId": "pbc_4092854851",
|
||||
// "collectionName": "products",
|
||||
// "created": "2025-05-26 15:43:11.113Z",
|
||||
// "description": "Пряжу 1400-1500м в 100г в 4 сложения, пряжу 700м в 2 сложения. Ориентир для конечной толщины – 300-350м в 100г.\r\nАртикулы, из которых мы вязали эту модель: Zermatt Zegna Baruffa, Cashfive, Baby Cashmere Loro Piana, Soft Donegal и другие.\r\nПримерный расход на шапку с подгибом 70-90г.",
|
||||
// "id": "411s42fl33008kt",
|
||||
// "price": 300,
|
||||
// "title": "Шорты вторник для машинного \r\nвязания",
|
||||
// "type": "Мужская одежда",
|
||||
// "typeCloses": "Мужчинам",
|
||||
// "updated": "2025-05-26 15:44:26.525Z"
|
||||
//}
|
||||
|
||||
public struct ServerProductsResponse: Decodable {
|
||||
public let items: [ServerProductInfoResponse]
|
||||
|
||||
}
|
48
Sources/NetworkApi/Models/ServerProjectsResponse.swift
Normal file
48
Sources/NetworkApi/Models/ServerProjectsResponse.swift
Normal file
@ -0,0 +1,48 @@
|
||||
//
|
||||
// File.swift
|
||||
// NetworkApi
|
||||
//
|
||||
// Created by User on 27.05.2025.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
//{
|
||||
// "page": 0,
|
||||
// "perPage": 0,
|
||||
// "totalPages": 0,
|
||||
// "totalItems": 0,
|
||||
// "items": [
|
||||
// {
|
||||
// "id": "string",
|
||||
// "collectionId": "string",
|
||||
// "collectionName": "string",
|
||||
// "created": "string",
|
||||
// "updated": "string",
|
||||
// "title": "string",
|
||||
// "dateStart": "string",
|
||||
// "dateEnd": "string",
|
||||
// "gender": "string",
|
||||
// "description_source": "string",
|
||||
// "category": "string",
|
||||
// "image": "string",
|
||||
// "user_id": "string"
|
||||
// }
|
||||
// ]
|
||||
//}
|
||||
|
||||
public struct ServerProjectsResponse: Decodable {
|
||||
public let items: [ProjectsResponse]
|
||||
|
||||
public struct ProjectsResponse: Decodable {
|
||||
public let approximate_cost: String
|
||||
public let collectionName: String
|
||||
public let description: String
|
||||
public let id: String
|
||||
public let title: String
|
||||
public let price: String
|
||||
public let type: String
|
||||
public let typeCloses: String
|
||||
}
|
||||
|
||||
}
|
36
Sources/NetworkApi/Models/ServerResponseUserInfo.swift
Normal file
36
Sources/NetworkApi/Models/ServerResponseUserInfo.swift
Normal file
@ -0,0 +1,36 @@
|
||||
//
|
||||
// File.swift
|
||||
// NetworkApi
|
||||
//
|
||||
// Created by User on 27.05.2025.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
//{
|
||||
// "collectionId": "string",
|
||||
// "collectionName": "string",
|
||||
// "created": "string",
|
||||
// "emailVisibility": true,
|
||||
// "firstname": "string",
|
||||
// "id": "string",
|
||||
// "lastname": "string",
|
||||
// "secondname": "string",
|
||||
// "updated": "string",
|
||||
// "verified": true,
|
||||
// "datebirthday": "string",
|
||||
// "gender": "string"
|
||||
//}
|
||||
|
||||
public struct ServerResponseUserInfo: Decodable {
|
||||
public let collectionId: String
|
||||
public let collectionName: String
|
||||
public let created: String
|
||||
public let firstname: String
|
||||
public let gender: String
|
||||
public let id: String
|
||||
public let lastname: String
|
||||
public let secondname: String
|
||||
public let dateBirthday: String
|
||||
public let updated: String
|
||||
}
|
@ -62,5 +62,10 @@ public final class NetworkUser: NetworkUserProtocol {
|
||||
let data = try await baseUrl.execute(path: URLS.deleteUser, method: .delete, headers: Headers.headerWithToken(token: token), parameters: ["id_token":idToken])
|
||||
}
|
||||
|
||||
public func getUserInfo(idUser: String) async throws -> ServerResponseUserInfo {
|
||||
let data = try await baseUrl.execute(path: URLS.getUserInfo, method: .get, headers: Headers.headers(), parameters: nil)
|
||||
return try JSONDecoder().decode(ServerResponseUserInfo.self, from: data)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -13,4 +13,5 @@ public protocol NetworkUserProtocol {
|
||||
func addUser(idUser: String, email: String, firstname: String, lastname: String, secondname: String, datebirthday: String, gender: String, token: String) async throws -> ServerResponseRegister
|
||||
func getIdToken(token: String) async throws -> String
|
||||
func deleteUser(idToken: String, token: String) async throws
|
||||
func getUserInfo(idUser: String) async throws -> ServerResponseUserInfo
|
||||
}
|
||||
|
@ -0,0 +1,38 @@
|
||||
//
|
||||
// File.swift
|
||||
// NetworkApi
|
||||
//
|
||||
// Created by User on 27.05.2025.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public final class NetworkProjects: NetworkProjectsProtocol {
|
||||
|
||||
let baseUrl: BaseNetworkServiceProtocol //Create request
|
||||
|
||||
public init(baseUrl: BaseNetworkServiceProtocol) {
|
||||
self.baseUrl = baseUrl
|
||||
}
|
||||
|
||||
public func getProjects(token: String) async throws -> ServerProjectsResponse {
|
||||
let data = try await baseUrl.execute(path: URLS.products, method: .get, headers: Headers.headerWithToken(token: token), parameters: nil)
|
||||
return try JSONDecoder().decode(ServerProjectsResponse.self, from: data)
|
||||
}
|
||||
|
||||
public func createProject(token: String, title: String, typeProject: String, user_id: String, dateStart: String, dateEnd:String, gender:String, description_source: String, category: String, image: String) async throws {
|
||||
|
||||
let data = try await baseUrl.execute(path: URLS.projects, method: .post, headers: Headers.headerWithToken(token: token), parameters: [
|
||||
"title": title,
|
||||
"typeProject": typeProject,
|
||||
"user_id": user_id,
|
||||
"dateStart": dateStart,
|
||||
"dateEnd": dateEnd,
|
||||
"gender": gender,
|
||||
"description_source": description_source,
|
||||
"category": category,
|
||||
"image": image
|
||||
])
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
//
|
||||
// File.swift
|
||||
// NetworkApi
|
||||
//
|
||||
// Created by User on 27.05.2025.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public protocol NetworkProjectsProtocol {
|
||||
func getProjects(token: String) async throws -> ServerProjectsResponse
|
||||
func createProject(token: String, title: String, typeProject: String, user_id: String, dateStart: String, dateEnd:String, gender:String, description_source: String, category: String, image: String) async throws
|
||||
}
|
33
Sources/NetworkApi/NetworkLayer/Shop/NetworkShop.swift
Normal file
33
Sources/NetworkApi/NetworkLayer/Shop/NetworkShop.swift
Normal file
@ -0,0 +1,33 @@
|
||||
//
|
||||
// File.swift
|
||||
// NetworkApi
|
||||
//
|
||||
// Created by User on 27.05.2025.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public final class NetworkShop: NetworkShopProtocol {
|
||||
|
||||
let baseUrl: BaseNetworkServiceProtocol //Create request
|
||||
|
||||
public init(baseUrl: BaseNetworkServiceProtocol) {
|
||||
self.baseUrl = baseUrl
|
||||
}
|
||||
|
||||
public func news(token: String) async throws -> ServerNewsResponse {
|
||||
let data = try await baseUrl.execute(path: URLS.news, method: .get, headers: Headers.headerWithToken(token: token), parameters: nil)
|
||||
return try JSONDecoder().decode(ServerNewsResponse.self, from: data)
|
||||
}
|
||||
|
||||
public func getInfoProduct(productID: String, token: String) async throws -> ServerProductInfoResponse {
|
||||
let data = try await baseUrl.execute(path: URLS.infoProduct + productID, method: .get, headers: Headers.headerWithToken(token: token), parameters: nil)
|
||||
return try JSONDecoder().decode(ServerProductInfoResponse.self, from: data)
|
||||
}
|
||||
|
||||
public func getProducts(token: String) async throws -> ServerProductsResponse {
|
||||
let data = try await baseUrl.execute(path: URLS.products, method: .get, headers: Headers.headerWithToken(token: token), parameters: nil)
|
||||
return try JSONDecoder().decode(ServerProductsResponse.self, from: data)
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
//
|
||||
// File.swift
|
||||
// NetworkApi
|
||||
//
|
||||
// Created by User on 27.05.2025.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public protocol NetworkShopProtocol {
|
||||
func news(token: String) async throws -> ServerNewsResponse
|
||||
func getInfoProduct(productID: String, token: String) async throws -> ServerProductInfoResponse
|
||||
func getProducts(token: String) async throws -> ServerProductsResponse
|
||||
}
|
@ -9,4 +9,81 @@ final class NetworkApiTests: XCTestCase {
|
||||
// Defining Test Cases and Test Methods
|
||||
// https://developer.apple.com/documentation/xctest/defining_test_cases_and_test_methods
|
||||
}
|
||||
|
||||
func testTrueLogin() async throws {
|
||||
var baseURL: BaseNetworkService {
|
||||
let service = BaseNetworkService()
|
||||
service.baseURL = URLS.baseURL
|
||||
return service
|
||||
}
|
||||
let netwrokApi = NetworkUser(baseUrl: baseURL)
|
||||
|
||||
let data = try await netwrokApi.login(identity: "eeeeexample@test.ru", password: "string12")
|
||||
|
||||
XCTAssertTrue(data.token != "")
|
||||
|
||||
}
|
||||
func testFalseLogin() async throws {
|
||||
var baseURL: BaseNetworkService {
|
||||
let service = BaseNetworkService()
|
||||
service.baseURL = URLS.baseURL
|
||||
return service
|
||||
}
|
||||
let netwrokApi = NetworkUser(baseUrl: baseURL)
|
||||
|
||||
let data = try await netwrokApi.login(identity: "eeeeex2ample@test.ru", password: "string12")
|
||||
|
||||
XCTAssertFalse(data.token != "")
|
||||
|
||||
}
|
||||
|
||||
func testSuccessRegister() async throws {
|
||||
var baseURL: BaseNetworkService {
|
||||
let service = BaseNetworkService()
|
||||
service.baseURL = URLS.baseURL
|
||||
return service
|
||||
}
|
||||
let netwrokApi = NetworkUser(baseUrl: baseURL)
|
||||
|
||||
let random = ["1","2","3","4","5","6","7","8","9", "10", "23"]
|
||||
|
||||
let email = random.joined() + "example@test.ru"
|
||||
|
||||
let data = try await netwrokApi.register(email: email, password: "register1234", passwordConfirm: "register1234", firstname: "Name", lastname: "Name", secondname: "Name", datebirthday: "", gender: "")
|
||||
|
||||
XCTAssertTrue(!data.id.isEmpty)
|
||||
|
||||
}
|
||||
|
||||
func testSuccessNews() async throws {
|
||||
|
||||
var baseURL: BaseNetworkService {
|
||||
let service = BaseNetworkService()
|
||||
service.baseURL = URLS.baseURL
|
||||
return service
|
||||
}
|
||||
let netwrokApi = NetworkShop(baseUrl: baseURL)
|
||||
|
||||
let data = try await netwrokApi.news(token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjb2xsZWN0aW9uSWQiOiJfcGJfdXNlcnNfYXV0aF8iLCJleHAiOjE3NDg5MzY3NzcsImlkIjoiZXUyOHgxMWthbnEwOG0yIiwicmVmcmVzaGFibGUiOnRydWUsInR5cGUiOiJhdXRoIn0.H-q53wd7Y7xVlZpYfktfi8ekpxx_DJyobxCVIlLvLTo")
|
||||
|
||||
XCTAssertTrue(!data.items.isEmpty)
|
||||
|
||||
}
|
||||
|
||||
func testFailedNews() async throws {
|
||||
|
||||
var baseURL: BaseNetworkService {
|
||||
let service = BaseNetworkService()
|
||||
service.baseURL = URLS.baseURL
|
||||
return service
|
||||
}
|
||||
let netwrokApi = NetworkShop(baseUrl: baseURL)
|
||||
|
||||
let data = try await netwrokApi.news(token: "")
|
||||
|
||||
XCTAssertTrue(data.items.isEmpty)
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user