-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/add coin information to detail page #93
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
Merged
meryemmsahin
merged 6 commits into
develop
from
feature/add_coin_information_to_detail_page
Jul 26, 2023
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0529924
added coin news endpoint
meryemmsahin 03bde36
added view model / created NavigationView for detailView page
meryemmsahin 379a6ac
change chart size
meryemmsahin 3c36330
add coin news list page
meryemmsahin ff4e308
add webView indicator
meryemmsahin f036bf2
Merge branch 'develop' into feature/add_coin_information_to_detail_page
meryemmsahin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
24 changes: 24 additions & 0 deletions
24
SampleAppSwiftUI/Network/RemoteDataSources/CoinNewsDataSource.swift
This file contains hidden or 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,24 @@ | ||
// | ||
// CoinNewsDataSource.swift | ||
// SampleAppSwiftUI | ||
// | ||
// Created by Meryem Şahin on 20.07.2023. | ||
// | ||
|
||
import Foundation | ||
|
||
protocol CoinNewsRemoteDataSourceProtocol { | ||
func getCoinNews(coinCode: String) async throws -> CoinNewsResponse | ||
} | ||
|
||
class CoinNewsRemoteDataSource: CoinNewsRemoteDataSourceProtocol { | ||
let coinNewsService: CoinNewsServiceProtocol | ||
|
||
init(coinNewsService: CoinNewsServiceProtocol = WebServiceProvider.shared.coinNewsService) { | ||
self.coinNewsService = coinNewsService | ||
} | ||
|
||
func getCoinNews(coinCode: String) async throws -> CoinNewsResponse { | ||
try await coinNewsService.coinNewsRequest(coinCode: coinCode) | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
SampleAppSwiftUI/Network/ResponseModels/CoinNewsResponse.swift
This file contains hidden or 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 @@ | ||
// | ||
// CoinNewsResponse.swift | ||
// SampleAppSwiftUI | ||
// | ||
// Created by Meryem Şahin on 20.07.2023. | ||
// | ||
|
||
import Foundation | ||
|
||
struct CoinNewsResponse: Codable, Hashable, Identifiable { | ||
var id = UUID() | ||
let type: Int | ||
let message: String | ||
let data: [CoinNewData]? | ||
let hasWarning: Bool | ||
|
||
enum CodingKeys: String, CodingKey { | ||
case type = "Type" | ||
case message = "Message" | ||
case data = "Data" | ||
case hasWarning = "HasWarning" | ||
} | ||
} | ||
|
||
// MARK: - Datum | ||
struct CoinNewData: Codable, Hashable, Identifiable { | ||
let id: String | ||
let imageurl: String | ||
let title: String | ||
let url: String | ||
let body: String | ||
let source: String | ||
|
||
enum CodingKeys: String, CodingKey { | ||
case id | ||
case imageurl, title, url, body | ||
case source | ||
} | ||
} |
This file contains hidden or 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,24 @@ | ||
// | ||
// CoinNewsUseCase.swift | ||
// SampleAppSwiftUI | ||
// | ||
// Created by Meryem Şahin on 20.07.2023. | ||
// | ||
|
||
import Foundation | ||
|
||
protocol CoinNewsUseCaseProtocol { | ||
func getCoinNews(coinCode: String) async throws -> CoinNewsResponse | ||
} | ||
|
||
class CoinNewsUseCase: CoinNewsUseCaseProtocol { | ||
let coinNewsRepository: CoinNewsRepositoryProtocol | ||
|
||
init(coinNewsRepository: CoinNewsRepositoryProtocol = CoinNewsRepository()) { | ||
self.coinNewsRepository = coinNewsRepository | ||
} | ||
|
||
func getCoinNews(coinCode: String) async throws -> CoinNewsResponse { | ||
try await coinNewsRepository.getCoinNews(coinCode: coinCode) | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
SampleAppSwiftUI/Network/WebServiceRepositories/CoinNewsRepository.swift
This file contains hidden or 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,24 @@ | ||
// | ||
// CoinNewsRepository.swift | ||
// SampleAppSwiftUI | ||
// | ||
// Created by Meryem Şahin on 20.07.2023. | ||
// | ||
|
||
import Foundation | ||
|
||
protocol CoinNewsRepositoryProtocol { | ||
func getCoinNews(coinCode: String) async throws -> CoinNewsResponse | ||
} | ||
|
||
class CoinNewsRepository: CoinNewsRepositoryProtocol { | ||
let coinNewsRemoteDataSource: CoinNewsRemoteDataSourceProtocol | ||
|
||
init(coinNewsRemoteDataSource: CoinNewsRemoteDataSourceProtocol = CoinNewsRemoteDataSource()) { | ||
self.coinNewsRemoteDataSource = coinNewsRemoteDataSource | ||
} | ||
|
||
func getCoinNews(coinCode: String) async throws -> CoinNewsResponse { | ||
try await coinNewsRemoteDataSource.getCoinNews(coinCode: coinCode) | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
SampleAppSwiftUI/Network/WebServices/CoinNewsService/CoinNewsService.swift
This file contains hidden or 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,27 @@ | ||
// | ||
// CoinNewsService.swift | ||
// SampleAppSwiftUI | ||
// | ||
// Created by Meryem Şahin on 20.07.2023. | ||
// | ||
|
||
import Foundation | ||
|
||
protocol CoinNewsServiceProtocol { | ||
func coinNewsRequest(coinCode: String) async throws -> CoinNewsResponse | ||
} | ||
|
||
final class CoinNewsService: CoinNewsServiceProtocol, BaseServiceProtocol { | ||
typealias Endpoint = CoinNewsServiceEndpoint | ||
|
||
var networkLoader: NetworkLoaderProtocol | ||
|
||
init(networkLoader: NetworkLoaderProtocol = NetworkLoaderProvider.shared.networkLoader) { | ||
self.networkLoader = networkLoader | ||
} | ||
|
||
func coinNewsRequest(coinCode: String) async throws -> CoinNewsResponse { | ||
let urlString = build(endpoint: .coinNews(coinCode: coinCode)) | ||
return try await request(with: RequestObject(url: urlString), responseModel: CoinNewsResponse.self) | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
SampleAppSwiftUI/Network/WebServices/CoinNewsService/CoinNewsServiceEndpoint.swift
This file contains hidden or 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,24 @@ | ||
// | ||
// CoinNewsServiceEndpoint.swift | ||
// SampleAppSwiftUI | ||
// | ||
// Created by Meryem Şahin on 20.07.2023. | ||
// | ||
|
||
import Foundation | ||
|
||
enum CoinNewsServiceEndpoint: TargetEndpointProtocol { | ||
|
||
case coinNews(coinCode: String) | ||
|
||
private struct Constants { | ||
static let coinNewsEndpoint = "v2/news/?categories=%@&api_key=%@" | ||
} | ||
|
||
var path: String { | ||
switch self { | ||
case .coinNews(coinCode: let coinCode): | ||
return BaseEndpoint.base.path + String(format: Constants.coinNewsEndpoint, coinCode, Configuration.coinApiKey) | ||
} | ||
} | ||
} |
This file contains hidden or 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 hidden or 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
21 changes: 21 additions & 0 deletions
21
SampleAppSwiftUI/Resources/Images.xcassets/world-news.imageset/Contents.json
This file contains hidden or 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 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"filename" : "world-news.png", | ||
"idiom" : "universal", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"idiom" : "universal", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"idiom" : "universal", | ||
"scale" : "3x" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
Binary file added
BIN
+23.3 KB
SampleAppSwiftUI/Resources/Images.xcassets/world-news.imageset/world-news.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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 hidden or 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
58 changes: 58 additions & 0 deletions
58
SampleAppSwiftUI/Scenes/Home/Coin/Detail/CoinNews/CoinNewsListView.swift
This file contains hidden or 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,58 @@ | ||
// | ||
// CoinNewsListView.swift | ||
// SampleAppSwiftUI | ||
// | ||
// Created by Meryem Şahin on 25.07.2023. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct CoinNewsListView: View { | ||
@StateObject private var viewModel: CoinDetailViewModel | ||
|
||
init(coinData: CoinData) { | ||
_viewModel = StateObject(wrappedValue: CoinDetailViewModel(coinData: coinData)) | ||
} | ||
var body: some View { | ||
VStack { | ||
ScrollView { | ||
NavigationView { | ||
if let newsModel = viewModel.coinNewsDataModel { | ||
List { | ||
ForEach(newsModel) { model in | ||
NavigationLink(destination: WebView(url: URL(string: model.url))) { | ||
HStack { | ||
AsyncImage(url: URL(string: model.imageurl)) { phase in | ||
if let image = phase.image { | ||
image.resizable() | ||
} else { | ||
Resources.Images.worldNews.swiftUIImage.resizable() | ||
} | ||
} | ||
.scaledToFit() | ||
.clipShape(Circle()) | ||
.frame(width: Dimensions.imageWidth, height: Dimensions.imageHeight) | ||
Text(model.title) | ||
} | ||
} | ||
} | ||
} | ||
.listStyle(.inset) | ||
} | ||
}.frame(height: UIScreen.main.bounds.height) | ||
.navigationTitle("News") | ||
.navigationBarTitleDisplayMode(.inline) | ||
.navigationViewStyle(.automatic) | ||
} | ||
} | ||
.onAppear { | ||
viewModel.onAppear() | ||
} | ||
} | ||
} | ||
|
||
struct CoinNewsListView_Previews: PreviewProvider { | ||
static var previews: some View { | ||
CoinNewsListView(coinData: CoinData.demo) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can delete this key and put warning again