Skip to content

Commit

Permalink
側の実装 (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
1uf3 authored Sep 11, 2023
1 parent 6b1051d commit ff5a926
Show file tree
Hide file tree
Showing 22 changed files with 514 additions and 67 deletions.
16 changes: 16 additions & 0 deletions backend/adaptor/service_server/auth_service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package service_server

import pbAuth "github.com/ritscc/Snack/pb/authentication/v1"

type AuthenticationService struct {
// converter *converter.UserGroupConverter
// interactor *interactor.UserGroupInteractor
pbAuth.UnimplementedAuthenticationServer
}

func InitAuthenticationService() *AuthenticationService {
return &AuthenticationService{
// converter: converter.NewUserConverter(),
// interactor: interactor.NewUserInteractor(),
}
}
29 changes: 29 additions & 0 deletions backend/adaptor/service_server/channel_service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package service_server

import pbChannel "github.com/ritscc/Snack/pb/channel/v1"

type ChannelService struct {
// converter *converter.UserGroupConverter
// interactor *interactor.UserGroupInteractor
pbChannel.UnimplementedChannelServiceServer
}

func InitChannelService() *ChannelService {
return &ChannelService{
// converter: converter.NewUserConverter(),
// interactor: interactor.NewUserInteractor(),
}
}

type MessageChannelService struct {
// converter *converter.UserGroupConverter
// interactor *interactor.UserGroupInteractor
pbChannel.UnimplementedMessageChannelServiceServer
}

func InitMessageChannelService() *MessageChannelService {
return &MessageChannelService{
// converter: converter.NewUserConverter(),
// interactor: interactor.NewUserInteractor(),
}
}
65 changes: 65 additions & 0 deletions backend/adaptor/service_server/converter/user_converter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package converter

import (
"github.com/ritscc/Snack/domain/model"
pbUser "github.com/ritscc/Snack/pb/user/v1"

"github.com/ritscc/Snack/logic/dto"
)

type UserConverter struct {
}

func NewUserConverter() *UserConverter {
return &UserConverter{}
}

func (converter UserConverter) UserTopbUser(user *model.User) *pbUser.User {
return &pbUser.User{
UserId: user.UserID,
Username: user.UserName,
Nick: user.Nick,
RealName: user.RealName,
Avatar: user.Avatar,
Role: user.Role,
Locale: user.Locale,
RitsEmail: user.RitsEmail,
OwnEmail: &user.OwnEmail,
Comment: user.Comment,
Status: pbUser.Status(user.Status),
Services: &pbUser.Service{
Twitter: &user.Services.Twitter,
Github: &user.Services.Github,
Discord: &user.Services.Discord,
},
}
}

func (converter UserConverter) PbUserToUser(user *pbUser.User) *model.User {
return &model.User{
UserID: user.UserId,
UserName: user.Username,
Nick: user.Nick,
RealName: user.RealName,
Avatar: user.Avatar,
Role: user.Role,
Locale: user.Locale,
RitsEmail: user.RitsEmail,
OwnEmail: *user.OwnEmail,
Comment: user.Comment,
Status: model.Status(user.Status),
Services: &model.Service{
Twitter: *user.Services.Twitter,
Github: *user.Services.Github,
Discord: *user.Services.Discord,
},
}
}

func (converter UserConverter) PbCreateUserRequestToCreateUserRequest(req *pbUser.CreateUserRequest) *dto.CreateUserRequest {
return &dto.CreateUserRequest{
Username: req.Username,
Email: req.Email,
Password: req.Password,
}
}
13 changes: 13 additions & 0 deletions backend/adaptor/service_server/event_service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package service_server

import pbEvent "github.com/ritscc/Snack/pb/event/v1"

type EventService struct {
// converter *converter.UserGroupConverter
// interactor *interactor.UserGroupInteractor
pbEvent.UnimplementedEventServiceServer
}

func InitEventService() *EventService {
return &EventService{}
}
18 changes: 18 additions & 0 deletions backend/adaptor/service_server/member_service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package service_server

import (
pbUserGroup "github.com/ritscc/Snack/pb/user_group/v1"
)

type MemberService struct {
// converter *converter.UserGroupConverter
// interactor *interactor.UserGroupInteractor
pbUserGroup.UnimplementedMemberServiceServer
}

func InitMemberService() *MemberService {
return &MemberService{
// converter: converter.NewUserConverter(),
// interactor: interactor.NewUserInteractor(),
}
}
16 changes: 16 additions & 0 deletions backend/adaptor/service_server/message_service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package service_server

import pbMessage "github.com/ritscc/Snack/pb/message/v1"

type MessageService struct {
// converter *converter.UserGroupConverter
// interactor *interactor.UserGroupInteractor
pbMessage.UnimplementedMessageServiceServer
}

func InitMessageService() *MessageService {
return &MessageService{
// converter: converter.NewUserConverter(),
// interactor: interactor.NewUserInteractor(),
}
}
36 changes: 36 additions & 0 deletions backend/adaptor/service_server/user_group_service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package service_server

import (
"context"

pbUserGroup "github.com/ritscc/Snack/pb/user_group/v1"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
emptypb "google.golang.org/protobuf/types/known/emptypb"
)

type UserGroupService struct {
// converter *converter.UserGroupConverter
// interactor *interactor.UserGroupInteractor
pbUserGroup.UnimplementedUserGroupServiceServer
}

func InitUserGroupService() *UserGroupService {
return &UserGroupService{
// converter: converter.NewUserConverter(),
// interactor: interactor.NewUserInteractor(),
}
}

func (*UserGroupService) CreateUserGroup(context.Context, *pbUserGroup.CreateUserGroupRequest) (*emptypb.Empty, error) {
return nil, status.Errorf(codes.Unimplemented, "method CreateUserGroup not implemented")
}
func (*UserGroupService) GetUserGroup(context.Context, *pbUserGroup.UserGroupID) (*pbUserGroup.UserGroup, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetUserGroup not implemented")
}
func (*UserGroupService) UpdateUserGroup(context.Context, *pbUserGroup.UpdateUserGroupRequest) (*emptypb.Empty, error) {
return nil, status.Errorf(codes.Unimplemented, "method UpdateUserGroup not implemented")
}
func (*UserGroupService) DeleteUserGroup(context.Context, *pbUserGroup.UserGroupID) (*emptypb.Empty, error) {
return nil, status.Errorf(codes.Unimplemented, "method DeleteUserGroup not implemented")
}
79 changes: 79 additions & 0 deletions backend/adaptor/service_server/user_service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package service_server

import (
"context"

codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
emptypb "google.golang.org/protobuf/types/known/emptypb"

"github.com/ritscc/Snack/adaptor/service_server/converter"
"github.com/ritscc/Snack/logic/interactor"
pbUser "github.com/ritscc/Snack/pb/user/v1"
)

type UserService struct {
converter *converter.UserConverter
interactor *interactor.UserInteractor
pbUser.UnimplementedUserServiceServer
}

func InitUserService() *UserService {
return &UserService{
converter: converter.NewUserConverter(),
interactor: interactor.NewUserInteractor(),
}
}

func (service *UserService) CreateUser(ctx context.Context, pbReq *pbUser.CreateUserRequest) (*emptypb.Empty, error) {
if service == nil {
return nil, status.Errorf(codes.Internal, "UserService is nil")
}

req := service.converter.PbCreateUserRequestToCreateUserRequest(pbReq)
service.interactor.CreateUser(ctx, req)
res := new(emptypb.Empty)

return res, nil
}

func (service *UserService) GetUser(ctx context.Context, req *pbUser.GetUserRequest) (*pbUser.User, error) {
if service == nil {
return nil, status.Errorf(codes.Internal, "UserService is nil")
}

user, err := service.interactor.GetUser(ctx, req.UserId)
if err != nil {
return nil, status.Errorf(codes.Internal, "err")
}

pbUser := service.converter.UserTopbUser(user)

return pbUser, nil
}

func (service *UserService) UpdateUser(ctx context.Context, pbUser *pbUser.User) (*emptypb.Empty, error) {
if service == nil {
return nil, status.Errorf(codes.Internal, "UserService is nil")
}

user := service.converter.PbUserToUser(pbUser)
if err := service.interactor.UpdateUser(ctx, user); err != nil {
return nil, status.Errorf(codes.Internal, "err")
}
res := new(emptypb.Empty)

return res, nil
}

func (service *UserService) DeleteUser(ctx context.Context, e *emptypb.Empty) (*emptypb.Empty, error) {
if service == nil {
return nil, status.Errorf(codes.Internal, "UserService is nil")
}

service.interactor.DeleteUser(ctx)

res := new(emptypb.Empty)

return res, nil
}
47 changes: 47 additions & 0 deletions backend/domain/model/event.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package model

// This event is used to notify the server or client side
// when data changes are made.
const (
UserCreated = iota
UserUpdated
UserDeleted
UserOnline
UserOffline

UserGroupCreated
UserGroupUpdated
UserGroupDeleted

MemberAdded
MemberUpdated
MemberRemoved

ChannelCreated
ChannelUpdated
ChannelDeleted

MessageChannelJoined
MessageChannelLeaved

VoiceChannelJoined
VoiceChannelLeaved

ChannelEventCreated
ChannelEventUpdated
ChannelEventDeleted
ChannelEventStamped
ChannelEventUnstamped

MessageCreated
MessageUpdated
MessageDeleted
MessageStamped
MessageUnstamped
MessagePinned
MessageUnpinned

StampCreated
StampUpdated
StampDeleted
)
31 changes: 31 additions & 0 deletions backend/domain/model/user.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package model

const (
STATUS_ONLINE Status = 0
STATUS_OFFLINE Status = 1
)

type User struct {
UserID int64
UserName string
Nick string
RealName string
Password [64]byte
Avatar string
Role string
Locale string
RitsEmail string
OwnEmail string
Comment string
Status Status
Services *Service
}

type Status int32

type Service struct {
Twitter string
Github string
Discord string
}

1 change: 0 additions & 1 deletion backend/driver/env/env_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"strconv"
)

// ValueNotFoundError error message for value not found
const ValueNotFoundError = "%s is not found. this environment value must be set."

// GetStrEnv get value
Expand Down
Loading

0 comments on commit ff5a926

Please sign in to comment.