Skip to content

Commit

Permalink
clear sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
FedorovVladimir committed Mar 19, 2022
1 parent 7d0014b commit aaf130a
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 154 deletions.
4 changes: 2 additions & 2 deletions bus/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type UserDTO struct {
Phone string `json:"phone"`
}

type UpdateUserDTO struct {
type UpdateUserRequest struct {
Email string `json:"email"`
FirstName string `json:"firstName"`
LastName string `json:"lastName"`
Expand All @@ -31,7 +31,7 @@ func (b *bus) GetAccount(ctx context.Context, accessToken string) (*UserDTO, err
return user, nil
}

func (b *bus) PutAccount(ctx context.Context, updateUserDTO UpdateUserDTO, accessToken string) (*UserDTO, error) {
func (b *bus) UpdateAccount(ctx context.Context, updateUserDTO UpdateUserRequest, accessToken string) (*UserDTO, error) {
u := b.createUrl("/v1/account", nil)
user := &UserDTO{}
if err := requests.PutRequest(ctx, u, updateUserDTO, user, auth(accessToken)); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions bus/send_feedback.go → bus/feedback.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import (
"github.com/3crabs/go-requests/go-requests"
)

type FeedbackDTO struct {
type FeedbackRequest struct {
Phone string `json:"phone"`
Subject string `json:"subject"`
Text string `json:"text"`
}

func (b *bus) SendFeedback(ctx context.Context, feedback FeedbackDTO) error {
func (b *bus) SendFeedback(ctx context.Context, feedback FeedbackRequest) error {
u := b.createUrl("/v1/feedbacks", nil)
return requests.PostRequest(ctx, u, feedback, nil)
}
7 changes: 2 additions & 5 deletions bus/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,14 @@ type JwtDTO struct {
ExpiresIn int `json:"expires_in"`
}

type LoginDTO struct {
type LoginRequest struct {
Username string `json:"username"`
Password string `json:"password"`
}

func (b *bus) Login(ctx context.Context, phone, password string) (*JwtDTO, error) {
u := b.createUrl("/login", nil)
l := LoginDTO{
Username: phone,
Password: password,
}
l := LoginRequest{Username: phone, Password: password}
jwt := &JwtDTO{}
if err := requests.PostRequest(ctx, u, l, jwt); err != nil {
return nil, err
Expand Down
70 changes: 70 additions & 0 deletions bus/orders.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,58 @@ type OrderDTO struct {
Total int `json:"total"`
}

type SaleRequest struct {
Birthday time.Time `json:"birthday"`
Citizenship string `json:"citizenship"`
DocNum string `json:"docNum"`
DocSeries string `json:"docSeries"`
DocTypeCode string `json:"docTypeCode"`
FirstName string `json:"firstName"`
Gender string `json:"gender"`
LastName string `json:"lastName"`
MiddleName string `json:"middleName"`
Phone string `json:"phone"`
SeatCode string `json:"seatCode"`
TicketTypeCode string `json:"ticketTypeCode"`
}

type TourDTO struct {
First struct {
RaceUid string `json:"raceUid"`
Sales []struct {
Birthday time.Time `json:"birthday"`
Citizenship string `json:"citizenship"`
DocNum string `json:"docNum"`
DocSeries string `json:"docSeries"`
DocTypeCode string `json:"docTypeCode"`
FirstName string `json:"firstName"`
Gender string `json:"gender"`
LastName string `json:"lastName"`
MiddleName string `json:"middleName"`
Phone string `json:"phone"`
SeatCode string `json:"seatCode"`
TicketTypeCode string `json:"ticketTypeCode"`
} `json:"sales"`
} `json:"first"`
Second struct {
RaceUid string `json:"raceUid"`
Sales []struct {
Birthday time.Time `json:"birthday"`
Citizenship string `json:"citizenship"`
DocNum string `json:"docNum"`
DocSeries string `json:"docSeries"`
DocTypeCode string `json:"docTypeCode"`
FirstName string `json:"firstName"`
Gender string `json:"gender"`
LastName string `json:"lastName"`
MiddleName string `json:"middleName"`
Phone string `json:"phone"`
SeatCode string `json:"seatCode"`
TicketTypeCode string `json:"ticketTypeCode"`
} `json:"sales"`
} `json:"second"`
}

func (b *bus) GetOrders(ctx context.Context, accessToken string) (*[]OrderDTO, error) {
u := b.createUrl("/v1/orders", nil)
orders := &[]OrderDTO{}
Expand All @@ -88,3 +140,21 @@ func (b *bus) CancelOrder(ctx context.Context, id int, accessToken string) (*Ord
}
return order, nil
}

func (b *bus) OrderOnOneRace(ctx context.Context, raceUID string, sales []SaleRequest, accessToken string) (*OrderDTO, error) {
u := b.createUrl(fmt.Sprintf("/v1/races/%s/orders", raceUID), nil)
busOrder := &OrderDTO{}
if err := requests.PostRequest(ctx, u, sales, busOrder, auth(accessToken)); err != nil {
return nil, err
}
return busOrder, nil
}

func (b *bus) OrderOnTwoRace(ctx context.Context, tourDTO TourDTO, accessToken string) (*OrderDTO, error) {
u := b.createUrl("/v1/races/orders", nil)
busOrder := &OrderDTO{}
if err := requests.PostRequest(ctx, u, tourDTO, busOrder, auth(accessToken)); err != nil {
return nil, err
}
return busOrder, nil
}
12 changes: 6 additions & 6 deletions bus/passergers.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ type PassengerDTO struct {
Phone string `json:"phone"`
}

type ConfirmPassengerEmailResponse struct {
type ConfirmPassengerEmailDTO struct {
Data string `json:"data"`
}

type PassengerCreateDTO struct {
type PassengerCreateRequest struct {
Birthday time.Time `json:"birthday"`
Citizenship string `json:"citizenship"`
DocNum string `json:"docNum"`
Expand All @@ -43,7 +43,7 @@ type PassengerCreateDTO struct {
Phone string `json:"phone"`
}

func (b *bus) AddPassenger(ctx context.Context, accessToken string, passenger PassengerCreateDTO) (*PassengerDTO, error) {
func (b *bus) AddPassenger(ctx context.Context, accessToken string, passenger PassengerCreateRequest) (*PassengerDTO, error) {
u := b.createUrl("/v1/passengers", nil)
newPassenger := &PassengerDTO{}
if err := requests.PostRequest(ctx, u, passenger, newPassenger, auth(accessToken)); err != nil {
Expand All @@ -61,7 +61,7 @@ func (b *bus) GetPassengers(ctx context.Context, accessToken string) (*[]Passeng
return passengers, nil
}

func (b *bus) PutPassengers(ctx context.Context, id int, newPassenger PassengerDTO, accessToken string) (*PassengerDTO, error) {
func (b *bus) UpdatePassengers(ctx context.Context, id int, newPassenger PassengerDTO, accessToken string) (*PassengerDTO, error) {
u := b.createUrl(fmt.Sprintf("/v1/passengers/%d", id), nil)
passenger := &PassengerDTO{}
if err := requests.PutRequest(ctx, u, newPassenger, passenger, auth(accessToken)); err != nil {
Expand All @@ -75,9 +75,9 @@ func (b *bus) DeletePassenger(ctx context.Context, accessToken string, passenger
return requests.DeleteRequest(ctx, u, nil, nil, auth(accessToken))
}

func (b *bus) ConfirmPassengerEmail(ctx context.Context, id int, accessToken string) (*ConfirmPassengerEmailResponse, error) {
func (b *bus) ConfirmPassengerEmail(ctx context.Context, id int, accessToken string) (*ConfirmPassengerEmailDTO, error) {
u := b.createUrl(fmt.Sprintf("/v1/passengers/%d/confirmEmailRequest", id), nil)
confirmPassengerEmailResponse := &ConfirmPassengerEmailResponse{}
confirmPassengerEmailResponse := &ConfirmPassengerEmailDTO{}
if err := requests.GetRequest(ctx, u, confirmPassengerEmailResponse, auth(accessToken)); err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions bus/payments.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type PaymentsUrlDTO struct {
URL string `json:"url"`
}

type PaymentsUrlRequest struct {
type PaymentsURLRequest struct {
OrderIds []int `json:"orderIds"`
PaymentTypeId int `json:"paymentTypeId"`
}
Expand All @@ -36,7 +36,7 @@ func (b *bus) GetPayments(ctx context.Context, accessToken string) (*[]PaymentTy
return paymentTypeDTOs, nil
}

func (b *bus) GetPaymentsURL(ctx context.Context, paymentsUrlRequest PaymentsUrlRequest, accessToken string) (*PaymentsUrlDTO, error) {
func (b *bus) GetPaymentsURL(ctx context.Context, paymentsUrlRequest PaymentsURLRequest, accessToken string) (*PaymentsUrlDTO, error) {
u := b.createUrl("/v1/payments", nil)
paymentsUrl := &PaymentsUrlDTO{}
if err := requests.PostRequest(ctx, u, paymentsUrlRequest, paymentsUrl, auth(accessToken)); err != nil {
Expand All @@ -45,7 +45,7 @@ func (b *bus) GetPaymentsURL(ctx context.Context, paymentsUrlRequest PaymentsUrl
return paymentsUrl, nil
}

func (b *bus) GetPaymentsRefundTickets(ctx context.Context, refundTicketsRequest RefundTicketsRequest, accessToken string) (*RefundTicketsDTO, error) {
func (b *bus) RefundTickets(ctx context.Context, refundTicketsRequest RefundTicketsRequest, accessToken string) (*RefundTicketsDTO, error) {
u := b.createUrl("/v1/payments/refund", nil)
refundTicketsDTO := &RefundTicketsDTO{}
if err := requests.PostRequest(ctx, u, refundTicketsRequest, refundTicketsDTO, auth(accessToken)); err != nil {
Expand Down
134 changes: 0 additions & 134 deletions bus/races.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,122 +125,6 @@ type RaceSummaryDTO struct {
} `json:"ticketTypes"`
}

type SaleDTO struct {
Birthday time.Time `json:"birthday"`
Citizenship string `json:"citizenship"`
DocNum string `json:"docNum"`
DocSeries string `json:"docSeries"`
DocTypeCode string `json:"docTypeCode"`
FirstName string `json:"firstName"`
Gender string `json:"gender"`
LastName string `json:"lastName"`
MiddleName string `json:"middleName"`
Phone string `json:"phone"`
SeatCode string `json:"seatCode"`
TicketTypeCode string `json:"ticketTypeCode"`
}

type BusOrderDTO struct {
Agent struct {
Extra int `json:"extra"`
FullName string `json:"fullName"`
Id int `json:"id"`
Markup int `json:"markup"`
} `json:"agent"`
Created time.Time `json:"created"`
Expired time.Time `json:"expired"`
Finished time.Time `json:"finished"`
Id int `json:"id"`
PaymentMethod string `json:"paymentMethod"`
Repayment int `json:"repayment"`
ReserveCode string `json:"reserveCode"`
Status string `json:"status"`
Tickets []struct {
ArrivalAddress string `json:"arrivalAddress"`
ArrivalDate time.Time `json:"arrivalDate"`
ArrivalStation string `json:"arrivalStation"`
Barcode string `json:"barcode"`
Birthday time.Time `json:"birthday"`
BusInfo string `json:"busInfo"`
Carrier string `json:"carrier"`
CarrierInn string `json:"carrierInn"`
Citizenship string `json:"citizenship"`
DispatchAddress string `json:"dispatchAddress"`
DispatchDate time.Time `json:"dispatchDate"`
DispatchStation string `json:"dispatchStation"`
DocNum string `json:"docNum"`
DocSeries string `json:"docSeries"`
DocType string `json:"docType"`
DownloadUrl string `json:"downloadUrl"`
Dues int `json:"dues"`
FirstName string `json:"firstName"`
Gender string `json:"gender"`
Id int `json:"id"`
LastName string `json:"lastName"`
MiddleName string `json:"middleName"`
Phone string `json:"phone"`
Platform string `json:"platform"`
Price int `json:"price"`
RaceClassId int `json:"raceClassId"`
RaceName string `json:"raceName"`
RaceNum string `json:"raceNum"`
RaceUid string `json:"raceUid"`
Repayment int `json:"repayment"`
Returned time.Time `json:"returned"`
Seat string `json:"seat"`
Status string `json:"status"`
SupplierDues int `json:"supplierDues"`
SupplierFare int `json:"supplierFare"`
SupplierPrice int `json:"supplierPrice"`
SupplierRepayment int `json:"supplierRepayment"`
TicketClass string `json:"ticketClass"`
TicketCode string `json:"ticketCode"`
TicketNum string `json:"ticketNum"`
TicketSeries string `json:"ticketSeries"`
TicketType string `json:"ticketType"`
Updatable bool `json:"updatable"`
Vat int `json:"vat"`
} `json:"tickets"`
Total int `json:"total"`
}

type TourDTO struct {
First struct {
RaceUid string `json:"raceUid"`
Sales []struct {
Birthday time.Time `json:"birthday"`
Citizenship string `json:"citizenship"`
DocNum string `json:"docNum"`
DocSeries string `json:"docSeries"`
DocTypeCode string `json:"docTypeCode"`
FirstName string `json:"firstName"`
Gender string `json:"gender"`
LastName string `json:"lastName"`
MiddleName string `json:"middleName"`
Phone string `json:"phone"`
SeatCode string `json:"seatCode"`
TicketTypeCode string `json:"ticketTypeCode"`
} `json:"sales"`
} `json:"first"`
Second struct {
RaceUid string `json:"raceUid"`
Sales []struct {
Birthday time.Time `json:"birthday"`
Citizenship string `json:"citizenship"`
DocNum string `json:"docNum"`
DocSeries string `json:"docSeries"`
DocTypeCode string `json:"docTypeCode"`
FirstName string `json:"firstName"`
Gender string `json:"gender"`
LastName string `json:"lastName"`
MiddleName string `json:"middleName"`
Phone string `json:"phone"`
SeatCode string `json:"seatCode"`
TicketTypeCode string `json:"ticketTypeCode"`
} `json:"sales"`
} `json:"second"`
}

func (b *bus) GetRaces(ctx context.Context, fromID, toID int, date string, count int) (*[]RaceDTO, error) {
v := url.Values{
"from": []string{strconv.Itoa(fromID)},
Expand All @@ -264,21 +148,3 @@ func (b *bus) GetRaceSummary(ctx context.Context, raceUID string) (*RaceSummaryD
}
return raceSummary, nil
}

func (b *bus) OrderOnOneRace(ctx context.Context, raceUID string, sales []SaleDTO, accessToken string) (*BusOrderDTO, error) {
u := b.createUrl(fmt.Sprintf("/v1/races/%s/orders", raceUID), nil)
busOrder := &BusOrderDTO{}
if err := requests.PostRequest(ctx, u, sales, busOrder, auth(accessToken)); err != nil {
return nil, err
}
return busOrder, nil
}

func (b *bus) OrderOnTwoRace(ctx context.Context, tourDTO TourDTO, accessToken string) (*BusOrderDTO, error) {
u := b.createUrl("/v1/races/orders", nil)
busOrder := &BusOrderDTO{}
if err := requests.PostRequest(ctx, u, tourDTO, busOrder, auth(accessToken)); err != nil {
return nil, err
}
return busOrder, nil
}
2 changes: 1 addition & 1 deletion examples/feedback/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
func main() {
b := bus.NewBus("http", consts.Host, "/api/bus")

f := bus.FeedbackDTO{
f := bus.FeedbackRequest{
Phone: "+7-000-000-00-00",
Subject: "Проблемы с меню",
Text: "Не работает кнопка назад",
Expand Down
2 changes: 1 addition & 1 deletion examples/passengers/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func main() {
}
}

p := bus.PassengerCreateDTO{
p := bus.PassengerCreateRequest{
Birthday: time.Time{},
Citizenship: "",
DocNum: "",
Expand Down

0 comments on commit aaf130a

Please sign in to comment.