parent
66f13688a5
commit
27bd45c071
@ -0,0 +1,25 @@
|
||||
// swift-tools-version: 5.8
|
||||
// The swift-tools-version declares the minimum version of Swift required to build this package.
|
||||
|
||||
import PackageDescription
|
||||
|
||||
let package = Package(
|
||||
name: "Api",
|
||||
products: [
|
||||
// Products define the executables and libraries a package produces, and make them visible to other packages.
|
||||
.library(
|
||||
name: "Api",
|
||||
targets: ["Api"]),
|
||||
],
|
||||
dependencies: [
|
||||
// Dependencies declare other packages that this package depends on.
|
||||
// .package(url: /* package url */, from: "1.0.0"),
|
||||
],
|
||||
targets: [
|
||||
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
|
||||
// Targets can depend on other targets in this package, and on products in packages this package depends on.
|
||||
.target(
|
||||
name: "Api",
|
||||
dependencies: []),
|
||||
]
|
||||
)
|
@ -0,0 +1,3 @@
|
||||
# Api
|
||||
|
||||
A description of this package.
|
@ -0,0 +1,52 @@
|
||||
//
|
||||
// UserApiManager.swift
|
||||
//
|
||||
//
|
||||
// Created by Emre on 31/12/2023.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Model
|
||||
|
||||
let allInApi = "https://codefirst.iut.uca.fr/containers/AllDev-api"
|
||||
|
||||
public struct UserApiManager: UserDataManager {
|
||||
|
||||
public init() {
|
||||
}
|
||||
|
||||
public func getBets(withIndex index: Int, withCount count: Int) -> [Bet] {
|
||||
fatalError("Not implemented yet")
|
||||
}
|
||||
|
||||
public func addBet(bet: Bet) {
|
||||
|
||||
let url = URL(string: allInApi + "bets/add")!
|
||||
var request = URLRequest(url: url)
|
||||
request.httpMethod = "POST"
|
||||
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
|
||||
|
||||
let dateFormatter = DateFormatter()
|
||||
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
|
||||
|
||||
let json = [
|
||||
"theme": bet.theme,
|
||||
"sentenceBet": bet.phrase,
|
||||
"endRegistration": dateFormatter.string(from: bet.endRegisterDate),
|
||||
"endBet": dateFormatter.string(from: bet.endBetDate),
|
||||
"isPrivate": String(bet.isPublic),
|
||||
"response": "",
|
||||
"createdBy": ""
|
||||
]
|
||||
|
||||
if let jsonData = try? JSONSerialization.data(withJSONObject: json, options: []){
|
||||
URLSession.shared.uploadTask(with: request, from: jsonData) { data, response, error in
|
||||
|
||||
}.resume()
|
||||
}
|
||||
}
|
||||
|
||||
public func getFriends() -> [User] {
|
||||
fatalError("Not implemented yet")
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
//
|
||||
// FactoryBet.swift
|
||||
//
|
||||
//
|
||||
// Created by Emre on 09/01/2024.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public protocol FactoryBet {
|
||||
func toResponse()
|
||||
func toModel() -> Bet
|
||||
func toModel(theme: String, description: String, endRegister: Date, endBet: Date, isPublic: Bool, creator: User, type: Int) -> Bet
|
||||
}
|
Loading…
Reference in new issue