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 {
|
||||
ID uuid.UUID `gorm:"type:uuid;primaryKey" json:"id"`
|
||||
Code string `gorm:"not null" json:"code"`
|
||||
Name string `gorm:"not null" json:"name"`
|
||||
CreatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP"`
|
||||
UpdatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP"`
|
||||
}
|
||||
|
||||
@ -5,13 +5,14 @@ import (
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
func (s *SubsPlan) Create(code string) error {
|
||||
spec := &subscribeplandomain.SubscribePlan{
|
||||
func (s *SubsPlan) Create(spec subscribeplandomain.SubscribePlanReq) error {
|
||||
data := &subscribeplandomain.SubscribePlan{
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
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
|
||||
|
||||
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 {
|
||||
DB *database.DB
|
||||
}
|
||||
|
||||
type SubsPlanIntf interface {
|
||||
Create(string) error
|
||||
Create(subscribeplandomain.SubscribePlanReq) error
|
||||
GetAll() ([]subscribeplandomain.SubscribePlan, error)
|
||||
}
|
||||
|
||||
func New(
|
||||
|
||||
@ -45,7 +45,7 @@ func CreateSubscribePlan(
|
||||
return
|
||||
}
|
||||
|
||||
if err := subsSvc.CreatePlan(spec.Code); err != nil {
|
||||
if err := subsSvc.CreatePlan(spec); err != nil {
|
||||
response.ResponseWithErrorCode(
|
||||
ctx,
|
||||
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",
|
||||
fx.Invoke(
|
||||
CreateSubscribePlan,
|
||||
GetAllPlan,
|
||||
),
|
||||
)
|
||||
|
||||
@ -4,9 +4,11 @@ import "github.com/google/uuid"
|
||||
|
||||
type SubscribePlanReq struct {
|
||||
Code string `json:"code" validate:"required"`
|
||||
Name string `json:"name" validate:"required"`
|
||||
}
|
||||
|
||||
type SubscribePlan struct {
|
||||
ID uuid.UUID `json:"id"`
|
||||
Code string `json:"code"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
package subscribeplansvc
|
||||
|
||||
func (sb *SubsPlanSvc) CreatePlan(code string) error {
|
||||
return sb.subsAccs.Create(code)
|
||||
import subscribeplandomain "github.com/ardeman/project-legalgo-go/internal/domain/subscribe_plan"
|
||||
|
||||
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
|
||||
|
||||
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 {
|
||||
subsAccs subscribeplanrepository.SubsPlanIntf
|
||||
}
|
||||
|
||||
type SubsPlanIntf interface {
|
||||
CreatePlan(string) error
|
||||
CreatePlan(subscribeplandomain.SubscribePlanReq) error
|
||||
GetAllPlan() ([]subscribeplandomain.SubscribePlan, error)
|
||||
}
|
||||
|
||||
func New(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user