Skip to content

Commit

Permalink
add car_model_service
Browse files Browse the repository at this point in the history
  • Loading branch information
alireza-fa committed Dec 24, 2023
1 parent 6f419da commit 44baaa2
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/api/dto/car.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,28 @@ type CarModelPropertyResponse struct {
Property PropertyResponse `json:"property,omitempty"`
Value string `json:"value"`
}

type CreateCarModelCommentRequest struct {
CarModelId int `json:"carModelId" binding:"required"`
UserId int `json:"userId"`
Message string `json:"message" binding:"required,max=100"`
}

type UpdateCarModelCommentRequest struct {
Message string `json:"message" binding:"required,max=100"`
}

type CarModelCommentResponse struct {
Id int `json:"id"`
CarModelId int `json:"carModelId"`
User
Message string `json:"message"`
}

type UserResponse struct {
Id int `json:"id"`
Username string `json:"username"`
FirstName string `json:"firstName"`
LastName string `json:"lastName"`
Email string `json:"email"`
}
53 changes: 53 additions & 0 deletions src/services/car_model_comment_service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package services

import (
"context"
"github.com/alireza-fa/golang-car-shop/api/dto"
"github.com/alireza-fa/golang-car-shop/config"
"github.com/alireza-fa/golang-car-shop/constants"
"github.com/alireza-fa/golang-car-shop/data/db"
"github.com/alireza-fa/golang-car-shop/data/models"
"github.com/alireza-fa/golang-car-shop/pkg/logging"
)

type CarModelCommentService struct {
base *BaseService[models.CarModelComment, dto.CreateCarModelCommentRequest, dto.UpdateCarModelCommentRequest, dto.CarModelCommentResponse]
}

func NewCarModelCommentService(cfg *config.Config) *CarModelCommentService {
return &CarModelCommentService{
base: &BaseService[models.CarModelComment, dto.CreateCarModelCommentRequest, dto.UpdateCarModelCommentRequest, dto.CarModelCommentResponse]{
Database: db.GetDb(),
Logger: logging.NewLogger(cfg),
Preloads: []preload{
{string: "User"},
},
},
}
}

// Create carModelComment
func (s *CarModelCommentService) Create(ctx context.Context, req *dto.CreateCarModelCommentRequest) (*dto.CarModelCommentResponse, error) {
req.UserId = int(ctx.Value(constants.UserIdKey).(float64))
return s.base.Create(ctx, req)
}

// Update carModelComment
func (s *CarModelCommentService) Update(ctx context.Context, req *dto.UpdateCarModelCommentRequest, id int) (*dto.CarModelCommentResponse, error) {
return s.base.Update(ctx, id, req)
}

// Delete carModelComment
func (s *CarModelCommentService) Delete(ctx context.Context, id int) error {
return s.base.Delete(ctx, id)
}

// GetById carModelComment
func (s *CarModelCommentService) GetById(ctx context.Context, id int) (*dto.CarModelCommentResponse, error) {
return s.base.GetById(ctx, id)
}

// GetByFilter carModelComment
func (s *CarModelCommentService) GetByFilter(ctx context.Context, req *dto.PaginationInputWithFilter) (*dto.PagedList[dto.CarModelCommentResponse], error) {
return s.base.GetByFilter(ctx, req)
}

0 comments on commit 44baaa2

Please sign in to comment.