Skip to content

Statistics/epic statistic 2 3 #47

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
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
248 changes: 224 additions & 24 deletions FakeNFT.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions FakeNFT/Foundation/MemoryStorage/Statistc/NftNetworkStorage.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import Foundation

protocol NftNetworkStorage: AnyObject {
func saveNft(_ nft: NftModel)
func getNft(with id: String) -> NftModel?
}

final class NftNetworkStorageImpl: NftNetworkStorage {
private var storage: [String: NftModel] = [:]

private let syncQueue = DispatchQueue(label: "sync-nftNetwork-queue")

func saveNft(_ nft: NftModel) {
DispatchQueue.main.async {
self.storage[nft.id] = nft
}
}

func getNft(with id: String) -> NftModel? {
DispatchQueue.global(qos: .userInitiated).sync {
return storage[id]
}
}
}
17 changes: 13 additions & 4 deletions FakeNFT/Foundation/NetworkClient/NetworkClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,11 @@ struct DefaultNetworkClient: NetworkClient {
}
}
guard let urlRequest = create(request: request) else { return nil }

let task = session.dataTask(with: urlRequest) { data, response, error in
guard let response = response as? HTTPURLResponse else {
onResponse(.failure(NetworkClientError.urlSessionError))
return
}

guard 200 ..< 300 ~= response.statusCode else {
onResponse(.failure(NetworkClientError.httpStatusCode(response.statusCode)))
return
Expand Down Expand Up @@ -120,10 +118,20 @@ struct DefaultNetworkClient: NetworkClient {

if let dto = request.dto,
let dtoEncoded = try? encoder.encode(dto) {
urlRequest.setValue("application/json", forHTTPHeaderField: "Content-Type")
urlRequest
.setValue("application/json",
forHTTPHeaderField: "Accept")
urlRequest.httpBody = dtoEncoded
}


if (request.isUrlEncoded) {
urlRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
}

let token = "107f0274-8faf-4343-b31f-c12b62673e2f"
urlRequest
.setValue("\(token)",
forHTTPHeaderField: "X-Practicum-Mobile-Token")
return urlRequest
}

Expand All @@ -132,6 +140,7 @@ struct DefaultNetworkClient: NetworkClient {
let response = try decoder.decode(T.self, from: data)
onResponse(.success(response))
} catch {
print(error)
onResponse(.failure(NetworkClientError.parsingError))
}
}
Expand Down
3 changes: 3 additions & 0 deletions FakeNFT/Foundation/NetworkClient/NetworkRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ protocol NetworkRequest {
var endpoint: URL? { get }
var httpMethod: HttpMethod { get }
var dto: Encodable? { get }
var putHeader: String? { get }
var isUrlEncoded: Bool { get }
}

// default values
extension NetworkRequest {
var httpMethod: HttpMethod { .get }
var dto: Encodable? { nil }
var putHeader: String? { nil }
}
6 changes: 6 additions & 0 deletions FakeNFT/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>UIAppFonts</key>
<array>
<string>SFProText-Regular.ttf</string>
<string>SFProText-Medium.ttf</string>
<string>SFProText-Bold.ttf</string>
</array>
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
Expand Down
19 changes: 19 additions & 0 deletions FakeNFT/Models/CollectionViewParams.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import Foundation

struct GeometricParams {
let heightCell: CGFloat
let cellCount: Int
let leftInset: CGFloat
let rightInset: CGFloat
let cellSpacing: CGFloat
let paddingWidth: CGFloat

init(heightCell: CGFloat, cellCount: Int, leftInset: CGFloat, rightInset: CGFloat, cellSpacing: CGFloat) {
self.heightCell = heightCell
self.cellCount = cellCount
self.leftInset = leftInset
self.rightInset = rightInset
self.cellSpacing = cellSpacing
self.paddingWidth = leftInset + rightInset + CGFloat(cellCount - 1) * cellSpacing
}
}
16 changes: 16 additions & 0 deletions FakeNFT/Models/Network/LeaderBoardModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import Foundation

struct UsersModel: Decodable {

let id: String
let name: String
let avatar: String
let rating: String
let website: String
let nfts: [String]
let description: String

func getRating() -> Int {
Int(rating) ?? 0
}
}
13 changes: 13 additions & 0 deletions FakeNFT/Models/Network/NftModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Foundation

struct NftModel: Decodable {

let id: String
let name: String
let images: [URL?]
let price: Float
let rating: Int
let createdAt: String
let description: String
let author: String
}
10 changes: 10 additions & 0 deletions FakeNFT/Models/Network/ProfileModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Foundation

struct ProfileModel: Decodable {
let id: String
let name: String
let avatar: URL
let description: String
let website: URL
let countOfNft: Int
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"images" : [
{
"filename" : "[email protected]",
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
Expand Down
6 changes: 6 additions & 0 deletions FakeNFT/Resources/Assets.xcassets/Icons/Cart/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "Property 1=Add.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "Property [email protected]",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "Property [email protected]",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "Cart.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
6 changes: 6 additions & 0 deletions FakeNFT/Resources/Assets.xcassets/Icons/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
6 changes: 6 additions & 0 deletions FakeNFT/Resources/Assets.xcassets/Icons/NFTCard/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "Active.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "No Active.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "No [email protected]",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "No [email protected]",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "backward.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading