Skip to content

Commit

Permalink
fix: unable to build due to unimplemented server error
Browse files Browse the repository at this point in the history
  • Loading branch information
Red-GV committed Apr 9, 2024
1 parent 6a7a52b commit 8946321
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 124 deletions.
35 changes: 17 additions & 18 deletions hotelReservation/cmd/attractions/db.go
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
package main

import (
"context"
"fmt"
"github.com/rs/zerolog/log"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"fmt"
"context"
)

type Restaurant struct {
RestaurantId string `bson:"restaurantId"`
RLat float64 `bson:"lat"`
RLon float64 `bson:"lon"`
RestaurantName string `bson:"restaurantName"`
Rating float32 `bson:"rating"`
Type string `bson:"type"`
RestaurantId string `bson:"restaurantId"`
RLat float64 `bson:"lat"`
RLon float64 `bson:"lon"`
RestaurantName string `bson:"restaurantName"`
Rating float32 `bson:"rating"`
Type string `bson:"type"`
}

type Museum struct {
MuseumId string `bson:"museumId"`
MLat float64 `bson:"lat"`
MLon float64 `bson:"lon"`
MuseumName string `bson:"museumName"`
Type string `bson:"type"`
MuseumId string `bson:"museumId"`
MLat float64 `bson:"lat"`
MLon float64 `bson:"lon"`
MuseumName string `bson:"museumName"`
Type string `bson:"type"`
}

type point struct {
Expand All @@ -49,17 +49,17 @@ func initializeDatabase(url string) (*mongo.Client, func()) {
&Restaurant{"4", 37.7862, -122.4212, "R4", 3.2, "sushi"},
&Restaurant{"5", 37.7839, -122.4052, "R5", 4.9, "fusion"},
&Restaurant{"6", 37.7831, -122.3812, "R6", 4.1, "american"},
}
}

newMuseums := []interface{}{
&Museum{"1", 35.7867, -122.4112, "M1", "history"},
&Museum{"2", 36.7867, -122.5112, "M2", "history"},
&Museum{"3", 38.7867, -122.4612, "M3", "nature"},
&Museum{"4", 37.7867, -122.4912, "M4", "nature"},
&Museum{"5", 36.9867, -122.4212, "M5", "nature"},
&Museum{"6", 37.3867, -122.5012, "M6", "technology"},
}
}

uri := fmt.Sprintf("mongodb://%s", url)
log.Info().Msgf("Attempting connection to %v", uri)

Expand Down Expand Up @@ -98,4 +98,3 @@ func initializeDatabase(url string) (*mongo.Client, func()) {
}

}

8 changes: 3 additions & 5 deletions hotelReservation/cmd/attractions/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/rs/zerolog/log"

"time"

// "github.com/bradfitz/gomemcache/memcache"
)

Expand Down Expand Up @@ -81,13 +80,12 @@ func main() {
srv := attractions.Server{
Tracer: tracer,
// Port: *port,
Registry: registry,
Port: serv_port,
IpAddr: serv_ip,
Registry: registry,
Port: serv_port,
IpAddr: serv_ip,
MongoClient: mongo_session,
}

log.Info().Msg("Starting server...")
log.Fatal().Msg(srv.Run().Error())
}

24 changes: 12 additions & 12 deletions hotelReservation/cmd/review/db.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
package main

import (
"context"
"fmt"
"github.com/rs/zerolog/log"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"fmt"
"context"
)

type Review struct {
ReviewId string `bson:"reviewId"`
HotelId string `bson:"hotelId"`
Name string `bson:"name"`
Rating float32 `bson:"rating"`
Description string `bson:"description"`
Image *Image `bson:"images"`
ReviewId string `bson:"reviewId"`
HotelId string `bson:"hotelId"`
Name string `bson:"name"`
Rating float32 `bson:"rating"`
Description string `bson:"description"`
Image *Image `bson:"images"`
}

type Image struct {
Url string `bson:"url"`
Default bool `bson:"default"`
Url string `bson:"url"`
Default bool `bson:"default"`
}

func initializeDatabase(url string) (*mongo.Client, func()) {
Expand Down Expand Up @@ -79,8 +79,8 @@ func initializeDatabase(url string) (*mongo.Client, func()) {
&Image{
"some url",
false}},
}
}

uri := fmt.Sprintf("mongodb://%s", url)
log.Info().Msgf("Attempting connection to %v", uri)

Expand Down
9 changes: 4 additions & 5 deletions hotelReservation/cmd/review/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/rs/zerolog/log"

"time"

// "github.com/bradfitz/gomemcache/memcache"
)

Expand Down Expand Up @@ -81,11 +80,11 @@ func main() {
srv := review.Server{
Tracer: tracer,
// Port: *port,
Registry: registry,
Port: serv_port,
IpAddr: serv_ip,
Registry: registry,
Port: serv_port,
IpAddr: serv_ip,
MongoClient: mongo_session,
MemcClient: memc_client,
MemcClient: memc_client,
}

log.Info().Msg("Starting server...")
Expand Down
38 changes: 19 additions & 19 deletions hotelReservation/services/attractions/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ const (

// Server implements the attractions service
type Server struct {
pb.UnimplementedRateServer

indexH *geoindex.ClusteringIndex
indexR *geoindex.ClusteringIndex
indexM *geoindex.ClusteringIndex
indexC *geoindex.ClusteringIndex
uuid string
uuid string

Registry *registry.Client
Tracer opentracing.Tracer
Expand Down Expand Up @@ -216,7 +218,6 @@ func (s *Server) NearbyCinema(ctx context.Context, req *pb.Request) (*pb.Result,
return res, nil
}


func (s *Server) getNearbyPointsHotel(ctx context.Context, lat, lon float64) []geoindex.Point {
log.Trace().Msgf("In geo getNearbyPoints, lat = %f, lon = %f", lat, lon)

Expand Down Expand Up @@ -401,12 +402,12 @@ func (p *point) Lon() float64 { return p.Plon }
func (p *point) Id() string { return p.Pid }

type Restaurant struct {
RestaurantId string `bson:"restaurantId"`
RLat float64 `bson:"lat"`
RLon float64 `bson:"lon"`
RestaurantName string `bson:"restaurantName"`
Rating float32 `bson:"rating"`
Type string `bson:"type"`
RestaurantId string `bson:"restaurantId"`
RLat float64 `bson:"lat"`
RLon float64 `bson:"lon"`
RestaurantName string `bson:"restaurantName"`
Rating float32 `bson:"rating"`
Type string `bson:"type"`
}

// Implement Restaurant interface
Expand All @@ -415,11 +416,11 @@ func (r *Restaurant) Lon() float64 { return r.RLon }
func (r *Restaurant) Id() string { return r.RestaurantId }

type Museum struct {
MuseumId string `bson:"museumId"`
MLat float64 `bson:"lat"`
MLon float64 `bson:"lon"`
MuseumName string `bson:"museumName"`
Type string `bson:"type"`
MuseumId string `bson:"museumId"`
MLat float64 `bson:"lat"`
MLon float64 `bson:"lon"`
MuseumName string `bson:"museumName"`
Type string `bson:"type"`
}

// Implement Museum interface
Expand All @@ -428,15 +429,14 @@ func (m *Museum) Lon() float64 { return m.MLon }
func (m *Museum) Id() string { return m.MuseumId }

type Cinema struct {
CinemaId string `bson:"cinemaId"`
CLat float64 `bson:"lat"`
CLon float64 `bson:"lon"`
CinemaName string `bson:"cinemaName"`
Type string `bson:"type"`
CinemaId string `bson:"cinemaId"`
CLat float64 `bson:"lat"`
CLon float64 `bson:"lon"`
CinemaName string `bson:"cinemaName"`
Type string `bson:"type"`
}

// Implement Cinema interface
func (c *Cinema) Lat() float64 { return c.CLat }
func (c *Cinema) Lon() float64 { return c.CLon }
func (c *Cinema) Id() string { return c.CinemaId }

64 changes: 30 additions & 34 deletions hotelReservation/services/frontend/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import (

"github.com/delimitrou/DeathStarBench/hotelreservation/dialer"
"github.com/delimitrou/DeathStarBench/hotelreservation/registry"
attractions "github.com/delimitrou/DeathStarBench/hotelreservation/services/attractions/proto"
profile "github.com/delimitrou/DeathStarBench/hotelreservation/services/profile/proto"
recommendation "github.com/delimitrou/DeathStarBench/hotelreservation/services/recommendation/proto"
reservation "github.com/delimitrou/DeathStarBench/hotelreservation/services/reservation/proto"
review "github.com/delimitrou/DeathStarBench/hotelreservation/services/review/proto"
search "github.com/delimitrou/DeathStarBench/hotelreservation/services/search/proto"
user "github.com/delimitrou/DeathStarBench/hotelreservation/services/user/proto"
review "github.com/delimitrou/DeathStarBench/hotelreservation/services/review/proto"
attractions "github.com/delimitrou/DeathStarBench/hotelreservation/services/attractions/proto"
"github.com/delimitrou/DeathStarBench/hotelreservation/tls"
"github.com/delimitrou/DeathStarBench/hotelreservation/tracing"
_ "github.com/mbobakov/grpc-consul-resolver"
Expand Down Expand Up @@ -342,7 +342,6 @@ func (s *Server) recommendHandler(w http.ResponseWriter, r *http.Request) {
json.NewEncoder(w).Encode(geoJSONResponse(profileResp.Hotels))
}


func (s *Server) reviewHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
ctx := r.Context()
Expand Down Expand Up @@ -374,19 +373,19 @@ func (s *Server) reviewHandler(w http.ResponseWriter, r *http.Request) {
return
}

revInput := review.Request{HotelId:hotelId}
revInput := review.Request{HotelId: hotelId}

revResp, err := s.reviewClient.GetReviews(ctx, &revInput)

str = "Have reviews = " + strconv.Itoa(len(revResp.Reviews))
if len(revResp.Reviews) == 0 {
str = "Failed. No Reviews. "
str = "Have reviews = " + strconv.Itoa(len(revResp.Reviews))
if len(revResp.Reviews) == 0 {
str = "Failed. No Reviews. "
}

if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

res := map[string]interface{}{
"message": str,
Expand All @@ -395,7 +394,6 @@ func (s *Server) reviewHandler(w http.ResponseWriter, r *http.Request) {
json.NewEncoder(w).Encode(res)
}


func (s *Server) restaurantHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
ctx := r.Context()
Expand Down Expand Up @@ -427,19 +425,19 @@ func (s *Server) restaurantHandler(w http.ResponseWriter, r *http.Request) {
return
}

revInput := attractions.Request{HotelId:hotelId}
revInput := attractions.Request{HotelId: hotelId}

revResp, err := s.attractionsClient.NearbyRest(ctx, &revInput)

str = "Have restaurants = " + strconv.Itoa(len(revResp.AttractionIds))
if len(revResp.AttractionIds) == 0 {
str = "Failed. No Restaurants. "
str = "Have restaurants = " + strconv.Itoa(len(revResp.AttractionIds))
if len(revResp.AttractionIds) == 0 {
str = "Failed. No Restaurants. "
}

if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

res := map[string]interface{}{
"message": str,
Expand All @@ -448,7 +446,6 @@ func (s *Server) restaurantHandler(w http.ResponseWriter, r *http.Request) {
json.NewEncoder(w).Encode(res)
}


func (s *Server) museumHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
ctx := r.Context()
Expand Down Expand Up @@ -480,19 +477,19 @@ func (s *Server) museumHandler(w http.ResponseWriter, r *http.Request) {
return
}

revInput := attractions.Request{HotelId:hotelId}
revInput := attractions.Request{HotelId: hotelId}

revResp, err := s.attractionsClient.NearbyMus(ctx, &revInput)

str = "Have museums = " + strconv.Itoa(len(revResp.AttractionIds))
if len(revResp.AttractionIds) == 0 {
str = "Failed. No Museums. "
str = "Have museums = " + strconv.Itoa(len(revResp.AttractionIds))
if len(revResp.AttractionIds) == 0 {
str = "Failed. No Museums. "
}

if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

res := map[string]interface{}{
"message": str,
Expand Down Expand Up @@ -532,19 +529,19 @@ func (s *Server) cinemaHandler(w http.ResponseWriter, r *http.Request) {
return
}

revInput := attractions.Request{HotelId:hotelId}
revInput := attractions.Request{HotelId: hotelId}

revResp, err := s.attractionsClient.NearbyCinema(ctx, &revInput)

str = "Have cinemas = " + strconv.Itoa(len(revResp.AttractionIds))
if len(revResp.AttractionIds) == 0 {
str = "Failed. No Cinemas. "
str = "Have cinemas = " + strconv.Itoa(len(revResp.AttractionIds))
if len(revResp.AttractionIds) == 0 {
str = "Failed. No Cinemas. "
}

if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

res := map[string]interface{}{
"message": str,
Expand Down Expand Up @@ -708,4 +705,3 @@ func checkDataFormat(date string) bool {
}
return true
}

Loading

0 comments on commit 8946321

Please sign in to comment.