feat: get all plans and improvement
This commit is contained in:
parent
3b2321d5db
commit
d492f3ce44
@ -22,6 +22,7 @@ type Subscribe struct {
|
|||||||
type SubscribePlan struct {
|
type SubscribePlan struct {
|
||||||
ID uuid.UUID `gorm:"type:uuid;primaryKey" json:"id"`
|
ID uuid.UUID `gorm:"type:uuid;primaryKey" json:"id"`
|
||||||
Code string `gorm:"not null" json:"code"`
|
Code string `gorm:"not null" json:"code"`
|
||||||
|
Name string `gorm:"not null" json:"name"`
|
||||||
CreatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP"`
|
CreatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP"`
|
||||||
UpdatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP"`
|
UpdatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP"`
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,13 +5,14 @@ import (
|
|||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *SubsPlan) Create(code string) error {
|
func (s *SubsPlan) Create(spec subscribeplandomain.SubscribePlanReq) error {
|
||||||
spec := &subscribeplandomain.SubscribePlan{
|
data := &subscribeplandomain.SubscribePlan{
|
||||||
ID: uuid.New(),
|
ID: uuid.New(),
|
||||||
Code: code,
|
Code: spec.Code,
|
||||||
|
Name: spec.Name,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := s.DB.Create(&spec).Error; err != nil {
|
if err := s.DB.Create(&data).Error; err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
15
internal/accessor/subscribeplan/get_all.go
Normal file
15
internal/accessor/subscribeplan/get_all.go
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
package subscribeplanrepository
|
||||||
|
|
||||||
|
import (
|
||||||
|
subscribeplandomain "github.com/ardeman/project-legalgo-go/internal/domain/subscribe_plan"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (s *SubsPlan) GetAll() ([]subscribeplandomain.SubscribePlan, error) {
|
||||||
|
var subscribePlans []subscribeplandomain.SubscribePlan
|
||||||
|
|
||||||
|
if err := s.DB.Find(&subscribePlans).Error; err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return subscribePlans, nil
|
||||||
|
}
|
||||||
@ -1,13 +1,17 @@
|
|||||||
package subscribeplanrepository
|
package subscribeplanrepository
|
||||||
|
|
||||||
import "github.com/ardeman/project-legalgo-go/database"
|
import (
|
||||||
|
"github.com/ardeman/project-legalgo-go/database"
|
||||||
|
subscribeplandomain "github.com/ardeman/project-legalgo-go/internal/domain/subscribe_plan"
|
||||||
|
)
|
||||||
|
|
||||||
type SubsPlan struct {
|
type SubsPlan struct {
|
||||||
DB *database.DB
|
DB *database.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
type SubsPlanIntf interface {
|
type SubsPlanIntf interface {
|
||||||
Create(string) error
|
Create(subscribeplandomain.SubscribePlanReq) error
|
||||||
|
GetAll() ([]subscribeplandomain.SubscribePlan, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(
|
func New(
|
||||||
|
|||||||
@ -45,7 +45,7 @@ func CreateSubscribePlan(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := subsSvc.CreatePlan(spec.Code); err != nil {
|
if err := subsSvc.CreatePlan(spec); err != nil {
|
||||||
response.ResponseWithErrorCode(
|
response.ResponseWithErrorCode(
|
||||||
ctx,
|
ctx,
|
||||||
w,
|
w,
|
||||||
|
|||||||
32
internal/api/http/subscribe_plan/get_all.go
Normal file
32
internal/api/http/subscribe_plan/get_all.go
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
package subscribeplanhttp
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
subscribeplansvc "github.com/ardeman/project-legalgo-go/internal/services/subscribe_plan"
|
||||||
|
"github.com/ardeman/project-legalgo-go/internal/utilities/response"
|
||||||
|
"github.com/go-chi/chi/v5"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetAllPlan(
|
||||||
|
router chi.Router,
|
||||||
|
subsPlanSvc subscribeplansvc.SubsPlanIntf,
|
||||||
|
) {
|
||||||
|
router.Get("/get-plans", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
ctx := r.Context()
|
||||||
|
subsPlan, err := subsPlanSvc.GetAllPlan()
|
||||||
|
if err != nil {
|
||||||
|
response.ResponseWithErrorCode(
|
||||||
|
ctx,
|
||||||
|
w,
|
||||||
|
err,
|
||||||
|
response.ErrBadRequest.Code,
|
||||||
|
response.ErrBadRequest.HttpCode,
|
||||||
|
response.ErrBadRequest.Message,
|
||||||
|
)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
response.RespondJsonSuccess(ctx, w, subsPlan)
|
||||||
|
})
|
||||||
|
}
|
||||||
@ -5,5 +5,6 @@ import "go.uber.org/fx"
|
|||||||
var Module = fx.Module("subscribe-plan",
|
var Module = fx.Module("subscribe-plan",
|
||||||
fx.Invoke(
|
fx.Invoke(
|
||||||
CreateSubscribePlan,
|
CreateSubscribePlan,
|
||||||
|
GetAllPlan,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|||||||
@ -4,9 +4,11 @@ import "github.com/google/uuid"
|
|||||||
|
|
||||||
type SubscribePlanReq struct {
|
type SubscribePlanReq struct {
|
||||||
Code string `json:"code" validate:"required"`
|
Code string `json:"code" validate:"required"`
|
||||||
|
Name string `json:"name" validate:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type SubscribePlan struct {
|
type SubscribePlan struct {
|
||||||
ID uuid.UUID `json:"id"`
|
ID uuid.UUID `json:"id"`
|
||||||
Code string `json:"code"`
|
Code string `json:"code"`
|
||||||
|
Name string `json:"name"`
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
package subscribeplansvc
|
package subscribeplansvc
|
||||||
|
|
||||||
func (sb *SubsPlanSvc) CreatePlan(code string) error {
|
import subscribeplandomain "github.com/ardeman/project-legalgo-go/internal/domain/subscribe_plan"
|
||||||
return sb.subsAccs.Create(code)
|
|
||||||
|
func (sb *SubsPlanSvc) CreatePlan(spec subscribeplandomain.SubscribePlanReq) error {
|
||||||
|
return sb.subsAccs.Create(spec)
|
||||||
}
|
}
|
||||||
|
|||||||
14
internal/services/subscribe_plan/get_all_plan.go
Normal file
14
internal/services/subscribe_plan/get_all_plan.go
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
package subscribeplansvc
|
||||||
|
|
||||||
|
import (
|
||||||
|
subscribeplandomain "github.com/ardeman/project-legalgo-go/internal/domain/subscribe_plan"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (s *SubsPlanSvc) GetAllPlan() ([]subscribeplandomain.SubscribePlan, error) {
|
||||||
|
subsPlan, err := s.subsAccs.GetAll()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return subsPlan, nil
|
||||||
|
}
|
||||||
@ -1,13 +1,17 @@
|
|||||||
package subscribeplansvc
|
package subscribeplansvc
|
||||||
|
|
||||||
import subscribeplanrepository "github.com/ardeman/project-legalgo-go/internal/accessor/subscribeplan"
|
import (
|
||||||
|
subscribeplanrepository "github.com/ardeman/project-legalgo-go/internal/accessor/subscribeplan"
|
||||||
|
subscribeplandomain "github.com/ardeman/project-legalgo-go/internal/domain/subscribe_plan"
|
||||||
|
)
|
||||||
|
|
||||||
type SubsPlanSvc struct {
|
type SubsPlanSvc struct {
|
||||||
subsAccs subscribeplanrepository.SubsPlanIntf
|
subsAccs subscribeplanrepository.SubsPlanIntf
|
||||||
}
|
}
|
||||||
|
|
||||||
type SubsPlanIntf interface {
|
type SubsPlanIntf interface {
|
||||||
CreatePlan(string) error
|
CreatePlan(subscribeplandomain.SubscribePlanReq) error
|
||||||
|
GetAllPlan() ([]subscribeplandomain.SubscribePlan, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(
|
func New(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user