Skip to content

Commit d5d051a

Browse files
author
PhongND
committed
fix server
Signed-off-by: PhongND <phongnd@ftech.ai>
1 parent be97052 commit d5d051a

File tree

139 files changed

+3274
-3478
lines changed

Some content is hidden

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

139 files changed

+3274
-3478
lines changed

.DS_Store

-6 KB
Binary file not shown.

.github/workflows/swift.yml

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,3 @@
22
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-swift
33

44
name: Swift
5-
6-
on:
7-
push:
8-
branches: [ "develop" ]
9-
pull_request:
10-
branches: [ "develop" ]
11-
12-
jobs:
13-
build:
14-
15-
runs-on: macos-latest
16-
17-
steps:
18-
- uses: actions/checkout@v3
19-
- name: Build
20-
run: swift build -v
21-
- name: Run tests
22-
run: swift test -v

AdvanceApp/.DS_Store

-6 KB
Binary file not shown.
Binary file not shown.

AdvanceApp/UIKit13+/.DS_Store

-6 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.

BasicApp/.DS_Store

-6 KB
Binary file not shown.

BasicApp/SwiftUI/.DS_Store

-8 KB
Binary file not shown.
Binary file not shown.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
@_exported import Transform
22
@_exported import MCombineRequest
33
@_exported import ComposableArchitecture
4+
@_exported import Json
5+
@_exported import SwiftLogger

BasicApp/SwiftUI/Todo+Combine+SwiftUI/Shared/CoreApp/TodoApp.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ struct TodoApp: App {
1111

1212
public extension DependencyValues {
1313
var urlString: String {
14-
"http://127.0.0.1:8080"
14+
"http://127.0.0.1:8080/todos"
1515
}
1616
}
1717

BasicApp/SwiftUI/Todo+Combine+SwiftUI/Shared/CoreApp/TodoApp/Models/TodoModel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ import Foundation
22

33
struct TodoModel: Codable, Identifiable, Equatable {
44
var id: UUID
5-
var title: String
5+
var text: String
66
var isCompleted: Bool
77
}

BasicApp/SwiftUI/Todo+Combine+SwiftUI/Shared/CoreApp/TodoApp/Views/AuthView.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import ComposableArchitecture
21
import SwiftUI
32

43
struct Auth: Reducer {

BasicApp/SwiftUI/Todo+Combine+SwiftUI/Shared/CoreApp/TodoApp/Views/MainView.swift

Lines changed: 64 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ struct Main: Reducer {
55
// MARK: State
66
struct State: Equatable {
77
var counterState = Counter.State()
8-
@BindingState var title: String = ""
8+
@BindingState var text: String = ""
99
var todos: IdentifiedArrayOf<TodoModel> = []
1010
var isLoading: Bool = false
1111
}
@@ -62,13 +62,13 @@ struct Main: Reducer {
6262
case .logout:
6363
return .send(.changeRootScreen(.auth))
6464
case .viewCreateTodo:
65-
if state.title.isEmpty {
65+
if state.text.isEmpty {
6666
return .none
6767
}
68-
let title = state.title
69-
state.title = ""
68+
let text = state.text
69+
state.text = ""
7070
let id = uuid()
71-
let todo = TodoModel(id: id, title: title, isCompleted: false)
71+
let todo = TodoModel(id: id, text: text, isCompleted: false)
7272
return .send(.createOrUpdateTodo(todo))
7373
// MARK: - Networking
7474
/// GET TODO
@@ -79,7 +79,7 @@ struct Main: Reducer {
7979
state.isLoading = true
8080
state.todos.removeAll()
8181
let request = MRequest {
82-
RUrl(urlString: urlString)
82+
RUrl(urlString)
8383
RMethod(.get)
8484
}
8585
if isUsingPublisher {
@@ -95,23 +95,28 @@ struct Main: Reducer {
9595
await send(.responseTodo(data))
9696
}
9797
}
98-
case .responseTodo(let json):
99-
if let items = json.toModel([TodoModel].self) {
98+
case .responseTodo(let data):
99+
log.info(Json(data))
100+
state.isLoading = false
101+
if let items = data.toModel([TodoModel].self) {
100102
for item in items {
101103
state.todos.updateOrAppend(item)
102104
}
103105
}
104106
/// CREATE OR UPDATE TODO
105107
case .createOrUpdateTodo(let todo):
108+
log.info(todo.toJson())
106109
let request = MRequest {
107-
RUrl(urlString: urlString)
108-
REncoding(JSONEncoding.default)
110+
RUrl(urlString)
109111
RMethod(.post)
110112
Rbody(todo.toData())
113+
REncoding(JSONEncoding.default)
114+
111115
}
112116
if isUsingPublisher {
113117
return .publisher {
114118
request
119+
.printCURLRequest()
115120
.compactMap{$0.data}
116121
.map(Main.Action.responseCreateOrUpdateTodo)
117122
.eraseToAnyPublisher()
@@ -122,21 +127,24 @@ struct Main: Reducer {
122127
await send(.responseCreateOrUpdateTodo(data))
123128
}
124129
}
125-
case .responseCreateOrUpdateTodo(let json):
126-
if let item = json.toModel(TodoModel.self) {
130+
case .responseCreateOrUpdateTodo(let data):
131+
log.info(Json(data))
132+
if let item = data.toModel(TodoModel.self) {
127133
state.todos.updateOrAppend(item)
128134
}
129135
/// UPDATE TODO
130136
case .updateTodo(let todo):
131137
let request = MRequest {
132-
RUrl(urlString: urlString)
138+
RUrl(urlString)
133139
.withPath(todo.id.toString())
134-
RMethod(.post)
135140
Rbody(todo.toData())
141+
RMethod(.post)
142+
REncoding(JSONEncoding.default)
136143
}
137144
if isUsingPublisher {
138145
return .publisher {
139146
request
147+
.printCURLRequest()
140148
.compactMap{$0.data}
141149
.map(Main.Action.responseUpdateTodo)
142150
.eraseToAnyPublisher()
@@ -147,14 +155,15 @@ struct Main: Reducer {
147155
await send(.responseUpdateTodo(data))
148156
}
149157
}
150-
case .responseUpdateTodo(let json):
151-
if let item = json.toModel(TodoModel.self) {
158+
case .responseUpdateTodo(let data):
159+
log.info(data.toJson())
160+
if let item = data.toModel(TodoModel.self) {
152161
state.todos.updateOrAppend(item)
153162
}
154163
/// DELETE TODO
155164
case .deleteTodo(let todo):
156165
let request = MRequest {
157-
RUrl(urlString: urlString)
166+
RUrl(urlString)
158167
.withPath(todo.id.toString())
159168
RMethod(.delete)
160169
}
@@ -201,38 +210,12 @@ struct MainView: View {
201210

202211
var body: some View {
203212
ZStack {
204-
#if os(macOS)
205-
content
206-
.toolbar {
207-
ToolbarItem(placement: .status) {
208-
HStack {
209-
CounterView(
210-
store: store
211-
.scope(
212-
state: \.counterState,
213-
action: Main.Action.counterAction
214-
)
215-
)
216-
Spacer()
217-
Button(action: {
218-
viewStore.send(.logout)
219-
}, label: {
220-
Text("Logout")
221-
.foregroundColor(Color.blue)
222-
})
223-
}
224-
}
225-
}
226-
.frame(maxWidth: .infinity, maxHeight: .infinity)
227-
#endif
228-
#if os(iOS)
229213
NavigationView {
230214
content
231215
.navigationTitle("Todos")
232216
.navigationBarItems(leading: leadingBarItems, trailing: trailingBarItems)
233217
}
234218
.navigationViewStyle(.stack)
235-
#endif
236219
}
237220
.onAppear {
238221
viewStore.send(.viewOnAppear)
@@ -243,67 +226,69 @@ struct MainView: View {
243226
}
244227
}
245228

246-
247229
extension MainView {
248230
/// create content view in screen
249231
private var content: some View {
250232
List {
251-
Section {
252-
ZStack {
253-
HStack {
254-
Spacer()
255-
if viewStore.isLoading {
256-
ProgressView()
257-
} else {
258-
Text("Reload")
259-
.bold()
260-
.onTapGesture {
261-
viewStore.send(.getTodo)
262-
}
263-
}
264-
Spacer()
265-
}
266-
.frame(height: 60)
267-
}
268-
}
269-
HStack {
270-
TextField("title", text: viewStore.$title)
271-
Button(action: {
272-
viewStore.send(.viewCreateTodo)
273-
}, label: {
274-
Text("Create")
275-
.bold()
276-
.foregroundColor(viewStore.title.isEmpty ? Color.gray : Color.green)
277-
})
278-
.disabled(viewStore.title.isEmpty)
279-
}
280-
233+
topview
234+
inputview
281235
ForEach(viewStore.todos) { todo in
282236
HStack {
283237
HStack {
284238
Image(systemName: todo.isCompleted ? "checkmark.square" : "square")
285239
.frame(width: 40, height: 40, alignment: .center)
286-
Text(todo.title)
240+
Text(todo.text)
287241
.underline(todo.isCompleted, color: Color.black)
288242
Spacer()
289243
}
290244
.contentShape(Rectangle())
291245
.onTapGesture {
292246
viewStore.send(.toggleTodo(todo))
293247
}
294-
Button(action: {
248+
Button {
295249
viewStore.send(.deleteTodo(todo))
296-
}, label: {
250+
} label: {
297251
Text("Delete")
298252
.foregroundColor(Color.gray)
299-
})
253+
}
300254
}
301255
}
302-
.padding(.all, 0)
303256
}
304257
.padding(.all, 0)
305258
}
306259

260+
private var topview: some View {
261+
Section {
262+
ZStack(alignment: .center) {
263+
if viewStore.isLoading {
264+
ProgressView()
265+
} else {
266+
Text("Reload")
267+
.bold()
268+
.onTapGesture {
269+
viewStore.send(.getTodo)
270+
}
271+
}
272+
}
273+
.frame(height: 60)
274+
.frame(maxWidth: .infinity)
275+
}
276+
}
277+
278+
private var inputview: some View {
279+
HStack {
280+
TextField("text", text: viewStore.$text)
281+
Button(action: {
282+
viewStore.send(.viewCreateTodo)
283+
}, label: {
284+
Text("Create")
285+
.bold()
286+
.foregroundColor(viewStore.text.isEmpty ? Color.gray : Color.green)
287+
})
288+
.disabled(viewStore.text.isEmpty)
289+
}
290+
}
291+
307292
private var leadingBarItems: some View {
308293
CounterView(
309294
store: store

BasicApp/SwiftUI/Todo+Combine+SwiftUI/Shared/CoreApp/TodoApp/Views/RootView.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import ComposableArchitecture
21
import SwiftUI
32

43
struct Root: Reducer {
@@ -55,8 +54,6 @@ struct Root: Reducer {
5554
}
5655
}
5756

58-
59-
6057
struct RootView: View {
6158

6259
private let store: StoreOf<Root>
@@ -99,9 +96,6 @@ struct RootView: View {
9996
.onDisappear {
10097
viewStore.send(.viewOnDisappear)
10198
}
102-
#if os(macOS)
103-
.frame(minWidth: 700, idealWidth: 700, maxWidth: .infinity, minHeight: 500, idealHeight: 500, maxHeight: .infinity, alignment: .center)
104-
#endif
10599
}
106100
}
107101

BasicApp/SwiftUI/Todo+Combine+SwiftUI/Shared/CoreApp/TodoApp/Views/SplashView.swift

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)