Skip to content
This repository was archived by the owner on Apr 14, 2024. It is now read-only.

Commit 7b27506

Browse files
Merge pull request #1 from piyushkumar12111111/main
updatedCode
2 parents 75920f1 + 86e271d commit 7b27506

24 files changed

Lines changed: 1037 additions & 151 deletions
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package handlers
2+
3+
import (
4+
"encoding/json"
5+
"net/http"
6+
7+
"github.com/piyushkumar/hotelsystem/models"
8+
)
9+
10+
// AddHotel adds a new hotel to the list.
11+
func AddHotel(w http.ResponseWriter, r *http.Request) {
12+
var hotel models.Hotel
13+
if err := json.NewDecoder(r.Body).Decode(&hotel); err != nil {
14+
http.Error(w, err.Error(), http.StatusBadRequest)
15+
return
16+
}
17+
18+
hotels = append(hotels, hotel) // Add the hotel to the in-memory store
19+
20+
w.WriteHeader(http.StatusCreated)
21+
json.NewEncoder(w).Encode(hotel)
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package handlers
2+
3+
import (
4+
"net/http"
5+
"github.com/gorilla/mux"
6+
)
7+
8+
// DeleteHotel removes a hotel from the list based on its ID.
9+
func DeleteHotel(w http.ResponseWriter, r *http.Request) {
10+
id := mux.Vars(r)["id"]
11+
12+
for index, hotel := range hotels {
13+
if hotel.ID == id {
14+
// Remove the hotel from the slice
15+
hotels = append(hotels[:index], hotels[index+1:]...)
16+
w.WriteHeader(http.StatusNoContent)
17+
return
18+
}
19+
}
20+
21+
http.Error(w, "Hotel not found", http.StatusNotFound)
22+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package handlers
2+
3+
import (
4+
"encoding/json"
5+
"net/http"
6+
7+
"github.com/piyushkumar/hotelsystem/models"
8+
)
9+
10+
// In-memory store for demonstration
11+
var hotels = []models.Hotel{
12+
{ID: "1", Name: "Hotel Sunshine", Location: "California", Rating: 5},
13+
{ID: "2", Name: "Grand Plaza", Location: "New York", Rating: 4},
14+
}
15+
16+
// ListHotels sends a list of hotels as a JSON response.
17+
func ListHotels(w http.ResponseWriter, r *http.Request) {
18+
w.Header().Set("Content-Type", "application/json")
19+
json.NewEncoder(w).Encode(hotels)
20+
}

Backend/main.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@ func main() {
4848

4949
log.Println("Server starting on port 9080...")
5050

51-
//!
51+
//! hotel apis
52+
53+
r.HandleFunc("/hotels", handlers.ListHotels).Methods("GET")
54+
r.HandleFunc("/hotel", handlers.AddHotel).Methods("POST")
55+
r.HandleFunc("/hotel/{id}", handlers.DeleteHotel).Methods("DELETE")
5256
// Start the server
5357

5458
log.Fatal(http.ListenAndServe(":9080", r))

Backend/models/hotelModel.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package models
2+
3+
// Hotel represents the hotel model.
4+
type Hotel struct {
5+
ID string `json:"id"`
6+
Name string `json:"name"`
7+
Location string `json:"location"`
8+
Rating int `json:"rating"`
9+
}

Backend/tmp/build-errors.log

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1
1+
exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1

Backend/tmp/main.exe

7.5 KB
Binary file not shown.

Backend/tmp/main.exe~

-7.42 MB
Binary file not shown.

Frontend/analysis_options.yaml

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
1-
# This file configures the analyzer, which statically analyzes Dart code to
2-
# check for errors, warnings, and lints.
3-
#
4-
# The issues identified by the analyzer are surfaced in the UI of Dart-enabled
5-
# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be
6-
# invoked from the command line by running `flutter analyze`.
1+
# # This file configures the analyzer, which statically analyzes Dart code to
2+
# # check for errors, warnings, and lints.
3+
# #
4+
# # The issues identified by the analyzer are surfaced in the UI of Dart-enabled
5+
# # IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be
6+
# # invoked from the command line by running `flutter analyze`.
77

8-
# The following line activates a set of recommended lints for Flutter apps,
9-
# packages, and plugins designed to encourage good coding practices.
10-
include: package:flutter_lints/flutter.yaml
8+
# # The following line activates a set of recommended lints for Flutter apps,
9+
# # packages, and plugins designed to encourage good coding practices.
10+
# include: package:flutter_lints/flutter.yaml
1111

12-
linter:
13-
# The lint rules applied to this project can be customized in the
14-
# section below to disable rules from the `package:flutter_lints/flutter.yaml`
15-
# included above or to enable additional rules. A list of all available lints
16-
# and their documentation is published at
17-
# https://dart-lang.github.io/linter/lints/index.html.
18-
#
19-
# Instead of disabling a lint rule for the entire project in the
20-
# section below, it can also be suppressed for a single line of code
21-
# or a specific dart file by using the `// ignore: name_of_lint` and
22-
# `// ignore_for_file: name_of_lint` syntax on the line or in the file
23-
# producing the lint.
24-
rules:
25-
# avoid_print: false # Uncomment to disable the `avoid_print` rule
26-
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule
12+
# linter:
13+
# # The lint rules applied to this project can be customized in the
14+
# # section below to disable rules from the `package:flutter_lints/flutter.yaml`
15+
# # included above or to enable additional rules. A list of all available lints
16+
# # and their documentation is published at
17+
# # https://dart-lang.github.io/linter/lints/index.html.
18+
# #
19+
# # Instead of disabling a lint rule for the entire project in the
20+
# # section below, it can also be suppressed for a single line of code
21+
# # or a specific dart file by using the `// ignore: name_of_lint` and
22+
# # `// ignore_for_file: name_of_lint` syntax on the line or in the file
23+
# # producing the lint.
24+
# rules:
25+
# # avoid_print: false # Uncomment to disable the `avoid_print` rule
26+
# # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule
2727

28-
# Additional information about this file can be found at
29-
# https://dart.dev/guides/language/analysis-options
28+
# # Additional information about this file can be found at
29+
# # https://dart.dev/guides/language/analysis-options

Frontend/android/app/build.gradle

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ if (localPropertiesFile.exists()) {
88

99
def flutterRoot = localProperties.getProperty('flutter.sdk')
1010
if (flutterRoot == null) {
11-
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
11+
// throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
1212
}
1313

1414
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
@@ -22,11 +22,14 @@ if (flutterVersionName == null) {
2222
}
2323

2424
apply plugin: 'com.android.application'
25+
// START: FlutterFire Configuration
26+
apply plugin: 'com.google.gms.google-services'
27+
// END: FlutterFire Configuration
2528
apply plugin: 'kotlin-android'
2629
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
2730

2831
android {
29-
compileSdkVersion flutter.compileSdkVersion
32+
compileSdkVersion 34
3033

3134
compileOptions {
3235
sourceCompatibility JavaVersion.VERSION_1_8

0 commit comments

Comments
 (0)