Skip to content

Commit

Permalink
removed the SearchRooms endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
CommanderStorm committed Sep 12, 2023
1 parent 1a266bd commit 5750f81
Showing 1 changed file with 0 additions and 43 deletions.
43 changes: 0 additions & 43 deletions server/backend/rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,49 +102,6 @@ func (s *CampusServer) GetNewsSources(ctx context.Context, _ *emptypb.Empty) (ne
return &pb.NewsSourceArray{Sources: resp}, nil
}

// SearchRooms returns all rooms that match the given search query.
func (s *CampusServer) SearchRooms(ctx context.Context, req *pb.SearchRoomsRequest) (*pb.SearchRoomsReply, error) {
if err := s.checkDevice(ctx); err != nil {
return nil, err
}
if req.Query == "" {
return &pb.SearchRoomsReply{Rooms: make([]*pb.Room, 0)}, nil
}
var res []struct { // struct to scan database query into
model.RoomfinderRooms
Campus string
Name string
}
err := s.db.Raw("SELECT r.*, a.campus, a.name "+
"FROM roomfinder_rooms r "+
"LEFT JOIN roomfinder_building2area a ON a.building_nr = r.building_nr "+
"WHERE MATCH(room_code, info, address) AGAINST(?)", req.Query).Scan(&res).Error
if errors.Is(err, gorm.ErrRecordNotFound) {
return &pb.SearchRoomsReply{Rooms: make([]*pb.Room, 0)}, nil
}
if err != nil {
log.WithError(err).Error("failed to search rooms")
return nil, status.Error(codes.Internal, err.Error())
}
response := &pb.SearchRoomsReply{
Rooms: make([]*pb.Room, len(res)),
}
for i, row := range res {
response.Rooms[i] = &pb.Room{
RoomId: row.RoomID,
RoomCode: row.RoomCode.String,
BuildingNr: row.BuildingNr.String,
ArchId: row.ArchID.String,
Info: row.Info.String,
Address: row.Address.String,
Purpose: row.Purpose.String,
Campus: row.Campus,
Name: row.Name,
}
}
return response, nil
}

func (s *CampusServer) GetTopNews(ctx context.Context, _ *emptypb.Empty) (*pb.GetTopNewsReply, error) {
if err := s.checkDevice(ctx); err != nil {
return nil, err
Expand Down

0 comments on commit 5750f81

Please sign in to comment.