Skip to content

Commit

Permalink
add All medicines endpoint full proccess
Browse files Browse the repository at this point in the history
  • Loading branch information
Alejandro Gabriel Guerrero authored and Alejandro Gabriel Guerrero committed Jan 27, 2024
1 parent 35d7a50 commit 0db5420
Show file tree
Hide file tree
Showing 8 changed files with 155 additions and 42 deletions.
57 changes: 42 additions & 15 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,32 +467,26 @@ const docTemplate = `{
"github_com_gbrayhan_microservices-go_src_domain_medicine.Medicine": {
"type": "object",
"properties": {
"created_at": {
"createdAt": {
"type": "string"
},
"description": {
"type": "string",
"example": "Some Description"
"type": "string"
},
"ean_code": {
"type": "string",
"example": "9900000124"
"eanCode": {
"type": "string"
},
"id": {
"type": "integer",
"example": 123
"type": "integer"
},
"laboratory": {
"type": "string",
"example": "Roche"
"type": "string"
},
"name": {
"type": "string",
"example": "Paracetamol"
"type": "string"
},
"updated_at": {
"type": "string",
"example": "2021-02-24 20:19:39"
"updatedAt": {
"type": "string"
}
}
},
Expand Down Expand Up @@ -531,6 +525,39 @@ const docTemplate = `{
}
}
},
"medicine.ResponseMedicine": {
"type": "object",
"properties": {
"createdAt": {
"type": "string",
"example": "2021-02-24 20:19:39"
},
"description": {
"type": "string",
"example": "Some Description"
},
"eanCode": {
"type": "string",
"example": "Some EanCode"
},
"id": {
"type": "integer",
"example": 1099
},
"laboratory": {
"type": "string",
"example": "Some Laboratory"
},
"name": {
"type": "string",
"example": "Aspirina"
},
"updatedAt": {
"type": "string",
"example": "2021-02-24 20:19:39"
}
}
},
"user.MessageResponse": {
"type": "object",
"properties": {
Expand Down
57 changes: 42 additions & 15 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -461,32 +461,26 @@
"github_com_gbrayhan_microservices-go_src_domain_medicine.Medicine": {
"type": "object",
"properties": {
"created_at": {
"createdAt": {
"type": "string"
},
"description": {
"type": "string",
"example": "Some Description"
"type": "string"
},
"ean_code": {
"type": "string",
"example": "9900000124"
"eanCode": {
"type": "string"
},
"id": {
"type": "integer",
"example": 123
"type": "integer"
},
"laboratory": {
"type": "string",
"example": "Roche"
"type": "string"
},
"name": {
"type": "string",
"example": "Paracetamol"
"type": "string"
},
"updated_at": {
"type": "string",
"example": "2021-02-24 20:19:39"
"updatedAt": {
"type": "string"
}
}
},
Expand Down Expand Up @@ -525,6 +519,39 @@
}
}
},
"medicine.ResponseMedicine": {
"type": "object",
"properties": {
"createdAt": {
"type": "string",
"example": "2021-02-24 20:19:39"
},
"description": {
"type": "string",
"example": "Some Description"
},
"eanCode": {
"type": "string",
"example": "Some EanCode"
},
"id": {
"type": "integer",
"example": 1099
},
"laboratory": {
"type": "string",
"example": "Some Laboratory"
},
"name": {
"type": "string",
"example": "Aspirina"
},
"updatedAt": {
"type": "string",
"example": "2021-02-24 20:19:39"
}
}
},
"user.MessageResponse": {
"type": "object",
"properties": {
Expand Down
36 changes: 27 additions & 9 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,25 +70,19 @@ definitions:
type: object
github_com_gbrayhan_microservices-go_src_domain_medicine.Medicine:
properties:
created_at:
createdAt:
type: string
description:
example: Some Description
type: string
ean_code:
example: "9900000124"
eanCode:
type: string
id:
example: 123
type: integer
laboratory:
example: Roche
type: string
name:
example: Paracetamol
type: string
updated_at:
example: "2021-02-24 20:19:39"
updatedAt:
type: string
type: object
medicine.MessageResponse:
Expand Down Expand Up @@ -116,6 +110,30 @@ definitions:
- laboratory
- name
type: object
medicine.ResponseMedicine:
properties:
createdAt:
example: "2021-02-24 20:19:39"
type: string
description:
example: Some Description
type: string
eanCode:
example: Some EanCode
type: string
id:
example: 1099
type: integer
laboratory:
example: Some Laboratory
type: string
name:
example: Aspirina
type: string
updatedAt:
example: "2021-02-24 20:19:39"
type: string
type: object
user.MessageResponse:
properties:
message:
Expand Down
7 changes: 6 additions & 1 deletion src/application/usecases/medicine/medicine.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var _ medicineDomain.Service = &Service{}

// GetData is a function that returns all medicines
func (s *Service) GetData(page int64, limit int64, sortBy string, sortDirection string, filters map[string][]string, searchText string, dateRangeFilters []domain.DateRangeFilter) (*medicineDomain.DataMedicine, error) {
return s.MedicineRepository.GetAll(page, limit, sortBy, sortDirection, filters, searchText, dateRangeFilters)
return s.MedicineRepository.GetData(page, limit, sortBy, sortDirection, filters, searchText, dateRangeFilters)
}

// GetByID is a function that returns a medicine by id
Expand Down Expand Up @@ -44,3 +44,8 @@ func (s *Service) Delete(id int) error {
func (s *Service) Update(id int, medicineMap map[string]any) (*medicineDomain.Medicine, error) {
return s.MedicineRepository.Update(id, medicineMap)
}

// GetAll is a function that returns all medicines
func (s *Service) GetAll() (*[]medicineDomain.Medicine, error) {
return s.MedicineRepository.GetAll()
}
1 change: 1 addition & 0 deletions src/domain/medicine/Medicine.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type DataMedicine struct {

// Service is a interface that contains the methods for the medicine service
type Service interface {
GetAll() (*[]Medicine, error)
GetData(page int64, limit int64, sortBy string, sortDirection string, filters map[string][]string, searchText string, dateRangeFilters []domain.DateRangeFilter) (*DataMedicine, error)
GetByID(id int) (*Medicine, error)
Create(medicine *NewMedicine) (*Medicine, error)
Expand Down
16 changes: 14 additions & 2 deletions src/infrastructure/repository/medicine/medicine.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ var ColumnsMedicineStructure = map[string]string{
"updatedAt": "UpdatedAt",
}

// GetAll Fetch all medicine data
func (r *Repository) GetAll(page int64, limit int64, sortBy string, sortDirection string, filters map[string][]string, searchText string, dateRangeFilters []domain.DateRangeFilter) (*domainMedicine.DataMedicine, error) {
// GetData Fetch all medicine data
func (r *Repository) GetData(page int64, limit int64, sortBy string, sortDirection string, filters map[string][]string, searchText string, dateRangeFilters []domain.DateRangeFilter) (*domainMedicine.DataMedicine, error) {
var users []Medicine
var total int64
offset := (page - 1) * limit
Expand Down Expand Up @@ -195,3 +195,15 @@ func (r *Repository) Delete(id int) (err error) {

return
}

// GetAll Fetch all medicine data no params just all data
func (r *Repository) GetAll() (*[]domainMedicine.Medicine, error) {
var medicines []Medicine
err := r.DB.Find(&medicines).Error
if err != nil {
err = domainErrors.NewAppErrorWithType(domainErrors.UnknownError)
return nil, err
}

return arrayToDomainMapper(&medicines), nil
}
21 changes: 21 additions & 0 deletions src/infrastructure/rest/controllers/medicine/Medicines.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,27 @@ func (c *Controller) NewMedicine(ctx *gin.Context) {
ctx.JSON(http.StatusOK, responseMedicine)
}

// GetAllMedicines godoc
// @Tags medicine
// @Summary Get all Medicines
// @Description Get all Medicines on the system
// @Success 200 {object} []ResponseMedicine
// @Failure 400 {object} MessageResponse
// @Failure 500 {object} MessageResponse
// @Router /medicine [get]
func (c *Controller) GetAllMedicines(ctx *gin.Context) {
medicines, err := c.MedicineService.GetAll()

if err != nil {
appError := domainError.NewAppErrorWithType(domainError.UnknownError)
_ = ctx.Error(appError)
return
}

ctx.JSON(http.StatusOK, arrayDomainToResponseMapper(medicines))

}

// GetDataMedicines godoc
// @Tags medicine
// @Summary Get all Medicines
Expand Down
2 changes: 2 additions & 0 deletions src/infrastructure/rest/routes/medicine.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ func MedicineRoutes(router *gin.RouterGroup, controller *medicineController.Cont
routerMedicine.Use(middlewares.AuthJWTMiddleware())

{
routerMedicine.GET("/", controller.GetAllMedicines)
routerMedicine.POST("/", controller.NewMedicine)
routerMedicine.GET("/:id", controller.GetMedicinesByID)
routerMedicine.POST("/data", controller.GetDataMedicines)
routerMedicine.PUT("/:id", controller.UpdateMedicine)
routerMedicine.DELETE("/:id", controller.DeleteMedicine)

}

}

0 comments on commit 0db5420

Please sign in to comment.