Skip to content

Commit

Permalink
Merge pull request #100 from Kos-Kita/updateid
Browse files Browse the repository at this point in the history
update webh
  • Loading branch information
lendral3n authored Feb 13, 2024
2 parents dbf59e2 + 7a884e5 commit 5ea6cc3
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 29 deletions.
1 change: 1 addition & 0 deletions features/admin/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ type DashboardData struct {
TotalUser int
TotalBooking int
TotalKos int
TotalBookingPerMonth int
}


Expand Down
19 changes: 5 additions & 14 deletions features/booking/data/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ type Payment struct {
PaidAt *time.Time `gorm:"default:null;"`
}

// type MonthCount struct {
// Month int
// Count int
// }

func CoreToModelBook(input booking.BookingCore) Booking {
return Booking{
Code: input.Code,
Expand Down Expand Up @@ -93,17 +98,3 @@ func WebhoocksCoreToModel(reqNotif booking.BookingCore) Booking {
Status: reqNotif.Status,
}
}

// func (mod *Booking) GenerateCode() (err error) {
// // mod.Code, err = strconv.Atoi(fmt.Sprintf("%d%d%d", mod.UserId, mod.BoardingHouseId, time.Now().Unix()))
// var bookCode int
// mod.Code, err = strconv.Atoi(fmt.Sprintf("%d%d%d", mod.UserId, mod.BoardingHouseId, time.Now().Unix()))
// if err != nil {
// return err
// }
// // var stringCode string
// stringCode := strconv.Itoa(bookCode)
// mod.Code = stringCode

// return
// }
19 changes: 15 additions & 4 deletions features/booking/data/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,6 @@ func (repo *bookQuery) GetRatingAndFacility(userId uint) ([]kos.Core, error) {
for _, k := range kosData {
result = append(result, k.ModelToCoreKos())
}
// for _, v := range kosData {
// fmt.Println(v.Ratings)

// }
return result, nil
}

Expand All @@ -157,3 +153,18 @@ func (repo *bookQuery) GetTotalBooking() (int, error) {
}
return int(count), nil
}

func (repo *bookQuery) GetTotalBookingPerYear(year int) ([]int, error) {
var counts []int
rows, err := repo.db.Raw("SELECT COUNT(*) as count FROM bookings WHERE YEAR(created_at) = ? GROUP BY MONTH(created_at) ORDER BY MONTH(created_at)", year).Rows()
if err != nil {
return nil, err
}
defer rows.Close()
for rows.Next() {
var count int
rows.Scan(&count)
counts = append(counts, count)
}
return counts, nil
}
11 changes: 6 additions & 5 deletions features/booking/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ type BookingCore struct {
Payment PaymentCore
}

// type WebhoocksRequesCore struct {
// Code string
// Status string
// Payment PaymentCore
// }
type MonthCount struct {
Month int
Count int
}


type PaymentCore struct {
Method string
Expand All @@ -47,6 +47,7 @@ type BookDataInterface interface {
GetBooking(userId uint) ([]BookingCore, error)
WebhoocksData(webhoocksReq BookingCore) error
GetTotalBooking() (int, error)
GetTotalBookingPerYear(year int) ([]int, error)
}

// interface untuk Service Layer
Expand Down
6 changes: 5 additions & 1 deletion features/booking/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ func (handler *BookHandler) CreateBook(c echo.Context) error {
return c.JSON(http.StatusInternalServerError, responses.WebResponse(errInsert.Error(), nil))
}

result := CoreToResponseBook(payment)
// result := CoreToResponseBook(payment)
result := BookingResponse{}
if payment != nil {
result = CoreToResponseBook(payment)
}

return c.JSON(http.StatusOK, responses.WebResponse("success booking kos", result))
}
Expand Down
12 changes: 7 additions & 5 deletions features/booking/service/logic.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ func (bs *bookService) Create(userIdLogin int, input booking.BookingCore) (*book
return nil, errors.New("anda bukan renter")
}

bookCore, err := bs.bookData.Insert(userIdLogin, input)
if err != nil {
return nil, err
}
// bookCore, err := bs.bookData.Insert(userIdLogin, input)
// if err != nil {
// return nil, err
// }



return bookCore, nil
return nil, nil
}

// CancelBooking implements booking.BookServiceInterface.
Expand Down

0 comments on commit 5ea6cc3

Please sign in to comment.