Skip to content

Commit 7313c59

Browse files
authored
Merge pull request #25 from cybozu/breaking-change-interface
Breaking Change to API
2 parents 756ce17 + 2300f22 commit 7313c59

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+663
-612
lines changed

Example/Example/ContentView.swift

+50-42
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ enum TabCategory {
2727
var appID: Int
2828
var isPresented = false
2929
var tabCategory = TabCategory.fetchApps
30-
var apps = [KintoneApp]()
31-
var layout = [FormLayout]()
32-
var fields = [FieldProperty]()
33-
var appSettings: AppSettings?
34-
var records = [Record.Read]()
35-
var statusSettings: AppStatusSettings?
30+
var appsResponse: FetchAppsResponse?
31+
var formLayoutResponse: FetchFormLayoutResponse?
32+
var fieldsResponse: FetchFieldsResponse?
33+
var appSettingsResponse: FetchAppSettingsResponse?
34+
var recordsResponse: FetchRecordsResponse?
35+
var appStatusSettingsResponse: FetchAppStatusSettingsResponse?
3636

3737
var kintoneAPI: KintoneAPI {
3838
.init(
@@ -61,18 +61,18 @@ enum TabCategory {
6161

6262
func onTask() async {
6363
do {
64-
apps = try await kintoneAPI.fetchApps()
65-
layout = try await kintoneAPI.fetchFormLayout(appID: appID)
66-
fields = try await kintoneAPI.fetchFields(appID: appID)
67-
appSettings = try await kintoneAPI.fetchAppSettings(appID: appID)
68-
records = try await kintoneAPI.fetchRecords(appID: appID)
69-
statusSettings = try await kintoneAPI.fetchAppStatusSettings(appID: appID)
64+
appsResponse = try await kintoneAPI.fetchApps()
65+
formLayoutResponse = try await kintoneAPI.fetchFormLayout(appID: appID)
66+
fieldsResponse = try await kintoneAPI.fetchFields(appID: appID)
67+
appSettingsResponse = try await kintoneAPI.fetchAppSettings(appID: appID)
68+
recordsResponse = try await kintoneAPI.fetchRecords(appID: appID)
69+
appStatusSettingsResponse = try await kintoneAPI.fetchAppStatusSettings(appID: appID)
7070
} catch {
7171
print(error.localizedDescription)
7272
}
7373
}
7474

75-
func fetchRecordComments(recordID: Int) async -> RecordComments? {
75+
func fetchRecordComments(recordID: Int) async -> FetchRecordCommentsResponse? {
7676
do {
7777
return try await kintoneAPI.fetchRecordComments(appID: appID, recordID: recordID)
7878
} catch {
@@ -83,9 +83,9 @@ enum TabCategory {
8383

8484
func updateStatus(recordIdentity: RecordIdentity.Write, action: StatusAction) async {
8585
do {
86-
let assignee = statusSettings?.states.first(where: { $0.name == action.to })?.assignee.entities.first?.code
86+
let assignee = appStatusSettingsResponse?.states.first(where: { $0.name == action.to })?.assignee.entities.first?.code
8787
try await kintoneAPI.updateStatus(appID: appID, recordIdentity: recordIdentity, actionName: action.name, assignee: assignee)
88-
records = try await kintoneAPI.fetchRecords(appID: appID)
88+
recordsResponse = try await kintoneAPI.fetchRecords(appID: appID)
8989
} catch {
9090
print(error.localizedDescription)
9191
}
@@ -100,7 +100,7 @@ enum TabCategory {
100100
}
101101
}
102102

103-
func onSubmitRecord(fields: [String: RecordFieldValue.Write]) async -> RecordIdentity.Read? {
103+
func onSubmitRecord(fields: [String: RecordFieldValue.Write]) async -> SubmitRecordResponse? {
104104
do {
105105
let fields = fields.compactMap { RecordField.Write(code: $0.key, value: $0.value) }
106106
let record = Record.Write(fields: fields)
@@ -111,7 +111,7 @@ enum TabCategory {
111111
}
112112
}
113113

114-
func onUpdateRecord(recordID: Int, fields: [String: RecordFieldValue.Write]) async -> RecordIdentity.Read? {
114+
func onUpdateRecord(recordID: Int, fields: [String: RecordFieldValue.Write]) async -> UpdateRecordResponse? {
115115
do {
116116
let recordIdentity = RecordIdentity.Write(id: recordID)
117117
let fields = fields.compactMap { RecordField.Write(code: $0.key, value: $0.value) }
@@ -132,7 +132,7 @@ enum TabCategory {
132132
}
133133
}
134134

135-
func uploadFile(fileArguments: FileArguments?) async -> String? {
135+
func uploadFile(fileArguments: FileArguments?) async -> UploadFileResponse? {
136136
guard let fileArguments else { return nil }
137137
do {
138138
return try await kintoneAPI.uploadFile(
@@ -200,23 +200,29 @@ enum TabCategory {
200200
.navigationBarTitleDisplayMode(.inline)
201201
.navigationDestination(isPresented: $viewModel.isPresented) {
202202
TabView(selection: $viewModel.tabCategory) {
203-
FetchAppsView(apps: viewModel.apps)
204-
.tabItem {
205-
Label("Apps", systemImage: "app.fill")
206-
}
207-
.tag(TabCategory.fetchApps)
208-
FetchFormLayoutView(layout: viewModel.layout)
209-
.tabItem {
210-
Label("Form Layout", systemImage: "square.grid.2x2")
211-
}
212-
.tag(TabCategory.fetchFormLayout)
213-
FetchFieldsView(fields: viewModel.fields)
214-
.tabItem {
215-
Label("Fields", systemImage: "square.3.layers.3d.down.left")
216-
}
217-
.tag(TabCategory.fetchFields)
203+
FetchAppsView(
204+
appsResponse: viewModel.appsResponse
205+
)
206+
.tabItem {
207+
Label("Apps", systemImage: "app.fill")
208+
}
209+
.tag(TabCategory.fetchApps)
210+
FetchFormLayoutView(
211+
formLayoutResponse: viewModel.formLayoutResponse
212+
)
213+
.tabItem {
214+
Label("Form Layout", systemImage: "square.grid.2x2")
215+
}
216+
.tag(TabCategory.fetchFormLayout)
217+
FetchFieldsView(
218+
fieldsResponse: viewModel.fieldsResponse
219+
)
220+
.tabItem {
221+
Label("Fields", systemImage: "square.3.layers.3d.down.left")
222+
}
223+
.tag(TabCategory.fetchFields)
218224
FetchAppSettingsView(
219-
appSettings: viewModel.appSettings,
225+
appSettingsResponse: viewModel.appSettingsResponse,
220226
downloadFileHandler: { fileKey in
221227
await viewModel.downloadFile(fileKey: fileKey)
222228
}
@@ -226,8 +232,8 @@ enum TabCategory {
226232
}
227233
.tag(TabCategory.fetchAppSettings)
228234
FetchRecordsView(
229-
records: viewModel.records,
230-
actions: viewModel.statusSettings?.actions ?? [],
235+
recordsResponse: viewModel.recordsResponse,
236+
appStatusSettingsResponse: viewModel.appStatusSettingsResponse,
231237
updateStatusHandler: { recordIdentity, action in
232238
await viewModel.updateStatus(recordIdentity: recordIdentity, action: action)
233239
},
@@ -243,7 +249,7 @@ enum TabCategory {
243249
}
244250
.tag(TabCategory.fetchRecords)
245251
SubmitRecordView(
246-
fields: viewModel.fields,
252+
fieldsResponse: viewModel.fieldsResponse,
247253
onSubmitRecordHandler: { fields in
248254
await viewModel.onSubmitRecord(fields: fields)
249255
},
@@ -265,11 +271,13 @@ enum TabCategory {
265271
Label("Upload File", systemImage: "square.and.arrow.up")
266272
}
267273
.tag(TabCategory.uploadFile)
268-
FetchAppStatusSettingsView(statusSettings: viewModel.statusSettings)
269-
.tabItem {
270-
Label("Status", systemImage: "point.bottomleft.forward.to.arrow.triangle.scurvepath.fill")
271-
}
272-
.tag(TabCategory.status)
274+
FetchAppStatusSettingsView(
275+
appStatusSettingsResponse: viewModel.appStatusSettingsResponse
276+
)
277+
.tabItem {
278+
Label("Status", systemImage: "point.bottomleft.forward.to.arrow.triangle.scurvepath.fill")
279+
}
280+
.tag(TabCategory.status)
273281
}
274282
.navigationTitle("kintone API")
275283
.task {

Example/Example/Extensions/KintoneAPI+Extension.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ extension KintoneApp: @retroactive Identifiable {
1111
public var id: Int { appID }
1212
}
1313

14-
extension FieldProperty: @retroactive Identifiable {
14+
extension Field: @retroactive Identifiable {
1515
public var id: String { code }
1616
}
1717

Example/Example/FetchAppSettings/FetchAppSettingsView.swift

+47-19
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,57 @@ import KintoneAPI
99
import SwiftUI
1010

1111
struct FetchAppSettingsView: View {
12-
var appSettings: AppSettings?
13-
var downloadFileHandler: (String) async -> Data?
12+
private var name: String?
13+
private var description: String?
14+
private var icon: AppIcon.Read?
15+
private var theme: AppThemeType?
16+
private var titleField: TitleField?
17+
private var enableThumbnails: Bool?
18+
private var enableBulkDeletion: Bool?
19+
private var enableComments: Bool?
20+
private var enableDuplicateRecord: Bool?
21+
private var enableInlineRecordEditing: Bool?
22+
private var numberPrecision: NumberPrecision?
23+
private var firstMonthOfFiscalYear: Int?
24+
private var revision: Int?
25+
private var downloadFileHandler: (String) async -> Data?
26+
27+
init(
28+
appSettingsResponse: FetchAppSettingsResponse?,
29+
downloadFileHandler: @escaping (String) async -> Data?
30+
) {
31+
name = appSettingsResponse?.name
32+
description = appSettingsResponse?.description
33+
icon = appSettingsResponse?.icon
34+
theme = appSettingsResponse?.theme
35+
titleField = appSettingsResponse?.titleField
36+
enableThumbnails = appSettingsResponse?.enableThumbnails
37+
enableBulkDeletion = appSettingsResponse?.enableBulkDeletion
38+
enableComments = appSettingsResponse?.enableComments
39+
enableDuplicateRecord = appSettingsResponse?.enableDuplicateRecord
40+
enableInlineRecordEditing = appSettingsResponse?.enableInlineRecordEditing
41+
numberPrecision = appSettingsResponse?.numberPrecision
42+
firstMonthOfFiscalYear = appSettingsResponse?.firstMonthOfFiscalYear
43+
revision = appSettingsResponse?.revision
44+
self.downloadFileHandler = downloadFileHandler
45+
}
1446

1547
var body: some View {
1648
ScrollView {
1749
VStack(spacing: 8) {
18-
if let appSettings {
19-
CornerRadiusText("Name: \(appSettings.name)")
20-
CornerRadiusText("Description: \(appSettings.description)")
21-
IconFileView(icon: appSettings.icon, downloadFileHandler: downloadFileHandler)
22-
CornerRadiusText("Theme: \(appSettings.theme)")
23-
TitleFieldView(titleField: appSettings.titleField)
24-
CornerRadiusText("Enable Thumbnails: \(appSettings.enableThumbnails)")
25-
CornerRadiusText("Enable Bulk Deletion: \(appSettings.enableBulkDeletion)")
26-
CornerRadiusText("Enable Comments: \(appSettings.enableComments)")
27-
CornerRadiusText("Enable Duplicate Record: \(appSettings.enableDuplicateRecord)")
28-
CornerRadiusText("Enable Inline Record Editing: \(appSettings.enableInlineRecordEditing)")
29-
NumberPrecisionView(numberPrecision: appSettings.numberPrecision)
30-
CornerRadiusText("First Month Of Fiscal Year: \(appSettings.firstMonthOfFiscalYear)")
31-
CornerRadiusText("Revision: \(appSettings.revision)")
32-
} else {
33-
Spacer()
34-
}
50+
CornerRadiusText("Name: \(String(optional: name))")
51+
CornerRadiusText("Description: \(String(optional: description))")
52+
IconFileView(icon: icon, downloadFileHandler: downloadFileHandler)
53+
CornerRadiusText("Theme: \(String(optional: theme?.rawValue))")
54+
TitleFieldView(titleField: titleField)
55+
CornerRadiusText("Enable Thumbnails: \(String(optional: enableThumbnails))")
56+
CornerRadiusText("Enable Bulk Deletion: \(String(optional: enableBulkDeletion))")
57+
CornerRadiusText("Enable Comments: \(String(optional: enableComments))")
58+
CornerRadiusText("Enable Duplicate Record: \(String(optional: enableDuplicateRecord))")
59+
CornerRadiusText("Enable Inline Record Editing: \(String(optional: enableInlineRecordEditing))")
60+
NumberPrecisionView(numberPrecision: numberPrecision)
61+
CornerRadiusText("First Month Of Fiscal Year: \(String(optional: firstMonthOfFiscalYear))")
62+
CornerRadiusText("Revision: \(String(optional: revision))")
3563
}
3664
.padding()
3765
}

Example/Example/FetchAppSettings/IconFileView.swift

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import SwiftUI
1010

1111
struct IconFileView: View {
1212
@State private var isPresented = false
13-
var icon: AppIcon.Read
13+
var icon: AppIcon.Read?
1414
var downloadFileHandler: (String) async -> Data?
1515

1616
var body: some View {
@@ -38,6 +38,9 @@ struct IconFileView: View {
3838
await downloadFileHandler(file.fileKey)
3939
}
4040
}
41+
case .none:
42+
Text("nil")
43+
.frame(maxWidth: .infinity, alignment: .leading)
4144
}
4245
}
4346
.cornerRadiusBorder()

Example/Example/FetchAppSettings/NumberPrecisionView.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ import KintoneAPI
99
import SwiftUI
1010

1111
struct NumberPrecisionView: View {
12-
var numberPrecision: NumberPrecision
12+
var numberPrecision: NumberPrecision?
1313

1414
var body: some View {
1515
HStack(alignment: .top) {
1616
Text("Number Precision:")
1717
Divider()
1818
VStack(alignment: .leading, spacing: 4) {
19-
Text("Digits: \(numberPrecision.digits)")
20-
Text("Decimal Places: \(numberPrecision.decimalPlaces)")
21-
Text("Rounding Mode: \(numberPrecision.roundingMode)")
19+
Text("Digits: \(String(optional: numberPrecision?.digits))")
20+
Text("Decimal Places: \(String(optional: numberPrecision?.decimalPlaces))")
21+
Text("Rounding Mode: \(String(optional: numberPrecision?.roundingMode.rawValue))")
2222
}
2323
.frame(maxWidth: .infinity, alignment: .leading)
2424
.cornerRadiusBorder()

Example/Example/FetchAppSettings/TitleFieldView.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ import KintoneAPI
99
import SwiftUI
1010

1111
struct TitleFieldView: View {
12-
var titleField: TitleField
12+
var titleField: TitleField?
1313

1414
var body: some View {
1515
HStack(alignment: .top) {
1616
Text("Title Field:")
1717
Divider()
1818
VStack(alignment: .leading, spacing: 4) {
19-
Text("Selection Mode: \(titleField.selectionMode)")
20-
Text("Code: \(titleField.code)")
19+
Text("Selection Mode: \(String(optional: titleField?.selectionMode.rawValue))")
20+
Text("Code: \(String(optional: titleField?.code))")
2121
}
2222
.frame(maxWidth: .infinity, alignment: .leading)
2323
.cornerRadiusBorder()

Example/Example/FetchAppStatusSettings/FetchAppStatusSettingsView.swift

+15-9
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,25 @@ import KintoneAPI
99
import SwiftUI
1010

1111
struct FetchAppStatusSettingsView: View {
12-
var statusSettings: AppStatusSettings?
12+
private var enable: Bool?
13+
private var states: [RecordState]
14+
private var actions: [StatusAction]
15+
private var revision: Int?
16+
17+
init(appStatusSettingsResponse: FetchAppStatusSettingsResponse?) {
18+
enable = appStatusSettingsResponse?.enable
19+
states = appStatusSettingsResponse?.states ?? []
20+
actions = appStatusSettingsResponse?.actions ?? []
21+
revision = appStatusSettingsResponse?.revision
22+
}
1323

1424
var body: some View {
1525
ScrollView {
1626
VStack(spacing: 8) {
17-
if let statusSettings {
18-
CornerRadiusText("Enable: \(statusSettings.enable)")
19-
CornerRadiusText("Revision: \(statusSettings.revision)")
20-
StatesView(states: statusSettings.states)
21-
ActionsView(actions: statusSettings.actions)
22-
} else {
23-
Spacer()
24-
}
27+
CornerRadiusText("Enable: \(String(optional: enable))")
28+
CornerRadiusText("Revision: \(String(optional: revision))")
29+
StatesView(states: states)
30+
ActionsView(actions: actions)
2531
}
2632
.padding()
2733
}

Example/Example/FetchApps/FetchAppsView.swift

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ import KintoneAPI
99
import SwiftUI
1010

1111
struct FetchAppsView: View {
12-
var apps: [KintoneApp]
12+
private var apps: [KintoneApp]
13+
14+
init(appsResponse: FetchAppsResponse?) {
15+
apps = appsResponse?.apps ?? []
16+
}
1317

1418
var body: some View {
1519
ScrollView {

Example/Example/FetchFields/FetchFieldsView.swift

+8-1
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,21 @@ import KintoneAPI
99
import SwiftUI
1010

1111
struct FetchFieldsView: View {
12-
var fields: [FieldProperty]
12+
private var fields: [Field]
13+
private var revision: Int?
14+
15+
init(fieldsResponse: FetchFieldsResponse?) {
16+
fields = fieldsResponse?.fields ?? []
17+
revision = fieldsResponse?.revision
18+
}
1319

1420
var body: some View {
1521
ScrollView {
1622
VStack(spacing: 16) {
1723
ForEach(fields) { field in
1824
FieldDetailView(field: field)
1925
}
26+
CornerRadiusText("Revision: \(String(optional: revision))")
2027
}
2128
.padding()
2229
}

Example/Example/FetchFields/FieldDetailView.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import KintoneAPI
99
import SwiftUI
1010

1111
struct FieldDetailView: View {
12-
var field: FieldProperty
12+
var field: Field
1313

1414
var body: some View {
1515
HStack(alignment: .top) {

0 commit comments

Comments
 (0)