Skip to content

Commit

Permalink
Merge branch 'main' into chore/remove-roomfinder-from-docs
Browse files Browse the repository at this point in the history
# Conflicts:
#	server/api/tumdev/campus_backend.pb.gw.go
#	server/api/tumdev/campus_backend.proto
#	server/api/tumdev/campus_backend.swagger.json
#	server/backend/rpcserver.go
  • Loading branch information
CommanderStorm committed Sep 19, 2023
2 parents 97df5b2 + 71bec88 commit 2fe3172
Show file tree
Hide file tree
Showing 121 changed files with 3,799 additions and 4,664 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ APNS_P8_FILE_PATH=/secrets/AuthKey_XXXX.p8

ENVIRONMENT=dev

SENTRY_DSN=
SENTRY_DSN=
10 changes: 6 additions & 4 deletions .github/workflows/ci.yml → .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
name: CI
name: lint
on:
push:
branches: [ main ]
pull_request:

permissions:
contents: read

jobs:
ci:
lint:
name: lint
runs-on: ubuntu-latest
steps:
Expand All @@ -29,3 +27,7 @@ jobs:
version: v1.54
working-directory: client
args: --timeout=30m
- run: go install golang.org/x/tools/cmd/goimports@latest
- run: bash server/api/installBuf.bash
- name: pre-commit
uses: pre-commit/[email protected]
13 changes: 13 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,21 @@ on:
pull_request:
branches: [ main ]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: '1.21'
cache-dependency-path: |
server/go.sum
- name: run tests
run: go test -v ./...
working-directory: ./server
build:
runs-on: ubuntu-latest
needs: [test]
steps:
- name: Checkout repository
uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ __debug_bin
.env.local

apns_auth_key.p8

venv
39 changes: 39 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-json
exclude: vscode/launch.json
- id: check-yaml
exclude: deployment/.*
- id: check-added-large-files
- repo: https://github.com/dnephin/pre-commit-golang
rev: v0.5.0
hooks:
- id: go-fmt
- id: go-imports
- repo: local
hooks:
- id: regen-protobuf
name: Regenerate protobuf files
files: server/api/
entry: bash server/api/generate.bash
language: system
pass_filenames: false
stages: [commit]
- id: go-mod-tidy-server
name: Check if go.mod and go.sum are up to date for server
files: server/
entry: sh -c "(cd server && go mod tidy)"
language: system
pass_filenames: false
stages: [commit]
- id: go-mod-tidy-client
name: Check if go.mod and go.sum are up to date for server
files: server/
entry: sh -c "(cd client && go get github.com/TUM-Dev/Campus-Backend/server && go mod tidy)"
language: system
pass_filenames: false
stages: [commit]
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@
"program": "${workspaceFolder}/client/publicServer/client.go",
}
]
}
}
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,18 @@ Take a look at the [`lauch.json`](.vscode/launch.json) file for more details.


Please be respectful with its usage!

## pre-commit

To ensure that that common pitfalls which can be automated are not done, we recommend you to install `pre-commit`.
You can do so via

```bash
python -m venv venv
source venv/bin/activate
pip install pre-commit
pre-commit install
```

Certain `pre-commit` hooks will now be run on every commit where you change specific files.
If you want to run all files instead, run `pre-commit run -a`
2 changes: 1 addition & 1 deletion client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ standard system TLS CA's configured to securely connect via `api-grpc.tum.app` t
Alternatively you can also test the API using [grpcurl](https://github.com/fullstorydev/grpcurl) (also located in the `testLiveApi.sh`):
```
grpcurl -protoset <(buf build -o -) -H "x-device-id:grpc-tests" api-grpc.tum.app:443 api.Campus/GetNewsSources
```
```
20 changes: 10 additions & 10 deletions client/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ module github.com/TUM-Dev/Campus-Backend/client
go 1.21

require (
github.com/TUM-Dev/Campus-Backend/server v0.0.0-20230913203125-6bbe13013fa5
github.com/TUM-Dev/Campus-Backend/server v0.0.0-20230919162132-71bec88330f7
github.com/sirupsen/logrus v1.9.3
google.golang.org/grpc v1.58.0
google.golang.org/protobuf v1.31.0
google.golang.org/grpc v1.58.1
)

require (
github.com/golang/protobuf v1.5.3 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.17.1 // indirect
golang.org/x/net v0.14.0 // indirect
golang.org/x/sys v0.11.0 // indirect
golang.org/x/text v0.12.0 // indirect
google.golang.org/genproto v0.0.0-20230803162519-f966b187b2e5 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230822172742-b8732ec3820d // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.0 // indirect
golang.org/x/net v0.15.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/text v0.13.0 // indirect
google.golang.org/genproto v0.0.0-20230913181813-007df8e322eb // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230913181813-007df8e322eb // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230913181813-007df8e322eb // indirect
google.golang.org/protobuf v1.31.0 // indirect
)
36 changes: 18 additions & 18 deletions client/go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/TUM-Dev/Campus-Backend/server v0.0.0-20230913203125-6bbe13013fa5 h1:/yMB5hJjFjEPB/HVP6wLTJWGqoCqQksXke+DiV2xUWY=
github.com/TUM-Dev/Campus-Backend/server v0.0.0-20230913203125-6bbe13013fa5/go.mod h1:7XoRdXmxK852GxcyraiovgyS5z/eZ9wsofV9on7wvGQ=
github.com/TUM-Dev/Campus-Backend/server v0.0.0-20230919162132-71bec88330f7 h1:TDgiN5Z1vi3V0Qo94MIXURiD9+U7TGiRtiUIqN/rulo=
github.com/TUM-Dev/Campus-Backend/server v0.0.0-20230919162132-71bec88330f7/go.mod h1:fjoLL3rbdY6wTRJIksekT2p3OUp5ocFfXjB/avV/TVI=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand All @@ -11,8 +11,8 @@ github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiu
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.17.1 h1:LSsiG61v9IzzxMkqEr6nrix4miJI62xlRjwT7BYD2SM=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.17.1/go.mod h1:Hbb13e3/WtqQ8U5hLGkek9gJvBLasHuPFI0UEGfnQ10=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.0 h1:RtRsiaGvWxcwd8y3BiRZxsylPT8hLWZ5SPcfI+3IDNk=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.0/go.mod h1:TzP6duP4Py2pHLVPPQp42aoYI92+PCrVotyR5e8Vqlk=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
Expand All @@ -21,22 +21,22 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
golang.org/x/net v0.14.0 h1:BONx9s002vGdD9umnlX1Po8vOZmrgH34qlHcD1MfK14=
golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI=
golang.org/x/net v0.15.0 h1:ugBLEUaxABaB5AJqW9enI0ACdci2RUd4eP51NTBvuJ8=
golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc=
golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/genproto v0.0.0-20230803162519-f966b187b2e5 h1:L6iMMGrtzgHsWofoFcihmDEMYeDR9KN/ThbPWGrh++g=
google.golang.org/genproto v0.0.0-20230803162519-f966b187b2e5/go.mod h1:oH/ZOT02u4kWEp7oYBGYFFkCdKS/uYR9Z7+0/xuuFp8=
google.golang.org/genproto/googleapis/api v0.0.0-20230822172742-b8732ec3820d h1:DoPTO70H+bcDXcd39vOqb2viZxgqeBeSGtZ55yZU4/Q=
google.golang.org/genproto/googleapis/api v0.0.0-20230822172742-b8732ec3820d/go.mod h1:KjSP20unUpOx5kyQUFa7k4OJg0qeJ7DEZflGDu2p6Bk=
google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d h1:uvYuEyMHKNt+lT4K3bN6fGswmK8qSvcreM3BwjDh+y4=
google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d/go.mod h1:+Bk1OCOj40wS2hwAMA+aCW9ypzm63QTBBHp6lQ3p+9M=
google.golang.org/grpc v1.58.0 h1:32JY8YpPMSR45K+c3o6b8VL73V+rR8k+DeMIr4vRH8o=
google.golang.org/grpc v1.58.0/go.mod h1:tgX3ZQDlNJGU96V6yHh1T/JeoBQ2TXdr43YbYSsCJk0=
google.golang.org/genproto v0.0.0-20230913181813-007df8e322eb h1:XFBgcDwm7irdHTbz4Zk2h7Mh+eis4nfJEFQFYzJzuIA=
google.golang.org/genproto v0.0.0-20230913181813-007df8e322eb/go.mod h1:yZTlhN0tQnXo3h00fuXNCxJdLdIdnVFVBaRJ5LWBbw4=
google.golang.org/genproto/googleapis/api v0.0.0-20230913181813-007df8e322eb h1:lK0oleSc7IQsUxO3U5TjL9DWlsxpEBemh+zpB7IqhWI=
google.golang.org/genproto/googleapis/api v0.0.0-20230913181813-007df8e322eb/go.mod h1:KjSP20unUpOx5kyQUFa7k4OJg0qeJ7DEZflGDu2p6Bk=
google.golang.org/genproto/googleapis/rpc v0.0.0-20230913181813-007df8e322eb h1:Isk1sSH7bovx8Rti2wZK0UZF6oraBDK74uoyLEEVFN0=
google.golang.org/genproto/googleapis/rpc v0.0.0-20230913181813-007df8e322eb/go.mod h1:+Bk1OCOj40wS2hwAMA+aCW9ypzm63QTBBHp6lQ3p+9M=
google.golang.org/grpc v1.58.1 h1:OL+Vz23DTtrrldqHK49FUOPHyY75rvFqJfXC84NYW58=
google.golang.org/grpc v1.58.1/go.mod h1:tgX3ZQDlNJGU96V6yHh1T/JeoBQ2TXdr43YbYSsCJk0=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
Expand Down
72 changes: 36 additions & 36 deletions client/localServer/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const (
testImage = "./localServer/images/sampleimage.jpeg"
)

// main connects to a seperatly started local server and creates ratings for both, cafeterias and dishes.
// main connects to a seperatly started local server and creates ratings for both, canteens and dishes.
// Afterwards, they are queried and displayed on the console
func main() {
// Set up a connection to the local server.
Expand All @@ -38,7 +38,7 @@ func main() {

canteenHeadCount(c, ctx)

cafeteriaRatingTools(c, ctx)
canteenRatingTools(c, ctx)

}

Expand All @@ -54,28 +54,28 @@ func canteenHeadCount(c pb.CampusClient, ctx context.Context) {
}
}

func cafeteriaRatingTools(c pb.CampusClient, ctx context.Context) {
func canteenRatingTools(c pb.CampusClient, ctx context.Context) {

currentCafeteria := "MENSA_GARCHING"
currentCanteen := "MENSA_GARCHING"
currentDish := "Vegane rote Grütze mit Soja-Vanillesauce" //must be in the dish table
generateDishRating(c, ctx, currentCafeteria, currentDish, 3)
generateCafeteriaRating(c, ctx, currentCafeteria, 2)
queryCafeteria(currentCafeteria, c, ctx, true)
queryDish(currentCafeteria, currentDish, c, ctx, false)
generateCafeteriaRating(c, ctx, currentCafeteria, 2)
generateCafeteriaRating(c, ctx, currentCafeteria, 2)
generateDishRating(c, ctx, currentCafeteria, currentDish, 1)
generateDishRating(c, ctx, currentCanteen, currentDish, 3)
generateCanteenRating(c, ctx, currentCanteen, 2)
queryCanteen(currentCanteen, c, ctx, true)
queryDish(currentCanteen, currentDish, c, ctx, false)
generateCanteenRating(c, ctx, currentCanteen, 2)
generateCanteenRating(c, ctx, currentCanteen, 2)
generateDishRating(c, ctx, currentCanteen, currentDish, 1)

queryCafeteria(currentCafeteria, c, ctx, false)
queryDish(currentCafeteria, currentDish, c, ctx, false)
queryCanteen(currentCanteen, c, ctx, false)
queryDish(currentCanteen, currentDish, c, ctx, false)

}

func queryDish(cafeteria string, dish string, c pb.CampusClient, ctx context.Context, imageShouldBeStored bool) {
res, err := c.GetDishRatings(ctx, &pb.DishRatingRequest{
Dish: dish,
CafeteriaId: cafeteria,
Limit: 3,
func queryDish(canteen string, dish string, c pb.CampusClient, ctx context.Context, imageShouldBeStored bool) {
res, err := c.GetDishRatings(ctx, &pb.GetDishRatingsRequest{
Dish: dish,
CanteenId: canteen,
Limit: 3,
})

if err != nil {
Expand Down Expand Up @@ -129,10 +129,10 @@ func queryDish(cafeteria string, dish string, c pb.CampusClient, ctx context.Con
}
}

func queryCafeteria(s string, c pb.CampusClient, ctx context.Context, imageShouldBeStored bool) {
res, err := c.GetCafeteriaRatings(ctx, &pb.CafeteriaRatingRequest{
CafeteriaId: s,
Limit: 3,
func queryCanteen(s string, c pb.CampusClient, ctx context.Context, imageShouldBeStored bool) {
res, err := c.GetCanteenRatings(ctx, &pb.GetCanteenRatingsRequest{
CanteenId: s,
Limit: 3,
// From: timestamppb.New(time.Date(2022, 7, 8, 16, 0, 0, 0, time.Local)),
// To: timestamppb.New(time.Date(2022, 7, 8, 17, 0, 0, 0, time.Local)),
})
Expand Down Expand Up @@ -178,7 +178,7 @@ func queryCafeteria(s string, c pb.CampusClient, ctx context.Context, imageShoul
}
}

func generateCafeteriaRating(c pb.CampusClient, ctx context.Context, cafeteria string, rating int32) {
func generateCanteenRating(c pb.CampusClient, ctx context.Context, canteen string, rating int32) {
y := make([]*pb.RatingTag, 2)
y[0] = &pb.RatingTag{
Points: float64(1 + rating),
Expand All @@ -189,12 +189,12 @@ func generateCafeteriaRating(c pb.CampusClient, ctx context.Context, cafeteria s
TagId: 2,
}

_, err := c.NewCafeteriaRating(ctx, &pb.NewCafeteriaRatingRequest{
Points: rating,
CafeteriaId: cafeteria,
Comment: "Alles super, 2 Sterne",
RatingTags: y,
Image: getImageToBytes(testImage),
_, err := c.NewCanteenRating(ctx, &pb.NewCanteenRatingRequest{
Points: rating,
CanteenId: canteen,
Comment: "Alles super, 2 Sterne",
RatingTags: y,
Image: getImageToBytes(testImage),
})

if err != nil {
Expand All @@ -204,7 +204,7 @@ func generateCafeteriaRating(c pb.CampusClient, ctx context.Context, cafeteria s
}
}

func generateDishRating(c pb.CampusClient, ctx context.Context, cafeteria string, dish string, rating int32) {
func generateDishRating(c pb.CampusClient, ctx context.Context, canteen string, dish string, rating int32) {
y := make([]*pb.RatingTag, 3)
y[0] = &pb.RatingTag{
Points: float64(1 + rating),
Expand All @@ -220,12 +220,12 @@ func generateDishRating(c pb.CampusClient, ctx context.Context, cafeteria string
}

_, err := c.NewDishRating(ctx, &pb.NewDishRatingRequest{
Points: rating,
CafeteriaId: cafeteria,
Dish: dish,
Comment: "Alles Hähnchen",
RatingTags: y,
Image: getImageToBytes(testImage),
Points: rating,
CanteenId: canteen,
Dish: dish,
Comment: "Alles Hähnchen",
RatingTags: y,
Image: getImageToBytes(testImage),
})

if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions client/publicServer/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package main
import (
"context"
"crypto/x509"
"time"

pb "github.com/TUM-Dev/Campus-Backend/server/api/tumdev"
log "github.com/sirupsen/logrus"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/metadata"
"google.golang.org/protobuf/types/known/emptypb"
"time"
)

const (
Expand Down Expand Up @@ -42,7 +42,7 @@ func main() {
ctx = metadata.NewOutgoingContext(ctx, md)

log.Info("Trying to fetch top news")
if r, err := c.GetTopNews(ctx, &emptypb.Empty{}); err != nil {
if r, err := c.GetTopNews(ctx, &pb.GetTopNewsRequest{}); err != nil {
log.WithError(err).Fatal("could not greet")
} else {
log.WithField("topNewsResponse", r.String()).Info("fetched top news successfully")
Expand Down
2 changes: 1 addition & 1 deletion client/testLiveApi.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash

grpcurl -protoset <(buf build -o -) -plaintext -H "x-device-id:grpc-tests" api.tum.app:50052 api.Campus/GetNewsSources
grpcurl -protoset <(buf build -o -) -plaintext -H "x-device-id:grpc-tests" api.tum.app:50052 api.Campus/GetNewsSources
2 changes: 1 addition & 1 deletion deployment/charts/backend/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ dependencies:
- condition: mariadb.enabled
name: mariadb
repository: https://charts.bitnami.com/bitnami
version: 12.x.x
version: 12.x.x
Loading

0 comments on commit 2fe3172

Please sign in to comment.