From ecc0157238579120da02dfe8855103934248b384 Mon Sep 17 00:00:00 2001 From: Idhibhat Pankam Date: Sun, 23 Jun 2024 10:25:08 +0700 Subject: [PATCH] fix: apperrors -> apperror --- .../apperrors.go => apperror/apperror.go | 2 +- internal/auth/auth.service.go | 38 +++++++++---------- internal/baan/baan.service.go | 26 ++++++------- internal/baan/test/baan.handler_test.go | 4 +- internal/baan/test/baan.service_test.go | 4 +- internal/router/context.go | 10 ++--- mocks/auth/auth.service.go | 22 +++++------ mocks/baan/baan.service.go | 10 ++--- mocks/router/context.mock.go | 4 +- 9 files changed, 60 insertions(+), 60 deletions(-) rename apperrors/apperrors.go => apperror/apperror.go (97%) diff --git a/apperrors/apperrors.go b/apperror/apperror.go similarity index 97% rename from apperrors/apperrors.go rename to apperror/apperror.go index 8e2c8bb..e78367f 100644 --- a/apperrors/apperrors.go +++ b/apperror/apperror.go @@ -1,4 +1,4 @@ -package apperrors +package apperror import "net/http" diff --git a/internal/auth/auth.service.go b/internal/auth/auth.service.go index 38a3284..6141ad9 100644 --- a/internal/auth/auth.service.go +++ b/internal/auth/auth.service.go @@ -4,7 +4,7 @@ import ( "context" "time" - "github.com/isd-sgcu/rpkm67-gateway/apperrors" + "github.com/isd-sgcu/rpkm67-gateway/apperror" "github.com/isd-sgcu/rpkm67-gateway/internal/dto" authProto "github.com/isd-sgcu/rpkm67-go-proto/rpkm67/auth/auth/v1" "go.uber.org/zap" @@ -15,11 +15,11 @@ import ( type Service interface { Validate() RefreshToken() - SignUp(req *dto.SignUpRequest) (*dto.Credential, *apperrors.AppError) - SignIn(req *dto.SignInRequest) (*dto.Credential, *apperrors.AppError) - SignOut(req *dto.TokenPayloadAuth) (*dto.SignOutResponse, *apperrors.AppError) - ForgotPassword(req *dto.ForgotPasswordRequest) (*dto.ForgotPasswordResponse, *apperrors.AppError) - ResetPassword(req *dto.ResetPasswordRequest) (*dto.ResetPasswordResponse, *apperrors.AppError) + SignUp(req *dto.SignUpRequest) (*dto.Credential, *apperror.AppError) + SignIn(req *dto.SignInRequest) (*dto.Credential, *apperror.AppError) + SignOut(req *dto.TokenPayloadAuth) (*dto.SignOutResponse, *apperror.AppError) + ForgotPassword(req *dto.ForgotPasswordRequest) (*dto.ForgotPasswordResponse, *apperror.AppError) + ResetPassword(req *dto.ResetPasswordRequest) (*dto.ResetPasswordResponse, *apperror.AppError) } type serviceImpl struct { @@ -39,7 +39,7 @@ func (s *serviceImpl) Validate() { func (s *serviceImpl) RefreshToken() { } -func (s *serviceImpl) SignUp(req *dto.SignUpRequest) (*dto.Credential, *apperrors.AppError) { +func (s *serviceImpl) SignUp(req *dto.SignUpRequest) (*dto.Credential, *apperror.AppError) { ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() @@ -53,15 +53,15 @@ func (s *serviceImpl) SignUp(req *dto.SignUpRequest) (*dto.Credential, *apperror if err != nil { st, ok := status.FromError(err) if !ok { - return nil, apperrors.InternalServer + return nil, apperror.InternalServer } switch st.Code() { case codes.AlreadyExists: - return nil, apperrors.BadRequestError("User already exists") + return nil, apperror.BadRequestError("User already exists") case codes.Internal: - return nil, apperrors.InternalServerError(err.Error()) + return nil, apperror.InternalServerError(err.Error()) default: - return nil, apperrors.ServiceUnavailable + return nil, apperror.ServiceUnavailable } } @@ -72,7 +72,7 @@ func (s *serviceImpl) SignUp(req *dto.SignUpRequest) (*dto.Credential, *apperror }, nil } -func (s *serviceImpl) SignIn(req *dto.SignInRequest) (*dto.Credential, *apperrors.AppError) { +func (s *serviceImpl) SignIn(req *dto.SignInRequest) (*dto.Credential, *apperror.AppError) { ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() @@ -83,15 +83,15 @@ func (s *serviceImpl) SignIn(req *dto.SignInRequest) (*dto.Credential, *apperror if err != nil { st, ok := status.FromError(err) if !ok { - return nil, apperrors.InternalServer + return nil, apperror.InternalServer } switch st.Code() { case codes.AlreadyExists: - return nil, apperrors.BadRequestError("User already exists") + return nil, apperror.BadRequestError("User already exists") case codes.Internal: - return nil, apperrors.InternalServerError(err.Error()) + return nil, apperror.InternalServerError(err.Error()) default: - return nil, apperrors.ServiceUnavailable + return nil, apperror.ServiceUnavailable } } @@ -102,14 +102,14 @@ func (s *serviceImpl) SignIn(req *dto.SignInRequest) (*dto.Credential, *apperror }, nil } -func (s *serviceImpl) SignOut(req *dto.TokenPayloadAuth) (*dto.SignOutResponse, *apperrors.AppError) { +func (s *serviceImpl) SignOut(req *dto.TokenPayloadAuth) (*dto.SignOutResponse, *apperror.AppError) { return nil, nil } -func (s *serviceImpl) ForgotPassword(req *dto.ForgotPasswordRequest) (*dto.ForgotPasswordResponse, *apperrors.AppError) { +func (s *serviceImpl) ForgotPassword(req *dto.ForgotPasswordRequest) (*dto.ForgotPasswordResponse, *apperror.AppError) { return nil, nil } -func (s *serviceImpl) ResetPassword(req *dto.ResetPasswordRequest) (*dto.ResetPasswordResponse, *apperrors.AppError) { +func (s *serviceImpl) ResetPassword(req *dto.ResetPasswordRequest) (*dto.ResetPasswordResponse, *apperror.AppError) { return nil, nil } diff --git a/internal/baan/baan.service.go b/internal/baan/baan.service.go index 63fdfb4..7aee13e 100644 --- a/internal/baan/baan.service.go +++ b/internal/baan/baan.service.go @@ -4,7 +4,7 @@ import ( "context" "time" - "github.com/isd-sgcu/rpkm67-gateway/apperrors" + "github.com/isd-sgcu/rpkm67-gateway/apperror" "github.com/isd-sgcu/rpkm67-gateway/internal/dto" baanProto "github.com/isd-sgcu/rpkm67-go-proto/rpkm67/backend/baan/v1" "go.uber.org/zap" @@ -13,8 +13,8 @@ import ( ) type Service interface { - FindAllBaan(req *dto.FindAllBaanRequest) (*dto.FindAllBaanResponse, *apperrors.AppError) - FindOneBaan(req *dto.FindOneBaanRequest) (*dto.FindOneBaanResponse, *apperrors.AppError) + FindAllBaan(req *dto.FindAllBaanRequest) (*dto.FindAllBaanResponse, *apperror.AppError) + FindOneBaan(req *dto.FindOneBaanRequest) (*dto.FindOneBaanResponse, *apperror.AppError) } type serviceImpl struct { @@ -29,7 +29,7 @@ func NewService(client baanProto.BaanServiceClient, log *zap.Logger) Service { } } -func (s *serviceImpl) FindAllBaan(req *dto.FindAllBaanRequest) (*dto.FindAllBaanResponse, *apperrors.AppError) { +func (s *serviceImpl) FindAllBaan(req *dto.FindAllBaanRequest) (*dto.FindAllBaanResponse, *apperror.AppError) { ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() @@ -37,15 +37,15 @@ func (s *serviceImpl) FindAllBaan(req *dto.FindAllBaanRequest) (*dto.FindAllBaan if err != nil { st, ok := status.FromError(err) if !ok { - return nil, apperrors.InternalServer + return nil, apperror.InternalServer } switch st.Code() { case codes.InvalidArgument: - return nil, apperrors.BadRequestError("Invalid argument") + return nil, apperror.BadRequestError("Invalid argument") case codes.Internal: - return nil, apperrors.InternalServerError(err.Error()) + return nil, apperror.InternalServerError(err.Error()) default: - return nil, apperrors.ServiceUnavailable + return nil, apperror.ServiceUnavailable } } @@ -54,7 +54,7 @@ func (s *serviceImpl) FindAllBaan(req *dto.FindAllBaanRequest) (*dto.FindAllBaan }, nil } -func (s *serviceImpl) FindOneBaan(req *dto.FindOneBaanRequest) (*dto.FindOneBaanResponse, *apperrors.AppError) { +func (s *serviceImpl) FindOneBaan(req *dto.FindOneBaanRequest) (*dto.FindOneBaanResponse, *apperror.AppError) { ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() @@ -64,15 +64,15 @@ func (s *serviceImpl) FindOneBaan(req *dto.FindOneBaanRequest) (*dto.FindOneBaan if err != nil { st, ok := status.FromError(err) if !ok { - return nil, apperrors.InternalServer + return nil, apperror.InternalServer } switch st.Code() { case codes.NotFound: - return nil, apperrors.NotFoundError("Baan not found") + return nil, apperror.NotFoundError("Baan not found") case codes.Internal: - return nil, apperrors.InternalServerError(err.Error()) + return nil, apperror.InternalServerError(err.Error()) default: - return nil, apperrors.ServiceUnavailable + return nil, apperror.ServiceUnavailable } } diff --git a/internal/baan/test/baan.handler_test.go b/internal/baan/test/baan.handler_test.go index a33e763..7200988 100644 --- a/internal/baan/test/baan.handler_test.go +++ b/internal/baan/test/baan.handler_test.go @@ -5,7 +5,7 @@ import ( "testing" "github.com/golang/mock/gomock" - "github.com/isd-sgcu/rpkm67-gateway/apperrors" + "github.com/isd-sgcu/rpkm67-gateway/apperror" "github.com/isd-sgcu/rpkm67-gateway/internal/baan" "github.com/isd-sgcu/rpkm67-gateway/internal/dto" baanMock "github.com/isd-sgcu/rpkm67-gateway/mocks/baan" @@ -23,7 +23,7 @@ type BaanHandlerTest struct { Baan *dto.Baan FindAllBaanReq *dto.FindAllBaanRequest FindOneBaanReq *dto.FindOneBaanRequest - Err *apperrors.AppError + Err *apperror.AppError ParamMock string } diff --git a/internal/baan/test/baan.service_test.go b/internal/baan/test/baan.service_test.go index ef9eb94..a3c8031 100644 --- a/internal/baan/test/baan.service_test.go +++ b/internal/baan/test/baan.service_test.go @@ -4,7 +4,7 @@ import ( "testing" "github.com/golang/mock/gomock" - "github.com/isd-sgcu/rpkm67-gateway/apperrors" + "github.com/isd-sgcu/rpkm67-gateway/apperror" "github.com/isd-sgcu/rpkm67-gateway/internal/baan" "github.com/isd-sgcu/rpkm67-gateway/internal/dto" baanMock "github.com/isd-sgcu/rpkm67-gateway/mocks/client/baan" @@ -26,7 +26,7 @@ type BaanServiceTest struct { FindAllBaanDtoReq *dto.FindAllBaanRequest FindOneBaanProtoReq *baanProto.FindOneBaanRequest FindOneBaanDtoReq *dto.FindOneBaanRequest - Err apperrors.AppError + Err apperror.AppError } func TestBaanService(t *testing.T) { diff --git a/internal/router/context.go b/internal/router/context.go index 3dd3d33..54bf0cf 100644 --- a/internal/router/context.go +++ b/internal/router/context.go @@ -3,13 +3,13 @@ package router import ( "github.com/gin-gonic/gin" "github.com/google/uuid" - "github.com/isd-sgcu/rpkm67-gateway/apperrors" + "github.com/isd-sgcu/rpkm67-gateway/apperror" "github.com/isd-sgcu/rpkm67-gateway/internal/dto" ) type Context interface { JSON(statusCode int, obj interface{}) - ResponseError(err *apperrors.AppError) + ResponseError(err *apperror.AppError) BadRequestError(err string) InternalServerError(err string) NewUUID() uuid.UUID @@ -32,16 +32,16 @@ func (c *contextImpl) JSON(statusCode int, obj interface{}) { c.Context.JSON(statusCode, obj) } -func (c *contextImpl) ResponseError(err *apperrors.AppError) { +func (c *contextImpl) ResponseError(err *apperror.AppError) { c.JSON(err.HttpCode, gin.H{"error": err.Error()}) } func (c *contextImpl) InternalServerError(err string) { - c.JSON(apperrors.InternalServer.HttpCode, gin.H{"error": err}) + c.JSON(apperror.InternalServer.HttpCode, gin.H{"error": err}) } func (c *contextImpl) BadRequestError(err string) { - c.JSON(apperrors.BadRequest.HttpCode, gin.H{"error": err}) + c.JSON(apperror.BadRequest.HttpCode, gin.H{"error": err}) } func (c *contextImpl) NewUUID() uuid.UUID { diff --git a/mocks/auth/auth.service.go b/mocks/auth/auth.service.go index 4621122..65bdb7d 100644 --- a/mocks/auth/auth.service.go +++ b/mocks/auth/auth.service.go @@ -8,7 +8,7 @@ import ( reflect "reflect" gomock "github.com/golang/mock/gomock" - apperrors "github.com/isd-sgcu/rpkm67-gateway/apperrors" + apperror "github.com/isd-sgcu/rpkm67-gateway/apperror" dto "github.com/isd-sgcu/rpkm67-gateway/internal/dto" ) @@ -36,11 +36,11 @@ func (m *MockService) EXPECT() *MockServiceMockRecorder { } // ForgotPassword mocks base method. -func (m *MockService) ForgotPassword(req *dto.ForgotPasswordRequest) (*dto.ForgotPasswordResponse, *apperrors.AppError) { +func (m *MockService) ForgotPassword(req *dto.ForgotPasswordRequest) (*dto.ForgotPasswordResponse, *apperror.AppError) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "ForgotPassword", req) ret0, _ := ret[0].(*dto.ForgotPasswordResponse) - ret1, _ := ret[1].(*apperrors.AppError) + ret1, _ := ret[1].(*apperror.AppError) return ret0, ret1 } @@ -63,11 +63,11 @@ func (mr *MockServiceMockRecorder) RefreshToken() *gomock.Call { } // ResetPassword mocks base method. -func (m *MockService) ResetPassword(req *dto.ResetPasswordRequest) (*dto.ResetPasswordResponse, *apperrors.AppError) { +func (m *MockService) ResetPassword(req *dto.ResetPasswordRequest) (*dto.ResetPasswordResponse, *apperror.AppError) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "ResetPassword", req) ret0, _ := ret[0].(*dto.ResetPasswordResponse) - ret1, _ := ret[1].(*apperrors.AppError) + ret1, _ := ret[1].(*apperror.AppError) return ret0, ret1 } @@ -78,11 +78,11 @@ func (mr *MockServiceMockRecorder) ResetPassword(req interface{}) *gomock.Call { } // SignIn mocks base method. -func (m *MockService) SignIn(req *dto.SignInRequest) (*dto.Credential, *apperrors.AppError) { +func (m *MockService) SignIn(req *dto.SignInRequest) (*dto.Credential, *apperror.AppError) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "SignIn", req) ret0, _ := ret[0].(*dto.Credential) - ret1, _ := ret[1].(*apperrors.AppError) + ret1, _ := ret[1].(*apperror.AppError) return ret0, ret1 } @@ -93,11 +93,11 @@ func (mr *MockServiceMockRecorder) SignIn(req interface{}) *gomock.Call { } // SignOut mocks base method. -func (m *MockService) SignOut(req *dto.TokenPayloadAuth) (*dto.SignOutResponse, *apperrors.AppError) { +func (m *MockService) SignOut(req *dto.TokenPayloadAuth) (*dto.SignOutResponse, *apperror.AppError) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "SignOut", req) ret0, _ := ret[0].(*dto.SignOutResponse) - ret1, _ := ret[1].(*apperrors.AppError) + ret1, _ := ret[1].(*apperror.AppError) return ret0, ret1 } @@ -108,11 +108,11 @@ func (mr *MockServiceMockRecorder) SignOut(req interface{}) *gomock.Call { } // SignUp mocks base method. -func (m *MockService) SignUp(req *dto.SignUpRequest) (*dto.Credential, *apperrors.AppError) { +func (m *MockService) SignUp(req *dto.SignUpRequest) (*dto.Credential, *apperror.AppError) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "SignUp", req) ret0, _ := ret[0].(*dto.Credential) - ret1, _ := ret[1].(*apperrors.AppError) + ret1, _ := ret[1].(*apperror.AppError) return ret0, ret1 } diff --git a/mocks/baan/baan.service.go b/mocks/baan/baan.service.go index bfdc0af..5404f84 100644 --- a/mocks/baan/baan.service.go +++ b/mocks/baan/baan.service.go @@ -8,7 +8,7 @@ import ( reflect "reflect" gomock "github.com/golang/mock/gomock" - apperrors "github.com/isd-sgcu/rpkm67-gateway/apperrors" + apperror "github.com/isd-sgcu/rpkm67-gateway/apperror" dto "github.com/isd-sgcu/rpkm67-gateway/internal/dto" ) @@ -36,11 +36,11 @@ func (m *MockService) EXPECT() *MockServiceMockRecorder { } // FindAllBaan mocks base method. -func (m *MockService) FindAllBaan(req *dto.FindAllBaanRequest) (*dto.FindAllBaanResponse, *apperrors.AppError) { +func (m *MockService) FindAllBaan(req *dto.FindAllBaanRequest) (*dto.FindAllBaanResponse, *apperror.AppError) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "FindAllBaan", req) ret0, _ := ret[0].(*dto.FindAllBaanResponse) - ret1, _ := ret[1].(*apperrors.AppError) + ret1, _ := ret[1].(*apperror.AppError) return ret0, ret1 } @@ -51,11 +51,11 @@ func (mr *MockServiceMockRecorder) FindAllBaan(req interface{}) *gomock.Call { } // FindOneBaan mocks base method. -func (m *MockService) FindOneBaan(req *dto.FindOneBaanRequest) (*dto.FindOneBaanResponse, *apperrors.AppError) { +func (m *MockService) FindOneBaan(req *dto.FindOneBaanRequest) (*dto.FindOneBaanResponse, *apperror.AppError) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "FindOneBaan", req) ret0, _ := ret[0].(*dto.FindOneBaanResponse) - ret1, _ := ret[1].(*apperrors.AppError) + ret1, _ := ret[1].(*apperror.AppError) return ret0, ret1 } diff --git a/mocks/router/context.mock.go b/mocks/router/context.mock.go index 358da37..36f7063 100644 --- a/mocks/router/context.mock.go +++ b/mocks/router/context.mock.go @@ -9,7 +9,7 @@ import ( gomock "github.com/golang/mock/gomock" uuid "github.com/google/uuid" - apperrors "github.com/isd-sgcu/rpkm67-gateway/apperrors" + apperror "github.com/isd-sgcu/rpkm67-gateway/apperror" dto "github.com/isd-sgcu/rpkm67-gateway/internal/dto" ) @@ -158,7 +158,7 @@ func (mr *MockContextMockRecorder) Query(key interface{}) *gomock.Call { } // ResponseError mocks base method. -func (m *MockContext) ResponseError(err *apperrors.AppError) { +func (m *MockContext) ResponseError(err *apperror.AppError) { m.ctrl.T.Helper() m.ctrl.Call(m, "ResponseError", err) }