diff --git a/api/openapi.yaml b/api/openapi.yaml index 65b0786fe908ed7fa5141b3f94419a9eac817a06..b24d5ea18ea9635d5e7a798b9d016c0f27b1059a 100644 --- a/api/openapi.yaml +++ b/api/openapi.yaml @@ -1,17 +1,10 @@ openapi: 3.0.3 info: - title: Swagger Petstore - OpenAPI 3.0 + title: Swagger real-estate-ads - OpenAPI 3.0 description: |- - This is a sample Pet Store Server based on the OpenAPI 3.0 specification. You can find out more about - Swagger at [https://swagger.io](https://swagger.io). In the third iteration of the pet store, we've switched to the design first approach! - You can now help us improve the API whether it's by making changes to the definition itself or to the code. - That way, with time, we can improve the API in general, and expose some of the new features in OAS3. - - _If you're looking for the Swagger 2.0/OAS 2.0 version of Petstore, then click [here](https://editor.swagger.io/?url=https://petstore.swagger.io/v2/swagger.yaml). Alternatively, you can load via the `Edit > Load Petstore OAS 2.0` menu option!_ - - Some useful links: - - [The Pet Store repository](https://github.com/swagger-api/swagger-petstore) - - [The source API definition for the Pet Store](https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml) + Bienvenue sur notre plateforme d'annonces immobilières, basée sur la spécification OpenAPI 3.0. Vous trouverez ici une variété d'annonces pour des propriétés immobilières, qu'il s'agisse de ventes ou de locations. Notre API est conçue pour faciliter la recherche, la publication et la gestion d'annonces de biens immobiliers. + Que vous soyez un utilisateur en quête de la maison de vos rêves ou un annonceur cherchant à promouvoir votre propriété, notre API vous offre des fonctionnalités avancées pour simplifier le processus. Vous pouvez contribuer à l'amélioration de notre API en proposant des modifications à la définition ou au code, ce qui nous permettra de continuer à améliorer l'expérience des utilisateurs et d'intégrer de nouvelles fonctionnalités liées à l'immobilier. + Explorez notre API pour découvrir comment elle peut répondre à vos besoins en matière d'annonces immobilières. Que vous cherchiez à acheter, vendre ou louer une propriété, nous sommes là pour vous simplifier la tâche et rendre votre expérience aussi fluide que possible. termsOfService: http://swagger.io/terms/ contact: email: apiteam@swagger.io @@ -23,443 +16,48 @@ externalDocs: description: Find out more about Swagger url: http://swagger.io servers: -- url: http://localhost:8080 + - url: http://localhost:8080 tags: -- name: pet - description: Everything about your Pets - externalDocs: - description: Find out more - url: http://swagger.io -- name: store - description: Access to Petstore orders - externalDocs: - description: Find out more about our store - url: http://swagger.io -- name: user - description: Operations about user + - name: ad + description: Everything about your ads + externalDocs: + description: Find out more + url: http://swagger.io + - name: user + description: Operations about user paths: - /pet: - put: - tags: - - pet - summary: Update an existing pet - description: Update an existing pet by Id - operationId: updatePet - requestBody: - description: Update an existent pet in the store - content: - application/json: - schema: - $ref: '#/components/schemas/Pet' - application/xml: - schema: - $ref: '#/components/schemas/Pet' - application/x-www-form-urlencoded: - schema: - $ref: '#/components/schemas/Pet' - required: true - responses: - "200": - description: Successful operation - content: - application/json: - schema: - $ref: '#/components/schemas/Pet' - application/xml: - schema: - $ref: '#/components/schemas/Pet' - "400": - description: Invalid ID supplied - "404": - description: Pet not found - "405": - description: Validation exception - security: - - petstore_auth: - - write:pets - - read:pets - x-swagger-router-controller: Pet + /ad: post: tags: - - pet - summary: Add a new pet to the store - description: Add a new pet to the store - operationId: addPet + - ad + summary: Add a new ad + description: Add a new ad to the list + operationId: addAd requestBody: - description: Create a new pet in the store + description: Create a new ad in the + required: true content: application/json: schema: - $ref: '#/components/schemas/Pet' - application/xml: - schema: - $ref: '#/components/schemas/Pet' - application/x-www-form-urlencoded: - schema: - $ref: '#/components/schemas/Pet' - required: true + $ref: '#/components/schemas/Ad' responses: "200": description: Successful operation content: application/json: schema: - $ref: '#/components/schemas/Pet' - application/xml: - schema: - $ref: '#/components/schemas/Pet' - "405": - description: Invalid input - security: - - petstore_auth: - - write:pets - - read:pets - x-swagger-router-controller: Pet - /pet/findByStatus: - get: - tags: - - pet - summary: Finds Pets by status - description: Multiple status values can be provided with comma separated strings - operationId: findPetsByStatus - parameters: - - name: status - in: query - description: Status values that need to be considered for filter - required: false - style: form - explode: true - schema: - type: string - default: available - enum: - - available - - pending - - sold - responses: - "200": - description: successful operation - content: - application/json: - schema: - type: array - items: - $ref: '#/components/schemas/Pet' - x-content-type: application/json - application/xml: - schema: - type: array - items: - $ref: '#/components/schemas/Pet' - "400": - description: Invalid status value - security: - - petstore_auth: - - write:pets - - read:pets - x-swagger-router-controller: Pet - /pet/findByTags: - get: - tags: - - pet - summary: Finds Pets by tags - description: "Multiple tags can be provided with comma separated strings. Use\ - \ tag1, tag2, tag3 for testing." - operationId: findPetsByTags - parameters: - - name: tags - in: query - description: Tags to filter by - required: false - style: form - explode: true - schema: - type: array - items: - type: string - responses: - "200": - description: successful operation - content: - application/json: - schema: - type: array - items: - $ref: '#/components/schemas/Pet' - x-content-type: application/json - application/xml: - schema: - type: array - items: - $ref: '#/components/schemas/Pet' - "400": - description: Invalid tag value - security: - - petstore_auth: - - write:pets - - read:pets - x-swagger-router-controller: Pet - /pet/{petId}: - get: - tags: - - pet - summary: Find pet by ID - description: Returns a single pet - operationId: getPetById - parameters: - - name: petId - in: path - description: ID of pet to return - required: true - style: simple - explode: false - schema: - type: integer - format: int64 - responses: - "200": - description: successful operation - content: - application/json: - schema: - $ref: '#/components/schemas/Pet' - application/xml: - schema: - $ref: '#/components/schemas/Pet' - "400": - description: Invalid ID supplied - "404": - description: Pet not found - security: - - api_key: [] - - petstore_auth: - - write:pets - - read:pets - x-swagger-router-controller: Pet - post: - tags: - - pet - summary: Updates a pet in the store with form data - description: "" - operationId: updatePetWithForm - parameters: - - name: petId - in: path - description: ID of pet that needs to be updated - required: true - style: simple - explode: false - schema: - type: integer - format: int64 - - name: name - in: query - description: Name of pet that needs to be updated - required: false - style: form - explode: true - schema: - type: string - - name: status - in: query - description: Status of pet that needs to be updated - required: false - style: form - explode: true - schema: - type: string - responses: + $ref: '#/components/schemas/Ad' "405": description: Invalid input security: - - petstore_auth: - - write:pets - - read:pets - x-swagger-router-controller: Pet - delete: - tags: - - pet - summary: Deletes a pet - description: delete a pet - operationId: deletePet - parameters: - - name: api_key - in: header - description: "" - required: false - style: simple - explode: false - schema: - type: string - - name: petId - in: path - description: Pet id to delete - required: true - style: simple - explode: false - schema: - type: integer - format: int64 - responses: - "400": - description: Invalid pet value - security: - - petstore_auth: - - write:pets - - read:pets - x-swagger-router-controller: Pet - /pet/{petId}/uploadImage: - post: - tags: - - pet - summary: uploads an image - description: "" - operationId: uploadFile - parameters: - - name: petId - in: path - description: ID of pet to update - required: true - style: simple - explode: false - schema: - type: integer - format: int64 - - name: additionalMetadata - in: query - description: Additional Metadata - required: false - style: form - explode: true - schema: - type: string - requestBody: - content: - application/octet-stream: - schema: - type: string - format: binary - responses: - "200": - description: successful operation - content: - application/json: - schema: - $ref: '#/components/schemas/ApiResponse' - security: - - petstore_auth: - - write:pets - - read:pets - x-swagger-router-controller: Pet - /store/inventory: - get: - tags: - - store - summary: Returns pet inventories by status - description: Returns a map of status codes to quantities - operationId: getInventory - responses: - "200": - description: successful operation - content: - application/json: - schema: - type: object - additionalProperties: - type: integer - format: int32 - x-content-type: application/json - security: - - api_key: [] - x-swagger-router-controller: Store - /store/order: - post: - tags: - - store - summary: Place an order for a pet - description: Place a new order in the store - operationId: placeOrder - requestBody: - content: - application/json: - schema: - $ref: '#/components/schemas/Order' - application/xml: - schema: - $ref: '#/components/schemas/Order' - application/x-www-form-urlencoded: - schema: - $ref: '#/components/schemas/Order' - responses: - "200": - description: successful operation - content: - application/json: - schema: - $ref: '#/components/schemas/Order' - "405": - description: Invalid input - x-swagger-router-controller: Store - /store/order/{orderId}: - get: - tags: - - store - summary: Find purchase order by ID - description: For valid response try integer IDs with value <= 5 or > 10. Other - values will generate exceptions. - operationId: getOrderById - parameters: - - name: orderId - in: path - description: ID of order that needs to be fetched - required: true - style: simple - explode: false - schema: - type: integer - format: int64 - responses: - "200": - description: successful operation - content: - application/json: - schema: - $ref: '#/components/schemas/Order' - application/xml: - schema: - $ref: '#/components/schemas/Order' - "400": - description: Invalid ID supplied - "404": - description: Order not found - x-swagger-router-controller: Store - delete: - tags: - - store - summary: Delete purchase order by ID - description: For valid response try integer IDs with value < 1000. Anything - above 1000 or nonintegers will generate API errors - operationId: deleteOrder - parameters: - - name: orderId - in: path - description: ID of the order that needs to be deleted - required: true - style: simple - explode: false - schema: - type: integer - format: int64 - responses: - "400": - description: Invalid ID supplied - "404": - description: Order not found - x-swagger-router-controller: Store + - real-estate-ads_auth: + - write:ads + - read:ads + x-swagger-router-controller: Ad /user: post: tags: - - user + - user summary: Create user description: This can only be done by the logged in user. operationId: createUser @@ -482,14 +80,14 @@ paths: application/json: schema: $ref: '#/components/schemas/User' - application/xml: - schema: - $ref: '#/components/schemas/User' + application/xml: + schema: + $ref: '#/components/schemas/User' x-swagger-router-controller: User /user/createWithList: post: tags: - - user + - user summary: Creates list of users with given input array description: Creates list of users with given input array operationId: createUsersWithListInput @@ -507,36 +105,36 @@ paths: application/json: schema: $ref: '#/components/schemas/User' - application/xml: - schema: - $ref: '#/components/schemas/User' + application/xml: + schema: + $ref: '#/components/schemas/User' default: description: successful operation x-swagger-router-controller: User /user/login: get: tags: - - user + - user summary: Logs user into the system description: "" operationId: loginUser parameters: - - name: username - in: query - description: The user name for login - required: false - style: form - explode: true - schema: - type: string - - name: password - in: query - description: The password for login in clear text - required: false - style: form - explode: true - schema: - type: string + - name: username + in: query + description: The user name for login + required: false + style: form + explode: true + schema: + type: string + - name: password + in: query + description: The password for login in clear text + required: false + style: form + explode: true + schema: + type: string responses: "200": description: successful operation @@ -560,16 +158,16 @@ paths: schema: type: string x-content-type: application/xml - application/json: - schema: - type: string + application/json: + schema: + type: string "400": description: Invalid username/password supplied x-swagger-router-controller: User /user/logout: get: tags: - - user + - user summary: Logs out current logged in user session description: "" operationId: logoutUser @@ -581,19 +179,19 @@ paths: /user/{username}: get: tags: - - user + - user summary: Get user by user name description: "" operationId: getUserByName parameters: - - name: username - in: path - description: 'The name that needs to be fetched. Use user1 for testing. ' - required: true - style: simple - explode: false - schema: - type: string + - name: username + in: path + description: 'The name that needs to be fetched. Use user1 for testing. ' + required: true + style: simple + explode: false + schema: + type: string responses: "200": description: successful operation @@ -601,9 +199,9 @@ paths: application/json: schema: $ref: '#/components/schemas/User' - application/xml: - schema: - $ref: '#/components/schemas/User' + application/xml: + schema: + $ref: '#/components/schemas/User' "400": description: Invalid username supplied "404": @@ -611,21 +209,21 @@ paths: x-swagger-router-controller: User put: tags: - - user + - user summary: Update user description: This can only be done by the logged in user. operationId: updateUser parameters: - - name: username - in: path - description: name that need to be deleted - required: true - style: simple - explode: false - schema: - type: string + - name: username + in: path + description: name that need to be deleted + required: true + style: simple + explode: false + schema: + type: string requestBody: - description: Update an existent user in the store + description: Update an existent user in the content: application/json: schema: @@ -642,19 +240,19 @@ paths: x-swagger-router-controller: User delete: tags: - - user + - user summary: Delete user description: This can only be done by the logged in user. operationId: deleteUser parameters: - - name: username - in: path - description: The name that needs to be deleted - required: true - style: simple - explode: false - schema: - type: string + - name: username + in: path + description: The name that needs to be deleted + required: true + style: simple + explode: false + schema: + type: string responses: "400": description: Invalid username supplied @@ -663,201 +261,90 @@ paths: x-swagger-router-controller: User components: schemas: - Order: + Ad: type: object properties: - id: - type: integer - format: int64 - example: 10 - petId: - type: integer - format: int64 - example: 198772 - quantity: - type: integer - format: int32 - example: 7 - shipDate: + title: type: string - format: date-time - status: + propertyType: type: string - description: Order Status - example: approved enum: - - placed - - approved - - delivered - complete: - type: boolean - example: - petId: 198772 - quantity: 7 - id: 10 - shipDate: 2000-01-23T04:56:07.000+00:00 - complete: true - status: approved - xml: - name: order - Customer: - type: object - properties: - id: - type: integer - format: int64 - example: 100000 - username: + - À la vente + - À la location + publicationStatus: type: string - example: fehguy - address: - type: array - xml: - name: addresses - wrapped: true - items: - $ref: '#/components/schemas/Address' - xml: - name: customer - Address: - type: object - properties: - street: - type: string - example: 437 Lytton - city: + enum: + - Publiée + - Non publiée + propertyStatus: type: string - example: Palo Alto - state: + enum: + - Disponible + - Loué + - Vendu + description: type: string - example: CA - zip: + price: + type: number + minimum: 0 + availabilityDate: type: string - example: "94301" - xml: - name: address - Category: - type: object - properties: - id: - type: integer - format: int64 - example: 1 - name: + format: date-time + photos: + type: array + items: + type: string + userName: type: string - example: Dogs - example: - name: Dogs - id: 1 - xml: - name: category + questions: + type: array + items: + type: object + properties: + user: + type: string + question: + type: string + answers: + type: array + items: + type: object + properties: + answer: + type: string + date: + type: string + format: date-time + required: + - title + - propertyType + - publicationStatus + - propertyStatus + - description + - price + - availabilityDate + - userName User: type: object properties: id: type: integer format: int64 - example: 10 username: type: string - example: theUser firstName: type: string - example: John lastName: type: string - example: James email: type: string - example: john@email.com password: type: string - example: "12345" phone: type: string - example: "12345" userStatus: type: integer - description: User Status format: int32 - example: 1 - example: - firstName: John - lastName: James - password: "12345" - userStatus: 1 - phone: "12345" - id: 10 - email: john@email.com - username: theUser - xml: - name: user - Tag: - type: object - properties: - id: - type: integer - format: int64 - name: - type: string - example: - name: name - id: 0 - xml: - name: tag - Pet: - required: - - name - - photoUrls - type: object - properties: - id: - type: integer - format: int64 - example: 10 - name: - type: string - example: doggie - category: - $ref: '#/components/schemas/Category' - photoUrls: - type: array - xml: - wrapped: true - items: - type: string - xml: - name: photoUrl - tags: - type: array - xml: - wrapped: true - items: - $ref: '#/components/schemas/Tag' - status: - type: string - description: pet status in the store - enum: - - available - - pending - - sold - example: - photoUrls: - - photoUrls - - photoUrls - name: doggie - id: 10 - category: - name: Dogs - id: 1 - tags: - - name: name - id: 0 - - name: name - id: 0 - status: available - xml: - name: pet ApiResponse: type: object properties: @@ -875,15 +362,6 @@ components: xml: name: '##default' requestBodies: - Pet: - description: Pet object that needs to be added to the store - content: - application/json: - schema: - $ref: '#/components/schemas/Pet' - application/xml: - schema: - $ref: '#/components/schemas/Pet' UserArray: description: List of user object content: @@ -893,11 +371,11 @@ components: items: $ref: '#/components/schemas/User' securitySchemes: - petstore_auth: + real-estate-ads_auth: type: oauth2 flows: implicit: - authorizationUrl: https://petstore3.swagger.io/oauth/authorize + authorizationUrl: https://real-estate-ads3.swagger.io/oauth/authorize scopes: write:pets: modify pets in your account read:pets: read your pets diff --git a/controllers/Ad.js b/controllers/Ad.js new file mode 100644 index 0000000000000000000000000000000000000000..28ea513b09ee84dcf06216adc5e3f9b498e5bbb9 --- /dev/null +++ b/controllers/Ad.js @@ -0,0 +1,74 @@ +'use strict'; + +var utils = require('../utils/writer.js'); +var Ad = require('../service/AdService'); // Assurez-vous d'importer le service Announcement + +module.exports.addAd = function addAd (req, res, next, body) { + Ad.addAd(body) + .then(function (response) { + utils.writeJson(res, response); + }) + .catch(function (response) { + utils.writeJson(res, response); + }); +}; + +/*module.exports.deleteAnnouncement = function deleteAnnouncement (req, res, next, announcementId) { + Announcement.deleteAnnouncement(announcementId) + .then(function (response) { + utils.writeJson(res, response); + }) + .catch(function (response) { + utils.writeJson(res, response); + }); +}; + +module.exports.getAllAnnouncements = function getAllAnnouncements (req, res, next) { + Announcement.getAllAnnouncements() + .then(function (response) { + utils.writeJson(res, response); + }) + .catch(function (response) { + utils.writeJson(res, response); + }); +}; + +module.exports.getAnnouncementById = function getAnnouncementById (req, res, next, announcementId) { + Announcement.getAnnouncementById(announcementId) + .then(function (response) { + utils.writeJson(res, response); + }) + .catch(function (response) { + utils.writeJson(res, response); + }); +}; + +module.exports.updateAnnouncement = function updateAnnouncement (req, res, next, announcementId, body) { + Announcement.updateAnnouncement(announcementId, body) + .then(function (response) { + utils.writeJson(res, response); + }) + .catch(function (response) { + utils.writeJson(res, response); + }); +}; + +module.exports.findAnnouncementsByStatus = function findAnnouncementsByStatus (req, res, next, status) { + Announcement.findAnnouncementsByStatus(status) + .then(function (response) { + utils.writeJson(res, response); + }) + .catch(function (response) { + utils.writeJson(res, response); + }); +}; + +module.exports.findAnnouncementsByPropertyType = function findAnnouncementsByPropertyType (req, res, next, propertyType) { + Announcement.findAnnouncementsByPropertyType(propertyType) + .then(function (response) { + utils.writeJson(res, response); + }) + .catch(function (response) { + utils.writeJson(res, response); + }); +};*/ diff --git a/controllers/Pet.js b/controllers/Pet.js deleted file mode 100644 index 9b79269b5a797e17957189dce1e509be4ef542ab..0000000000000000000000000000000000000000 --- a/controllers/Pet.js +++ /dev/null @@ -1,104 +0,0 @@ -'use strict'; - -var utils = require('../utils/writer.js'); -var Pet = require('../service/PetService'); - -module.exports.addPet = function addPet (req, res, next, body) { - Pet.addPet(body) - .then(function (response) { - utils.writeJson(res, response); - }) - .catch(function (response) { - utils.writeJson(res, response); - }); -}; - -module.exports.addPet = function addPet (req, res, next, body) { - Pet.addPet(body) - .then(function (response) { - utils.writeJson(res, response); - }) - .catch(function (response) { - utils.writeJson(res, response); - }); -}; - -module.exports.deletePet = function deletePet (req, res, next, petId, api_key) { - Pet.deletePet(petId, api_key) - .then(function (response) { - utils.writeJson(res, response); - }) - .catch(function (response) { - utils.writeJson(res, response); - }); -}; - -module.exports.findPetsByStatus = function findPetsByStatus (req, res, next, status) { - Pet.findPetsByStatus(status) - .then(function (response) { - utils.writeJson(res, response); - }) - .catch(function (response) { - utils.writeJson(res, response); - }); -}; - -module.exports.findPetsByTags = function findPetsByTags (req, res, next, tags) { - Pet.findPetsByTags(tags) - .then(function (response) { - utils.writeJson(res, response); - }) - .catch(function (response) { - utils.writeJson(res, response); - }); -}; - -module.exports.getPetById = function getPetById (req, res, next, petId) { - Pet.getPetById(petId) - .then(function (response) { - utils.writeJson(res, response); - }) - .catch(function (response) { - utils.writeJson(res, response); - }); -}; - -module.exports.updatePet = function updatePet (req, res, next, body) { - Pet.updatePet(body) - .then(function (response) { - utils.writeJson(res, response); - }) - .catch(function (response) { - utils.writeJson(res, response); - }); -}; - -module.exports.updatePet = function updatePet (req, res, next, body) { - Pet.updatePet(body) - .then(function (response) { - utils.writeJson(res, response); - }) - .catch(function (response) { - utils.writeJson(res, response); - }); -}; - -module.exports.updatePetWithForm = function updatePetWithForm (req, res, next, petId, name, status) { - Pet.updatePetWithForm(petId, name, status) - .then(function (response) { - utils.writeJson(res, response); - }) - .catch(function (response) { - utils.writeJson(res, response); - }); -}; - -module.exports.uploadFile = function uploadFile (req, res, next, body, additionalMetadata, petId) { - Pet.uploadFile(body, additionalMetadata, petId) - .then(function (response) { - utils.writeJson(res, response); - }) - .catch(function (response) { - utils.writeJson(res, response); - }); -}; diff --git a/controllers/Store.js b/controllers/Store.js deleted file mode 100644 index c970eae47224cab90a93fe1258d6c2fc47c2bc3c..0000000000000000000000000000000000000000 --- a/controllers/Store.js +++ /dev/null @@ -1,54 +0,0 @@ -'use strict'; - -var utils = require('../utils/writer.js'); -var Store = require('../service/StoreService'); - -module.exports.deleteOrder = function deleteOrder (req, res, next, orderId) { - Store.deleteOrder(orderId) - .then(function (response) { - utils.writeJson(res, response); - }) - .catch(function (response) { - utils.writeJson(res, response); - }); -}; - -module.exports.getInventory = function getInventory (req, res, next) { - Store.getInventory() - .then(function (response) { - utils.writeJson(res, response); - }) - .catch(function (response) { - utils.writeJson(res, response); - }); -}; - -module.exports.getOrderById = function getOrderById (req, res, next, orderId) { - Store.getOrderById(orderId) - .then(function (response) { - utils.writeJson(res, response); - }) - .catch(function (response) { - utils.writeJson(res, response); - }); -}; - -module.exports.placeOrder = function placeOrder (req, res, next, body) { - Store.placeOrder(body) - .then(function (response) { - utils.writeJson(res, response); - }) - .catch(function (response) { - utils.writeJson(res, response); - }); -}; - -module.exports.placeOrder = function placeOrder (req, res, next, body) { - Store.placeOrder(body) - .then(function (response) { - utils.writeJson(res, response); - }) - .catch(function (response) { - utils.writeJson(res, response); - }); -}; diff --git a/nodemon.json b/nodemon.json new file mode 100644 index 0000000000000000000000000000000000000000..7797061cf267a36aa8886446f58615876d3ff075 --- /dev/null +++ b/nodemon.json @@ -0,0 +1,7 @@ +{ + "watch": ["openapi.yaml"], + "ext": "yaml,yml,json", + "execMap": { + "js": "node --experimental-json-modules" + } +} diff --git a/service/AdService.js b/service/AdService.js new file mode 100644 index 0000000000000000000000000000000000000000..1563c0303bbba586c9253dbef7ff5c2445268c39 --- /dev/null +++ b/service/AdService.js @@ -0,0 +1,102 @@ +const Ad = require('../models/Ad'); + +// Méthode pour ajouter une nouvelle annonce +exports.addAd = function (body) { + return new Promise(async (resolve, reject) => { + try { + const newAd = new Ad(body); + const savedAd = await newAd.save(); + resolve(savedAd); + } catch (error) { + reject(error); + } + }); +} + +// Méthode pour supprimer une annonce par son ID +exports.deleteAd = function (AdId) { + return new Promise(async (resolve, reject) => { + try { + const deletedAd = await Ad.findByIdAndRemove(AdId); + if (!deletedAd) { + reject('Annonce non trouvée'); + } else { + resolve('Annonce supprimée avec succès'); + } + } catch (error) { + reject(error); + } + }); +} + +// Méthode pour récupérer toutes les annonces +exports.getAllAds = function () { + return new Promise(async (resolve, reject) => { + try { + const Ads = await Ad.find(); + resolve(Ads); + } catch (error) { + reject(error); + } + }); +} + +// Méthode pour récupérer une annonce par son ID +exports.getAdById = function (AdId) { + return new Promise(async (resolve, reject) => { + try { + const Ad = await Ad.findById(AdId); + if (!Ad) { + reject('Annonce non trouvée'); + } else { + resolve(Ad); + } + } catch (error) { + reject(error); + } + }); +} + +// Méthode pour mettre à jour une annonce par son ID +exports.updateAd = function (AdId, body) { + return new Promise(async (resolve, reject) => { + try { + const updatedAd = await Ad.findByIdAndUpdate( + AdId, + body, + { new: true } + ); + if (!updatedAd) { + reject('Annonce non trouvée'); + } else { + resolve(updatedAd); + } + } catch (error) { + reject(error); + } + }); +} + +// Méthode pour rechercher des annonces par statut +exports.findAdsByStatus = function (status) { + return new Promise(async (resolve, reject) => { + try { + const Ads = await Ad.find({ publicationStatus: status }); + resolve(Ads); + } catch (error) { + reject(error); + } + }); +} + +// Méthode pour rechercher des annonces par type de propriété +exports.findAdsByPropertyType = function (propertyType) { + return new Promise(async (resolve, reject) => { + try { + const Ads = await Ad.find({ propertyType }); + resolve(Ads); + } catch (error) { + reject(error); + } + }); +} diff --git a/service/PetService.js b/service/PetService.js deleted file mode 100644 index 7a00d00c3d5f879461c09b5eaf306af7cbf6b38a..0000000000000000000000000000000000000000 --- a/service/PetService.js +++ /dev/null @@ -1,341 +0,0 @@ -'use strict'; - - -/** - * Add a new pet to the store - * Add a new pet to the store - * - * body Pet Create a new pet in the store - * returns Pet - **/ -exports.addPet = function(body) { - return new Promise(function(resolve, reject) { - var examples = {}; - examples['application/json'] = { - "photoUrls" : [ "photoUrls", "photoUrls" ], - "name" : "doggie", - "id" : 10, - "category" : { - "name" : "Dogs", - "id" : 1 - }, - "tags" : [ { - "name" : "name", - "id" : 0 - }, { - "name" : "name", - "id" : 0 - } ], - "status" : "available" -}; - if (Object.keys(examples).length > 0) { - resolve(examples[Object.keys(examples)[0]]); - } else { - resolve(); - } - }); -} - - -/** - * Add a new pet to the store - * Add a new pet to the store - * - * body Pet Create a new pet in the store - * returns Pet - **/ -exports.addPet = function(body) { - return new Promise(function(resolve, reject) { - var examples = {}; - examples['application/json'] = { - "photoUrls" : [ "photoUrls", "photoUrls" ], - "name" : "doggie", - "id" : 10, - "category" : { - "name" : "Dogs", - "id" : 1 - }, - "tags" : [ { - "name" : "name", - "id" : 0 - }, { - "name" : "name", - "id" : 0 - } ], - "status" : "available" -}; - if (Object.keys(examples).length > 0) { - resolve(examples[Object.keys(examples)[0]]); - } else { - resolve(); - } - }); -} - - -/** - * Deletes a pet - * delete a pet - * - * petId Long Pet id to delete - * api_key String (optional) - * no response value expected for this operation - **/ -exports.deletePet = function(petId,api_key) { - return new Promise(function(resolve, reject) { - resolve(); - }); -} - - -/** - * Finds Pets by status - * Multiple status values can be provided with comma separated strings - * - * status String Status values that need to be considered for filter (optional) - * returns List - **/ -exports.findPetsByStatus = function(status) { - return new Promise(function(resolve, reject) { - var examples = {}; - examples['application/json'] = [ { - "photoUrls" : [ "photoUrls", "photoUrls" ], - "name" : "doggie", - "id" : 10, - "category" : { - "name" : "Dogs", - "id" : 1 - }, - "tags" : [ { - "name" : "name", - "id" : 0 - }, { - "name" : "name", - "id" : 0 - } ], - "status" : "available" -}, { - "photoUrls" : [ "photoUrls", "photoUrls" ], - "name" : "doggie", - "id" : 10, - "category" : { - "name" : "Dogs", - "id" : 1 - }, - "tags" : [ { - "name" : "name", - "id" : 0 - }, { - "name" : "name", - "id" : 0 - } ], - "status" : "available" -} ]; - if (Object.keys(examples).length > 0) { - resolve(examples[Object.keys(examples)[0]]); - } else { - resolve(); - } - }); -} - - -/** - * Finds Pets by tags - * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. - * - * tags List Tags to filter by (optional) - * returns List - **/ -exports.findPetsByTags = function(tags) { - return new Promise(function(resolve, reject) { - var examples = {}; - examples['application/json'] = [ { - "photoUrls" : [ "photoUrls", "photoUrls" ], - "name" : "doggie", - "id" : 10, - "category" : { - "name" : "Dogs", - "id" : 1 - }, - "tags" : [ { - "name" : "name", - "id" : 0 - }, { - "name" : "name", - "id" : 0 - } ], - "status" : "available" -}, { - "photoUrls" : [ "photoUrls", "photoUrls" ], - "name" : "doggie", - "id" : 10, - "category" : { - "name" : "Dogs", - "id" : 1 - }, - "tags" : [ { - "name" : "name", - "id" : 0 - }, { - "name" : "name", - "id" : 0 - } ], - "status" : "available" -} ]; - if (Object.keys(examples).length > 0) { - resolve(examples[Object.keys(examples)[0]]); - } else { - resolve(); - } - }); -} - - -/** - * Find pet by ID - * Returns a single pet - * - * petId Long ID of pet to return - * returns Pet - **/ -exports.getPetById = function(petId) { - return new Promise(function(resolve, reject) { - var examples = {}; - examples['application/json'] = { - "photoUrls" : [ "photoUrls", "photoUrls" ], - "name" : "doggie", - "id" : 10, - "category" : { - "name" : "Dogs", - "id" : 1 - }, - "tags" : [ { - "name" : "name", - "id" : 0 - }, { - "name" : "name", - "id" : 0 - } ], - "status" : "available" -}; - if (Object.keys(examples).length > 0) { - resolve(examples[Object.keys(examples)[0]]); - } else { - resolve(); - } - }); -} - - -/** - * Update an existing pet - * Update an existing pet by Id - * - * body Pet Update an existent pet in the store - * returns Pet - **/ -exports.updatePet = function(body) { - return new Promise(function(resolve, reject) { - var examples = {}; - examples['application/json'] = { - "photoUrls" : [ "photoUrls", "photoUrls" ], - "name" : "doggie", - "id" : 10, - "category" : { - "name" : "Dogs", - "id" : 1 - }, - "tags" : [ { - "name" : "name", - "id" : 0 - }, { - "name" : "name", - "id" : 0 - } ], - "status" : "available" -}; - if (Object.keys(examples).length > 0) { - resolve(examples[Object.keys(examples)[0]]); - } else { - resolve(); - } - }); -} - - -/** - * Update an existing pet - * Update an existing pet by Id - * - * body Pet Update an existent pet in the store - * returns Pet - **/ -exports.updatePet = function(body) { - return new Promise(function(resolve, reject) { - var examples = {}; - examples['application/json'] = { - "photoUrls" : [ "photoUrls", "photoUrls" ], - "name" : "doggie", - "id" : 10, - "category" : { - "name" : "Dogs", - "id" : 1 - }, - "tags" : [ { - "name" : "name", - "id" : 0 - }, { - "name" : "name", - "id" : 0 - } ], - "status" : "available" -}; - if (Object.keys(examples).length > 0) { - resolve(examples[Object.keys(examples)[0]]); - } else { - resolve(); - } - }); -} - - -/** - * Updates a pet in the store with form data - * - * petId Long ID of pet that needs to be updated - * name String Name of pet that needs to be updated (optional) - * status String Status of pet that needs to be updated (optional) - * no response value expected for this operation - **/ -exports.updatePetWithForm = function(petId,name,status) { - return new Promise(function(resolve, reject) { - resolve(); - }); -} - - -/** - * uploads an image - * - * body Object (optional) - * additionalMetadata String Additional Metadata (optional) - * petId Long ID of pet to update - * returns ApiResponse - **/ -exports.uploadFile = function(body,additionalMetadata,petId) { - return new Promise(function(resolve, reject) { - var examples = {}; - examples['application/json'] = { - "code" : 0, - "type" : "type", - "message" : "message" -}; - if (Object.keys(examples).length > 0) { - resolve(examples[Object.keys(examples)[0]]); - } else { - resolve(); - } - }); -} - diff --git a/service/StoreService.js b/service/StoreService.js deleted file mode 100644 index d91aeed8ec5011a321243c70e46203b0d343c28d..0000000000000000000000000000000000000000 --- a/service/StoreService.js +++ /dev/null @@ -1,118 +0,0 @@ -'use strict'; - - -/** - * Delete purchase order by ID - * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors - * - * orderId Long ID of the order that needs to be deleted - * no response value expected for this operation - **/ -exports.deleteOrder = function(orderId) { - return new Promise(function(resolve, reject) { - resolve(); - }); -} - - -/** - * Returns pet inventories by status - * Returns a map of status codes to quantities - * - * returns Map - **/ -exports.getInventory = function() { - return new Promise(function(resolve, reject) { - var examples = {}; - examples['application/json'] = { - "key" : 0 -}; - if (Object.keys(examples).length > 0) { - resolve(examples[Object.keys(examples)[0]]); - } else { - resolve(); - } - }); -} - - -/** - * Find purchase order by ID - * For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions. - * - * orderId Long ID of order that needs to be fetched - * returns Order - **/ -exports.getOrderById = function(orderId) { - return new Promise(function(resolve, reject) { - var examples = {}; - examples['application/json'] = { - "petId" : 198772, - "quantity" : 7, - "id" : 10, - "shipDate" : "2000-01-23T04:56:07.000+00:00", - "complete" : true, - "status" : "approved" -}; - if (Object.keys(examples).length > 0) { - resolve(examples[Object.keys(examples)[0]]); - } else { - resolve(); - } - }); -} - - -/** - * Place an order for a pet - * Place a new order in the store - * - * body Order (optional) - * returns Order - **/ -exports.placeOrder = function(body) { - return new Promise(function(resolve, reject) { - var examples = {}; - examples['application/json'] = { - "petId" : 198772, - "quantity" : 7, - "id" : 10, - "shipDate" : "2000-01-23T04:56:07.000+00:00", - "complete" : true, - "status" : "approved" -}; - if (Object.keys(examples).length > 0) { - resolve(examples[Object.keys(examples)[0]]); - } else { - resolve(); - } - }); -} - - -/** - * Place an order for a pet - * Place a new order in the store - * - * body Order (optional) - * returns Order - **/ -exports.placeOrder = function(body) { - return new Promise(function(resolve, reject) { - var examples = {}; - examples['application/json'] = { - "petId" : 198772, - "quantity" : 7, - "id" : 10, - "shipDate" : "2000-01-23T04:56:07.000+00:00", - "complete" : true, - "status" : "approved" -}; - if (Object.keys(examples).length > 0) { - resolve(examples[Object.keys(examples)[0]]); - } else { - resolve(); - } - }); -} - diff --git a/service/UserService.js b/service/UserService.js index f697bccf105232e8561a41e3aac99ff7406fca63..b102f62953ae35d93e871ddc1f6d24001342be5f 100644 --- a/service/UserService.js +++ b/service/UserService.js @@ -1,30 +1,22 @@ 'use strict'; +const User = require('../models/User') /** - * Create user - * This can only be done by the logged in user. + * Créer un nouvel utilisateur + * Cela ne peut être fait que par l'utilisateur connecté. * - * body User Created user object (optional) + * body User Object utilisateur créé (optionnel) * returns User **/ exports.createUser = function(body) { - return new Promise(function(resolve, reject) { - var examples = {}; - examples['application/json'] = { - "firstName" : "John", - "lastName" : "James", - "password" : "12345", - "userStatus" : 1, - "phone" : "12345", - "id" : 10, - "email" : "john@email.com", - "username" : "theUser" -}; - if (Object.keys(examples).length > 0) { - resolve(examples[Object.keys(examples)[0]]); - } else { - resolve(); + return new Promise(async (resolve, reject) => { + try { + const newUser = new User(body); + const savedUser = await newUser.save(); + resolve(savedUser); + } catch (error) { + reject(error); } }); } @@ -105,7 +97,7 @@ exports.deleteUser = function(username) { /** * Get user by user name * - * username String The name that needs to be fetched. Use user1 for testing. + * username String The name that needs to be fetched. Use user1 for testing. * returns User **/ exports.getUserByName = function(username) { @@ -170,11 +162,13 @@ exports.logoutUser = function() { * username String name that need to be deleted * no response value expected for this operation **/ -exports.updateUser = function(body,username) { - return new Promise(function(resolve, reject) { - resolve(); +exports.updateUser = function (body, username) { + return new Promise(function (resolve, reject) { + User.findOneAndUpdate({ username: username }, body, { new: true }) + .then((user) => resolve(user)) + .catch((error) => reject(error)); }); -} +}; /**