Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
kmer1024 committed Dec 13, 2024
2 parents 33ddde5 + 63fedc1 commit 1d0939f
Show file tree
Hide file tree
Showing 23 changed files with 2,520 additions and 514 deletions.
48 changes: 48 additions & 0 deletions noto-App/noto-App.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@
62D1EA682CFDA6B1005801F6 /* Project_DataModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62D1EA672CFDA6AC005801F6 /* Project_DataModel.swift */; };
62D1EA6A2CFDA962005801F6 /* ProgressList_Page.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62D1EA692CFDA95B005801F6 /* ProgressList_Page.swift */; };
62FB214A2CFEAE1800B298F0 /* Project_Page.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62FB21492CFEAE0300B298F0 /* Project_Page.swift */; };
7D62A1602D02992600939D4B /* Todo_Model.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D62A15F2D02990900939D4B /* Todo_Model.swift */; };
7D62A16A2D02A09B00939D4B /* Model_Api.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D62A1682D02A08A00939D4B /* Model_Api.swift */; };
7D62A16D2D02A94E00939D4B /* Get_Api.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D62A16B2D02A94400939D4B /* Get_Api.swift */; };
7D62A16F2D02D32600939D4B /* Request_Model.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D62A16E2D02D30C00939D4B /* Request_Model.swift */; };
7D62A1712D02E29100939D4B /* Project_Model.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D62A1702D02E27300939D4B /* Project_Model.swift */; };
7D62A1772D07827C00939D4B /* Delete_Api.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D62A1762D07827300939D4B /* Delete_Api.swift */; };
7D62A1792D087AAC00939D4B /* Post_Api.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D62A1782D087AA500939D4B /* Post_Api.swift */; };
7D62A17B2D0885B700939D4B /* User_Model.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D62A17A2D0885B000939D4B /* User_Model.swift */; };
7D62A17D2D0889DF00939D4B /* Put_Api.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D62A17C2D0889DA00939D4B /* Put_Api.swift */; };
7D62A17F2D0B1A9000939D4B /* Patch_Api.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D62A17E2D0B1A8A00939D4B /* Patch_Api.swift */; };
7D8261FC2CED8A210045913B /* Modal_Component.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D8261FB2CED8A100045913B /* Modal_Component.swift */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -90,6 +100,16 @@
62D1EA672CFDA6AC005801F6 /* Project_DataModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Project_DataModel.swift; sourceTree = "<group>"; };
62D1EA692CFDA95B005801F6 /* ProgressList_Page.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProgressList_Page.swift; sourceTree = "<group>"; };
62FB21492CFEAE0300B298F0 /* Project_Page.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Project_Page.swift; sourceTree = "<group>"; };
7D62A15F2D02990900939D4B /* Todo_Model.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Todo_Model.swift; sourceTree = "<group>"; };
7D62A1682D02A08A00939D4B /* Model_Api.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Model_Api.swift; sourceTree = "<group>"; };
7D62A16B2D02A94400939D4B /* Get_Api.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Get_Api.swift; sourceTree = "<group>"; };
7D62A16E2D02D30C00939D4B /* Request_Model.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Request_Model.swift; sourceTree = "<group>"; };
7D62A1702D02E27300939D4B /* Project_Model.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Project_Model.swift; sourceTree = "<group>"; };
7D62A1762D07827300939D4B /* Delete_Api.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Delete_Api.swift; sourceTree = "<group>"; };
7D62A1782D087AA500939D4B /* Post_Api.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Post_Api.swift; sourceTree = "<group>"; };
7D62A17A2D0885B000939D4B /* User_Model.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = User_Model.swift; sourceTree = "<group>"; };
7D62A17C2D0889DA00939D4B /* Put_Api.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Put_Api.swift; sourceTree = "<group>"; };
7D62A17E2D0B1A8A00939D4B /* Patch_Api.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Patch_Api.swift; sourceTree = "<group>"; };
7D8261FB2CED8A100045913B /* Modal_Component.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Modal_Component.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -145,6 +165,7 @@
1371F01A2CDDE0150034FC36 /* noto-App */ = {
isa = PBXGroup;
children = (
7D62A1732D03045000939D4B /* Api */,
62D1EA5D2CFD80D8005801F6 /* DataModel */,
621B9BCD2CF4448F00451367 /* Page */,
627FFE9A2CEC293800DF70E8 /* Component */,
Expand Down Expand Up @@ -226,6 +247,10 @@
62D1EA5D2CFD80D8005801F6 /* DataModel */ = {
isa = PBXGroup;
children = (
7D62A17A2D0885B000939D4B /* User_Model.swift */,
7D62A1702D02E27300939D4B /* Project_Model.swift */,
7D62A16E2D02D30C00939D4B /* Request_Model.swift */,
7D62A15F2D02990900939D4B /* Todo_Model.swift */,
62251AA32D0090F5004E1453 /* User_DataModel.swift */,
62D1EA672CFDA6AC005801F6 /* Project_DataModel.swift */,
62D1EA652CFD9775005801F6 /* Person_DataModel.swift */,
Expand All @@ -235,6 +260,19 @@
path = DataModel;
sourceTree = "<group>";
};
7D62A1732D03045000939D4B /* Api */ = {
isa = PBXGroup;
children = (
7D62A17E2D0B1A8A00939D4B /* Patch_Api.swift */,
7D62A17C2D0889DA00939D4B /* Put_Api.swift */,
7D62A1782D087AA500939D4B /* Post_Api.swift */,
7D62A16B2D02A94400939D4B /* Get_Api.swift */,
7D62A1762D07827300939D4B /* Delete_Api.swift */,
7D62A1682D02A08A00939D4B /* Model_Api.swift */,
);
path = Api;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -369,28 +407,38 @@
buildActionMask = 2147483647;
files = (
1371F01E2CDDE0150034FC36 /* ContentView.swift in Sources */,
7D62A16D2D02A94E00939D4B /* Get_Api.swift in Sources */,
621B9BD72CF46B5800451367 /* Main_Page.swift in Sources */,
627FFE9C2CEC295100DF70E8 /* FontStyle.swift in Sources */,
62251AA22D008827004E1453 /* RequestDetail_Page.swift in Sources */,
62D1EA612CFD813D005801F6 /* Todo_DataModel.swift in Sources */,
621B9BD92CF46C5100451367 /* Project_Progress_Component.swift in Sources */,
62D1EA632CFD8865005801F6 /* TodoDetail_Page.swift in Sources */,
7D62A1792D087AAC00939D4B /* Post_Api.swift in Sources */,
7D8261FC2CED8A210045913B /* Modal_Component.swift in Sources */,
7D62A1602D02992600939D4B /* Todo_Model.swift in Sources */,
7D62A1772D07827C00939D4B /* Delete_Api.swift in Sources */,
62D1EA662CFD9779005801F6 /* Person_DataModel.swift in Sources */,
7D62A1712D02E29100939D4B /* Project_Model.swift in Sources */,
627FFE9E2CEC299700DF70E8 /* Frame_Component.swift in Sources */,
7D62A17F2D0B1A9000939D4B /* Patch_Api.swift in Sources */,
1371F0202CDDE0150034FC36 /* Item.swift in Sources */,
62FB214A2CFEAE1800B298F0 /* Project_Page.swift in Sources */,
621B9BDD2CF47F2C00451367 /* RequestList_Page.swift in Sources */,
62D1EA6A2CFDA962005801F6 /* ProgressList_Page.swift in Sources */,
62251AA42D009101004E1453 /* User_DataModel.swift in Sources */,
7D62A17D2D0889DF00939D4B /* Put_Api.swift in Sources */,
62D1EA5F2CFD80F6005801F6 /* Request_DataModel.swift in Sources */,
62D1EA682CFDA6B1005801F6 /* Project_DataModel.swift in Sources */,
1371F01C2CDDE0150034FC36 /* noto_AppApp.swift in Sources */,
621B9BD52CF46B3B00451367 /* Sub_Component.swift in Sources */,
7D62A17B2D0885B700939D4B /* User_Model.swift in Sources */,
621B9BC92CF4440800451367 /* Request_Component.swift in Sources */,
7D62A16A2D02A09B00939D4B /* Model_Api.swift in Sources */,
621B9BC72CF443D600451367 /* Navigation_Componenet.swift in Sources */,
627078DE2CE30A660027FF09 /* ColorStyle.swift in Sources */,
621B9BC52CF4438800451367 /* Header_Component.swift in Sources */,
7D62A16F2D02D32600939D4B /* Request_Model.swift in Sources */,
621B9BCB2CF4442C00451367 /* SearchBar_Component.swift in Sources */,
621B9BDB2CF4750400451367 /* Setting_Page.swift in Sources */,
);
Expand Down
41 changes: 41 additions & 0 deletions noto-App/noto-App/Api/Delete_Api.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// Delete_Api.swift
// noto-App
//
// Created by 박상현 on 12/10/24.
//
import SwiftUI

// DELETE 요청을 처리하는 함수
func delete(url: String) async throws -> ApiModel<String?> {
// URL을 유효한 형식으로 만들기
guard let url = URL(string: url) else {
throw NSError(domain: "Invalid URL", code: 0, userInfo: nil) // URL이 유효하지 않으면 에러 던지기
}

// URLRequest 객체 생성
var request = URLRequest(url: url)
request.httpMethod = "DELETE" // DELETE 요청 메소드 설정

// 비동기적으로 DELETE 요청 보내기
let (data, _) = try await URLSession.shared.data(for: request)

// 응답 데이터 출력 (디버깅용)
if let jsonString = String(data: data, encoding: .utf8) {
print("Raw JSON Response: \(jsonString)")
}

// JSONDecoder 생성
let decoder = JSONDecoder()

// Custom DateFormatter를 사용하여 특정 날짜 형식 처리
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd" // 필요한 날짜 형식으로 설정

// 커스텀 포맷터를 디코더에 설정
decoder.dateDecodingStrategy = .formatted(formatter)

// API 응답을 지정된 모델로 디코딩
let apiResponse = try decoder.decode(ApiModel<String?>.self, from: data)
return apiResponse
}
40 changes: 40 additions & 0 deletions noto-App/noto-App/Api/Get_Api.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// Get_Api.swift
// noto-App
//
// Created by 박상현 on 12/6/24.
//
import SwiftUI

// GET 요청을 처리하는 함수
func get<T: Codable>(url: String, responseType: T.Type) async throws -> ApiModel<T> {
// Try to create a URL from the string
guard let url = URL(string: url) else {
throw NSError(domain: "Invalid URL", code: 0, userInfo: nil) // Throw error if URL is invalid
}

// Now `url` is of type URL, so we can proceed with the network request
let (data, _) = try await URLSession.shared.data(from: url)

// Print the raw data for debugging
if let jsonString = String(data: data, encoding: .utf8) {
print("Raw JSON Response: \(jsonString)")
}

// Create a JSON decoder
let decoder = JSONDecoder()

// Custom DateFormatter for the expected date format
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd" // Specify your custom date format here

// Set the custom formatter to the decoder
decoder.dateDecodingStrategy = .formatted(formatter)

// Decode the API response
let apiResponse = try decoder.decode(ApiModel<T>.self, from: data)
return apiResponse
}



13 changes: 13 additions & 0 deletions noto-App/noto-App/Api/Model_Api.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// Model_Api.swift
// noto-App
//
// Created by 박상현 on 12/6/24.
//
import SwiftUI

struct ApiModel<T: Codable>: Codable {
let code: String
let message: String
let data: T
}
53 changes: 53 additions & 0 deletions noto-App/noto-App/Api/Patch_Api.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//
// Patch_Api.swift
// noto-App
//
// Created by 박상현 on 12/12/24.
//
import SwiftUI

// PATCH 요청을 처리하는 함수
func patch<U: Codable>(url: String, body: U) async throws -> ApiModel<String?> {
// Try to create a URL from the string
guard let url = URL(string: url) else {
throw NSError(domain: "Invalid URL", code: 0, userInfo: nil) // Throw error if URL is invalid
}

// Create the URLRequest for the PUT request
var request = URLRequest(url: url)
request.httpMethod = "PATCH" // HTTP method 변경 (PUT)

// Set the request's content-type header (application/json for JSON data)
request.setValue("application/json", forHTTPHeaderField: "Content-Type")

// Encode the body into JSON
let encoder = JSONEncoder()

// 날짜 포맷 설정
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd" // 서버에서 요구하는 날짜 형식으로 설정

// JSONEncoder에 날짜 인코딩 전략 설정
encoder.dateEncodingStrategy = .formatted(formatter)

let bodyData = try encoder.encode(body)
request.httpBody = bodyData

// Perform the network request and get the response data
let (data, _) = try await URLSession.shared.data(for: request)

// Print the raw data for debugging
if let jsonString = String(data: data, encoding: .utf8) {
print("Raw JSON Response: \(jsonString)")
}

// Create a JSON decoder
let decoder = JSONDecoder()

// Set the custom formatter to the decoder
decoder.dateDecodingStrategy = .formatted(formatter)

// Decode the API response
let apiResponse = try decoder.decode(ApiModel<String?>.self, from: data)
return apiResponse
}
57 changes: 57 additions & 0 deletions noto-App/noto-App/Api/Post_Api.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//
// Post_Api.swift
// noto-App
//
// Created by 박상현 on 12/10/24.
//
import SwiftUI

// POST 요청을 처리하는 함수
func post<T: Codable, U: Codable>(url: String, body: U, responseType: T.Type) async throws -> ApiModel<T> {
// Try to create a URL from the string
guard let url = URL(string: url) else {
throw NSError(domain: "Invalid URL", code: 0, userInfo: nil) // Throw error if URL is invalid
}

// Create the URLRequest for the POST request
var request = URLRequest(url: url)
request.httpMethod = "POST"

// Set the request's content-type header (application/json for JSON data)
request.setValue("application/json", forHTTPHeaderField: "Content-Type")

// Encode the body into JSON
let encoder = JSONEncoder()

// 날짜 포맷 설정
let formatter0 = DateFormatter()
formatter0.dateFormat = "yyyy-MM-dd" // 서버에서 요구하는 날짜 형식으로 설정

// JSONEncoder에 날짜 인코딩 전략 설정
encoder.dateEncodingStrategy = .formatted(formatter0)

let bodyData = try encoder.encode(body)
request.httpBody = bodyData

// Perform the network request and get the response data
let (data, _) = try await URLSession.shared.data(for: request)

// Print the raw data for debugging
if let jsonString = String(data: data, encoding: .utf8) {
print("Raw JSON Response: \(jsonString)")
}

// Create a JSON decoder
let decoder = JSONDecoder()

// Custom DateFormatter for the expected date format
let formatter1 = DateFormatter()
formatter1.dateFormat = "yyyy-MM-dd" // Specify your custom date format here

// Set the custom formatter to the decoder
decoder.dateDecodingStrategy = .formatted(formatter1)

// Decode the API response
let apiResponse = try decoder.decode(ApiModel<T>.self, from: data)
return apiResponse
}
Loading

0 comments on commit 1d0939f

Please sign in to comment.