Skip to content

Commit

Permalink
add time format
Browse files Browse the repository at this point in the history
  • Loading branch information
mulmuri committed Nov 26, 2022
1 parent ef70697 commit 2936da1
Show file tree
Hide file tree
Showing 23 changed files with 121 additions and 104 deletions.
27 changes: 4 additions & 23 deletions database/db/coupon.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package db
import (
"context"
"database/sql"
"fmt"
"time"

"mr.jackpot-backend/database/orm"
Expand All @@ -16,7 +15,7 @@ type CouponLayer interface {
GetCouponInfo(couponid int) (model.CouponInfo, error)
GetCouponListByID(userid int) ([]model.CouponInfo, error)

CreateCoupon(model.CouponInfo) (model.CouponInfo, error)
CreateCoupon(model.CouponInfo) (int, error)
GetIssuedCouponList() ([]model.CouponInfo, error)
DeleteCoupon(int) error
UseCoupon(userid, couponid int) error
Expand Down Expand Up @@ -60,7 +59,6 @@ func (db *CouponDB) GetCouponInfo(couponid int) (model.CouponInfo, error) {
ID: int(coupon.CouponID),
Title: coupon.Title.String,
Message: coupon.Description.String,
CreatedAt: coupon.CreatedAt,
ExpiresAt: coupon.ExpiresAt,
}, err
}
Expand All @@ -69,8 +67,6 @@ func (db *CouponDB) GetCouponListByID(userid int) ([]model.CouponInfo, error) {
ctx := context.Background()

couponList, err := db.q.GetCouponAvailable(ctx, int64(userid))
fmt.Println(userid)
fmt.Println(len(couponList))

CouponList := make([]model.CouponInfo, 0);
for _, coupon := range couponList {
Expand All @@ -91,7 +87,7 @@ func (db *CouponDB) GetCouponListByID(userid int) ([]model.CouponInfo, error) {
return CouponList, err
}

func (db *CouponDB) CreateCoupon(coupon model.CouponInfo) (model.CouponInfo, error) {
func (db *CouponDB) CreateCoupon(coupon model.CouponInfo) (int, error) {
ctx := context.Background()

result, err := db.q.IssueCoupon(ctx, orm.IssueCouponParams{
Expand All @@ -105,29 +101,15 @@ func (db *CouponDB) CreateCoupon(coupon model.CouponInfo) (model.CouponInfo, err
String: coupon.Message,
Valid: true,
},
CreatedAt: coupon.CreatedAt,
ExpiresAt: coupon.ExpiresAt,
})

if err != nil {
return model.CouponInfo{}, err
return 0, err
}

couponID, err := result.LastInsertId()
if err != nil {
return model.CouponInfo{}, err
}

couponIssued, err := db.q.GetCouponInfo(ctx, couponID)

return model.CouponInfo{
ID: int(couponID),
Amount: int(couponIssued.Amount),
Code: couponIssued.Code,
Title: couponIssued.Title.String,
Message: couponIssued.Description.String,
ExpiresAt: couponIssued.ExpiresAt,
}, err
return int(couponID), err
}

func (db *CouponDB) GetIssuedCouponList() ([]model.CouponInfo, error) {
Expand All @@ -146,7 +128,6 @@ func (db *CouponDB) GetIssuedCouponList() ([]model.CouponInfo, error) {
Code: coupon.Code,
Title: coupon.Title.String,
Message: coupon.Description.String,
CreatedAt: coupon.CreatedAt,
ExpiresAt: coupon.ExpiresAt,
})
}
Expand Down
5 changes: 1 addition & 4 deletions database/db/vui.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package db

import (
"context"
"fmt"

"mr.jackpot-backend/database/orm"
"mr.jackpot-backend/model"
Expand Down Expand Up @@ -93,7 +92,7 @@ func (db *VUIDB) ReadAllProOrderList() ([]model.ProOrderTable, error) {
}

proOrder.EntityType = ProOrder.Typename
fmt.Println(Id)

switch (proOrder.EntityType) {
case "dinner":
id, err := db.q.GetDinnerId(ctx, int32(proOrder.Id))
Expand Down Expand Up @@ -143,8 +142,6 @@ func (db *VUIDB) ReadAllProOrderList() ([]model.ProOrderTable, error) {
break
}

fmt.Println("found: ", proOrder.EntityId)

proOrderList = append(proOrderList, proOrder)
}

Expand Down
15 changes: 5 additions & 10 deletions database/orm/coupon.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion database/orm/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions database/orm/vui.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions database/sql/coupon.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-- name: IssueCoupon :execresult
INSERT INTO coupon_issued (code, amount, title, description, created_at, expires_at)
VALUES (?, ?, ?, ?, ?, ?);
INSERT INTO coupon_issued (code, amount, title, description, expires_at)
VALUES (?, ?, ?, ?, ?);

-- name: GetCouponIssued :many
SELECT *
Expand All @@ -27,7 +27,7 @@ WHERE coupon_id = (?)
AND owner_id = (?);

-- name: GetCouponAvailable :many
SELECT issued.coupon_id, code, amount, title, description, created_at, expires_at
SELECT issued.coupon_id, code, amount, title, description, expires_at
FROM coupon_owned owned, coupon_issued issued
WHERE owned.owner_id = (?)
AND owned.coupon_id = issued.coupon_id
Expand Down
1 change: 0 additions & 1 deletion database/sql/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ CREATE TABLE coupon_issued (
amount int NOT NULL DEFAULT 0,
title varchar(256),
description varchar(256),
created_at timestamp NOT NULL,
expires_at timestamp NOT NULL,

PRIMARY KEY (coupon_id),
Expand Down
2 changes: 1 addition & 1 deletion database/sql/vui.sql
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ AND pro_order_choice.seq_id = board_entity.target_id
AND board_entity.entity_id = style.entity_id;

-- name: GetCountId :one
SELECT count_id
SELECT count
FROM pro_order_choice, entity_count
WHERE pro_order_choice.seq_id = entity_count.target_id
AND pro_order_choice.seq_id = (?);
Expand Down
5 changes: 1 addition & 4 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package main

import (
"fmt"
"log"
"time"

"mr.jackpot-backend/database/db"
"mr.jackpot-backend/rest"
Expand All @@ -27,8 +25,7 @@ func main() {
}


loc, _ := time.LoadLocation("Asia/Seoul")
fmt.Println(time.Now().In(loc))


log.Fatal(rest.RunAPI("0.0.0.0:8000"))
}
Expand Down
4 changes: 2 additions & 2 deletions model/coupon.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ type CouponInfo struct {
Amount int
Title string
Message string
CreatedAt time.Time
ExpiresAt time.Time
}

type CouponString struct {
ID int
Code string
Title string
Amount int
Message string
CreatedAt string
ExpiresAt string
}
8 changes: 8 additions & 0 deletions model/format.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package model




var TimeDayFormat string = "2006.01.02"
var TimeMinuteFormat string = "2006.01.02 15:04"
var TimeSecondFormat string = "2006.01.02 15:04:05"
4 changes: 0 additions & 4 deletions model/order.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ type Order struct {
DinnerList []DinnerOrder `json:"dinnerList"`
}

type OrderResponse struct {
Order
AllOrderInfo
}

type DinnerOrder struct {
DinnerId int `json:"dinnerId"`
Expand Down
24 changes: 24 additions & 0 deletions model/orderinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,27 @@ type AllOrderInfo struct {
CouponPrice int `json:"couponPrice"`
CouponName string `json:"couponName"`
}

type OrderResponse struct {
Order
AllOrderInfoResponse
}


type AllOrderInfoResponse struct {
ID int `json:"orderId"`
OwnerID int `json:"-"`
StateID int `json:"stateId"`

Name string `json:"reserveName"`
Phone string `json:"contact"`
Address string `json:"address"`
Message string `json:"requestDetail"`

ReserveAt string `json:"reserveDate"`
CreatedAt string `json:"createTime"`

Price int `json:"price"`
CouponPrice int `json:"couponPrice"`
CouponName string `json:"couponName"`
}
2 changes: 0 additions & 2 deletions rest/coupon/staff.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package coupon

import (
"fmt"
"net/http"

"github.com/gin-gonic/gin"
Expand All @@ -20,7 +19,6 @@ func (h *CouponHandler) GetIssuedCouponList(c *gin.Context) {
c.JSON(http.StatusInternalServerError, err.Error())
return
}
fmt.Println(len(couponlist))
c.JSON(http.StatusOK, couponlist)
}

Expand Down
4 changes: 2 additions & 2 deletions rest/order/customer.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (h *OrderHandler) GetOrderInfo(c *gin.Context) {
}

c.JSON(http.StatusOK, gin.H{
"orderinfo": order.AllOrderInfo,
"orderinfo": order.AllOrderInfoResponse,
"order": order.Order,
})

Expand All @@ -43,7 +43,7 @@ func (h *OrderHandler) CreateOrder(c *gin.Context) {
request.Info.OwnerID = userid

if err := h.order.CreateOrder(userid, request.Info, request.Order); err != nil {
c.JSON(http.StatusInternalServerError, request)
c.JSON(http.StatusInternalServerError, err.Error())
return
}

Expand Down
Loading

0 comments on commit 2936da1

Please sign in to comment.