Skip to content

Commit

Permalink
Merge pull request #25 from YanisGitHubCours/main
Browse files Browse the repository at this point in the history
merge to back
  • Loading branch information
ElMoucheh authored Sep 14, 2022
2 parents e598cce + 9858a39 commit da9eced
Show file tree
Hide file tree
Showing 23 changed files with 547 additions and 65 deletions.
3 changes: 2 additions & 1 deletion API/client/placeuser.http
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
###
GET http://localhost:8081/getPlaceUser HTTP/1.1
Content-Type: application/json
Authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiNjMwYTM1ZjFkYWMwMDQ4NjlhYjUxMjVhIiwiZW1haWwiOiJUZXN0QGdtYWlsLmNvbSIsImlhdCI6MTY2MzExMDkzMCwiZXhwIjoxNjYzMTM2MTMwfQ.wwQyWz_F7aJzv-R8iXOgmAWlKomypCbT1pDCQa7MInk
Authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiNjMwYTM1ZjFkYWMwMDQ4NjlhYjUxMjVhIiwiZW1haWwiOiJUZXN0QGdtYWlsLmNvbSIsImlhdCI6MTY2MzExMzY5MSwiZXhwIjoxNjYzMTM4ODkxfQ.APwPe34yKzGmkNJxNH0mT6FN21COc--3REUvM803yB8


5 changes: 3 additions & 2 deletions API/client/rent.http
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ Authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiNjMyMGE5MGVi
###
POST http://localhost:8081/getRentByIdUSer HTTP/1.1
Content-Type: application/json
Authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiNjMwYTM1ZjFkYWMwMDQ4NjlhYjUxMjVhIiwiZW1haWwiOiJUZXN0QGdtYWlsLmNvbSIsImlhdCI6MTY2MzEwOTgwNSwiZXhwIjoxNjYzMTM1MDA1fQ.Rkfo8lOjvWkRfQuiux8t54mLW1LX2LtYwzXvRmlspmg

Authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiNjMwYTM1ZjFkYWMwMDQ4NjlhYjUxMjVhIiwiZW1haWwiOiJUZXN0QGdtYWlsLmNvbSIsImlhdCI6MTY2MzExODgyMywiZXhwIjoxNjYzMTQ0MDIzfQ.SdiQ0jDlUaHfopmXIgo0ihcwk7Z00DWJRfOmDOYXMCk

{
"id": "630a35f1dac004869ab5125a"
"id": "630a35f1dac004869ab5125a"
}
1 change: 0 additions & 1 deletion API/controller/admin/user.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

const Mongoose = require('mongoose');
const UserModel = require('../../model/user.js')
const SubModel = require('../../model/sub.js')
Expand Down
24 changes: 20 additions & 4 deletions API/controller/user/rent.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const Mongoose = require("mongoose")
const slpModel = require('../../model/placelinkschedules.js')

const { Mongoose } = require("mongoose")
const RentModel = require("../../model/rent.js")
const slpModel = require('../../model/placelinkschedules.js')
const PlaceModel = require('../../model/place.js')

const createRent = async(body, res) => {
if(!body.fk_user || !body.fk_pls || !body.fk_place){
Expand All @@ -25,13 +27,27 @@ const createRent = async(body, res) => {
}
}
const getRentByIdUser = async(body,res) => {
console.log(body.id)
if(!body.id){
res.status(400).send("all input are required")
}else{
const id = Mongoose.Types.ObjectId(body.id)
const id = body.id
const rent = await RentModel.find({fk_user: id})
if(rent){
res.status(200).send(rent)
const slp = await slpModel.find({fk_place: rent.fk_place, fk_pls: rent.fk_pls, rent: true})
if(slp){
var result = []
for(i in slp){
console.log(slp[i].idPlace)
var name = await PlaceModel.findOne({_id: slp[i].idPlace})
result.push({"name": name.name, "day": slp[i].day, "time": slp[i].time, "fk_pls": slp[i]._id, "fk_place": slp[i].idPlace, "fk_user": rent[i].fk_user})
console.log(result)
}
res.status(200).json([{rent: result}])
} else {
res.status(400).send("slp not found")
}

}else{
res.status(400).send("dont find rent")
}
Expand Down
5 changes: 5 additions & 0 deletions API/routes/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ router.get('/getSub', isAuthorized, async(req,res) => {
await sub.getSub(res)
})

router.get('/getSubForUsers', isAuthorized, async(req,res) => {
await sub.getSub(res)
})


router.post('/getSubById',isAuthorized, async(req,res) => {
await sub.getSubById(req.body,res)
})
Expand Down
36 changes: 36 additions & 0 deletions CoWorkApp/CoWorkApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@
FA6B273C28AFD8D600507AA4 /* Comfortaa.ttf in Resources */ = {isa = PBXBuildFile; fileRef = FA6B273B28AFD8D600507AA4 /* Comfortaa.ttf */; };
FA6B273E28AFD8DF00507AA4 /* BungeeShade.ttf in Resources */ = {isa = PBXBuildFile; fileRef = FA6B273D28AFD8DF00507AA4 /* BungeeShade.ttf */; };
FAC27C9028D11664000C923D /* UserGetRentService.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAC27C8F28D11664000C923D /* UserGetRentService.swift */; };
FAC27C9228D1429C000C923D /* UserRent.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAC27C9128D1429C000C923D /* UserRent.swift */; };
FAC27C9428D14433000C923D /* AllUserRentService.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAC27C9328D14433000C923D /* AllUserRentService.swift */; };
FAC27C9628D147AD000C923D /* UserRentResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAC27C9528D147AD000C923D /* UserRentResponse.swift */; };
FAC27C9828D15357000C923D /* userRentAllView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAC27C9728D15357000C923D /* userRentAllView.swift */; };
FAC27C9A28D172BE000C923D /* UserCancelRentService.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAC27C9928D172BE000C923D /* UserCancelRentService.swift */; };
FAC27C9C28D1843D000C923D /* Sub.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAC27C9B28D1843D000C923D /* Sub.swift */; };
FAC27C9E28D18528000C923D /* DisplaySubService.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAC27C9D28D18528000C923D /* DisplaySubService.swift */; };
FAC27CA028D188A7000C923D /* subPage.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAC27C9F28D188A7000C923D /* subPage.swift */; };
FAC27CA228D195FD000C923D /* SubResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAC27CA128D195FD000C923D /* SubResponse.swift */; };
FAD4066528C50F7C0083320B /* DisplayRentService.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAD4066428C50F7C0083320B /* DisplayRentService.swift */; };
FAD4067028C641E20083320B /* NavigationStack in Frameworks */ = {isa = PBXBuildFile; productRef = FAD4066F28C641E20083320B /* NavigationStack */; };
FAD4067328C641F70083320B /* NavigationStack in Frameworks */ = {isa = PBXBuildFile; productRef = FAD4067228C641F70083320B /* NavigationStack */; };
Expand Down Expand Up @@ -54,6 +63,15 @@
FA6B273B28AFD8D600507AA4 /* Comfortaa.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = Comfortaa.ttf; sourceTree = "<group>"; };
FA6B273D28AFD8DF00507AA4 /* BungeeShade.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = BungeeShade.ttf; sourceTree = "<group>"; };
FAC27C8F28D11664000C923D /* UserGetRentService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserGetRentService.swift; sourceTree = "<group>"; };
FAC27C9128D1429C000C923D /* UserRent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserRent.swift; sourceTree = "<group>"; };
FAC27C9328D14433000C923D /* AllUserRentService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AllUserRentService.swift; sourceTree = "<group>"; };
FAC27C9528D147AD000C923D /* UserRentResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserRentResponse.swift; sourceTree = "<group>"; };
FAC27C9728D15357000C923D /* userRentAllView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = userRentAllView.swift; sourceTree = "<group>"; };
FAC27C9928D172BE000C923D /* UserCancelRentService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserCancelRentService.swift; sourceTree = "<group>"; };
FAC27C9B28D1843D000C923D /* Sub.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Sub.swift; sourceTree = "<group>"; };
FAC27C9D28D18528000C923D /* DisplaySubService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DisplaySubService.swift; sourceTree = "<group>"; };
FAC27C9F28D188A7000C923D /* subPage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = subPage.swift; sourceTree = "<group>"; };
FAC27CA128D195FD000C923D /* SubResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SubResponse.swift; sourceTree = "<group>"; };
FAD4066428C50F7C0083320B /* DisplayRentService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DisplayRentService.swift; sourceTree = "<group>"; };
FAD4067428C657E60083320B /* PlaceResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlaceResponse.swift; sourceTree = "<group>"; };
FAD4067628C659120083320B /* ScheduleResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScheduleResponse.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -159,8 +177,10 @@
FAEE3CAB28BA82CF00A4A67D /* homePage.swift */,
FAEE3CAD28BA8ADC00A4A67D /* userProfile.swift */,
FAE2D95728C23FC000A47606 /* userEditProfile.swift */,
FAC27C9728D15357000C923D /* userRentAllView.swift */,
FAEE3CAF28BA8BD800A4A67D /* userRent.swift */,
FAEE3CB128BA8C4900A4A67D /* logout.swift */,
FAC27C9F28D188A7000C923D /* subPage.swift */,
FAF013CF28CEB812001ACFC4 /* selectedPlace.swift */,
);
path = View;
Expand All @@ -183,6 +203,10 @@
FAD4067428C657E60083320B /* PlaceResponse.swift */,
FAD4067628C659120083320B /* ScheduleResponse.swift */,
FAF013C828CE3693001ACFC4 /* RentResponse.swift */,
FAC27C9128D1429C000C923D /* UserRent.swift */,
FAC27C9528D147AD000C923D /* UserRentResponse.swift */,
FAC27C9B28D1843D000C923D /* Sub.swift */,
FAC27CA128D195FD000C923D /* SubResponse.swift */,
);
path = Model;
sourceTree = "<group>";
Expand All @@ -197,6 +221,9 @@
FAD4066428C50F7C0083320B /* DisplayRentService.swift */,
FAE2D95D28C2497A00A47606 /* UserProfielupdateService.swift */,
FAC27C8F28D11664000C923D /* UserGetRentService.swift */,
FAC27C9328D14433000C923D /* AllUserRentService.swift */,
FAC27C9928D172BE000C923D /* UserCancelRentService.swift */,
FAC27C9D28D18528000C923D /* DisplaySubService.swift */,
);
path = API;
sourceTree = "<group>";
Expand Down Expand Up @@ -304,23 +331,32 @@
FAE2D95C28C2401400A47606 /* UserLogoutService.swift in Sources */,
FAEE3CA628BA78CD00A4A67D /* landingPage.swift in Sources */,
FA6B272928AFD09B00507AA4 /* ContentView.swift in Sources */,
FAC27C9E28D18528000C923D /* DisplaySubService.swift in Sources */,
FAE2D95E28C2497A00A47606 /* UserProfielupdateService.swift in Sources */,
FAEE3CA428BA71CB00A4A67D /* UserSignInService.swift in Sources */,
FAF013C928CE3693001ACFC4 /* RentResponse.swift in Sources */,
FAEE3CAC28BA82CF00A4A67D /* homePage.swift in Sources */,
FAC27C9228D1429C000C923D /* UserRent.swift in Sources */,
FAEE3C9D28B42B9400A4A67D /* APIService.swift in Sources */,
FAC27C9828D15357000C923D /* userRentAllView.swift in Sources */,
FAEE3C9528B37F1700A4A67D /* signUp.swift in Sources */,
FAC27C9A28D172BE000C923D /* UserCancelRentService.swift in Sources */,
FAD4067728C659120083320B /* ScheduleResponse.swift in Sources */,
FAE2D95828C23FC000A47606 /* userEditProfile.swift in Sources */,
FAC27C9628D147AD000C923D /* UserRentResponse.swift in Sources */,
FAEE3CAE28BA8ADC00A4A67D /* userProfile.swift in Sources */,
FAF013D028CEB812001ACFC4 /* selectedPlace.swift in Sources */,
FAC27C9028D11664000C923D /* UserGetRentService.swift in Sources */,
FAC27CA228D195FD000C923D /* SubResponse.swift in Sources */,
FA6B272728AFD09B00507AA4 /* CoWorkAppApp.swift in Sources */,
FAC27C9C28D1843D000C923D /* Sub.swift in Sources */,
FAE2D95A28C2400D00A47606 /* UserProfileService.swift in Sources */,
FAEE3C9828B3904200A4A67D /* User.swift in Sources */,
FAD4066528C50F7C0083320B /* DisplayRentService.swift in Sources */,
FAEE3C9F28B7D15000A4A67D /* ApiResponse.swift in Sources */,
FAEE3CAA28BA7BA700A4A67D /* buttonLandingStyle.swift in Sources */,
FAC27CA028D188A7000C923D /* subPage.swift in Sources */,
FAC27C9428D14433000C923D /* AllUserRentService.swift in Sources */,
FAD4067528C657E60083320B /* PlaceResponse.swift in Sources */,
FAEE3C9A28B3951600A4A67D /* UserSignUpService.swift in Sources */,
FAEE3C9128B3744000A4A67D /* signIn.swift in Sources */,
Expand Down
Binary file not shown.
38 changes: 38 additions & 0 deletions CoWorkApp/CoWorkApp/Model/Sub.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// User.swift
// CoWorkApp
//
// Created by Alexandre Marcos on 22/08/2022.
//

import Foundation

class Sub: CustomStringConvertible, Identifiable {
var description: String {
"This is a user"
}

let id: String?
let name: String
let price: String
let fk_service: String

public init(id: String?, name: String, price: String, fk_service: String){
self.id = id
self.name = name
self.price = price
self.fk_service = fk_service
}

public class func fromDict(_ array: [String: Any]) -> Sub? {
guard let id = array["id"] as? String,
let name = array["name"] as? String,
let price = array["price"] as? String,
let fk_service = array["fk_service"] as? String else {
return nil
}

return Sub(id: id, name: name, price: price, fk_service: fk_service )
}

}
31 changes: 31 additions & 0 deletions CoWorkApp/CoWorkApp/Model/SubResponse.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// ApiResponse.swift
// CoWorkApp
//
// Created by Alexandre Marcos on 25/08/2022.
//

import SwiftUI

class SubResponse: CustomStringConvertible, Identifiable {
var description: String {
"Api default response"
}

let sub: [Sub]

public init(sub: [Sub]){
self.sub = sub
}

public class func fromDict(_ array: [String: Any]) -> SubResponse? {

guard let subOnly = array["sub"] as? [[String: Any]] else {
return nil
}

let subR = subOnly.compactMap(Sub.fromDict(_:))

return SubResponse(sub: subR)
}
}
46 changes: 46 additions & 0 deletions CoWorkApp/CoWorkApp/Model/UserRent.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//
// ApiResponse.swift
// CoWorkApp
//
// Created by Alexandre Marcos on 25/08/2022.
//

import SwiftUI

class UserRent: CustomStringConvertible, Identifiable {
var description: String {
"Api default response"
}

let name: String
let time: String
let day: String
let placeId: String
let scheduleId: String
let userId: String

public init(name: String, time: String, day: String, placeId: String, scheduleId: String, userId: String){
self.name = name
self.time = time
self.day = day
self.placeId = placeId
self.scheduleId = scheduleId
self.userId = userId
}

public class func fromDict(_ array: [String: Any]) -> UserRent? {

guard let name = array["name"] as? String,
let time = array["time"] as? String,
let day = array["day"] as? String,
let placeId = array["fk_place"] as? String,
let scheduleId = array["fk_pls"] as? String,
let userId = array["fk_user"] as? String else {
return nil
}



return UserRent(name: name, time: time, day: day, placeId: placeId, scheduleId: scheduleId, userId: userId)
}
}
31 changes: 31 additions & 0 deletions CoWorkApp/CoWorkApp/Model/UserRentResponse.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// ApiResponse.swift
// CoWorkApp
//
// Created by Alexandre Marcos on 25/08/2022.
//

import SwiftUI

class UserRentResponse: CustomStringConvertible, Identifiable {
var description: String {
"Api default response"
}

let userRent: [UserRent]

public init(userRent: [UserRent]){
self.userRent = userRent
}

public class func fromDict(_ array: [String: Any]) -> UserRentResponse? {

guard let userRent = array["rent"] as? [[String: Any]] else {
return nil
}

let UserRentResponseArray = userRent.compactMap(UserRent.fromDict(_:))

return UserRentResponse(userRent: UserRentResponseArray)
}
}
49 changes: 49 additions & 0 deletions CoWorkApp/CoWorkApp/Service/API/AllUserRentService.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//
// UserSignUpService.swift
// CoWorkApp
//
// Created by Alexandre Marcos on 22/08/2022.
//

import SwiftUI


class AllUserRentService {
class func Show(completion: @escaping ([UserRentResponse]) -> Void){
guard let url = URL(string: ApiService.URL + "/getRentByIdUSer") else {
completion([])
return
}

var urlRequest = URLRequest(url: url)
urlRequest.httpMethod = "POST"
urlRequest.addValue("application/json", forHTTPHeaderField: "Content-Type")
urlRequest.addValue(ApiService.TOKEN, forHTTPHeaderField: "Authorization")

var dataArray:[String:Any] = [:]

dataArray["id"] = ApiService.USER!.id


let datas = try? JSONSerialization.data(withJSONObject: dataArray, options: .fragmentsAllowed)
urlRequest.httpBody = datas

let req = URLSession.shared.dataTask(with: urlRequest) { (datas, res, err) in
guard err == nil, let d = datas else {
completion([])
return
}

let json = try? JSONSerialization.jsonObject(with: d,options: .allowFragments)

guard let apiResponseArray = json as? [[String: Any]] else {
completion([])
return
}

completion(apiResponseArray.compactMap(UserRentResponse.fromDict(_:)))

}
req.resume()
}
}
Loading

0 comments on commit da9eced

Please sign in to comment.