Skip to content
This repository has been archived by the owner on Jul 8, 2024. It is now read-only.

Commit

Permalink
ref(#35): change restaurant controller and update bruno requests
Browse files Browse the repository at this point in the history
  • Loading branch information
floriaaan committed Jan 10, 2024
1 parent 449bdd6 commit c67f2eb
Show file tree
Hide file tree
Showing 12 changed files with 207 additions and 65 deletions.
3 changes: 3 additions & 0 deletions requests/environments/local.bru
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
vars {
baseUrl: http://localhost:50000
}
vars:secret [
token
]
43 changes: 43 additions & 0 deletions requests/restaurant/create restaurant.bru
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
meta {
name: create restaurant
type: http
seq: 2
}

post {
url: {{baseUrl}}/api/restaurant
body: json
auth: bearer
}

headers {
Content-Type: application/json
}

auth:bearer {
token: {{token}}
}

body:json {
{
"name": "restaurant-name",
"description": "restaurant-desc",
"address": {
"street": "restaurant-street",
"city": "restaurant-city",
"zipCode": "restaurant-postalCode",
"country": "restaurant-country",
"lat": 49.443,
"lng": 1.099
},
"openingHoursList": [
"12h-14h",
"19h-22h"
],
"phone": "restaurant-phone",
"userIds": [
"user-id-1",
"user-id-2"
]
}
}
22 changes: 22 additions & 0 deletions requests/restaurant/get restaurant by id.bru
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
meta {
name: get restaurant by id
type: http
seq: 6
}

get {
url: {{baseUrl}}/api/restaurant/clr7ocdea00006tc1c5pc1gcn
body: none
auth: none
}

headers {
Content-Type: application/json
}

body:json {
{
"lat": 49.443,
"lng": 1.099
}
}
22 changes: 22 additions & 0 deletions requests/restaurant/list restaurants.bru
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
meta {
name: list restaurants
type: http
seq: 5
}

get {
url: {{baseUrl}}/api/restaurant/
body: none
auth: none
}

headers {
Content-Type: application/json
}

body:json {
{
"lat": 49.443,
"lng": 1.099
}
}
6 changes: 2 additions & 4 deletions requests/restaurant/post restaurant by location.bru
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ headers {

body:json {
{
"locationList": [
"<number>",
"<number>"
]
"lat": 49.443,
"lng": 1.099
}
}
36 changes: 0 additions & 36 deletions requests/restaurant/post restaurant.bru

This file was deleted.

43 changes: 43 additions & 0 deletions requests/restaurant/update restaurant.bru
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
meta {
name: update restaurant
type: http
seq: 4
}

put {
url: {{baseUrl}}/api/restaurant/clr7ocdea00006tc1c5pc1gcn
body: json
auth: bearer
}

headers {
Content-Type: application/json
}

auth:bearer {
token: {{token}}
}

body:json {
{
"name": "restaurant-name-updated",
"description": "restaurant-desc",
"address": {
"street": "restaurant-street-updated",
"city": "restaurant-city",
"zipCode": "restaurant-postalCode",
"country": "restaurant-country",
"lat": 59.445,
"lng": 2.099
},
"openingHoursList": [
"12h-14h",
"19h-22h"
],
"phone": "restaurant-phone",
"userIds": [
"user-id-1",
"user-id-2"
]
}
}
67 changes: 47 additions & 20 deletions services/gateway/src/controller/restaurant/restaurant.controller.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { Request, Response, Router } from "express";
import { restaurantServiceClient } from "@gateway/services/clients/restaurant.client";
import { RestaurantId } from "@gateway/proto/product_pb";
import { Empty } from "google-protobuf/google/protobuf/empty_pb";

import {
ByLocationInput,
Restaurant,
RestaurantId,
RestaurantCreateInput,
RestaurantDeleteInput,
Address,
} from "@gateway/proto/restaurant_pb";
import { withCheck } from "@gateway/middleware/auth";

Expand Down Expand Up @@ -38,19 +40,17 @@ restaurantRoutes.post("/api/restaurant/by-location", async (req: Request, res: R
in: 'body',
required: true,
schema: {
locationList: [1.099, 49.443]
lat: 49.443,
lng: 1.099
}
}
*/

const { locationList } = req.body;
restaurantServiceClient.getRestaurantsByLocation(
new ByLocationInput().setLocationList(locationList),
(error, response) => {
if (error) return res.status(500).send({ error });
else return res.status(200).json(response.toObject());
},
);
const { lat, lng } = req.body;
restaurantServiceClient.getRestaurantsByLocation(new ByLocationInput().setLat(lat).setLng(lng), (error, response) => {
if (error) return res.status(500).send({ error });
else return res.status(200).json(response.toObject());
});
});

restaurantRoutes.post("/api/restaurant", withCheck({ role: "ADMIN" }), (req: Request, res: Response) => {
Expand All @@ -60,8 +60,14 @@ restaurantRoutes.post("/api/restaurant", withCheck({ role: "ADMIN" }), (req: Req
schema: {
name: "restaurant-name",
description: "restaurant-desc",
locationList: [1.099, 49.443],
address: "restaurant-address",
address: {
street: "restaurant-street",
city: "restaurant-city",
zipCode: "restaurant-postalCode",
country: "restaurant-country",
lat: 49.443,
lng: 1.099
},
openingHoursList: ["12h-14h", "19h-22h"],
phone: "restaurant-phone",
userIds: ["user-id-1", "user-id-2"]
Expand All @@ -72,12 +78,20 @@ restaurantRoutes.post("/api/restaurant", withCheck({ role: "ADMIN" }), (req: Req
required: true,
type: 'string'
} */
const { name, description, locationList, address, openingHoursList, phone, userIds } = req.body;
const { name, description, address, openingHoursList, phone, userIds } = req.body;

const restaurantCreateInput = new RestaurantCreateInput()
.setName(name)
.setDescription(description)
.setLocationList(locationList)
.setAddress(address)
.setAddress(
new Address()
.setStreet(address.street)
.setCity(address.city)
.setZipcode(address.zipCode)
.setCountry(address.country)
.setLat(address.lat)
.setLng(address.lng),
)
.setOpeninghoursList(openingHoursList)
.setPhone(phone)
.setUseridsList(userIds);
Expand All @@ -103,8 +117,14 @@ restaurantRoutes.put(
schema: {
name: "restaurant-name",
description: "restaurant-desc",
locationList: [1.099, 49.443],
address: "restaurant-address",
address: {
street: "restaurant-street",
city: "restaurant-city",
zipCode: "restaurant-postalCode",
country: "restaurant-country",
lat: 49.443,
lng: 1.099
},
openingHoursList: ["12h-14h", "19h-22h"],
phone: "restaurant-phone",
userIds: ["user-id-1", "user-id-2"]
Expand All @@ -116,13 +136,20 @@ restaurantRoutes.put(
type: 'string'
} */
const { id } = req.params;
const { name, description, locationList, address, openingHoursList, phone, userIds } = req.body;
const { name, description, address, openingHoursList, phone, userIds } = req.body;
const restaurantInput = new Restaurant()
.setId(id)
.setName(name)
.setDescription(description)
.setLocationList(locationList)
.setAddress(address)
.setAddress(
new Address()
.setStreet(address.street)
.setCity(address.city)
.setZipcode(address.zipCode)
.setCountry(address.country)
.setLat(address.lat)
.setLng(address.lng),
)
.setOpeninghoursList(openingHoursList)
.setPhone(phone)
.setUseridsList(userIds);
Expand Down
4 changes: 2 additions & 2 deletions services/proto/restaurant.proto
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ message Restaurant {
}

message Address {
string id = 1;
optional string id = 1;

float lat = 2;
float lng = 3;
Expand All @@ -31,7 +31,7 @@ message Address {
optional string zipcode = 6;
optional string country = 7;

string restaurantId = 8;
optional string restaurantId = 8;
}

message RestaurantCreateInput{
Expand Down
12 changes: 11 additions & 1 deletion services/restaurant/src/handler/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,17 @@ export const CreateRestaurant = async (
data: {
name,
openingHours,
address: { create: address },
address: {
create: {
lat: address.lat,
lng: address.lng,

street: address.street,
city: address.city,
zipcode: address.zipcode,
country: address.country,
},
},
description,
phone,
userIds,
Expand Down
12 changes: 11 additions & 1 deletion services/restaurant/src/handler/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,17 @@ export const UpdateRestaurant = async (
data: {
name,
openingHours,
address: { update: address },
address: {
update: {
lat: address.lat,
lng: address.lng,

street: address.street,
city: address.city,
zipcode: address.zipcode,
country: address.country,
},
},
description,
phone,
userIds,
Expand Down
2 changes: 1 addition & 1 deletion services/restaurant/src/types/restaurant.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export type Address = {
zipcode?: string;
country?: string;

restaurantId: string;
restaurantId?: string;
};

export type RestaurantCreateInput = Omit<
Expand Down

0 comments on commit c67f2eb

Please sign in to comment.