commit
5b0c2248a4
After Width: | Height: | Size: 120 KiB |
@ -1,3 +1,55 @@
|
||||
# Swift
|
||||
<div align="center">
|
||||
|
||||
Client IOS
|
||||
<img src="Documentation/Images/Banner-AllIn.png" />
|
||||
|
||||
---
|
||||
|
||||

|
||||

|
||||
|
||||
---
|
||||
|
||||
[Présentation](#apple---all-in) | [Répartition du dépôt](#répartition-du-gitlab) | [Structures](#structures) | [Technologies](#technologies) | [Outils](#outils) | [Wiki](https://codefirst.iut.uca.fr/git/AllDev/Gestion_de_projet/wiki)
|
||||
|
||||
</div>
|
||||
|
||||
### Apple - ALL IN!
|
||||
|
||||
**Contexte** : Application Swift et SwiftUI pour le projet universitaire de troisième année (B.U.T Informatique de Clermont-Ferrand) intitulé *All In*.
|
||||
</br>
|
||||
|
||||
**Description** : Ce dépôt contient l'ensemble du code pour la partie client iOS de l'application *ALL IN*.
|
||||
</br>
|
||||
|
||||
# Répartition du GitLab
|
||||
|
||||
[**Sources**](Sources) : **Code de l'application**
|
||||
|
||||
[**Documentation**](Documentation) : **Documentation de l'application**
|
||||
|
||||
|
||||
# Structures
|
||||
|
||||
- MVVM
|
||||
|
||||
|
||||
|
||||
# Technologies
|
||||
|
||||
<img src="" />
|
||||
|
||||
Pour réaliser l'interface visuelle, nous avons opté pour **SwiftUI** du fait qu'elle permet de réaliser des interfaces utilisateurs complexes de manière élégante. Le framework est récent, mis à jour régulièrement, et facile à prendre en main pour le développement.
|
||||
|
||||
# Outils
|
||||
|
||||
Pour la partie API, nous avons utilisé plusieurs outils :
|
||||
|
||||
- UserDefaults
|
||||
|
||||
Pour stocker le token localement, nous utilisons l'outil fourni par SwiftUI qui est UserDefaults, afin de réaliser une authentification automatique lorsque le client ouvre l'application, en récupérant son token lors de la précédente connexion.
|
||||
|
||||
<div align="center">
|
||||
|
||||
© AllDev - Apple
|
||||
|
||||
</div>
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
@ -0,0 +1,30 @@
|
||||
//
|
||||
// DetailsViewModel.swift
|
||||
// AllIn
|
||||
//
|
||||
// Created by Emre on 16/01/2024.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
import DependencyInjection
|
||||
import Model
|
||||
|
||||
class DetailsViewModel: ObservableObject {
|
||||
|
||||
@Inject var manager: Manager
|
||||
var id: String
|
||||
|
||||
@Published var betDetail: BetDetail?
|
||||
|
||||
init(id: String) {
|
||||
self.id = id
|
||||
getItem(withId: id)
|
||||
}
|
||||
|
||||
func getItem(withId id: String) {
|
||||
manager.getBet(withId: id) { bet in
|
||||
self.betDetail = bet
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
//
|
||||
// HistoricBetViewModel.swift
|
||||
// AllIn
|
||||
//
|
||||
// Created by Emre on 16/01/2024.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
import DependencyInjection
|
||||
import Model
|
||||
|
||||
class HistoricBetViewModel: ObservableObject {
|
||||
|
||||
@Inject var manager: Manager
|
||||
|
||||
init() {
|
||||
getItems()
|
||||
}
|
||||
|
||||
func getItems() {
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
//
|
||||
// BetApiManager.swift
|
||||
//
|
||||
//
|
||||
// Created by Emre on 12/01/2024.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Model
|
||||
|
||||
public struct BetApiManager: BetDataManager {
|
||||
|
||||
public init() { }
|
||||
|
||||
public func getBets(withIndex index: Int, withCount count: Int, completion: @escaping ([Bet]) -> Void) {
|
||||
let url = URL(string: allInApi + "bets/gets")!
|
||||
|
||||
var request = URLRequest(url: url)
|
||||
request.httpMethod = "GET"
|
||||
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
|
||||
|
||||
var bets: [Bet] = []
|
||||
|
||||
URLSession.shared.dataTask(with: request) { data, response, error in
|
||||
if let data = data {
|
||||
print ("ALLIN : get bets")
|
||||
do {
|
||||
if let httpResponse = response as? HTTPURLResponse, let jsonArray = try JSONSerialization.jsonObject(with: data, options: []) as? [[String: Any]] {
|
||||
for json in jsonArray {
|
||||
if let bet = FactoryApiBet().toModel(from: json) {
|
||||
bets.append(bet)
|
||||
print(bet.theme)
|
||||
}
|
||||
}
|
||||
print(httpResponse.statusCode)
|
||||
completion(bets)
|
||||
}
|
||||
} catch {
|
||||
print("Error parsing JSON: \(error)")
|
||||
}
|
||||
}
|
||||
}.resume()
|
||||
}
|
||||
|
||||
public func getUsers(username: String) -> [User] {
|
||||
return []
|
||||
}
|
||||
|
||||
public func getBet(withId id: String, completion: @escaping (BetDetail) -> Void) {
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
//
|
||||
// BetAnswerDetail.swift
|
||||
//
|
||||
//
|
||||
// Created by Emre on 19/01/2024.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
/// A class representing detailed information about a specific answer option for a bet.
|
||||
public class BetAnswerDetail: ObservableObject {
|
||||
|
||||
/// The response or outcome associated with this answer.
|
||||
public private(set) var response: String
|
||||
|
||||
/// The total amount of stakes placed on this answer.
|
||||
public private(set) var totalStakes: Int
|
||||
|
||||
/// The total number of participants who selected this answer.
|
||||
public private(set) var totalParticipants: Int
|
||||
|
||||
/// The highest stake placed on this answer.
|
||||
public private(set) var highestStake: Int
|
||||
|
||||
/// The odds associated with this answer.
|
||||
public private(set) var odds: Float
|
||||
|
||||
/// Custom Constructor
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - response: The response or outcome associated with this answer.
|
||||
/// - totalStakes: The total amount of stakes placed on this answer.
|
||||
/// - totalParticipants: The total number of participants who selected this answer.
|
||||
/// - highestStake: The highest stake placed on this answer.
|
||||
/// - odds: The odds associated with this answer.
|
||||
public init(response: String, totalStakes: Int, totalParticipants: Int, highestStake: Int, odds: Float) {
|
||||
self.response = response
|
||||
self.totalStakes = totalStakes
|
||||
self.totalParticipants = totalParticipants
|
||||
self.highestStake = highestStake
|
||||
self.odds = odds
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
//
|
||||
// BetDetail.swift
|
||||
//
|
||||
//
|
||||
// Created by Emre on 19/01/2024.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
/// A class representing detailed information about a specific bet, including answers and user participations.
|
||||
public class BetDetail: ObservableObject {
|
||||
|
||||
/// The main bet information.
|
||||
public private(set) var bet: Bet
|
||||
|
||||
/// Details about the answers available for the bet.
|
||||
public private(set) var answers: [BetAnswerDetail]
|
||||
|
||||
/// List of user participations in the bet.
|
||||
public private(set) var participations: [Participation]
|
||||
|
||||
/// The user's own participation in the bet.
|
||||
public private(set) var userParticipation: Participation
|
||||
|
||||
/// Custom Constructor
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - bet: The main bet information.
|
||||
/// - answers: Details about the answers available for the bet.
|
||||
/// - participations: List of user participations in the bet.
|
||||
/// - userParticipation: The user's own participation in the bet.
|
||||
public init(bet: Bet, answers: [BetAnswerDetail], participations: [Participation], userParticipation: Participation) {
|
||||
self.bet = bet
|
||||
self.answers = answers
|
||||
self.participations = participations
|
||||
self.userParticipation = userParticipation
|
||||
}
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
//
|
||||
// BinaryParticipation.swift
|
||||
//
|
||||
//
|
||||
// Created by Emre on 28/12/2023.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
/// Enum to represent the possible answers for a binary participation.
|
||||
public enum YesNo {
|
||||
case yes
|
||||
case no
|
||||
}
|
||||
|
||||
/// A subclass of Participation that represents a binary participation (yes/no) in a bet.
|
||||
public class BinaryParticipation: Participation {
|
||||
/// The answer for the binary participation (yes or no).
|
||||
public var answer: YesNo
|
||||
|
||||
/// Custom Constructor
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - coinAmount: The amount of coins involved in the binary participation.
|
||||
/// - date: The date and time when the binary participation occurred.
|
||||
/// - user: The user who participated in the binary bet.
|
||||
/// - bet: The binary bet in which the user participated.
|
||||
/// - answer: The answer for the binary participation (yes or no).
|
||||
public init(coinAmount: Int, date: Date, user: User, bet: Bet, answer: YesNo) {
|
||||
self.answer = answer
|
||||
super.init(coinAmount: coinAmount, date: date, user: user, bet: bet)
|
||||
}
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
//
|
||||
// CustomParticipation.swift
|
||||
//
|
||||
//
|
||||
// Created by Emre on 28/12/2023.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
/// A subclass of Participation that represents a custom participation in a bet.
|
||||
public class CustomParticipation: Participation {
|
||||
/// The user's response to the custom bet.
|
||||
public var answer: CustomBetResponse
|
||||
|
||||
/// Custom Constructor
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - coinAmount: The amount of coins involved in the custom participation.
|
||||
/// - date: The date and time when the custom participation occurred.
|
||||
/// - user: The user who participated in the custom bet.
|
||||
/// - bet: The custom bet in which the user participated.
|
||||
/// - answer: The user's response to the custom bet.
|
||||
public init(coinAmount: Int, date: Date, user: User, bet: Bet, answer: CustomBetResponse) {
|
||||
self.answer = answer
|
||||
super.init(coinAmount: coinAmount, date: date, user: user, bet: bet)
|
||||
}
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
//
|
||||
// MatchParticipation.swift
|
||||
//
|
||||
//
|
||||
// Created by Emre on 28/12/2023.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
/// A subclass of Participation that represents a user's participation in a match bet.
|
||||
public class MatchParticipation: Participation {
|
||||
/// The points earned by the user for the first team in the match.
|
||||
public var pointsTeam1: Int
|
||||
|
||||
/// The points earned by the user for the second team in the match.
|
||||
public var pointsTeam2: Int
|
||||
|
||||
/// Custom Constructor
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - coinAmount: The amount of coins involved in the match participation.
|
||||
/// - date: The date and time when the match participation occurred.
|
||||
/// - user: The user who participated in the match bet.
|
||||
/// - bet: The match bet in which the user participated.
|
||||
/// - pointsTeam1: The points earned by the user for the first team in the match.
|
||||
/// - pointsTeam2: The points earned by the user for the second team in the match.
|
||||
public init(coinAmount: Int, date: Date, user: User, bet: Bet, pointsTeam1: Int, pointsTeam2: Int) {
|
||||
self.pointsTeam1 = pointsTeam1
|
||||
self.pointsTeam2 = pointsTeam2
|
||||
super.init(coinAmount: coinAmount, date: date, user: user, bet: bet)
|
||||
}
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
//
|
||||
// UserStubManager.swift
|
||||
//
|
||||
//
|
||||
// Created by Emre on 31/12/2023.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Model
|
||||
|
||||
public struct UserStubManager: UserDataManager {
|
||||
|
||||
private var username: String
|
||||
|
||||
public init(username: String) {
|
||||
self.username = username
|
||||
}
|
||||
|
||||
public func getBets(withIndex index: Int, withCount count: Int) -> [Bet] {
|
||||
return Stub.shared.bets.filter { bet in
|
||||
bet.registered.contains { user in
|
||||
user.username == self.username
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public func addBet(bet: Bet) {
|
||||
Stub.shared.add(bet: bet)
|
||||
}
|
||||
|
||||
public func getFriends() -> [User] {
|
||||
return Stub.shared.users.filter { user in
|
||||
user.friends.contains { friend in
|
||||
friend.username == self.username
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
// 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: "ViewModel",
|
||||
platforms: [
|
||||
.iOS(.v13)
|
||||
],
|
||||
products: [
|
||||
// Products define the executables and libraries a package produces, and make them visible to other packages.
|
||||
.library(
|
||||
name: "ViewModel",
|
||||
targets: ["ViewModel"]),
|
||||
],
|
||||
dependencies: [
|
||||
// Dependencies declare other packages that this package depends on.
|
||||
// .package(url: /* package url */, from: "1.0.0"),
|
||||
.package(name: "Model", path: "../Model")
|
||||
],
|
||||
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: "ViewModel",
|
||||
dependencies: ["Model"]),
|
||||
]
|
||||
)
|
@ -1,3 +0,0 @@
|
||||
# ViewModel
|
||||
|
||||
A description of this package.
|
@ -1,25 +0,0 @@
|
||||
//
|
||||
// ManagerVM.swift
|
||||
//
|
||||
//
|
||||
// Created by Emre on 30/12/2023.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Model
|
||||
|
||||
public class ManagerVM: ObservableObject {
|
||||
@Published var model: Manager
|
||||
|
||||
public init(withModel model: Manager) {
|
||||
self.model = model
|
||||
}
|
||||
|
||||
public func getPublicBets() {
|
||||
|
||||
}
|
||||
|
||||
public func addBet(theme: String, description: String, endRegister: Date, endBet: Date, isPublic: Bool, creator: User) {
|
||||
model.addBet(bet: BinaryBet(theme: theme, phrase: description, endRegisterDate: endRegister, endBetDate: endBet, totalStakes: 0, isPublic: isPublic, invited: [], author: creator, registered: []))
|
||||
}
|
||||
}
|
Loading…
Reference in new issue