Skip to content
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
30 changes: 30 additions & 0 deletions campick/GoogleService-Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>API_KEY</key>
<string>AIzaSyDDXXGt2O1elBA0wB9X3bbXMfGWhOhTGsU</string>
<key>GCM_SENDER_ID</key>
<string>717701143130</string>
<key>PLIST_VERSION</key>
<string>1</string>
<key>BUNDLE_ID</key>
<string>com.nobody.campick</string>
<key>PROJECT_ID</key>
<string>campick-8b1ac</string>
<key>STORAGE_BUCKET</key>
<string>campick-8b1ac.firebasestorage.app</string>
<key>IS_ADS_ENABLED</key>
<false></false>
<key>IS_ANALYTICS_ENABLED</key>
<false></false>
<key>IS_APPINVITE_ENABLED</key>
<true></true>
<key>IS_GCM_ENABLED</key>
<true></true>
<key>IS_SIGNIN_ENABLED</key>
<true></true>
<key>GOOGLE_APP_ID</key>
<string>1:717701143130:ios:4fbfcf7017bff4fb9b9663</string>
</dict>
</plist>
14 changes: 14 additions & 0 deletions campick/Models/Car.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// Car.swift
// campick
//
// Created by Kihwan Jo on 9/16/25.
//


struct Car: Identifiable {
let id: String? // ID는 옵셔널로, 플랫폼에 따라 생성 여부 달라짐
let brand: String
let model: String
let year: Int
}
25 changes: 25 additions & 0 deletions campick/Models/CarFirebase.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// CarFirebase.swift
// campick
//
// Created by Kihwan Jo on 9/16/25.
//


import FirebaseFirestore

struct CarFirebase: Codable {
@DocumentID var id: String? // Firestore 문서 ID
let brand: String
let model: String
let year: Int

enum CodingKeys: String, CodingKey {
case brand, model, year
}

// 도메인 모델로 변환
func toDomain() -> Car {
Car(id: id, brand: brand, model: model, year: year)
}
}
19 changes: 19 additions & 0 deletions campick/Models/CarSpring.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// CarSpring.swift
// campick
//
// Created by Kihwan Jo on 9/16/25.
//


struct CarSpring: Codable {
let id: String? // Spring Boot에서 ID 제공 여부에 따라 조정
let brand: String
let model: String
let year: Int

// 도메인 모델로 변환
func toDomain() -> Car {
Car(id: id, brand: brand, model: model, year: year)
}
}
21 changes: 21 additions & 0 deletions campick/Repositories/CarFiebaseRepository.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// CarFiebaseRepository.swift
// campick
//
// Created by Kihwan Jo on 9/16/25.
//

import FirebaseFirestore

class CarFirebaseRepository: CarRepositoryProtocol {
private let db = Firestore.firestore()
private let collectionPath = "cars"

func fetchCars() async throws -> [Car] {
let snapshot = try await db.collection(collectionPath).getDocuments()
return try snapshot.documents.compactMap { document in
let carFirebase = try document.data(as: CarFirebase.self)
return carFirebase.toDomain()
}
}
}
11 changes: 11 additions & 0 deletions campick/Repositories/CarRepositoryProtocol.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//
// CarRepositoryProtocol.swift
// campick
//
// Created by Kihwan Jo on 9/16/25.
//


protocol CarRepositoryProtocol {
func fetchCars() async throws -> [Car]
}
20 changes: 20 additions & 0 deletions campick/Repositories/CarSpringRepository.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// CarSpringRepository.swift
// campick
//
// Created by Kihwan Jo on 9/16/25.
//

import Foundation

class CarSpringRepository: CarRepositoryProtocol {
private let urlSession = URLSession.shared
private let baseURL = URL(string: "http://192.168.201.15:8080")!

func fetchCars() async throws -> [Car] {
let url = baseURL.appendingPathComponent("cars")
let (data, _) = try await urlSession.data(from: url)
let carsSpring = try JSONDecoder().decode([CarSpring].self, from: data)
return carsSpring.map { $0.toDomain() }
}
}
27 changes: 27 additions & 0 deletions campick/ViewModels/CarViewModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// CarViewModel.swift
// campick
//
// Created by Kihwan Jo on 9/16/25.
//
import SwiftUI

@MainActor
class CarViewModel: ObservableObject {
@Published var cars: [Car] = []

private let repository: CarRepositoryProtocol

init(repository: CarRepositoryProtocol = CarSpringRepository()) {
// init(repository: CarRepositoryProtocol = CarFiebaseRepository()) {
self.repository = repository
Task {
await fetchCars()
}
}

func fetchCars() async {
let cars = try? await repository.fetchCars()
self.cars = cars ?? []
}
}
30 changes: 30 additions & 0 deletions campick/Views/CarListView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// CarListFirebaseView.swift
// campick
//
// Created by Kihwan Jo on 9/16/25.
//

import SwiftUI

struct CarListView: View {
@StateObject private var viewModel = CarViewModel()

var body: some View {
NavigationView {
List(viewModel.cars) { car in
VStack(alignment: .leading) {
Text("\(car.brand) \(car.model)")
.font(.headline)
Text("Year: \(car.year)")
.font(.subheadline)
}
}
.navigationTitle("Cars")
}
}
}

#Preview {
CarListView()
}
2 changes: 1 addition & 1 deletion campick/Views/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ struct HomeView: View {
.font(.headline)
}
Spacer()
NavigationLink(destination: Text("전체 매물")) {
NavigationLink(destination: CarListView()) {
HStack {
Text("전체보기")
.foregroundColor(.brandLightOrange)
Expand Down
5 changes: 5 additions & 0 deletions campick/campickApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@
//

import SwiftUI
import FirebaseCore

@main
struct campickApp: App {
init() {
FirebaseApp.configure()
}

var body: some Scene {
WindowGroup {
ContentView()
Expand Down