Skip to content

Commit

Permalink
update: add get user info
Browse files Browse the repository at this point in the history
  • Loading branch information
brian030128 committed Jun 22, 2024
1 parent fbbe52c commit 73b3662
Show file tree
Hide file tree
Showing 32 changed files with 900 additions and 226 deletions.
2 changes: 1 addition & 1 deletion Dockerfile.media
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ RUN go build -o /app /usr/src/app/cmd/media_service/main.go

FROM alpine:3.19
COPY --from=build /app /app
EXPOSE 8081
EXPOSE 8080
CMD ["/app"]


4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ docker_push_monify: docker_build_monify
docker_push_media: docker_build_media
docker push registry.nccupass.com/media_service
docker_push: docker_push_proxy docker_push_monify docker_push_media
docker_build: docker_build_proxy docker_build_monify
docker_build: docker_build_proxy docker_build_monify docker_build_media
docker_build_proxy:
docker build -f Dockerfile.proxy -t registry.nccupass.com/monify_restful_proxy .
docker_build_monify:
docker build -f Dockerfile.api -t registry.nccupass.com/monify .

docker_build_media:
docker build -f Dockerfile.media -t registry.nccupass.com/media_service .

Expand Down
2 changes: 1 addition & 1 deletion cmd/media_service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ func main() {
if err != nil {
panic(err)
}
media.NewHttpServer(infra)
media.NewServer(infra).Start()
}
6 changes: 3 additions & 3 deletions lib/auth/auth_middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import (
"strings"
)

type AuthMiddleware struct {
type Middleware struct {
JwtSecret string
}

func (m AuthMiddleware) HttpMiddleware(next http.Handler) http.Handler {
func (m Middleware) HttpMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
auth := r.Header.Get("Authorization")
if auth != "" {
Expand All @@ -34,7 +34,7 @@ func (m AuthMiddleware) HttpMiddleware(next http.Handler) http.Handler {
})
}

func (m AuthMiddleware) GrpcExtractUserId(ctx context.Context, req any, info *grpc.UnaryServerInfo) (uuid.UUID, error) {
func (m Middleware) GrpcExtractUserId(ctx context.Context, req any, info *grpc.UnaryServerInfo) (uuid.UUID, error) {
md, exists := metadata.FromIncomingContext(ctx)
if !exists {
return uuid.Nil, nil
Expand Down
2 changes: 1 addition & 1 deletion lib/context_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ type DatabaseContextKey struct{}
type LoggerContextKey struct{}
type KafkaWriterContextKey struct{}
type ConfigContextKey struct{}
type ImageStorageContextKey struct{}
type FileServiceContextKey struct{}
17 changes: 6 additions & 11 deletions lib/media/media_usage.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
package media

type Usage int
import monify "monify/protobuf/gen/go"

const (
Undefined Usage = iota
UserAvatar
GroupAvatar
)

func Parse(str string) Usage {
func Parse(str string) monify.Usage {
println(str)
switch str {
case "userAvatar":
return UserAvatar
return monify.Usage_UserAvatar
case "groupAvatar":
return GroupAvatar
return monify.Usage_GroupAvatar
default:
return Undefined
return monify.Usage_Undefined
}
}
4 changes: 4 additions & 0 deletions lib/media/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ type Storage interface {

Delete(path string) error

FileHost
}

type FileHost interface {
GetHost() string
GetUrl(path string) string
}
9 changes: 5 additions & 4 deletions lib/media/tmp_image.go → lib/media/tmp_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@ package media

import (
"github.com/google/uuid"
monify "monify/protobuf/gen/go"
"time"
)

type TmpImage struct {
type TmpFile struct {
Id uuid.UUID
ExpectedUsage Usage
ExpectedUsage monify.Usage
Uploader uuid.UUID
UploadedAt time.Time
Path string
}

type ConfirmedImage struct {
type ConfirmedFile struct {
Id uuid.UUID
Usage Usage
Usage monify.Usage
Uploader uuid.UUID
UploadedAt time.Time
Path string
Expand Down
4 changes: 2 additions & 2 deletions migrations/2406170339_create_image_table.down.sql
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
DROP TABLE TmpImage;
DROP TABLE ConfirmedImage;
DROP TABLE tmp_file;
DROP TABLE confirmed_file;
26 changes: 13 additions & 13 deletions migrations/2406170339_create_image_table.up.sql
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
CREATE TABLE TmpImage(
imgId uuid PRIMARY KEY,
path varchar(100) NOT NULL ,
expected_usage int8 NOT NULL ,
uploader uuid references user_identity(user_id) NOT NULL,
uploaded_at timestamp NOT NULL
CREATE TABLE tmp_file(
fileId uuid PRIMARY KEY,
path varchar(100) NOT NULL ,
expected_usage int8 NOT NULL ,
uploader uuid references user_identity(user_id) NOT NULL,
uploaded_at timestamp NOT NULL
);

CREATE TABLE ConfirmedImage(
imgId uuid PRIMARY KEY,
path varchar(100) NOT NULL ,
usage int8 NOT NULL ,
uploader uuid references user_identity(user_id) NOT NULL,
uploaded_at timestamp NOT NULL,
confirmed_at timestamp NOT NULL
CREATE TABLE confirmed_file(
fileId uuid PRIMARY KEY,
path varchar(100) NOT NULL ,
usage int8 NOT NULL ,
uploader uuid references user_identity(user_id) NOT NULL,
uploaded_at timestamp NOT NULL,
confirmed_at timestamp NOT NULL
)

1 change: 1 addition & 0 deletions migrations/2406210105_default_avatar.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE user_identity DROP COLUMN avatar_url;
1 change: 1 addition & 0 deletions migrations/2406210105_default_avatar.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE user_identity ADD COLUMN avatar_url VARCHAR(255) DEFAULT '/default_avatar.png' NOT NULL;
Loading

0 comments on commit 73b3662

Please sign in to comment.