Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update main #40

Merged
merged 118 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
118 commits
Select commit Hold shift + click to select a range
5d00cdb
feat: implement forgot password service
Nitiwat-owen Jan 15, 2024
b9cca29
feat: generate mock
Nitiwat-owen Jan 15, 2024
1ce9fe8
feat: implement forgot password handler
Nitiwat-owen Jan 15, 2024
bfd48bf
feat: add forgot password route
Nitiwat-owen Jan 15, 2024
5a3ad46
chore: update docs
Nitiwat-owen Jan 15, 2024
13320ac
fix: exclude forgot-password path from middleware
Nitiwat-owen Jan 15, 2024
55baee8
feat: implement reset password service
Nitiwat-owen Jan 15, 2024
1e153af
feat: generate mock
Nitiwat-owen Jan 15, 2024
c12d12d
feat: implement reset password handler
Nitiwat-owen Jan 15, 2024
9d0efb5
feat: add reset-password route
Nitiwat-owen Jan 15, 2024
bcf3a15
chore
Nitiwat-owen Jan 15, 2024
9992675
chore: update docs
Nitiwat-owen Jan 15, 2024
b388de5
Merge pull request #26 from isd-sgcu/feature/JOH-51
Nitiwat-owen Jan 16, 2024
3d502df
feat: env config
bookpanda Jan 16, 2024
4834b70
fix: docker compose
bookpanda Jan 16, 2024
1025784
feat: load env bash
bookpanda Jan 16, 2024
239c92e
fix: compose
bookpanda Jan 16, 2024
ca32b84
fix: config loader
bookpanda Jan 16, 2024
c3af07b
fix: prod compose
bookpanda Jan 16, 2024
794fe39
fix: remove unused code
Nitiwat-owen Jan 17, 2024
8674d10
Merge pull request #27 from isd-sgcu/feature/JOH-53
Nitiwat-owen Jan 17, 2024
d27bc47
chore: remove config.yaml
bookpanda Jan 17, 2024
c6a45d8
Merge pull request #28 from isd-sgcu/JOH-37/migrate-to-env
bookpanda Jan 17, 2024
e454e21
fix: swagger docs
bookpanda Jan 21, 2024
d780a0a
feat: image docs
bookpanda Jan 21, 2024
01aa36d
chore: gen docs
bookpanda Jan 21, 2024
720712e
feat: docs add tags
bookpanda Jan 21, 2024
65e030c
chore: gen docs
bookpanda Jan 21, 2024
9263ab8
chore: update proto
macgeargear Jan 23, 2024
18d52eb
fix: pet dto
macgeargear Jan 23, 2024
77e1225
fix: pet utils
macgeargear Jan 23, 2024
9896c9b
Merge pull request #29 from isd-sgcu/gear/joh-71-johnjud-gateway-chan…
macgeargear Jan 23, 2024
e7e8552
temp: disable admin paths
bookpanda Jan 24, 2024
4a72dbf
fix: docker compose redis/auth
bookpanda Jan 24, 2024
9cad6c2
fix: docker file
bookpanda Jan 29, 2024
aee0830
fix: image upload remove /
bookpanda Jan 29, 2024
750b722
fix: image upload swagger
bookpanda Jan 29, 2024
ff4f68a
fix: image upload petId not required
bookpanda Jan 29, 2024
c4daf1c
fix: update swagger
bookpanda Jan 29, 2024
a171fd1
feat: context file, formdata
bookpanda Jan 29, 2024
069ba3c
feat: add maxfilesize
bookpanda Jan 29, 2024
7968b17
feat: file const
bookpanda Jan 29, 2024
00d5a8e
feat: image upload use form
bookpanda Jan 29, 2024
32a8dcd
fix: maxfilesize * MB
bookpanda Jan 29, 2024
b458a5f
feat: router add bodylimit
bookpanda Jan 29, 2024
2f63ddb
fix: docker prod
bookpanda Jan 29, 2024
ee9c4e6
feat: swagger + data -> file
bookpanda Jan 29, 2024
2b7c8d7
Merge pull request #30 from isd-sgcu/JOH-83/use-form-multipart
bookpanda Jan 29, 2024
e14e0fe
fix: image upload use filename from file
bookpanda Jan 30, 2024
d79b669
feat: image client mock
macgeargear Feb 2, 2024
a47734b
chore: fix petService
macgeargear Feb 2, 2024
42a2ef8
feat: image utils
macgeargear Feb 2, 2024
fd98be2
fix: pet service test
macgeargear Feb 2, 2024
9fced93
feat: use imageService instead `mock` image
macgeargear Feb 2, 2024
1cdf4fc
fix: pet handler test
macgeargear Feb 2, 2024
1ced6eb
chore: use `[]*ImageResponse` instead `[]ImageResponse`
macgeargear Feb 2, 2024
7d4b139
chore
macgeargear Feb 3, 2024
d21e7ac
chore
macgeargear Feb 3, 2024
e028125
Merge pull request #32 from isd-sgcu/gear/joh-49-johnjud-gateway-comb…
macgeargear Feb 3, 2024
ef488d6
feat: update proto
bookpanda Feb 16, 2024
892249d
feat: image svc add findall, add petid
bookpanda Feb 16, 2024
7831831
feat: pet findall, update add real image
bookpanda Feb 16, 2024
233bfc4
Merge pull request #33 from isd-sgcu/pet-findall/image
bookpanda Feb 16, 2024
c68bbdb
fix: get one pet unauth
bookpanda Feb 16, 2024
76fc556
feat: add auto imagetag change
bookpanda Feb 16, 2024
a3a3933
feat: img svc add deletebypetid
bookpanda Feb 17, 2024
932ff3b
feat: pet svc delete use image's deletebypetid
bookpanda Feb 17, 2024
d32347c
Merge pull request #34 from isd-sgcu/pet-svc/delete-cascade-img
bookpanda Feb 17, 2024
507b44e
fix: updatepetproto add bool fields
bookpanda Feb 17, 2024
11d4613
Merge pull request #35 from isd-sgcu/pet-svc/delete-cascade-img
bookpanda Feb 17, 2024
7164624
fix: visivle not required, adopt remove pet_id body
bookpanda Feb 17, 2024
23292bb
fix: pet delete image before pet
bookpanda Feb 20, 2024
cb4ff13
fix: unit test pet
bookpanda Feb 20, 2024
8f3c9c4
feat: isAdmin pet findall
bookpanda Feb 21, 2024
9869ce9
Merge pull request #36 from isd-sgcu/findalladmin
bookpanda Feb 21, 2024
0e276b2
tmp: log findall
bookpanda Feb 21, 2024
cdfcf26
fix: remove tmp logs
bookpanda Feb 22, 2024
8a00e46
feat: open admin auth
bookpanda Mar 16, 2024
015013c
fix: reset password url
bookpanda Mar 24, 2024
f6383ae
feat: add owner, tel in pet
bookpanda May 12, 2024
d25513c
Merge pull request #37 from isd-sgcu/contacts
bookpanda May 12, 2024
396fb40
fix: remove address from CreatePetRequest
bookpanda May 12, 2024
9ee6ca1
fix: add refreshToken to excludePath
bookpanda May 17, 2024
6baa209
Merge pull request #38 from isd-sgcu/refreshToken
bookpanda May 17, 2024
35dccbf
internal folder
bookpanda Aug 20, 2024
010ecc5
constant folder
bookpanda Aug 20, 2024
6127a1a
auth
bookpanda Aug 20, 2024
96b83ef
remove like
bookpanda Aug 21, 2024
20daef7
dc
bookpanda Aug 21, 2024
fe1f4d0
image svc
bookpanda Aug 21, 2024
982ae86
pet
bookpanda Aug 21, 2024
b44c4d4
pr tmp
bookpanda Aug 21, 2024
f3219ed
user
bookpanda Aug 21, 2024
2b48473
utils
bookpanda Aug 21, 2024
6d1da74
config, air
bookpanda Aug 21, 2024
234ad38
model, constant
bookpanda Aug 21, 2024
045cf5b
imrgate token jwt
bookpanda Aug 21, 2024
b45903f
migrate auth
bookpanda Aug 21, 2024
ee61ada
env
bookpanda Aug 21, 2024
228650c
fix conf
bookpanda Aug 21, 2024
8a5c3a4
swagger
bookpanda Aug 21, 2024
bcfbf32
add conf
bookpanda Aug 22, 2024
5b35bc6
model
bookpanda Aug 22, 2024
4a27414
utils, mock
bookpanda Aug 22, 2024
4809829
image repo, buc cli
bookpanda Aug 22, 2024
867e172
image svc
bookpanda Aug 22, 2024
7d66e0d
pet repo
bookpanda Aug 22, 2024
1ce3666
merge backend, file monolith
bookpanda Aug 23, 2024
5f8826c
readme
bookpanda Aug 23, 2024
8477b80
wf no push gitops
bookpanda Aug 23, 2024
871d3e2
github.com/isd-sgcu/johnjud-backend
bookpanda Aug 23, 2024
915699b
trigger
bookpanda Aug 23, 2024
2af3b05
trigger
bookpanda Aug 23, 2024
be3b9ac
Merge branch 'dev' into make-monolith
bookpanda Aug 23, 2024
b2c3144
fix dockerfiel
bookpanda Aug 23, 2024
c33630b
fix wf test
bookpanda Aug 23, 2024
5f316ff
remove cache repo test
bookpanda Aug 23, 2024
e8ec9c6
Merge pull request #39 from isd-sgcu/make-monolith
bookpanda Aug 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions .air.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
root = "."
testdata_dir = "testdata"
tmp_dir = "tmp"

[build]
args_bin = []
bin = "./tmp/main"
cmd = "go build -o ./tmp/main ./cmd/main.go"
delay = 1000
exclude_dir = ["assets", "tmp", "vendor", "testdata"]
exclude_file = []
exclude_regex = ["_test.go"]
exclude_unchanged = false
follow_symlink = false
full_bin = ""
include_dir = []
include_ext = ["go", "tpl", "tmpl", "html"]
include_file = []
kill_delay = "0s"
log = "build-errors.log"
poll = false
poll_interval = 0
post_cmd = []
pre_cmd = []
rerun = false
rerun_delay = 500
send_interrupt = false
stop_on_error = false

[color]
app = ""
build = "yellow"
main = "magenta"
runner = "green"
watcher = "cyan"

[log]
main_only = false
time = false

[misc]
clean_on_exit = false

[proxy]
app_port = 0
enabled = false
proxy_port = 0

[screen]
clear_on_rebuild = false
keep_scroll = true
27 changes: 27 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
APP_PORT=3001
APP_ENV=development
APP_MAX_FILE_SIZE=10

DB_URL=postgres://root:root@localhost:5432/johnjud_db

JWT_SECRET=secret
JWT_EXPIRES_IN=3600
JWT_REFRESH_TOKEN_TTL=604800
JWT_ISSUER=issuer
JWT_RESET_TOKEN_TTL=900

REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_PASSWORD=

AUTH_CLIENT_URL=http://localhost:3000

SENDGRID_API_KEY=api_key
SENDGRID_NAME=johnjud
[email protected]

BUCKET_ENDPOINT=BUCKET_ENDPOINT
BUCKET_ACCESS_KEY=BUCKET_ACCESS_KEY
BUCKET_SECRET_KEY=BUCKET_SECRET_KEY
BUCKET_NAME=johnjud-pet-images
BUCKET_USE_SSL=true
26 changes: 25 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,28 @@ jobs:
push: true
tags: ${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }},${{ env.IMAGE_NAME }}:latest
cache-from: type=registry,ref=${{ env.IMAGE_NAME }}:buildcache
cache-to: type=registry,ref=${{ env.IMAGE_NAME }}:buildcache,mode=max
cache-to: type=registry,ref=${{ env.IMAGE_NAME }}:buildcache,mode=max

# update-gitops:
# name: Update gitops repository
# runs-on: ubuntu-latest

# steps:
# - name: Checkout gitops repository
# uses: actions/checkout@v4
# with:
# repository: isd-sgcu/isd-gitops
# token: ${{ secrets.GITOPS_TOKEN }}

# - name: Update image tag
# uses: mikefarah/yq@master
# env:
# NEW_TAG: ${{ github.ref_type == 'tag' && github.ref_name || env.IMAGE_TAG }}
# with:
# cmd: yq -i '.gateway.imageTag = strenv(NEW_TAG)' projects/johnjud/values/gateway-dev.values.yaml

# - name: Commit & Push changes
# uses: actions-js/[email protected]
# with:
# github_token: ${{ secrets.GITOPS_TOKEN }}
# repository: isd-sgcu/isd-gitops
2 changes: 1 addition & 1 deletion .github/workflows/run-unit-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ jobs:

- name: Test
run: |
go test -v -coverpkg ./src/app/... -coverprofile coverage.out -covermode count ./src/app/...
go test -v -coverpkg ./internal/... -coverprofile coverage.out -covermode count ./internal/...
go tool cover -func="./coverage.out"
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,6 @@ github.com
coverage.out
coverage.html

token.txt
token.txt
tmp
docker-compose.qa.yaml
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ RUN go mod download
COPY . .

# Build the application
RUN go build -o server ./src/.
RUN go build -o server ./cmd/main.go

# Create master image
FROM alpine AS master
Expand Down
25 changes: 15 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,26 @@ publish:

test:
go vet ./...
go test -v -coverpkg ./src/app/... -coverprofile coverage.out -covermode count ./src/app/...
go test -v -coverpkg ./internal/... -coverprofile coverage.out -covermode count ./internal/...
go tool cover -func=coverage.out
go tool cover -html=coverage.out -o coverage.html

server:
go run ./src/.
go run ./cmd/.

docker-qa:
docker-compose -f docker-compose.qa.yaml up

mock-gen:
mockgen -source ./src/pkg/service/auth/auth.service.go -destination ./src/mocks/service/auth/auth.mock.go
mockgen -source ./src/pkg/service/user/user.service.go -destination ./src/mocks/service/user/user.mock.go
mockgen -source ./src/pkg/service/pet/pet.service.go -destination ./src/mocks/service/pet/pet.mock.go
mockgen -source ./src/pkg/service/like/like.service.go -destination ./src/mocks/service/like/like.mock.go
mockgen -source ./src/pkg/service/image/image.service.go -destination ./src/mocks/service/image/image.mock.go
mockgen -source ./src/app/validator/validator.go -destination ./src/mocks/validator/validator.mock.go
mockgen -source ./src/app/router/context.go -destination ./src/mocks/router/context.mock.go
mockgen -source ./internal/cache/cache.repository.go -destination ./mocks/repository/cache/cache.mock.go
mockgen -source ./internal/auth/auth.repository.go -destination ./mocks/repository/auth/auth.mock.go
mockgen -source ./internal/auth/auth.service.go -destination ./mocks/service/auth/auth.mock.go
mockgen -source ./internal/user/user.service.go -destination ./mocks/service/user/user.mock.go
mockgen -source ./internal/pet/pet.service.go -destination ./mocks/service/pet/pet.mock.go
mockgen -source ./client/bucket/bucket.client.go -destination ./mocks/client/bucket/bucket.mock.go
mockgen -source ./internal/image/image.service.go -destination ./mocks/service/image/image.mock.go
mockgen -source ./internal/validator/validator.go -destination ./mocks/validator/validator.mock.go
mockgen -source ./internal/router/context.go -destination ./mocks/router/context.mock.go

create-doc:
swag init -d ./src -o ./src/docs -md ./src/docs/markdown
swag init -d ./internal -g ../cmd/main.go -o ./docs -md ./docs/markdown --parseDependency --parseInternal
23 changes: 8 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
# Johnjud-gateway
# Johnjud-backend

Johnjud-gateway is a routing and request handling service for the Johnjud project.
Johnjud-backend is a routing and request handling service for the Johnjud project.

### What is Johnjud?
Johnjud is a pet adoption web application of the [CUVET For Animal Welfare Club](https://www.facebook.com/CUVETforAnimalWelfareClub)

## Stack

- golang
- gRPC
- go-fiber

## Getting Started
Expand All @@ -22,22 +21,16 @@ Johnjud is a pet adoption web application of the [CUVET For Animal Welfare Club]
### Installation

1. Clone this repo
2. Copy every `config.example.yaml` in `config` and paste it in the same directory with `.example` removed from its name.

2. Copy `.env.template` in root directory and paste it in the same directory as `.env` with proper values.
3. Run `go mod download` to download all the dependencies.

### Running
1. Run `docker-compose up -d`
2. Run `make server` or `go run ./src/.`
1. Run `docker-compose -f docker-compose.example.yaml up`
2. Run `make server` or `go run ./cmd/.`

### Testing
1. Run `make test` or `go test -v -coverpkg ./... -coverprofile coverage.out -covermode count ./...`

## Other microservices/repositories of Johnjud
- [Johnjud-gateway](https://github.com/isd-sgcu/johnjud-gateway): Routing and request handling
- [Johnjud-auth](https://github.com/isd-sgcu/johnjud-auth): Authentication and authorization
- [Johnjud-backend](https://github.com/isd-sgcu/johnjud-backend): Main business logic
- [Johnjud-file](https://github.com/isd-sgcu/johnjud-file): File management service
- [Johnjud-proto](https://github.com/isd-sgcu/johnjud-proto): Protobuf files generator
- [Johnjud-go-proto](https://github.com/isd-sgcu/johnjud-go-proto): Generated protobuf files for golang
- [Johnjud-frontend](https://github.com/isd-sgcu/johnjud-frontend): Frontend web application
## Other repositories of Johnjud
- [Johnjud-backend](https://github.com/isd-sgcu/johnjud-backend)
- [Johnjud-frontend](https://github.com/isd-sgcu/johnjud-frontend)
99 changes: 99 additions & 0 deletions client/bucket/bucket.client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package bucket

import (
"bytes"
"context"
"time"

"github.com/isd-sgcu/johnjud-backend/config"
"github.com/minio/minio-go/v7"
"github.com/pkg/errors"
"github.com/rs/zerolog/log"
)

type Client interface {
Upload([]byte, string) (string, string, error)
Delete(string) error
DeleteMany([]string) error
}

type clientImpl struct {
conf config.Bucket
minio *minio.Client
}

func NewClient(conf config.Bucket, minioClient *minio.Client) Client {
return &clientImpl{conf: conf, minio: minioClient}
}

func (c *clientImpl) Upload(file []byte, objectKey string) (string, string, error) {
ctx := context.Background()
_, cancel := context.WithTimeout(ctx, 50*time.Second)
defer cancel()

buffer := bytes.NewReader(file)

uploadOutput, err := c.minio.PutObject(context.Background(), c.conf.BucketName, objectKey, buffer,
buffer.Size(), minio.PutObjectOptions{ContentType: "application/octet-stream"})
if err != nil {
log.Error().
Err(err).
Str("service", "file").
Str("module", "bucket client").
Msgf("Couldn't upload object to %v:%v.", c.conf.BucketName, objectKey)

return "", "", errors.Wrap(err, "Error while uploading the object")
}

return c.getURL(objectKey), uploadOutput.Key, nil
}

func (c *clientImpl) Delete(objectKey string) error {
ctx := context.Background()
_, cancel := context.WithTimeout(ctx, 50*time.Second)
defer cancel()

opts := minio.RemoveObjectOptions{
GovernanceBypass: true,
}
err := c.minio.RemoveObject(context.Background(), c.conf.BucketName, objectKey, opts)
if err != nil {
log.Error().
Err(err).
Str("service", "file").
Str("module", "bucket client").
Msgf("Couldn't delete object from bucket %v:%v.", c.conf.BucketName, objectKey)

return errors.Wrap(err, "Error while deleting the object")
}

return nil
}

func (c *clientImpl) DeleteMany(objectKeys []string) error {
ctx := context.Background()
_, cancel := context.WithTimeout(ctx, 50*time.Second)
defer cancel()

opts := minio.RemoveObjectOptions{
GovernanceBypass: true,
}
for _, objectKey := range objectKeys {
err := c.minio.RemoveObject(context.Background(), c.conf.BucketName, objectKey, opts)
if err != nil {
log.Error().
Err(err).
Str("service", "file").
Str("module", "bucket client").
Msgf("Couldn't delete object from bucket %v:%v.", c.conf.BucketName, objectKey)

return errors.Wrap(err, "Error while deleting the object")
}
}

return nil
}

func (c *clientImpl) getURL(objectKey string) string {
return "https://" + c.conf.Endpoint + "/" + c.conf.BucketName + "/" + objectKey
}
Loading
Loading