-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
114 lines (93 loc) · 4.85 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package main
import (
"golang-pinjol/config"
"golang-pinjol/controller"
"golang-pinjol/middleware"
"golang-pinjol/repository"
"golang-pinjol/services"
"log"
_ "golang-pinjol/docs"
swaggerFiles "github.com/swaggo/files"
ginSwagger "github.com/swaggo/gin-swagger"
"github.com/gin-gonic/gin"
"gorm.io/gorm"
)
var (
db *gorm.DB = config.ConnectDB()
// Repository
customerRepository repository.CustomerRepository = repository.NewCustomerRepository(db)
jobsRepository repository.CustomerJobsRepository = repository.NewCustomerJobsRepository(db)
loanRepository repository.LoansRepository = repository.NewLoansRepository(db)
paymentRepository repository.PaymentRepository = repository.NewPaymentRepository(db)
historyRepository repository.HistoryPaymentRepository = repository.NewHistoryPaymentRepository(db)
// Service
jwtService services.JwtService = services.NewJwtService()
authService services.AuthenticationService = services.NewAuthenticationService(customerRepository)
customerService services.CustomerServices = services.NewCustomerService(customerRepository)
customerJobsService services.JobsCustomerService = services.NewJobsCustomerService(jobsRepository)
loanService services.LoanService = services.NewLoanService(loanRepository, customerRepository)
paymentService services.PaymentService = services.NewPaymentService(paymentRepository)
historyService services.HistoryPaymentService = services.NewHistoryPaymentService(historyRepository)
// Controller
authController controller.AuthController = controller.NewAuthController(authService, jwtService)
customerController controller.CustomerController = controller.NewCustomerController(customerService, jwtService)
uploadFileController controller.UploadFileController = controller.NewUploadFileController(jwtService, db)
customerJobsController controller.CustomerJobsController = controller.NewJobsCustomerController(customerJobsService, jwtService)
loanController controller.LoanController = controller.NewLoanController(loanService, jwtService)
paymentController controller.PaymentController = controller.NewPaymentController(paymentService, jwtService)
historyPaymentController controller.HistoryPaymentController = controller.NewHistoryPaymentController(historyService, jwtService)
)
// @title Golang Pinjol
// @description Dokumentasi REST API
// @version 0.1
// @host localhost:3000
func main() {
defer config.CloseDB(db)
log.Println(db)
r := gin.Default()
auth := r.Group("app/auth")
{
auth.POST("/register", authController.Register)
auth.POST("/login", authController.Login)
}
customer := r.Group("app/customer", middleware.Authorize(jwtService))
{
customer.PUT("/update", customerController.UpdateCustomerController)
customer.GET("/profile", customerController.ProfileCustomerController)
}
documentCustomer := r.Group("app/document", middleware.Authorize(jwtService))
{
documentCustomer.PUT("/upload/:customer_id", uploadFileController.UploadFile)
}
customerJobs := r.Group("app/jobs", middleware.Authorize(jwtService))
{
customerJobs.POST("/addJobs", customerJobsController.AddCustomerJobsController)
customerJobs.PUT("/:id", customerJobsController.UpdateCustomerJobsController)
customerJobs.GET("/:id", customerJobsController.SearchCustomerJobsByIdController)
customerJobs.DELETE("/:id", customerJobsController.DeleteCustomerJobsController)
}
customerLoans := r.Group("app/loans", middleware.Authorize(jwtService))
{
customerLoans.POST("/loan", loanController.CreateLoanController)
customerLoans.PUT("/:id", loanController.UpdateLoanController)
customerLoans.GET("/:id", loanController.SearchLoanByIdController)
customerLoans.PUT("/verification/:id", loanController.UpdateStatusApprovalController)
customerLoans.DELETE("/:id", loanController.DeleteLoanController)
}
customerPayments := r.Group("app/payments", middleware.Authorize(jwtService))
{
customerPayments.POST("/payment", paymentController.PaymentLoanController)
customerPayments.GET("/status/:status", paymentController.ListPaymentByStatusController)
customerPayments.PUT("/:id", paymentController.UpdatePaymentController)
customerPayments.GET("/:id", paymentController.GetPaymentPerBulanController)
customerPayments.GET("/total-payments/:id", paymentController.GetTotalPaymentController)
customerPayments.DELETE("/:id", paymentController.DeletePaymentController)
}
historyPaymentCustomer := r.Group("app/history/payment", middleware.Authorize(jwtService))
{
historyPaymentCustomer.GET("/", historyPaymentController.GetAllHistoryPaymentController)
historyPaymentCustomer.GET("/:id", historyPaymentController.GetHistoryPaymentByIdController)
}
r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
r.Run("localhost:3000")
}