Skip to content

Commit

Permalink
Merge branch 'dev' into fixReg
Browse files Browse the repository at this point in the history
  • Loading branch information
timurIsaevIY authored Oct 23, 2024
2 parents dbff1c6 + 295ed86 commit 28bb501
Show file tree
Hide file tree
Showing 12 changed files with 1,240 additions and 2 deletions.
15 changes: 13 additions & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import (
"2024_2_ThereWillBeName/internal/pkg/places/delivery"
placerepo "2024_2_ThereWillBeName/internal/pkg/places/repo"
placeusecase "2024_2_ThereWillBeName/internal/pkg/places/usecase"
triphandler "2024_2_ThereWillBeName/internal/pkg/trips/delivery/http"
triprepo "2024_2_ThereWillBeName/internal/pkg/trips/repo"
tripusecase "2024_2_ThereWillBeName/internal/pkg/trips/usecase"
"crypto/rand"
"database/sql"
"encoding/hex"
Expand Down Expand Up @@ -39,7 +42,6 @@ func main() {
newPlaceRepo := placerepo.NewPLaceRepository()
placeUsecase := placeusecase.NewPlaceUsecase(newPlaceRepo)
handler := delivery.NewPlacesHandler(placeUsecase)

logger := log.New(os.Stdout, "", log.Ldate|log.Ltime)

db, err := openDB(cfg.ConnStr)
Expand All @@ -58,7 +60,9 @@ func main() {
jwtHandler := jwt.NewJWT(string(jwtSecret))
authUseCase := usecase.NewAuthUsecase(authRepo, jwtHandler)
h := httpHandler.NewAuthHandler(authUseCase, jwtHandler)

tripsRepo := triprepo.NewTripRepository(db)
tripUsecase := tripusecase.NewTripsUsecase(tripsRepo)
tripHandler := triphandler.NewTripHandler(tripUsecase)
corsMiddleware := middleware.NewCORSMiddleware([]string{cfg.AllowedOrigin})

r := mux.NewRouter().PathPrefix("/api/v1").Subrouter()
Expand All @@ -77,9 +81,16 @@ func main() {
auth.HandleFunc("/logout", h.Logout).Methods(http.MethodPost)
users := r.PathPrefix("/users").Subrouter()
users.Handle("/me", middleware.MiddlewareAuth(jwtHandler, http.HandlerFunc(h.CurrentUser))).Methods(http.MethodGet)
user := users.PathPrefix("/{userID}").Subrouter()
places := r.PathPrefix("/places").Subrouter()
places.HandleFunc("", handler.GetPlaceHandler).Methods(http.MethodGet)
r.PathPrefix("/swagger").Handler(httpSwagger.WrapHandler)
trips := r.PathPrefix("/trips").Subrouter()
trips.HandleFunc("", tripHandler.CreateTripHandler).Methods(http.MethodPost)
trips.HandleFunc("/{id}", tripHandler.UpdateTripHandler).Methods(http.MethodPut)
trips.HandleFunc("/{id}", tripHandler.DeleteTripHandler).Methods(http.MethodDelete)
trips.HandleFunc("/{id}", tripHandler.GetTripHandler).Methods(http.MethodGet)
user.HandleFunc("/trips", tripHandler.GetTripsByUserIDHandler).Methods(http.MethodGet)
srv := &http.Server{
Addr: fmt.Sprintf(":%d", cfg.Port),
Handler: r,
Expand Down
265 changes: 265 additions & 0 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,192 @@ const docTemplate = `{
}
}
},
"/trips": {
"post": {
"description": "Create a new trip with given fields",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"summary": "Create a new trip",
"parameters": [
{
"description": "Trip details",
"name": "trip",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/models.Trip"
}
}
],
"responses": {
"201": {
"description": "Trip created successfully",
"schema": {
"$ref": "#/definitions/models.Trip"
}
},
"400": {
"description": "Invalid request",
"schema": {
"$ref": "#/definitions/httpresponses.ErrorResponse"
}
},
"404": {
"description": "Invalid request",
"schema": {
"$ref": "#/definitions/httpresponses.ErrorResponse"
}
},
"500": {
"description": "Failed to create trip",
"schema": {
"$ref": "#/definitions/httpresponses.ErrorResponse"
}
}
}
}
},
"/trips/{id}": {
"get": {
"description": "Get trip details by trip ID",
"produces": [
"application/json"
],
"summary": "Retrieve a trip by ID",
"parameters": [
{
"type": "integer",
"description": "Trip ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "Trip details",
"schema": {
"$ref": "#/definitions/models.Trip"
}
},
"400": {
"description": "Invalid trip ID",
"schema": {
"$ref": "#/definitions/httpresponses.ErrorResponse"
}
},
"404": {
"description": "Trip not found",
"schema": {
"$ref": "#/definitions/httpresponses.ErrorResponse"
}
},
"500": {
"description": "Failed to retrieve trip",
"schema": {
"$ref": "#/definitions/httpresponses.ErrorResponse"
}
}
}
},
"put": {
"description": "Update trip details by trip ID",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"summary": "Update an existing trip",
"parameters": [
{
"type": "integer",
"description": "Trip ID",
"name": "id",
"in": "path",
"required": true
},
{
"description": "Updated trip details",
"name": "trip",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/models.Trip"
}
}
],
"responses": {
"200": {
"description": "Trip updated successfully",
"schema": {
"$ref": "#/definitions/models.Trip"
}
},
"400": {
"description": "Invalid trip data",
"schema": {
"$ref": "#/definitions/httpresponses.ErrorResponse"
}
},
"404": {
"description": "Trip not found",
"schema": {
"$ref": "#/definitions/httpresponses.ErrorResponse"
}
},
"500": {
"description": "Failed to update trip",
"schema": {
"$ref": "#/definitions/httpresponses.ErrorResponse"
}
}
}
},
"delete": {
"description": "Delete a trip by trip ID",
"produces": [
"application/json"
],
"summary": "Delete a trip",
"parameters": [
{
"type": "integer",
"description": "Trip ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"204": {
"description": "Trip deleted successfully"
},
"400": {
"description": "Invalid trip ID",
"schema": {
"$ref": "#/definitions/httpresponses.ErrorResponse"
}
},
"404": {
"description": "Trip not found",
"schema": {
"$ref": "#/definitions/httpresponses.ErrorResponse"
}
},
"500": {
"description": "Failed to delete trip",
"schema": {
"$ref": "#/definitions/httpresponses.ErrorResponse"
}
}
}
}
},
"/users/me": {
"get": {
"description": "Retrieve the current authenticated user information",
Expand Down Expand Up @@ -195,6 +381,53 @@ const docTemplate = `{
}
}
}
},
"/users/{userID}/trips": {
"get": {
"description": "Get all trips for a specific user",
"produces": [
"application/json"
],
"summary": "Retrieve trips by user ID",
"parameters": [
{
"type": "integer",
"description": "User ID",
"name": "userID",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "List of trips",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/models.Trip"
}
}
},
"400": {
"description": "Invalid user ID",
"schema": {
"$ref": "#/definitions/httpresponses.ErrorResponse"
}
},
"404": {
"description": "Trips not found",
"schema": {
"$ref": "#/definitions/httpresponses.ErrorResponse"
}
},
"500": {
"description": "Failed to retrieve trips",
"schema": {
"$ref": "#/definitions/httpresponses.ErrorResponse"
}
}
}
}
}
},
"definitions": {
Expand Down Expand Up @@ -234,6 +467,38 @@ const docTemplate = `{
}
}
},
"models.Trip": {
"type": "object",
"properties": {
"city_id": {
"type": "integer"
},
"created_at": {
"type": "string"
},
"description": {
"type": "string"
},
"end_date": {
"type": "string"
},
"id": {
"type": "integer"
},
"name": {
"type": "string"
},
"private": {
"type": "boolean"
},
"start_date": {
"type": "string"
},
"user_id": {
"type": "integer"
}
}
},
"models.User": {
"type": "object",
"properties": {
Expand Down
Loading

0 comments on commit 28bb501

Please sign in to comment.