Skip to content

Commit

Permalink
Merge pull request #8 from isd-sgcu/user
Browse files Browse the repository at this point in the history
User Svc
  • Loading branch information
bookpanda authored Jun 29, 2024
2 parents f69c8a8 + 5e16bc6 commit 5f8a6de
Show file tree
Hide file tree
Showing 18 changed files with 721 additions and 11 deletions.
1 change: 1 addition & 0 deletions .env.template
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
APP_PORT=3001
APP_ENV=development
APP_MAX_FILE_SIZE_MB=10

SERVICE_AUTH=auth:3002
SERVICE_BACKEND=backend:3003
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ coverage.out
coverage.html

tmp
staff.json
staff.json
docker-compose.qa.yml
23 changes: 23 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
pull-latest-mac:
docker pull --platform linux/x86_64 ghcr.io/isd-sgcu/rpkm67-gateway:latest
docker pull --platform linux/x86_64 ghcr.io/isd-sgcu/rpkm67-auth:latest
docker pull --platform linux/x86_64 ghcr.io/isd-sgcu/rpkm67-backend:latest
docker pull --platform linux/x86_64 ghcr.io/isd-sgcu/rpkm67-checkin:latest
docker pull --platform linux/x86_64 ghcr.io/isd-sgcu/rpkm67-store:latest

pull-latest-windows:
docker pull ghcr.io/isd-sgcu/rpkm67-gateway:latest
docker pull ghcr.io/isd-sgcu/rpkm67-auth:latest
docker pull ghcr.io/isd-sgcu/rpkm67-backend:latest
docker pull ghcr.io/isd-sgcu/rpkm67-checkin:latest
docker pull ghcr.io/isd-sgcu/rpkm67-store:latest

docker:
docker rm -v -f $$(docker ps -qa)
docker-compose up

docker-qa:
docker rm -v -f $$(docker ps -qa)
docker-compose -f docker-compose.qa.yml up

server:
go run cmd/main.go

watch:
air

mock-gen:
mockgen -source ./internal/auth/auth.service.go -destination ./mocks/auth/auth.service.go
mockgen -source ./internal/pin/pin.service.go -destination ./mocks/pin/pin.service.go
Expand All @@ -25,5 +45,8 @@ test:
proto:
go get github.com/isd-sgcu/rpkm67-go-proto@latest

model:
go get github.com/isd-sgcu/rpkm67-model@latest

swagger:
swag init -d ./internal/file -g ../../cmd/main.go -o ./docs -md ./docs/markdown --parseDependency --parseInternal
48 changes: 48 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,49 @@
# rpkm67-gateway

## Stack

- golang
- gRPC
- postgresql
- redis
- minio

## Getting Started

### Prerequisites

- 💻
- golang 1.22 or [later](https://go.dev)
- docker
- makefile
- [Go Air](https://github.com/air-verse/air)

### Installation

1. Clone this repo
2. Run `go mod download` to download all the dependencies.

### Running only this service
1. Copy `.env.template` and paste it in the same directory as `.env`. Fill in the appropriate values.
2. Run `make docker`.
3. Run `make server` or `air` for hot-reload.

### Running all RPKM67 services (all other services are run as containers)
1. Copy `docker-compose.qa.template.yml` and paste it in the same directory as `docker-compose.qa.yml`. Fill in the appropriate values.
2. Run `make pull-latest-mac` or `make pull-latest-windows` to pull the latest images of other services.
1. Run `make docker-qa`.
2. Run `make server` or `air` for hot-reload.

### Unit Testing
1. Run `make test`

## Other microservices/repositories of RPKM67
- [gateway](https://github.com/isd-sgcu/rpkm67-gateway): Routing and request handling
- [auth](https://github.com/isd-sgcu/rpkm67-auth): Authentication and user service
- [backend](https://github.com/isd-sgcu/rpkm67-backend): Group, Baan selection and Stamp, Pin business logic
- [checkin](https://github.com/isd-sgcu/rpkm67-checkin): Checkin for events service
- [store](https://github.com/isd-sgcu/rpkm67-store): Object storage service for user profile pictures
- [model](https://github.com/isd-sgcu/rpkm67-model): SQL table schema and models
- [proto](https://github.com/isd-sgcu/rpkm67-proto): Protobuf files generator
- [go-proto](https://github.com/isd-sgcu/rpkm67-go-proto): Generated protobuf files for golang
- [frontend](https://github.com/isd-sgcu/firstdate-rpkm67-frontend): Frontend web application
11 changes: 11 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ import (
"fmt"

"github.com/isd-sgcu/rpkm67-gateway/config"
"github.com/isd-sgcu/rpkm67-gateway/constant"
auth "github.com/isd-sgcu/rpkm67-gateway/internal/auth"
"github.com/isd-sgcu/rpkm67-gateway/internal/checkin"
"github.com/isd-sgcu/rpkm67-gateway/internal/router"
"github.com/isd-sgcu/rpkm67-gateway/internal/user"
"github.com/isd-sgcu/rpkm67-gateway/internal/validator"
"github.com/isd-sgcu/rpkm67-gateway/logger"
"github.com/isd-sgcu/rpkm67-gateway/middleware"
authProto "github.com/isd-sgcu/rpkm67-go-proto/rpkm67/auth/auth/v1"
userProto "github.com/isd-sgcu/rpkm67-go-proto/rpkm67/auth/user/v1"
checkinProto "github.com/isd-sgcu/rpkm67-go-proto/rpkm67/checkin/checkin/v1"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
Expand Down Expand Up @@ -45,6 +48,10 @@ func main() {
authSvc := auth.NewService(authClient, logger)
authHdr := auth.NewHandler(authSvc, validate, logger)

userClient := userProto.NewUserServiceClient(authConn)
userSvc := user.NewService(userClient, logger)
userHdr := user.NewHandler(userSvc, conf.App.MaxFileSizeMb, constant.AllowedContentType, validate, logger)

checkinClient := checkinProto.NewCheckInServiceClient(checkinConn)
checkinSvc := checkin.NewService(checkinClient, logger)
checkinHdr := checkin.NewHandler(checkinSvc, validate, logger)
Expand All @@ -55,6 +62,10 @@ func main() {
r.V1Post("/auth/verify-google", authHdr.VerifyGoogleLogin)
r.V1Post("/auth/test", authHdr.Test)

r.V1Get("/user/:id", userHdr.FindOne)
r.V1Patch("/user/profile/:id", userHdr.UpdateProfile)
r.V1Put("/user/picture/:id", userHdr.UpdatePicture)

r.V1Post("/checkin/create", checkinHdr.Create)
r.V1Get("/checkin/:userId", checkinHdr.FindByUserID)
r.V1Get("/checkin/email/:email", checkinHdr.FindByEmail)
Expand Down
16 changes: 12 additions & 4 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package config

import (
"os"
"strconv"

"github.com/joho/godotenv"
)

type AppConfig struct {
Port string
Env string
Port string
Env string
MaxFileSizeMb int
}

type ServiceConfig struct {
Expand All @@ -34,9 +36,15 @@ func LoadConfig() (*Config, error) {
}
}

maxFileSizeMb, err := strconv.ParseInt(os.Getenv("MAX_FILE_SIZE_MB"), 10, 64)
if err != nil {
return nil, err
}

appConfig := AppConfig{
Port: os.Getenv("APP_PORT"),
Env: os.Getenv("APP_ENV"),
Port: os.Getenv("APP_PORT"),
Env: os.Getenv("APP_ENV"),
MaxFileSizeMb: int(maxFileSizeMb),
}

serviceConfig := ServiceConfig{
Expand Down
9 changes: 9 additions & 0 deletions constant/user.constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package constant

var AllowedContentType = map[string]struct{}{
"image/jpeg": {},
"image/jpg": {},
"image/png": {},
"image/gif": {},
"image/webp": {},
}
123 changes: 123 additions & 0 deletions docker-compose.qa.template.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
version: "3.9"

services:
# gateway:
# image: ghcr.io/isd-sgcu/rpkm67-gateway:latest
# container_name: gateway
# restart: unless-stopped
# environment:
# APP_PORT: 3001
# APP_ENV: development
# APP_MAX_FILE_SIZE_MB: 10
# CORS_ORIGINS: http://localhost:3000
# SERVICE_AUTH: http://localhost:3002
# SERVICE_BACKEND: backend:3003
# SERVICE_CHECKIN: checkin:3004
# SERVICE_STORE: store:3005
# networks:
# - rpkm67
# ports:
# - "3001:3001"

auth:
image: ghcr.io/isd-sgcu/rpkm67-auth:latest
container_name: auth
restart: unless-stopped
environment:
APP_PORT: 3002
APP_ENV: development
DB_URL: postgres://root:1234@db:5432/rpkm67_db
REDIS_HOST: localhost
REDIS_PORT: 6379
REDIS_PASSWORD: 5678
JWT_SECRET: secret
JWT_ACCESS_TTL: 3600
JWT_REFRESH_TTL: 259200
JWT_ISSUER: rpkm67.sgcu.in.th
JWT_RESET_TOKEN_TTL: 900
networks:
- rpkm67
ports:
- "3002:3002"

backend:
image: ghcr.io/isd-sgcu/rpkm67-backend:latest
container_name: backend
restart: unless-stopped
environment:
APP_PORT: 3003
APP_ENV: development
DB_URL: postgres://root:1234@db:5432/rpkm67_db
REDIS_HOST: cache
REDIS_PORT: 6379
REDIS_PASSWORD: 5678
PIN_WORKSHOP_CODE: workshop
PIN_WORKSHOP_COUNT: 5
PIN_LANDMARK_CODE: landmark
PIN_LANDMARK_COUNT: 4
networks:
- rpkm67
ports:
- "3003:3003"

checkin:
image: ghcr.io/isd-sgcu/rpkm67-checkin:latest
container_name: checkin
restart: unless-stopped
environment:
APP_PORT: 3004
APP_ENV: development
DB_URL: postgres://root:1234@db:5432/rpkm67_db
networks:
- rpkm67
ports:
- "3004:3004"

store:
image: ghcr.io/isd-sgcu/rpkm67-store:latest
container_name: store
restart: unless-stopped
environment:
APP_PORT: 3005
APP_ENV: development
APP_MAX_FILE_SIZE_MB: 20
STORE_ENDPOINT: endpoint
STORE_ACCESS_KEY: access_key
STORE_SECRET_KEY: secret_key
STORE_USE_SSL: true
STORE_BUCKET_NAME: rpkm67-local
networks:
- rpkm67
ports:
- "3005:3005"

db:
image: postgres:15.1-alpine3.17
container_name: db
restart: unless-stopped
environment:
POSTGRES_USER: root
POSTGRES_PASSWORD: "1234"
POSTGRES_DB: rpkm67_db
networks:
- rpkm67
volumes:
- ./volumes/postgres:/var/lib/postgresql/data
ports:
- "5432:5432"

cache:
image: redis:7.2.3-alpine
container_name: cache
restart: unless-stopped
environment:
REDIS_HOST: localhost
REDIS_PASSWORD: "5678"
networks:
- rpkm67
ports:
- "6379:6379"

networks:
rpkm67:
name: rpkm67
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require (
github.com/golang/mock v1.6.0
github.com/google/uuid v1.6.0
github.com/isd-sgcu/rpkm67-go-proto v0.1.6
github.com/isd-sgcu/rpkm67-model v0.0.4
github.com/joho/godotenv v1.5.1
github.com/stretchr/testify v1.9.0
github.com/swaggo/files v1.0.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/isd-sgcu/rpkm67-go-proto v0.1.6 h1:6mubghe7HuGJYv+hgpIxJBBrmVk5UdjHjdvzykLLhQ0=
github.com/isd-sgcu/rpkm67-go-proto v0.1.6/go.mod h1:Z5SYz5kEe4W+MdqPouF0zEOiaqvg+s9I1S5d0q6e+Jw=
github.com/isd-sgcu/rpkm67-model v0.0.4 h1:tk6z6pXnhWBoG2SaSIoyLxNnwRaXwdbSIEEa/cSi8EY=
github.com/isd-sgcu/rpkm67-model v0.0.4/go.mod h1:dxgLSkrFpbQOXsrzqgepZoEOyZUIG2LBGtm5gsuBbVc=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
Expand Down
Loading

0 comments on commit 5f8a6de

Please sign in to comment.