-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/Banjerr/OpenTerps.git
- Loading branch information
Showing
93 changed files
with
1,166 additions
and
7,207 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
FROM heroku/heroku:18-build as build | ||
|
||
COPY . /app | ||
WORKDIR /app | ||
|
||
# Setup buildpack | ||
RUN mkdir -p /tmp/buildpack/heroku/go /tmp/build_cache /tmp/env | ||
RUN curl https://codon-buildpacks.s3.amazonaws.com/buildpacks/heroku/go.tgz | tar xz -C /tmp/buildpack/heroku/go | ||
|
||
#Execute Buildpack | ||
RUN STACK=heroku-18 /tmp/buildpack/heroku/go/bin/compile /app /tmp/build_cache /tmp/env | ||
|
||
# Prepare final, minimal image | ||
FROM heroku/heroku:18 | ||
|
||
COPY --from=build /app /app | ||
ENV HOME /app | ||
WORKDIR /app | ||
RUN useradd -m heroku | ||
USER heroku | ||
CMD /app/bin/openterps |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
GO_BUILD_ENV := CGO_ENABLED=0 GOOS=linux GOARCH=amd64 | ||
DOCKER_BUILD=$(shell pwd)/.docker_build | ||
DOCKER_CMD=$(DOCKER_BUILD)/go-getting-started | ||
|
||
$(DOCKER_CMD): clean | ||
mkdir -p $(DOCKER_BUILD) | ||
$(GO_BUILD_ENV) go build -v -o $(DOCKER_CMD) . | ||
|
||
clean: | ||
rm -rf $(DOCKER_BUILD) | ||
|
||
heroku: $(DOCKER_CMD) | ||
heroku container:push web | ||
|
||
build: | ||
export GO111MODULE=on | ||
env GOOS=linux GOARCH=amd64 go build -o bin/openterps -v . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
web: bin/openterps |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# OpenTerps 🍁 | ||
|
||
An open source API to categorize cannabis and it's terpenes/effects/tastes/smells. | ||
|
||
[docs](https://app.swaggerhub.com/apis-docs/CountryFriedCoders/OpenTerps/0.0.2) | ||
|
||
``` | ||
| | ||
|.| | ||
|\./| | ||
|\./| | ||
. |\./| . | ||
\^.\ |\\.//| /.^/ | ||
\--.|\ |\\.//| /|.--/ | ||
\--.| \ |\\.//| / |.--/ | ||
\---.|\ |\./| /|.---/ | ||
\--.|\ |\./| /|.--/ | ||
\ .\ |.| /. / | ||
_ -_^_^_^_- \ \\ // / -_^_^_^_- _ | ||
- -/_/_/- ^ ^ | ^ ^ -\_\_\- - | ||
/-./ | \.-\ | ||
/-/ | \-\ | ||
;|' '|; | ||
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- | ||
.---. ,---. ,---. .-. .-. _______ ,---. ,---. ,---. .---. ,--, ,-. ,-. | ||
/ .-. ) | .-.\ | .-' | \| ||__ __|| .-' | .-.\ | .-.\ ( .-._) .' .') | | |(| | ||
| | |(_)| |-' )| `-. | | | )| | | `-. | `-'/ | |-' )(_) \ | |(_) | | (_) | ||
| | | | | |--' | .-' | |\ | (_) | | .-' | ( | |--' _ \ \ \ \ | | | | | ||
\ `-' / | | | `--.| | |)| | | | `--.| |\ \ | | ( `-' ) \ `-. | `--. | | | ||
)---' /( /( __.'/( (_) `-' /( __.'|_| \)\ /( `----' \____\|( __.'`-' | ||
(_) (__) (__) (__) (__) (__)(__) (_) | ||
``` |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package categories | ||
|
||
import ( | ||
"net/http" | ||
|
||
"openterps/dbconnector" | ||
"openterps/models" | ||
|
||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
// GET /categories | ||
// Get all categories | ||
func GetCategories(c *gin.Context) { | ||
var categories []models.Category | ||
dbconnector.DB.Find(&categories) | ||
|
||
c.JSON(http.StatusOK, gin.H{"data": categories}) | ||
} | ||
|
||
type categoriesInput struct { | ||
Name string `json:"name" binding:"required"` | ||
} | ||
|
||
// POST /categories | ||
// Create a categories | ||
func CreateCategories(c *gin.Context) { | ||
// Validate input | ||
var input categoriesInput | ||
if err := c.ShouldBindJSON(&input); err != nil { | ||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) | ||
return | ||
} | ||
|
||
// Create categories | ||
categories := models.Category{ | ||
Name: input.Name, | ||
} | ||
dbconnector.DB.Create(&categories) | ||
|
||
c.JSON(http.StatusOK, gin.H{"data": categories}) | ||
} | ||
|
||
// PATCH /categories/:id | ||
// Update a categories | ||
func UpdateCategories(c *gin.Context) { | ||
var categories models.Category | ||
if err := dbconnector.DB.Where("id = ?", c.Param("id")).First(&categories).Error; err != nil { | ||
c.JSON(http.StatusBadRequest, gin.H{"error": "Category not found!"}) | ||
return | ||
} | ||
|
||
// Validate input | ||
var input categoriesInput | ||
if err := c.ShouldBindJSON(&input); err != nil { | ||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) | ||
return | ||
} | ||
|
||
dbconnector.DB.Model(&categories).Updates(input) | ||
|
||
c.JSON(http.StatusOK, gin.H{"data": categories}) | ||
} | ||
|
||
// DELETE /categories/:id | ||
// Delete a categories | ||
func DeleteCategories(c *gin.Context) { | ||
var categories models.Category | ||
if err := dbconnector.DB.Where("id = ?", c.Param("id")).First(&categories).Error; err != nil { | ||
c.JSON(http.StatusBadRequest, gin.H{"error": "Category not found!"}) | ||
return | ||
} | ||
|
||
dbconnector.DB.Delete(&categories) | ||
|
||
c.JSON(http.StatusOK, gin.H{"data": true}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package dbconnector | ||
|
||
import ( | ||
"fmt" | ||
|
||
"gorm.io/driver/postgres" | ||
"gorm.io/gorm" | ||
) | ||
|
||
// TODO turn this stuff into env vars | ||
|
||
var DB *gorm.DB | ||
|
||
// ConnectDatabase - connects to database | ||
// returns gorm DB instance, error | ||
func ConnectDatabase(Host, Port, User, Password, Name string) *gorm.DB { | ||
fmt.Println("Host", Host) | ||
dsn := fmt.Sprintf("host=%s port=%s user=%s password=%s dbname=%s sslmode=disable", Host, Port, User, Password, Name) | ||
db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{}) | ||
|
||
if err != nil { | ||
fmt.Println("Error connecting to databse: ", dsn) | ||
} | ||
|
||
DB = db | ||
|
||
return DB | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package effects | ||
|
||
import ( | ||
"net/http" | ||
|
||
"openterps/dbconnector" | ||
"openterps/models" | ||
"openterps/simpleauth" | ||
|
||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
// GET /effects | ||
// Get all effects | ||
func GetEffects(c *gin.Context) { | ||
var effects []models.Effect | ||
dbconnector.DB.Find(&effects) | ||
|
||
c.JSON(http.StatusOK, gin.H{"data": effects}) | ||
} | ||
|
||
type effectInput struct { | ||
Name string `json:"name" binding:"required"` | ||
} | ||
|
||
// POST /effect | ||
// Create a effect | ||
func CreateEffect(c *gin.Context) { | ||
userIsLoggedIn := simpleauth.ValidateRequest(c) | ||
|
||
if userIsLoggedIn { | ||
// Validate input | ||
var input effectInput | ||
if err := c.ShouldBindJSON(&input); err != nil { | ||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) | ||
return | ||
} | ||
|
||
// Create effect | ||
effect := models.Effect{ | ||
Name: input.Name, | ||
} | ||
dbconnector.DB.Create(&effect) | ||
|
||
c.JSON(http.StatusOK, gin.H{"data": effect}) | ||
} | ||
} | ||
|
||
// PATCH /effects/:id | ||
// Update a effect | ||
func UpdateEffect(c *gin.Context) { | ||
userIsLoggedIn := simpleauth.ValidateRequest(c) | ||
|
||
if userIsLoggedIn { | ||
var effect models.Effect | ||
if err := dbconnector.DB.Where("id = ?", c.Param("id")).First(&effect).Error; err != nil { | ||
c.JSON(http.StatusBadRequest, gin.H{"error": "Effect not found!"}) | ||
return | ||
} | ||
|
||
// Validate input | ||
var input effectInput | ||
if err := c.ShouldBindJSON(&input); err != nil { | ||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) | ||
return | ||
} | ||
|
||
dbconnector.DB.Model(&effect).Updates(input) | ||
|
||
c.JSON(http.StatusOK, gin.H{"data": effect}) | ||
} | ||
} | ||
|
||
// DELETE /effects/:id | ||
// Delete a effects | ||
func DeleteEffect(c *gin.Context) { | ||
userIsLoggedIn := simpleauth.ValidateRequest(c) | ||
|
||
if userIsLoggedIn { | ||
var effect models.Effect | ||
if err := dbconnector.DB.Where("id = ?", c.Param("id")).First(&effect).Error; err != nil { | ||
c.JSON(http.StatusBadRequest, gin.H{"error": "Effect not found!"}) | ||
return | ||
} | ||
|
||
dbconnector.DB.Delete(&effect) | ||
|
||
c.JSON(http.StatusOK, gin.H{"data": true}) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.