init project

This commit is contained in:
aditya.siregar
2024-05-28 14:14:55 +07:00
commit 67f1dbc850
141 changed files with 16879 additions and 0 deletions
+15
View File
@@ -0,0 +1,15 @@
package request
type LoginRequest struct {
Email string `json:"email"`
Password string `json:"password"`
}
type ResetPasswordRequest struct {
Email string `json:"email" validate:"required,email"`
}
type ResetPasswordChangeRequest struct {
Token string `json:"token" validate:"required"`
Password string `json:"password" validate:"required"`
}
+36
View File
@@ -0,0 +1,36 @@
package request
import (
"furtuna-be/internal/constants/branch"
"furtuna-be/internal/entity"
)
type BranchParam struct {
Search string `form:"search" json:"search" example:"Ketua Umum"`
Name string `form:"name" json:"name" example:"Ketua Umum"`
Limit int `form:"limit" json:"limit" example:"10"`
Offset int `form:"offset" json:"offset" example:"0"`
}
func (p *BranchParam) ToEntity() entity.BranchSearch {
return entity.BranchSearch{
Search: p.Search,
Name: p.Name,
Limit: p.Limit,
Offset: p.Offset,
}
}
type Branch struct {
Name string `json:"name" validate:"required"`
Location string `json:"location" validate:"required"`
Status branch.BranchStatus `json:"status"`
}
func (e *Branch) ToEntity() *entity.Branch {
return &entity.Branch{
Name: e.Name,
Location: e.Location,
Status: e.Status,
}
}
+21
View File
@@ -0,0 +1,21 @@
package request
import (
"furtuna-be/internal/common/mycontext"
"github.com/gin-gonic/gin"
)
func GetMyContext(c *gin.Context) mycontext.Context {
rawCtx, exists := c.Get("myCtx")
if !exists {
// handle missing context
return mycontext.NewContext(c)
}
myCtx, ok := rawCtx.(mycontext.Context)
if !ok {
return mycontext.NewContext(c)
}
return myCtx
}
+86
View File
@@ -0,0 +1,86 @@
package request
import (
"fmt"
"time"
"github.com/go-playground/validator/v10"
"furtuna-be/internal/entity"
)
type EventParam struct {
Name string `form:"name" json:"name" example:"Ketua Umum"`
Limit int `form:"limit" json:"limit" example:"10"`
Offset int `form:"offset" json:"offset" example:"0"`
}
func (p *EventParam) ToEntity() entity.EventSearch {
return entity.EventSearch{
Name: p.Name,
Limit: p.Limit,
Offset: p.Offset,
}
}
type Event struct {
Name string `json:"name" validate:"required"`
Description string `json:"description"`
StartDate string `json:"start_date" validate:"required"`
StartTime string `json:"start_time"`
EndDate string `json:"end_date" validate:"required"`
EndTime string `json:"end_time"`
Location string `json:"location" validate:"required"`
Level string `json:"level" validate:"required"`
Included []string `json:"included"`
Price float64 `json:"price"`
Paid bool `json:"paid"`
Status entity.Status `json:"status"`
LocationID int64 `json:"location_id"`
startDateTime time.Time
endDateTime time.Time
}
func (e *Event) ToEntity() *entity.Event {
return &entity.Event{
Name: e.Name,
Description: e.Description,
StartDate: e.startDateTime,
EndDate: e.endDateTime,
Location: e.Location,
Level: e.Level,
Included: e.Included,
Price: e.Price,
Paid: e.Paid,
LocationID: &e.LocationID,
Status: e.Status,
}
}
func (e *Event) Validate() error {
validate := validator.New()
if err := validate.Struct(e); err != nil {
return err
}
startDateTimeStr := e.StartDate + "T" + e.StartTime + "Z"
endDateTimeStr := e.EndDate + "T" + e.EndTime + "Z"
startDateTime, err := time.Parse(time.RFC3339, startDateTimeStr)
if err != nil {
fmt.Println("Error parsing start date-time:", err)
return err
}
e.startDateTime = startDateTime
endDateTime, err := time.Parse(time.RFC3339, endDateTimeStr)
if err != nil {
fmt.Println("Error parsing end date-time:", err)
return err
}
e.endDateTime = endDateTime
return nil
}
+116
View File
@@ -0,0 +1,116 @@
package request
import (
"furtuna-be/internal/constants/order"
"furtuna-be/internal/constants/transaction"
"furtuna-be/internal/entity"
"time"
)
type Order struct {
BranchID int64 `json:"branch_id" validate:"required"`
Amount float64 `json:"amount" validate:"required"`
CustomerName string `json:"customer_name" validate:"required"`
CustomerPhone string `json:"customer_phone" validate:"required"`
Pax int `json:"pax" validate:"required"`
PaymentMethod transaction.PaymentMethod `json:"payment_method" validate:"required"`
OrderItem []OrderItem `json:"order_items" validate:"required"`
}
type OrderItem struct {
ItemID int64 `json:"item_id" validate:"required"`
ItemType order.ItemType `json:"item_type" validate:"required"`
Price float64 `json:"price" validate:"required"`
Qty int64 `json:"qty" validate:"required"`
}
type OrderParam struct {
Search string `form:"search" json:"search" example:"name,branch_name,item_name"`
StatusActive order.OrderSearchStatus `form:"status_active" json:"status_active" example:"active,inactive"`
Status order.OrderStatus `form:"status" json:"status" example:"NEW,PAID,CANCEL"`
BranchID int64 `form:"branch_id" json:"branch_id" example:"1"`
Limit int `form:"limit" json:"limit" example:"10"`
Offset int `form:"offset" json:"offset" example:"0"`
}
func (p *OrderParam) ToEntity() entity.OrderSearch {
return entity.OrderSearch{
Search: p.Search,
StatusActive: p.StatusActive,
Status: p.Status,
BranchID: p.BranchID,
Limit: p.Limit,
Offset: p.Offset,
}
}
func (o *Order) ToEntity() *entity.Order {
var ordItems []entity.OrderItem
if len(o.OrderItem) > 0 {
for _, i := range o.OrderItem {
ordItems = append(ordItems, entity.OrderItem{
ItemID: i.ItemID,
ItemType: i.ItemType,
Price: i.Price,
Qty: i.Qty,
})
}
}
transaction := entity.Transaction{
BranchID: o.BranchID,
CustomerName: o.CustomerName,
CustomerPhone: o.CustomerPhone,
PaymentMethod: o.PaymentMethod,
}
return &entity.Order{
BranchID: o.BranchID,
Amount: o.Amount,
CustomerName: o.CustomerName,
CustomerPhone: o.CustomerPhone,
Pax: o.Pax,
Transaction: transaction,
OrderItem: ordItems,
}
}
type OrderTotalRevenueParam struct {
Year int `form:"year" json:"year" example:"1,2,3"`
Month int `form:"month" json:"month" example:"1,2,3"`
BranchID int64 `form:"branch_id" json:"branch_id" example:"1"`
DateStart *time.Time `form:"date_start" json:"date_start" example:"2024-01-01" time_format:"2006-1-2"`
DateEnd *time.Time `form:"date_end" json:"date_end" example:"2024-01-01" time_format:"2006-1-2"`
}
func (p *OrderTotalRevenueParam) ToEntity() entity.OrderTotalRevenueSearch {
return entity.OrderTotalRevenueSearch{
Year: p.Year,
Month: p.Month,
BranchID: p.BranchID,
DateStart: p.DateStart,
DateEnd: p.DateEnd,
}
}
type OrderBranchRevenueParam struct {
DateStart *time.Time `form:"date_start" json:"date_start" example:"2024-01-01" time_format:"2006-1-2"`
DateEnd *time.Time `form:"date_end" json:"date_end" example:"2024-01-01" time_format:"2006-1-2"`
}
func (p *OrderBranchRevenueParam) ToEntity() entity.OrderBranchRevenueSearch {
return entity.OrderBranchRevenueSearch{
DateStart: p.DateStart,
DateEnd: p.DateEnd,
}
}
type UpdateStatus struct {
Status order.OrderStatus `form:"status" json:"status" example:"NEW,PAID,CANCEL"`
}
func (o *UpdateStatus) ToEntity() *entity.Order {
return &entity.Order{
Status: o.Status,
}
}
+35
View File
@@ -0,0 +1,35 @@
package request
import (
"furtuna-be/internal/entity"
)
type PartnerParam struct {
Search string `form:"search" json:"search" example:"Ketua Umum"`
Name string `form:"name" json:"name" example:"Ketua Umum"`
Limit int `form:"limit" json:"limit" example:"10"`
Offset int `form:"offset" json:"offset" example:"0"`
}
func (p *PartnerParam) ToEntity() entity.PartnerSearch {
return entity.PartnerSearch{
Search: p.Search,
Name: p.Name,
Limit: p.Limit,
Offset: p.Offset,
}
}
type Partner struct {
Name string `json:"name" validate:"required"`
Address string `json:"address" validate:"required"`
Status string `json:"status"`
}
func (e *Partner) ToEntity() *entity.Partner {
return &entity.Partner{
Name: e.Name,
Address: e.Address,
Status: e.Status,
}
}
+52
View File
@@ -0,0 +1,52 @@
package request
import (
"furtuna-be/internal/constants/product"
"furtuna-be/internal/entity"
)
type ProductParam struct {
Search string `form:"search" json:"search" example:"Nasi Goreng"`
Name string `form:"name" json:"name" example:"Nasi Goreng"`
Type product.ProductType `form:"type" json:"type" example:"FOOD/BEVERAGE"`
BranchID int64 `form:"branch_id" json:"branch_id" example:"1"`
Available product.ProductStock `form:"available" json:"available" example:"1" example:"AVAILABLE/UNAVAILABLE"`
Limit int `form:"limit" json:"limit" example:"10"`
Offset int `form:"offset" json:"offset" example:"0"`
}
func (p *ProductParam) ToEntity() entity.ProductSearch {
return entity.ProductSearch{
Search: p.Search,
Name: p.Name,
Type: p.Type,
BranchID: p.BranchID,
Available: p.Available,
Limit: p.Limit,
Offset: p.Offset,
}
}
type Product struct {
Name string `json:"name" validate:"required"`
Type product.ProductType `json:"type" validate:"required"`
Price float64 `json:"price" validate:"required"`
Status product.ProductStatus `json:"status" validate:"required"`
Description string `json:"description" `
Image string `json:"image" `
BranchID int64 `json:"branch_id" validate:"required"`
StockQty int64 `json:"stock_qty" `
}
func (e *Product) ToEntity() *entity.Product {
return &entity.Product{
Name: e.Name,
Type: e.Type,
Price: e.Price,
Status: e.Status,
Description: e.Description,
Image: e.Image,
BranchID: e.BranchID,
StockQty: e.StockQty,
}
}
+53
View File
@@ -0,0 +1,53 @@
package request
import (
"encoding/json"
"furtuna-be/internal/constants/studio"
"furtuna-be/internal/entity"
)
type StudioParam struct {
Id string `form:"id" json:"id" example:"1"`
Name string `form:"name" json:"name" example:"Studio A"`
Status studio.StudioStatus `form:"status" json:"status" example:"Active"`
BranchId int64 `form:"branch_id" json:"branch_id" example:"1"`
Limit int `form:"limit" json:"limit" example:"10"`
Offset int `form:"offset" json:"offset" example:"0"`
}
func (p *StudioParam) ToEntity() entity.StudioSearch {
return entity.StudioSearch{
Name: p.Name,
Status: p.Status,
BranchId: p.BranchId,
Limit: p.Limit,
Offset: p.Offset,
}
}
type Studio struct {
Name string `json:"name" validate:"required"`
BranchId int64 `json:"branch_id" validate:"required"`
Status studio.StudioStatus `json:"status"`
Price float64 `json:"price" validate:"required"`
Metadata map[string]interface{} `json:"metadata"`
}
func (e *Studio) ToEntity() *entity.Studio {
studioEntity := &entity.Studio{
BranchId: e.BranchId,
Name: e.Name,
Status: e.Status,
Price: e.Price,
}
if e.Metadata != nil {
jsonData, err := json.Marshal(e.Metadata)
if err != nil {
//TODO @taufanvps
}
studioEntity.Metadata = jsonData
}
return studioEntity
}
+9
View File
@@ -0,0 +1,9 @@
package request
import (
"furtuna-be/internal/constants/transaction"
)
type Transaction struct {
PaymentMethod transaction.PaymentMethod
}
+58
View File
@@ -0,0 +1,58 @@
package request
import (
"furtuna-be/internal/constants/role"
"furtuna-be/internal/entity"
"github.com/go-playground/validator/v10"
)
type User struct {
Name string `json:"name" validate:"required"`
Email string `json:"email" validate:"required"`
Password string `json:"password" validate:"required"`
PartnerID *int64 `json:"partner_id"`
RoleID int64 `json:"role_id" validate:"required"`
NIK string `json:"nik"`
UserType string `json:"user_type"`
PhoneNumber string `json:"phone_number"`
}
func (e *User) Validate() error {
validate := validator.New()
if err := validate.Struct(e); err != nil {
return err
}
return nil
}
func (u *User) ToEntity() *entity.User {
return &entity.User{
Name: u.Name,
Email: u.Email,
Password: u.Password,
RoleID: role.Role(u.RoleID),
PartnerID: u.PartnerID,
}
}
type UserParam struct {
Search string `form:"search" json:"search" example:"admin,branch1"`
Name string `form:"name" json:"name" example:"Admin 1"`
RoleID int64 `form:"role_id" json:"role_id" example:"1"`
PartnerID int64 `form:"partner_id" json:"partner_id" example:"1"`
Limit int `form:"limit,default=10" json:"limit" example:"10"`
Offset int `form:"offset,default=0" json:"offset" example:"0"`
}
func (p *UserParam) ToEntity() entity.UserSearch {
return entity.UserSearch{
Search: p.Search,
Name: p.Name,
RoleID: p.RoleID,
PartnerID: p.PartnerID,
Limit: p.Limit,
Offset: p.Offset,
}
}