Skip to content

Commit ee27535

Browse files
committed
final changes
1 parent 650abbe commit ee27535

File tree

4 files changed

+36
-6
lines changed

4 files changed

+36
-6
lines changed

admin/src/service/general.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export const serverUrl = () => {
22
return process.env.NODE_ENV === "development"
3-
? "http://localhost:8080"
3+
? "https://financeapp.tudoresan.ro"
44
: "https://financeapp.tudoresan.ro";
55
};

server/controllers/reservationController.go

+33-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ func (controller *ReservationController) FilterReservations() gin.HandlerFunc {
137137
}
138138
}
139139

140-
func (controller *ReservationController) GetUserReservations() gin.HandlerFunc {
140+
func (controller *ReservationController) GetAllReservations() gin.HandlerFunc {
141141
return func(c *gin.Context) {
142142
ctx, cancel := context.WithTimeout(context.Background(), time.Second*15)
143143
defer cancel()
@@ -185,3 +185,35 @@ func (controller *ReservationController) DeleteReservation() gin.HandlerFunc {
185185
c.JSON(200, gin.H{"message": "Reservation deleted"})
186186
}
187187
}
188+
189+
func (controller *ReservationController) GetUserReservations() gin.HandlerFunc {
190+
return func(c *gin.Context) {
191+
ctx, cancel := context.WithTimeout(context.Background(), time.Second*15)
192+
defer cancel()
193+
194+
claims := c.MustGet("claims").(*models.SignedDetails)
195+
idS := claims.Id
196+
197+
userId, err := primitive.ObjectIDFromHex(idS)
198+
if err != nil {
199+
controller.l.Error("Could not get user id", err)
200+
c.JSON(400, gin.H{"message": err.Error()})
201+
return
202+
}
203+
204+
var reservations []models.Reservation
205+
cursor, err := controller.reservationCollection.Find(ctx, bson.M{"userId": userId})
206+
if err != nil {
207+
controller.l.Error("Could not get reservation", err)
208+
c.JSON(400, gin.H{"message": err.Error()})
209+
return
210+
}
211+
for cursor.Next(ctx) {
212+
var reservation models.Reservation
213+
cursor.Decode(&reservation)
214+
reservations = append(reservations, reservation)
215+
}
216+
217+
c.JSON(200, reservations)
218+
}
219+
}

server/main.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,11 @@ func main() {
1616
l := hclog.Default()
1717
router := gin.Default()
1818

19-
2019
// disable cors
2120
config := cors.DefaultConfig()
2221
config.AllowCredentials = true
2322
config.AllowHeaders = []string{"Content-Type", "Authorization", "Origin", "Accept", "Access-Control-Allow-Origin", "token"}
24-
config.AllowOrigins = []string{"http://localhost:3000"}
23+
config.AllowOrigins = []string{"http://localhost:3000", "http://financeapp.tudoresan.ro:3000/"}
2524
config.AllowMethods = []string{"GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"}
2625
// config.AllowOrigins = []string{"*"}
2726

@@ -35,7 +34,6 @@ func main() {
3534
})
3635
})
3736

38-
3937
userController := controllers.NewUserController(l, mongoClient)
4038
roomsController := controllers.NewRoomController(l, mongoClient)
4139
userGroup := router.Group("")

server/routes/reservationRoutes.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
func InitReservationRoutes(r *gin.RouterGroup, c *controllers.ReservationController) {
1010
r.Use(middlewares.VerifyAuth())
1111
r.GET("/allReservations", c.GetReservations())
12-
r.GET("/reservation", c.GetUserReservations())
12+
r.GET("/reservations", c.GetUserReservations())
1313
r.GET("reservationFilter", c.FilterReservations())
1414
r.POST("/reservation/:from", c.AddReservation())
1515
r.DELETE("/reservation/:id", c.DeleteReservation())

0 commit comments

Comments
 (0)