Skip to content

Commit

Permalink
fix: apperrors -> apperror
Browse files Browse the repository at this point in the history
  • Loading branch information
bookpanda committed Jun 23, 2024
1 parent bad1fbe commit ecc0157
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 60 deletions.
2 changes: 1 addition & 1 deletion apperrors/apperrors.go → apperror/apperror.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package apperrors
package apperror

import "net/http"

Expand Down
38 changes: 19 additions & 19 deletions internal/auth/auth.service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand All @@ -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()

Expand All @@ -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
}
}

Expand All @@ -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()

Expand All @@ -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
}
}

Expand All @@ -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
}
26 changes: 13 additions & 13 deletions internal/baan/baan.service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand All @@ -29,23 +29,23 @@ 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()

res, err := s.client.FindAllBaan(ctx, &baanProto.FindAllBaanRequest{})
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
}
}

Expand All @@ -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()

Expand All @@ -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
}
}

Expand Down
4 changes: 2 additions & 2 deletions internal/baan/test/baan.handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -23,7 +23,7 @@ type BaanHandlerTest struct {
Baan *dto.Baan
FindAllBaanReq *dto.FindAllBaanRequest
FindOneBaanReq *dto.FindOneBaanRequest
Err *apperrors.AppError
Err *apperror.AppError
ParamMock string
}

Expand Down
4 changes: 2 additions & 2 deletions internal/baan/test/baan.service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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) {
Expand Down
10 changes: 5 additions & 5 deletions internal/router/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down
22 changes: 11 additions & 11 deletions mocks/auth/auth.service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions mocks/baan/baan.service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions mocks/router/context.mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ecc0157

Please sign in to comment.