-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from isd-sgcu/count-svc
Count svc
- Loading branch information
Showing
9 changed files
with
107 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package count | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/isd-sgcu/rpkm67-gateway/apperror" | ||
"github.com/isd-sgcu/rpkm67-gateway/internal/dto" | ||
countProto "github.com/isd-sgcu/rpkm67-go-proto/rpkm67/backend/count/v1" | ||
|
||
"go.uber.org/zap" | ||
) | ||
|
||
type Service interface { | ||
Create(req *dto.CreateCountRequest) (*dto.CreateCountResponse, *apperror.AppError) | ||
} | ||
|
||
type serviceImpl struct { | ||
client countProto.CountServiceClient | ||
log *zap.Logger | ||
} | ||
|
||
func NewService(client countProto.CountServiceClient, log *zap.Logger) Service { | ||
return &serviceImpl{ | ||
client: client, | ||
log: log, | ||
} | ||
} | ||
|
||
func (s *serviceImpl) Create(req *dto.CreateCountRequest) (*dto.CreateCountResponse, *apperror.AppError) { | ||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) | ||
defer cancel() | ||
|
||
res, err := s.client.Create(ctx, &countProto.CreateCountRequest{ | ||
Name: req.Name, | ||
}) | ||
if err != nil { | ||
s.log.Named("Create").Error("Create: ", zap.Error(err)) | ||
return nil, apperror.HandleServiceError(err) | ||
} | ||
|
||
return &dto.CreateCountResponse{ | ||
Count: &dto.Count{ | ||
ID: res.Count.Id, | ||
Name: res.Count.Name, | ||
}, | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,14 @@ | ||
package dto | ||
|
||
type CountResponse struct { | ||
Success bool `json:"success"` | ||
type Count struct { | ||
ID string `json:"id"` | ||
Name string `json:"name"` | ||
} | ||
|
||
type CreateCountRequest struct { | ||
Name string `json:"name"` | ||
} | ||
|
||
type CreateCountResponse struct { | ||
Count *Count `json:"count"` | ||
} |