diff --git a/README.md b/README.md index ab42d92..8be0eb9 100644 --- a/README.md +++ b/README.md @@ -1 +1,102 @@ -# uber4freefood \ No newline at end of file +# uber4freefood +## Food Api + +###### Running +Clone files into go src directory +run `docker-compose up` + +###### port `*:8080` + +###### Api Routes +`GET /food` +This return all the records from the table +``` +{ + "data": [ + { + "id": 1, + "foodName": "", + "dietType": "", + "description": "", + "specialIngridients": "", + "serving": "", + "SpecialNote": "", + "foodImageId": "", + "locationLat": "", + "locationLong": "", + "status": "" + } + ] +} +``` + +`POST /food` +This is used to create a record +``` +{ + "data": [ + { + "foodName": "", + "dietType": "", + "description": "", + "specialIngridients": "", + "serving": "", + "SpecialNote": "", + "foodImageId": "", + "locationLat": "", + "locationLong": "", + "status": "" + } + ] +} +``` +`GET /food/:id` +return specific record from given id +``` +{ + "data": [ + { + "foodName": "", + "dietType": "", + "description": "", + "specialIngridients": "", + "serving": "", + "SpecialNote": "", + "foodImageId": "", + "locationLat": "", + "locationLong": "", + "status": "" + } + ] +} +``` +PATCH /food/:id +Edit staus for food +`{"Status": ""}` +returns +``` +{ + "data": [ + { + "id": 1, + "foodName": "", + "dietType": "", + "description": "", + "specialIngridients": "", + "serving": "", + "SpecialNote": "", + "foodImageId": "", + "locationLat": "", + "locationLong": "", + "status": "" + } + ] +} +``` +`DELETE /food/:id` +delete specified record +``` +{ + "data": true +} +``` diff --git a/Src/Backend/foodApi/Dockerfile b/Src/Backend/foodApi/Dockerfile new file mode 100644 index 0000000..4c6651b --- /dev/null +++ b/Src/Backend/foodApi/Dockerfile @@ -0,0 +1,27 @@ +FROM golang@sha256:0991060a1447cf648bab7f6bb60335d1243930e38420bee8fec3db1267b84cfa as builder +ENV GO111MODULE=on +RUN apk update && apk add --no-cache git ca-certificates tzdata && update-ca-certificates +ENV USER=appuser +ENV UID=10001 +RUN adduser \ + --disabled-password \ + --gecos "" \ + --home "/nonexistent" \ + --shell "/sbin/nologin" \ + --no-create-home \ + --uid "${UID}" \ + "${USER}" +WORKDIR $GOPATH/src/mypackage/myapp/ +COPY . . +RUN go mod vendor +RUN ls +RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-w -s" -o /go/bin/hello -mod vendor main.go +FROM scratch +COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo +COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ +COPY --from=builder /etc/passwd /etc/passwd +COPY --from=builder /etc/group /etc/group +COPY --from=builder /go/bin/hello /go/bin/hello +USER appuser:appuser +ENTRYPOINT ["/go/bin/hello"] +EXPOSE 8080 \ No newline at end of file diff --git a/Src/Backend/foodApi/README.md b/Src/Backend/foodApi/README.md new file mode 100644 index 0000000..a18bfe7 --- /dev/null +++ b/Src/Backend/foodApi/README.md @@ -0,0 +1,113 @@ +# uber4freefood +## Food Api + +###### Running +Clone files into go src directory +run `docker-compose up` + +###### port `*:8080` + +###### Api Routes +`GET /food` +This return all the records from the table +``` +{ + "data": [ + { + "id": 1, + "foodName": "", + "dietType": "", + "description": "", + "specialIngridients": "", + "serving": "", + "SpecialNote": "", + "foodImageId": "", + "locationLat": "", + "locationLong": "", + "angelUserID": "", + "humanUserID": "", + "status": "", + "CreatedAt": "", + "UpdatedAt": "", + "DeletedAt": "" + } + ] +} +``` + +`POST /food` +This is used to create a record +``` +{ + "data": [ + { + "foodName": "", + "dietType": "", + "description": "", + "specialIngridients": "", + "serving": "", + "SpecialNote": "", + "foodImageId": "", + "locationLat": "", + "locationLong": "", + "angelUserID": "", + "humanUserID": "", + "status": "" + } + ] +} +``` +`GET /food/:id` +return specific record from given id +``` +{ + "data": [ + { + "foodName": "", + "dietType": "", + "description": "", + "specialIngridients": "", + "serving": "", + "SpecialNote": "", + "foodImageId": "", + "locationLat": "", + "locationLong": "", + "angelUserID": "", + "humanUserID": "", + "status": "" + } + ] +} +``` +PATCH /food/:id +Edit staus for food +`{"Status": ""}` +returns +``` +{ + "data": [ + { + "id": 1, + "foodName": "", + "dietType": "", + "description": "", + "specialIngridients": "", + "serving": "", + "SpecialNote": "", + "foodImageId": "", + "locationLat": "", + "locationLong": "", + "angelUserID": "", + "humanUserID": "", + "status": "" + } + ] +} +``` +`DELETE /food/:id` +delete specified record +``` +{ + "data": true +} +``` \ No newline at end of file diff --git a/Src/Backend/foodApi/controllers/food.go b/Src/Backend/foodApi/controllers/food.go index ec552e2..0a33edf 100644 --- a/Src/Backend/foodApi/controllers/food.go +++ b/Src/Backend/foodApi/controllers/food.go @@ -26,7 +26,7 @@ func CreateFood(c *gin.Context) { return } //create food post - food := models.Food{FoodName: input.FoodName, DietType: input.DietType, Description: input.Description, SpecialIngridients: input.SpecialIngridients, Serving: input.Serving, SpecialNote: input.SpecialNote, FoodImageId: input.FoodImageId, LocationLat: input.LocationLat, LocationLong: input.LocationLong, Status: input.Status} + food := models.Food{FoodName: input.FoodName, DietType: input.DietType, Description: input.Description, SpecialIngridients: input.SpecialIngridients, Serving: input.Serving, SpecialNote: input.SpecialNote, FoodImageId: input.FoodImageId, LocationLat: input.LocationLat, LocationLong: input.LocationLong, AngelUserID:input.AngelUserID, HumanUserID: input.HumanUserID, Status: input.Status} db.Create(&food) c.JSON(http.StatusOK, gin.H{"data": food}) } diff --git a/Src/Backend/foodApi/database.env b/Src/Backend/foodApi/database.env new file mode 100644 index 0000000..0a65131 --- /dev/null +++ b/Src/Backend/foodApi/database.env @@ -0,0 +1,5 @@ +POSTGRES_DB=postgres +POSTGRES_PASSWORD=postgres +POSTGRES_USER=postgres +POSTGRES_HOST=db +POSTGRES_PORT=5432 \ No newline at end of file diff --git a/Src/Backend/foodApi/docker-compose.yaml b/Src/Backend/foodApi/docker-compose.yaml new file mode 100644 index 0000000..334897c --- /dev/null +++ b/Src/Backend/foodApi/docker-compose.yaml @@ -0,0 +1,30 @@ +version: '3.7' + +volumes: + database_data: + driver: local + +services: + db: + image: 'postgres:latest' # use latest official postgres version + ports: + - '5432:5432' + expose: + - 5432 + environment: + POSTGRES_DB: postgres + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + volumes: + - database_data:/var/lib/postgresql/data + web: + build: . + ports: + - '8080:8080' + environment: + POSTGRES_HOST: db + POSTGRES_PORT: 5432 + env_file: + - database.env # configure postgres + links: + - db diff --git a/Src/Backend/foodApi/models/food.go b/Src/Backend/foodApi/models/food.go index f7e7fe1..bc232f4 100644 --- a/Src/Backend/foodApi/models/food.go +++ b/Src/Backend/foodApi/models/food.go @@ -1,30 +1,50 @@ package models +import "time" + type Food struct { - ID uint `json:"id" gorm:"primary_key"` - FoodName string `json:"foodName"` - DietType string `json:"dietType"` - Description string `json:"description"` - SpecialIngridients string `json:"specialIngridients"` - Serving string `json:"serving"` - SpecialNote string `json:specialNote"` - FoodImageId string `json:"foodImageId"` - LocationLat string `json:"locationLat"` - LocationLong string `json:"locationLong"` - Status string `json:"status"` + ID uint `json:"id" gorm:"primary_key"` + FoodName string `json:"foodName"` + DietType string `json:"dietType"` + Description string `json:"description"` + SpecialIngridients string `json:"specialIngridients"` + Serving string `json:"serving"` + SpecialNote string `json:"specialNote"` + FoodImageId string `json:"foodImageId"` + LocationLat string `json:"locationLat"` + LocationLong string `json:"locationLong"` + AngelUserID string `json:"angelUserID"` + HumanUserID string `json:"humanUserID"` + Status string `json:"status"` + CreatedAt time.Time + UpdatedAt time.Time + DeletedAt *time.Time } type CreateFoodInput struct { - FoodName string `json:"foodName" binding:"required"` - DietType string `json:"dietType"` - Description string `json:"description" binding:"required"` - SpecialIngridients string `json:"specialIngridients"` - Serving string `json:"serving"` - SpecialNote string `json:specialNote"` - FoodImageId string `json:"foodImageId"` - LocationLat string `json:"locationLat" binding:"required"` - LocationLong string `json:"locationLong" binding:"required"` - Status string `json:"status"` + FoodName string `json:"foodName" binding:"required"` + DietType string `json:"dietType"` + Description string `json:"description" binding:"required"` + SpecialIngridients string `json:"specialIngridients"` + Serving string `json:"serving"` + SpecialNote string `json:"specialNote"` + FoodImageId string `json:"foodImageId"` + LocationLat string `json:"locationLat" binding:"required"` + LocationLong string `json:"locationLong" binding:"required"` + AngelUserID string `json:"angelUserID"` + HumanUserID string `json:"humanUserID"` + Status string `json:"status"` } type UpdateStatusInput struct { - Status string `json:"status"` -} \ No newline at end of file + FoodName string `json:"foodName"` + DietType string `json:"dietType"` + Description string `json:"description"` + SpecialIngridients string `json:"specialIngridients"` + Serving string `json:"serving"` + SpecialNote string `json:"specialNote"` + FoodImageId string `json:"foodImageId"` + LocationLat string `json:"locationLat"` + LocationLong string `json:"locationLong"` + AngelUserID string `json:"angelUserID"` + HumanUserID string `json:"humanUserID"` + Status string `json:"status"` +} diff --git a/Src/Backend/foodApi/models/setup.go b/Src/Backend/foodApi/models/setup.go index f51095c..c1256f3 100644 --- a/Src/Backend/foodApi/models/setup.go +++ b/Src/Backend/foodApi/models/setup.go @@ -3,16 +3,17 @@ package models "fmt" "github.com/jinzhu/gorm" _ "github.com/jinzhu/gorm/dialects/postgres" - //"github.com/spf13/viper" + "github.com/spf13/viper" ) func SetupModels () *gorm.DB { + viper.AutomaticEnv() //read .env file - viper_user := "postgres" //viper.Get("POSTGRES_USER") - viper_password := "#Avrilla8" //viper.Get("POSTGRES_PASSWORD") - viper_db := "foodApi" //viper.Get("POSTGRES_DB") - viper_host := "localhost" //viper.Get("POSTGRES_HOST") - viper_port := "5432" //viper.Get("POSTGRES_PORT") + viper_user := viper.Get("POSTGRES_USER") + viper_password := viper.Get("POSTGRES_PASSWORD") + viper_db := viper.Get("POSTGRES_DB") + viper_host := viper.Get("POSTGRES_HOST") + viper_port := viper.Get("POSTGRES_PORT") //formart prosgret_conname := fmt.Sprintf("host=%v port=%v user=%v dbname=%v password=%v sslmode=disable", viper_host, viper_port, viper_user, viper_db, viper_password) fmt.Println("conname is\t\t", prosgret_conname)