Skip to content

Commit

Permalink
fix cart service and add github repository to docker nightly job
Browse files Browse the repository at this point in the history
  • Loading branch information
almostinf committed Dec 4, 2023
1 parent eb2059c commit 160cace
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 112 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docker-nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ jobs:
with:
file: ./${{matrix.services}}/Dockerfile
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{matrix.services}}-nightly:${{env.DOCKER_TAG}},${{ secrets.DOCKERHUB_USERNAME }}/${{matrix.services}}-nightly:latest
tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ github.repository }}-${{matrix.services}}-nightly:${{env.DOCKER_TAG}},${{ secrets.DOCKERHUB_USERNAME }}/${{ github.repository }}-${{matrix.services}}-nightly:latest
1 change: 0 additions & 1 deletion cart/internal/api/grpc/controller/cart.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ func CreateCartline(
cartline := &model.CartLine{
UserID: userID,
ProductID: productID,
Name: productResp.Name,
Quantity: 1,
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
Expand Down
2 changes: 0 additions & 2 deletions cart/internal/infrastructure/repository/cart_pg.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ func scanFullCart(rows pgx.Rows, cart *model.Cart, cartline *model.CartLine) err
&cart.UpdatedAt,
&cartline.UserID,
&cartline.ProductID,
&cartline.Name,
&cartline.Quantity,
&cartline.CreatedAt,
&cartline.UpdatedAt,
Expand All @@ -49,7 +48,6 @@ func scanCartline(rows pgx.Rows, cartline *model.CartLine) error {
return rows.Scan(
&cartline.UserID,
&cartline.ProductID,
&cartline.Name,
&cartline.Quantity,
&cartline.CreatedAt,
&cartline.UpdatedAt,
Expand Down
8 changes: 0 additions & 8 deletions cart/internal/infrastructure/repository/sql_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ func getFullCartsQuery() sq.SelectBuilder {
"carts.updated_at",
"cartlines.user_id",
"cartlines.product_id",
"cartlines.name",
"cartlines.quantity",
"cartlines.created_at",
"cartlines.updated_at",
Expand Down Expand Up @@ -75,7 +74,6 @@ func getCartlines() sq.SelectBuilder {
return psql.Select(
"user_id",
"product_id",
"name",
"quantity",
"created_at",
"updated_at",
Expand All @@ -100,15 +98,13 @@ func createCartlineQuery(cartline *model.CartLine) sq.InsertBuilder {
Columns(
"user_id",
"product_id",
"name",
"quantity",
"created_at",
"updated_at",
).
Values(
cartline.UserID,
cartline.ProductID,
cartline.Name,
cartline.Quantity,
cartline.CreatedAt,
cartline.UpdatedAt,
Expand All @@ -118,10 +114,6 @@ func createCartlineQuery(cartline *model.CartLine) sq.InsertBuilder {
func updateCartlineQuery(cartline model.CartLine) sq.UpdateBuilder {
query := psql.Update("cartlines")

if cartline.Name != "" {
query = query.Set("name", cartline.Name)
}

if cartline.Quantity != 0 {
query = query.Set("quantity", cartline.Quantity)
}
Expand Down
2 changes: 0 additions & 2 deletions cart/internal/model/cart.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ func (cart *Cart) ToProto() *pbCart.CartResponse {
type CartLine struct {
UserID uuid.UUID `json:"user_id"`
ProductID uuid.UUID `json:"product_id"`
Name string `json:"name" validate:"max=128"`
Quantity int64 `json:"quantity" validate:"min=0,max=10000000"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Expand All @@ -51,7 +50,6 @@ func (cartline *CartLine) ToProto() *pbCart.CartlineResponse {
return &pbCart.CartlineResponse{
UserId: cartline.UserID.String(),
ProductId: cartline.ProductID.String(),
Name: cartline.Name,
Quantity: cartline.Quantity,
CreatedAt: timestamppb.New(cartline.CreatedAt),
UpdatedAt: timestamppb.New(cartline.UpdatedAt),
Expand Down
11 changes: 0 additions & 11 deletions cart/internal/model/cart_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package model_test

import (
"strings"
"testing"

"github.com/Go-Marketplace/backend/cart/internal/model"
Expand All @@ -19,23 +18,13 @@ func TestValidate(t *testing.T) {
{
name: "Cartline is valid",
cartline: &model.CartLine{
Name: "test",
Quantity: 10,
},
wasError: false,
},
{
name: "Too long name",
cartline: &model.CartLine{
Name: strings.Repeat("t", 129),
Quantity: 10,
},
wasError: true,
},
{
name: "Too big quantity",
cartline: &model.CartLine{
Name: "test",
Quantity: 100000000,
},
wasError: true,
Expand Down
1 change: 0 additions & 1 deletion cart/migrations/20231118205846_create_tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ VALUES
CREATE TABLE IF NOT EXISTS cartlines (
user_id UUID NOT NULL,
product_id UUID NOT NULL,
name TEXT NOT NULL,
quantity BIGINT NOT NULL,
created_at TIMESTAMP NOT NULL,
updated_at TIMESTAMP NOT NULL,
Expand Down
2 changes: 1 addition & 1 deletion order/internal/api/grpc/controller/order.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func CreateOrder(
orderline := &model.Orderline{
OrderID: newOrder.ID,
ProductID: productID,
Name: cartline.Name,
Name: products[i].Name,
Quantity: cartline.Quantity,
Price: products[i].Price,
Status: model.PendingPayment,
Expand Down
7 changes: 3 additions & 4 deletions proto/cart.proto
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,9 @@ message CartResponse {
message CartlineResponse {
string user_id = 1;
string product_id = 2;
string name = 3;
int64 quantity = 4;
google.protobuf.Timestamp created_at = 5;
google.protobuf.Timestamp updated_at = 6;
int64 quantity = 3;
google.protobuf.Timestamp created_at = 4;
google.protobuf.Timestamp updated_at = 5;
}

message DeleteCartResponse {}
Expand Down
150 changes: 70 additions & 80 deletions proto/gen/cart/cart.pb.go

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

1 change: 0 additions & 1 deletion proto/gen/cart/cart_grpc.pb.go

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

0 comments on commit 160cace

Please sign in to comment.