Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
41788c6
restructure project and add json sample files
Jan 28, 2023
faeb4e7
gitignore added
Jan 28, 2023
54641a6
Delete .DS_Store
farzaneh-Givehchian Jan 28, 2023
6464118
swiftlint added
Jan 28, 2023
89d2f8b
Merge branch 'master' of https://github.com/farzaneh-Givehchian/tech-…
Jan 28, 2023
711a806
network layer and models added
Jan 28, 2023
bde9ab1
network layer and models added
Jan 28, 2023
77468aa
mock service added
Jan 28, 2023
ebbf363
constant file added
Jan 28, 2023
b34944b
image model and extensions added
Jan 28, 2023
4ad0e58
image helper added
Jan 28, 2023
a9bf539
fixed lint of imageloader
Jan 28, 2023
76eca12
base protocol added
Jan 28, 2023
b0c976f
movie scene added
Jan 28, 2023
13947bb
movie detail added
Jan 28, 2023
8dbcc84
loadable json test added
Jan 28, 2023
b208d03
executer test added
Jan 28, 2023
44b1bb1
Test FailExecuter added
Jan 28, 2023
6eaff7e
viewcontroller test added
Jan 28, 2023
82e3247
add cache to network layer
Jan 28, 2023
147b13d
stringdict added for localization
Jan 28, 2023
aebabe7
timeout added to network layer
Jan 28, 2023
f889cdc
logger added to network layer
Jan 28, 2023
2a0f00d
favorite storage added
Jan 28, 2023
d104998
favorite storage model changed to list
Jan 28, 2023
7525556
favorite storage and its test added
Jan 29, 2023
bd5c26f
favorite scene added
Jan 29, 2023
c81f0b3
layout changed
Jan 29, 2023
0963b1b
colors added both for light and dark
Jan 29, 2023
c2f6a09
uiimage extension added
Jan 29, 2023
b6654b9
viewModel test added
Jan 29, 2023
06e5213
constant added
Jan 29, 2023
daaafc6
detail data fixed
Jan 29, 2023
d6f1c04
sync function added
Jan 29, 2023
ccc21bb
add header to list
Jan 29, 2023
a805839
add constant
Jan 29, 2023
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
Prev Previous commit
Next Next commit
favorite storage added
  • Loading branch information
Farzaneh committed Jan 28, 2023
commit 2a0f00dbb363864c9c68caec29cc449a92663ccd
8 changes: 8 additions & 0 deletions DarsayTechTest.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
EE2293C32985859F0077B40D /* LocalizeHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE2293C22985859F0077B40D /* LocalizeHelper.swift */; };
EE2293C5298594AA0077B40D /* LoggerHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE2293C4298594AA0077B40D /* LoggerHelper.swift */; };
EE2293C7298595F20077B40D /* Data.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE2293C6298595F20077B40D /* Data.swift */; };
EE2293C929859F100077B40D /* StorageHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE2293C829859F100077B40D /* StorageHelper.swift */; };
EE2293CB2985AA330077B40D /* StorageTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE2293CA2985AA330077B40D /* StorageTest.swift */; };
EEB43ADC29850E4000DF5CAD /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEB43ADB29850E4000DF5CAD /* AppDelegate.swift */; };
EEB43ADE29850E4000DF5CAD /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEB43ADD29850E4000DF5CAD /* SceneDelegate.swift */; };
EEB43AE529850E4100DF5CAD /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = EEB43AE429850E4100DF5CAD /* Assets.xcassets */; };
Expand Down Expand Up @@ -115,6 +117,8 @@
EE2293C22985859F0077B40D /* LocalizeHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocalizeHelper.swift; sourceTree = "<group>"; };
EE2293C4298594AA0077B40D /* LoggerHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoggerHelper.swift; sourceTree = "<group>"; };
EE2293C6298595F20077B40D /* Data.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Data.swift; sourceTree = "<group>"; };
EE2293C829859F100077B40D /* StorageHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StorageHelper.swift; sourceTree = "<group>"; };
EE2293CA2985AA330077B40D /* StorageTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StorageTest.swift; sourceTree = "<group>"; };
EEB43AD829850E4000DF5CAD /* DarsayTechTest.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = DarsayTechTest.app; sourceTree = BUILT_PRODUCTS_DIR; };
EEB43ADB29850E4000DF5CAD /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
EEB43ADD29850E4000DF5CAD /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -203,6 +207,7 @@
EE1A9EC929851F9800E4F9EF /* ImageLoader.swift */,
EE2293C22985859F0077B40D /* LocalizeHelper.swift */,
EE2293C4298594AA0077B40D /* LoggerHelper.swift */,
EE2293C829859F100077B40D /* StorageHelper.swift */,
);
path = Helper;
sourceTree = "<group>";
Expand Down Expand Up @@ -254,6 +259,7 @@
EE1A9EEC298529A300E4F9EF /* LoadableJSONTest.swift */,
EE1A9EEE29852A7300E4F9EF /* ExecuterTest.swift */,
EEB43AF229850E4100DF5CAD /* ViewControllerTest.swift */,
EE2293CA2985AA330077B40D /* StorageTest.swift */,
);
path = DarsayTechTestTests;
sourceTree = "<group>";
Expand Down Expand Up @@ -561,6 +567,7 @@
EEB43ADE29850E4000DF5CAD /* SceneDelegate.swift in Sources */,
EE1A9EB729851B3800E4F9EF /* ResultList.swift in Sources */,
EE1A9EB929851B4E00E4F9EF /* Movie.swift in Sources */,
EE2293C929859F100077B40D /* StorageHelper.swift in Sources */,
EE1A9EDA2985210700E4F9EF /* MovieTopRatedView.swift in Sources */,
EE1A9EB029851A6200E4F9EF /* MovieServiceEndPoint.swift in Sources */,
EE1A9ED8298520D600E4F9EF /* MovieListViewModel.swift in Sources */,
Expand Down Expand Up @@ -596,6 +603,7 @@
EE1A9EEF29852A7300E4F9EF /* ExecuterTest.swift in Sources */,
EE1A9EF129852AD200E4F9EF /* MockExecuter.swift in Sources */,
EEB43AF329850E4100DF5CAD /* ViewControllerTest.swift in Sources */,
EE2293CB2985AA330077B40D /* StorageTest.swift in Sources */,
EE1A9EBD29851CAB00E4F9EF /* MockService.swift in Sources */,
EE1A9EED298529A300E4F9EF /* LoadableJSONTest.swift in Sources */,
);
Expand Down
Binary file not shown.
45 changes: 45 additions & 0 deletions DarsayTechTest/Helper/StorageHelper.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//
// StorageHelper.swift
// DarsayTechTest
//
// Created by Farzaneh on 11/8/1401 AP.
//

import Foundation

protocol StorageProtocol {

associatedtype StoredObject: Codable

func setObject(for key: String, object: StoredObject)
func getObject(by key: String) -> StoredObject?
func remove(key: String)
}

extension StorageProtocol {

func setObject(for key: String, object: StoredObject) {
let data = try? JSONEncoder().encode(object)
UserDefaults.standard.set(data, forKey: key)
}

func getObject(by key: String) -> StoredObject? {
guard let data = UserDefaults.standard.object(forKey: key) as? Data else {
return nil
}

let value = try? JSONDecoder().decode(StoredObject.self, from: data)
return value
}

func remove(key: String) {
UserDefaults.standard.removeObject(forKey: key)
}
}

final class FavoriteStorage: StorageProtocol {
typealias StoredObject = Movie

static let shared = FavoriteStorage()

}
2 changes: 1 addition & 1 deletion DarsayTechTest/Models/Networking Models/Movie.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

struct Movie: Codable {
struct Movie: Codable, Hashable {
let adult: Bool
let backdropPath: String
let genreIDS: [Int]?
Expand Down
55 changes: 55 additions & 0 deletions DarsayTechTestTests/StorageTest.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//
// StorageTest.swift
// DarsayTechTestTests
//
// Created by Farzaneh on 11/8/1401 AP.
//

import Foundation
import Combine
import XCTest
@testable import DarsayTechTest

final class StorageTest: XCTestCase {

override func setUpWithError() throws {
// Put setup code here. This method is called before the invocation of each test method in the class.
}

override func tearDownWithError() throws {
// Put teardown code here. This method is called after the invocation of each test method in the class.
}

func testStorage() {

let mockService = MockService()
var cancellables = Set<AnyCancellable>()

mockService.getPopularMovies().sinkToResult { result in

switch result {
case .success(let list):
XCTAssertEqual(list.results.count, 1)

guard let firstMovie = list.results.first else {
return XCTFail("load json failed")
}

FavoriteStorage.shared.setObject(for: "popular", object: firstMovie)

var retreivedObject = FavoriteStorage.shared.getObject(by: "popular")

XCTAssertEqual(firstMovie, retreivedObject)

FavoriteStorage.shared.remove(key: "popular")

retreivedObject = FavoriteStorage.shared.getObject(by: "popular")

XCTAssertNil(retreivedObject)

case .failure(let error):
XCTFail(error.localizedDescription)
}
}.store(in: &cancellables)
}
}