Skip to content
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

Fix signup #71

Open
wants to merge 57 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
4fcaab6
Adding logo test
jxeyallen Sep 2, 2024
83ca9f9
Merge pull request #1 from rokesby/Logo
maryashariq Sep 2, 2024
96f4a25
added login button
maryashariq Sep 2, 2024
df2d0f3
added login button
maryashariq Sep 2, 2024
8afbe48
Add page structure
santy1315 Sep 2, 2024
8d7eae3
Merge pull request #2 from rokesby/create-pages
jxeyallen Sep 2, 2024
110047b
Welcome Page updated design and styling
jxeyallen Sep 2, 2024
f08c7cb
Further styling changes
jxeyallen Sep 2, 2024
2a47d37
For changes
jxeyallen Sep 2, 2024
de8d94f
Final Styling changes
jxeyallen Sep 2, 2024
ab301dc
Merge pull request #3 from rokesby/Welcome-Page
rokesby Sep 3, 2024
1fc70f3
Spacer Changes
jxeyallen Sep 3, 2024
03c6e30
Further changes
jxeyallen Sep 3, 2024
cc6944a
Login Page Styling
jxeyallen Sep 3, 2024
f39e8eb
Adding style for login button
jxeyallen Sep 3, 2024
e6592f8
Merge pull request #4 from rokesby/Welcome-Page
rokesby Sep 3, 2024
f0861e6
first draft of user profile page
JohnK02 Sep 3, 2024
5d161ac
Merge remote-tracking branch 'origin' into UserProfile
JohnK02 Sep 3, 2024
16716ca
Changes
jxeyallen Sep 3, 2024
cdc8950
Merge pull request #5 from rokesby/Welcome-Page
santy1315 Sep 3, 2024
598d239
added basic signup form
maryashariq Sep 3, 2024
b05f76b
Added functionality for Login button to navigate to login page
jxeyallen Sep 3, 2024
6cd3bd4
starter for feed page structure
rokesby Sep 3, 2024
509cc13
Merge pull request #6 from rokesby/Homepage-1
JohnK02 Sep 3, 2024
f4cd8bc
upload image functionality for signup
maryashariq Sep 3, 2024
b9ae52f
Merge pull request #7 from rokesby/Welcome-Page
JohnK02 Sep 3, 2024
99f5276
committing changes to merge from main
JohnK02 Sep 3, 2024
94a4021
Merge remote-tracking branch 'origin' into UserProfile
JohnK02 Sep 3, 2024
6c05fad
Merge branch 'main' into signup-view
santy1315 Sep 3, 2024
5645fe6
Merge pull request #8 from rokesby/signup-view
santy1315 Sep 3, 2024
5a0e5d5
Revert "Merge pull request #8 from rokesby/signup-view"
maryashariq Sep 3, 2024
3e185e8
committing to create main backup
JohnK02 Sep 3, 2024
0136492
create-post-page
santy1315 Sep 3, 2024
ca30852
upload image
santy1315 Sep 3, 2024
9ee4981
add image
santy1315 Sep 4, 2024
3207ad2
FIXED THE PBXPROJ FILE!!!!
maryashariq Sep 4, 2024
184b4c0
Second iteration for form work
rokesby Sep 4, 2024
f385d3b
Merge pull request #10 from rokesby/create-post-page
rokesby Sep 4, 2024
3bb9700
Fixing image Picker
jxeyallen Sep 4, 2024
8764776
Adding functionality for sign up
jxeyallen Sep 4, 2024
d7b2afa
fix-image-picker
santy1315 Sep 4, 2024
fe37388
Merge pull request #12 from rokesby/fix-image-picker
jxeyallen Sep 4, 2024
297d117
Merge pull request #11 from rokesby/Homepage-1
jxeyallen Sep 4, 2024
b622a44
added a functioning nav bar, hidden back button on other pages where …
JohnK02 Sep 4, 2024
dfd6997
previous commit didn't actually do what I needed, this commit is correct
JohnK02 Sep 4, 2024
258ac70
Merge pull request #13 from rokesby/UserProfile
rokesby Sep 4, 2024
5539515
added userviewmodel for signing up user
maryashariq Sep 4, 2024
bfec065
adding terms and conditions check box
jxeyallen Sep 4, 2024
9eec6b9
removing whitespace
jxeyallen Sep 4, 2024
a544194
Merge pull request #14 from rokesby/Welcome-Page
rokesby Sep 4, 2024
3d93312
can add a user to the database but cannot properly save imageurl
maryashariq Sep 5, 2024
bfb9b46
user is being successfully created with a login image
maryashariq Sep 5, 2024
db3d79c
update styling
santy1315 Sep 5, 2024
f52ac62
Merge pull request #16 from rokesby/create-post-styling
rokesby Sep 5, 2024
8f024d0
Merge branch 'main' into userviewmodel
maryashariq Sep 5, 2024
734c430
Merge pull request #15 from rokesby/userviewmodel
maryashariq Sep 5, 2024
195af66
fixed signup page variable scope errors
maryashariq Sep 5, 2024
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
Binary file modified .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
*.xcworkspace/xcuserdata/
DerivedData/
build/
*DS_Store*
46 changes: 45 additions & 1 deletion MobileAcebook.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
919D73622C886922000BA941 /* NavigationBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 919D73612C886922000BA941 /* NavigationBar.swift */; };
AE5D85B02AC8A221009680C6 /* MobileAcebookApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE5D85AF2AC8A221009680C6 /* MobileAcebookApp.swift */; };
AE5D85B42AC8A224009680C6 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = AE5D85B32AC8A224009680C6 /* Assets.xcassets */; };
AE5D85B72AC8A224009680C6 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = AE5D85B62AC8A224009680C6 /* Preview Assets.xcassets */; };
Expand All @@ -19,6 +20,15 @@
AE5D85E32AC9AFD2009680C6 /* MockAuthenticationService.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE5D85E22AC9AFD2009680C6 /* MockAuthenticationService.swift */; };
AE5D85E62AC9B077009680C6 /* AuthenticationServiceProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE5D85E52AC9B077009680C6 /* AuthenticationServiceProtocol.swift */; };
AE5D85E82AC9B29A009680C6 /* User.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE5D85E72AC9B29A009680C6 /* User.swift */; };
F12EC4E32C873A1800467C46 /* ImagePicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = F12EC4E22C873A1700467C46 /* ImagePicker.swift */; };
F1E9EC0A2C886AEB00F974C6 /* UserViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1E9EC092C886AEB00F974C6 /* UserViewModel.swift */; };
F52702832C872E7900C5B8E7 /* Post.swift in Sources */ = {isa = PBXBuildFile; fileRef = F52702822C872E7900C5B8E7 /* Post.swift */; };
F52702852C872FB500C5B8E7 /* PostsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = F52702842C872FB500C5B8E7 /* PostsViewModel.swift */; };
F8E51E812C861051005418F9 /* SignUpPageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8E51E802C861051005418F9 /* SignUpPageView.swift */; };
F8E51E832C861062005418F9 /* LoginPageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8E51E822C861062005418F9 /* LoginPageView.swift */; };
F8E51E852C861071005418F9 /* FeedPageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8E51E842C861071005418F9 /* FeedPageView.swift */; };
F8E51E872C861086005418F9 /* CreatePostsPageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8E51E862C861086005418F9 /* CreatePostsPageView.swift */; };
F8E51E892C861095005418F9 /* ProfilePageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8E51E882C861095005418F9 /* ProfilePageView.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand All @@ -39,6 +49,7 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
919D73612C886922000BA941 /* NavigationBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationBar.swift; sourceTree = "<group>"; };
AE5D85AC2AC8A221009680C6 /* MobileAcebook.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MobileAcebook.app; sourceTree = BUILT_PRODUCTS_DIR; };
AE5D85AF2AC8A221009680C6 /* MobileAcebookApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MobileAcebookApp.swift; sourceTree = "<group>"; };
AE5D85B32AC8A224009680C6 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
Expand All @@ -54,6 +65,15 @@
AE5D85E22AC9AFD2009680C6 /* MockAuthenticationService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockAuthenticationService.swift; sourceTree = "<group>"; };
AE5D85E52AC9B077009680C6 /* AuthenticationServiceProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthenticationServiceProtocol.swift; sourceTree = "<group>"; };
AE5D85E72AC9B29A009680C6 /* User.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = User.swift; sourceTree = "<group>"; };
F12EC4E22C873A1700467C46 /* ImagePicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImagePicker.swift; sourceTree = "<group>"; };
F1E9EC092C886AEB00F974C6 /* UserViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserViewModel.swift; sourceTree = "<group>"; };
F52702822C872E7900C5B8E7 /* Post.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Post.swift; sourceTree = "<group>"; };
F52702842C872FB500C5B8E7 /* PostsViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostsViewModel.swift; sourceTree = "<group>"; };
F8E51E802C861051005418F9 /* SignUpPageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignUpPageView.swift; sourceTree = "<group>"; };
F8E51E822C861062005418F9 /* LoginPageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginPageView.swift; sourceTree = "<group>"; };
F8E51E842C861071005418F9 /* FeedPageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedPageView.swift; sourceTree = "<group>"; };
F8E51E862C861086005418F9 /* CreatePostsPageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreatePostsPageView.swift; sourceTree = "<group>"; };
F8E51E882C861095005418F9 /* ProfilePageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfilePageView.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -111,6 +131,13 @@
AE5D85B32AC8A224009680C6 /* Assets.xcassets */,
AE5D85B52AC8A224009680C6 /* Preview Content */,
AE5D85D92AC8A337009680C6 /* WelcomePageView.swift */,
F8E51E802C861051005418F9 /* SignUpPageView.swift */,
F8E51E822C861062005418F9 /* LoginPageView.swift */,
F8E51E842C861071005418F9 /* FeedPageView.swift */,
F8E51E862C861086005418F9 /* CreatePostsPageView.swift */,
F8E51E882C861095005418F9 /* ProfilePageView.swift */,
F12EC4E22C873A1700467C46 /* ImagePicker.swift */,
919D73612C886922000BA941 /* NavigationBar.swift */,
);
path = MobileAcebook;
sourceTree = "<group>";
Expand Down Expand Up @@ -162,6 +189,9 @@
isa = PBXGroup;
children = (
AE5D85E72AC9B29A009680C6 /* User.swift */,
F1E9EC092C886AEB00F974C6 /* UserViewModel.swift */,
F52702822C872E7900C5B8E7 /* Post.swift */,
F52702842C872FB500C5B8E7 /* PostsViewModel.swift */,
);
path = Models;
sourceTree = "<group>";
Expand Down Expand Up @@ -238,7 +268,7 @@
attributes = {
BuildIndependentTargetsInParallel = 1;
LastSwiftUpdateCheck = 1420;
LastUpgradeCheck = 1420;
LastUpgradeCheck = 1540;
TargetAttributes = {
AE5D85AB2AC8A221009680C6 = {
CreatedOnToolsVersion = 14.2;
Expand Down Expand Up @@ -305,8 +335,18 @@
buildActionMask = 2147483647;
files = (
AE5D85E12AC9AFA9009680C6 /* AuthenticationService.swift in Sources */,
F52702832C872E7900C5B8E7 /* Post.swift in Sources */,
F8E51E892C861095005418F9 /* ProfilePageView.swift in Sources */,
F8E51E852C861071005418F9 /* FeedPageView.swift in Sources */,
AE5D85E62AC9B077009680C6 /* AuthenticationServiceProtocol.swift in Sources */,
F1E9EC0A2C886AEB00F974C6 /* UserViewModel.swift in Sources */,
F8E51E832C861062005418F9 /* LoginPageView.swift in Sources */,
AE5D85B02AC8A221009680C6 /* MobileAcebookApp.swift in Sources */,
F8E51E812C861051005418F9 /* SignUpPageView.swift in Sources */,
F12EC4E32C873A1800467C46 /* ImagePicker.swift in Sources */,
F52702852C872FB500C5B8E7 /* PostsViewModel.swift in Sources */,
F8E51E872C861086005418F9 /* CreatePostsPageView.swift in Sources */,
919D73622C886922000BA941 /* NavigationBar.swift in Sources */,
AE5D85E82AC9B29A009680C6 /* User.swift in Sources */,
AE5D85DA2AC8A337009680C6 /* WelcomePageView.swift in Sources */,
);
Expand Down Expand Up @@ -383,6 +423,7 @@
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
ENABLE_USER_SCRIPT_SANDBOXING = YES;
GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
Expand Down Expand Up @@ -443,6 +484,7 @@
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_USER_SCRIPT_SANDBOXING = YES;
GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
Expand All @@ -469,6 +511,7 @@
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "\"MobileAcebook/Preview Content\"";
DEVELOPMENT_TEAM = 93ARFXYW45;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
Expand Down Expand Up @@ -497,6 +540,7 @@
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "\"MobileAcebook/Preview Content\"";
DEVELOPMENT_TEAM = 93ARFXYW45;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
Expand Down
114 changes: 114 additions & 0 deletions MobileAcebook.xcodeproj/xcshareddata/xcschemes/MobileAcebook.xcscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1540"
version = "1.8">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES"
buildArchitectures = "Automatic">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "AE5D85AB2AC8A221009680C6"
BuildableName = "MobileAcebook.app"
BlueprintName = "MobileAcebook"
ReferencedContainer = "container:MobileAcebook.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<TestPlans>
<TestPlanReference
reference = "container:MobileAcebook.xctestplan"
default = "YES">
</TestPlanReference>
</TestPlans>
<Testables>
<TestableReference
skipped = "NO"
parallelizable = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "AE5D85BB2AC8A224009680C6"
BuildableName = "MobileAcebookTests.xctest"
BlueprintName = "MobileAcebookTests"
ReferencedContainer = "container:MobileAcebook.xcodeproj">
</BuildableReference>
</TestableReference>
<TestableReference
skipped = "YES"
parallelizable = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "AE5D85C52AC8A224009680C6"
BuildableName = "MobileAcebookUITests.xctest"
BlueprintName = "MobileAcebookUITests"
ReferencedContainer = "container:MobileAcebook.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "AE5D85AB2AC8A221009680C6"
BuildableName = "MobileAcebook.app"
BlueprintName = "MobileAcebook"
ReferencedContainer = "container:MobileAcebook.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<EnvironmentVariables>
<EnvironmentVariable
key = "IDEPreferLogStreaming"
value = "YES"
isEnabled = "YES">
</EnvironmentVariable>
</EnvironmentVariables>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "AE5D85AB2AC8A221009680C6"
BuildableName = "MobileAcebook.app"
BlueprintName = "MobileAcebook"
ReferencedContainer = "container:MobileAcebook.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
{
"colors" : [
{
"color" : {
"color-space" : "display-p3",
"components" : {
"alpha" : "1.000",
"blue" : "0.697",
"green" : "0.696",
"red" : "0.671"
}
},
"idiom" : "universal"
}
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"images" : [
{
"filename" : "makers-logo.png",
"filename" : "Screenshot 2024-09-02 at 15.59.50.png",
"idiom" : "universal",
"scale" : "1x"
},
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
101 changes: 101 additions & 0 deletions MobileAcebook/CreatePostsPageView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import SwiftUI
import UIKit


// The main view
struct CreatePostsPageView: View {
@State private var postMessage = ""
@State private var selectedImage: UIImage? = nil
@State private var isImagePickerPresented = false
@State private var isLogin = true

var body: some View {
NavigationView {
HStack {
VStack(alignment: .center) {
// Display the selected image, or a button to select one
if let image = selectedImage {
Image(uiImage: image)
.resizable()
.scaledToFit()
.frame(width: 200, height: 200)
.padding()
} else {
Button(action: {
}) {
TextField("What's on your mind...", text: $postMessage)
.padding()
// .scrollContentBackground(.hidden)
}
.padding()
}

Form {
Button ("selected an Image", action:{

isImagePickerPresented = true
})
NavigationLink(destination: ContentView()) {
Text("Submit")
}
}
.frame(width: 300.0, height: 150.0)
// .scrollContentBackground(/*@START_MENU_TOKEN@*/.hidden/*@END_MENU_TOKEN@*/)
}
.padding()
.sheet(isPresented: $isImagePickerPresented) {
ImagePicker(image: $selectedImage)
}

.navigationBarBackButtonHidden(false)
}
CustomNavigationBar()
}
}
}

// Preview
struct CreatePostsPageView_Previews: PreviewProvider {
static var previews: some View {
CreatePostsPageView()
}
}


class PostService {
static let shared = PostService()

let baseURL = "https://your-backend-url.com/api" // Replace with your actual backend URL

func createPost(post: Post, completion: @escaping (Result<Post, Error>) -> Void) {
guard let url = URL(string: "\(baseURL)/posts") else { return }

var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("application/json", forHTTPHeaderField: "Content-Type")

do {
let jsonData = try JSONEncoder().encode(post)
request.httpBody = jsonData

let task = URLSession.shared.dataTask(with: request) { data, response, error in
if let error = error {
completion(.failure(error))
return
}

guard let data = data else { return }

do {
let createdPost = try JSONDecoder().decode(Post.self, from: data)
completion(.success(createdPost))
} catch {
completion(.failure(error))
}
}
task.resume()
} catch {
completion(.failure(error))
}
}
}
Loading