merch module enabled + fix
This commit is contained in:
parent
78a54cc4ac
commit
3ff0e6d641
5 changed files with 34 additions and 27 deletions
|
|
@ -5,6 +5,7 @@ import (
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"merch-parser-api/config"
|
"merch-parser-api/config"
|
||||||
_ "merch-parser-api/docs" //for swagger
|
_ "merch-parser-api/docs" //for swagger
|
||||||
|
"merch-parser-api/internal/api/merch"
|
||||||
"merch-parser-api/internal/api/user"
|
"merch-parser-api/internal/api/user"
|
||||||
"merch-parser-api/internal/app"
|
"merch-parser-api/internal/app"
|
||||||
"merch-parser-api/internal/interfaces"
|
"merch-parser-api/internal/interfaces"
|
||||||
|
|
@ -72,9 +73,15 @@ func main() {
|
||||||
ApiPrefix: c.AppConf.ApiPrefix,
|
ApiPrefix: c.AppConf.ApiPrefix,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
merchModule := merch.NewHandler(merch.Deps{
|
||||||
|
DB: database,
|
||||||
|
Utils: utilsProvider,
|
||||||
|
})
|
||||||
|
|
||||||
//collect modules
|
//collect modules
|
||||||
modules := []interfaces.Module{
|
modules := []interfaces.Module{
|
||||||
users,
|
users,
|
||||||
|
merchModule,
|
||||||
}
|
}
|
||||||
|
|
||||||
//keep last
|
//keep last
|
||||||
|
|
|
||||||
|
|
@ -70,10 +70,10 @@ func (co *controller) addMerch(c *gin.Context) {
|
||||||
// @Description Получить всю информацию про мерч по его uuid
|
// @Description Получить всю информацию про мерч по его uuid
|
||||||
// @Tags Merch
|
// @Tags Merch
|
||||||
// @Security BearerAuth
|
// @Security BearerAuth
|
||||||
// @Param uuid path string true "merch_uuid"
|
// @Param uuid path string true "merch_uuid"
|
||||||
// @Success 200 {object} MerchDTO
|
// @Success 200 {object} MerchDTO
|
||||||
// @Failure 400 {object} responses.ErrorResponse400
|
// @Failure 400 {object} responses.ErrorResponse400
|
||||||
// @Failure 500 {object} responses.ErrorResponse500
|
// @Failure 500 {object} responses.ErrorResponse500
|
||||||
// @Router /merch/{uuid} [get]
|
// @Router /merch/{uuid} [get]
|
||||||
func (co *controller) getSingleMerch(c *gin.Context) {
|
func (co *controller) getSingleMerch(c *gin.Context) {
|
||||||
merchUuid := c.Param("uuid")
|
merchUuid := c.Param("uuid")
|
||||||
|
|
@ -103,9 +103,9 @@ func (co *controller) getSingleMerch(c *gin.Context) {
|
||||||
// @Description Получить все записи мерча
|
// @Description Получить все записи мерча
|
||||||
// @Tags Merch
|
// @Tags Merch
|
||||||
// @Security BearerAuth
|
// @Security BearerAuth
|
||||||
// @Success 200 {array} ListResponse
|
// @Success 200 {array} ListResponse
|
||||||
// @Failure 400 {object} responses.ErrorResponse400
|
// @Failure 400 {object} responses.ErrorResponse400
|
||||||
// @Failure 500 {object} responses.ErrorResponse500
|
// @Failure 500 {object} responses.ErrorResponse500
|
||||||
// @Router /merch/{uuid} [get]
|
// @Router /merch/{uuid} [get]
|
||||||
func (co *controller) getAllMerch(c *gin.Context) {
|
func (co *controller) getAllMerch(c *gin.Context) {
|
||||||
userUuid, err := co.utils.GetUserUuidFromContext(c)
|
userUuid, err := co.utils.GetUserUuidFromContext(c)
|
||||||
|
|
@ -129,10 +129,10 @@ func (co *controller) getAllMerch(c *gin.Context) {
|
||||||
// @Description Обновить информацию про мерч по его uuid в json-е
|
// @Description Обновить информацию про мерч по его uuid в json-е
|
||||||
// @Tags Merch
|
// @Tags Merch
|
||||||
// @Security BearerAuth
|
// @Security BearerAuth
|
||||||
// @Param body body MerchDTO true "merch_uuid"
|
// @Param body body MerchDTO true "merch_uuid"
|
||||||
// @Success 200 {object} MerchDTO
|
// @Success 200 {object} MerchDTO
|
||||||
// @Failure 400 {object} responses.ErrorResponse400
|
// @Failure 400 {object} responses.ErrorResponse400
|
||||||
// @Failure 500 {object} responses.ErrorResponse500
|
// @Failure 500 {object} responses.ErrorResponse500
|
||||||
// @Router /merch/{uuid} [put]
|
// @Router /merch/{uuid} [put]
|
||||||
func (co *controller) updateMerch(c *gin.Context) {
|
func (co *controller) updateMerch(c *gin.Context) {
|
||||||
var payload MerchDTO
|
var payload MerchDTO
|
||||||
|
|
@ -160,10 +160,10 @@ func (co *controller) updateMerch(c *gin.Context) {
|
||||||
// @Description Пометить мерч как удаленный по его uuid
|
// @Description Пометить мерч как удаленный по его uuid
|
||||||
// @Tags Merch
|
// @Tags Merch
|
||||||
// @Security BearerAuth
|
// @Security BearerAuth
|
||||||
// @Param uuid path string true "merch_uuid"
|
// @Param uuid path string true "merch_uuid"
|
||||||
// @Success 200 {object} MerchDTO
|
// @Success 200 {object} MerchDTO
|
||||||
// @Failure 400 {object} responses.ErrorResponse400
|
// @Failure 400 {object} responses.ErrorResponse400
|
||||||
// @Failure 500 {object} responses.ErrorResponse500
|
// @Failure 500 {object} responses.ErrorResponse500
|
||||||
// @Router /merch/{uuid} [delete]
|
// @Router /merch/{uuid} [delete]
|
||||||
func (co *controller) deleteMerch(c *gin.Context) {
|
func (co *controller) deleteMerch(c *gin.Context) {
|
||||||
merchUuid := c.Param("uuid")
|
merchUuid := c.Param("uuid")
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
package merch
|
package merch
|
||||||
|
|
||||||
type merchBundle struct {
|
type merchBundle struct {
|
||||||
Merch Merch
|
Merch *Merch
|
||||||
Surugaya Surugaya
|
Surugaya *Surugaya
|
||||||
Mandarake Mandarake
|
Mandarake *Mandarake
|
||||||
}
|
}
|
||||||
type MerchDTO struct {
|
type MerchDTO struct {
|
||||||
MerchUuid string `json:"merch_uuid"`
|
MerchUuid string `json:"merch_uuid"`
|
||||||
|
|
|
||||||
|
|
@ -28,15 +28,15 @@ type repository interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Repo) addMerch(bundle merchBundle) error {
|
func (r *Repo) addMerch(bundle merchBundle) error {
|
||||||
if err := r.db.Create(bundle.Merch).Error; err != nil {
|
if err := r.db.Model(&Merch{}).Create(bundle.Merch).Error; err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := r.db.Create(bundle.Surugaya).Error; err != nil {
|
if err := r.db.Model(&Surugaya{}).Create(bundle.Surugaya).Error; err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := r.db.Create(bundle.Mandarake).Error; err != nil {
|
if err := r.db.Model(&Mandarake{}).Create(bundle.Mandarake).Error; err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -44,7 +44,7 @@ func (r *Repo) addMerch(bundle merchBundle) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Repo) getSingleMerch(userUuid, merchUuid string) (merchBundle, error) {
|
func (r *Repo) getSingleMerch(userUuid, merchUuid string) (merchBundle, error) {
|
||||||
var merch Merch
|
var merch *Merch
|
||||||
if err := r.db.
|
if err := r.db.
|
||||||
Where("user_uuid = ?", userUuid).
|
Where("user_uuid = ?", userUuid).
|
||||||
Where("merch_uuid = ?", merchUuid).
|
Where("merch_uuid = ?", merchUuid).
|
||||||
|
|
@ -53,14 +53,14 @@ func (r *Repo) getSingleMerch(userUuid, merchUuid string) (merchBundle, error) {
|
||||||
return merchBundle{}, err
|
return merchBundle{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var surugaya Surugaya
|
var surugaya *Surugaya
|
||||||
if err := r.db.
|
if err := r.db.
|
||||||
Where("merch_uuid = ?", merchUuid).
|
Where("merch_uuid = ?", merchUuid).
|
||||||
First(&surugaya).Error; err != nil {
|
First(&surugaya).Error; err != nil {
|
||||||
return merchBundle{}, err
|
return merchBundle{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var mandarake Mandarake
|
var mandarake *Mandarake
|
||||||
if err := r.db.
|
if err := r.db.
|
||||||
Where("merch_uuid = ?", merchUuid).
|
Where("merch_uuid = ?", merchUuid).
|
||||||
First(&mandarake).Error; err != nil {
|
First(&mandarake).Error; err != nil {
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ func (s *service) addMerch(payload MerchDTO, userUuid string) error {
|
||||||
merchUuid := uuid.NewString()
|
merchUuid := uuid.NewString()
|
||||||
|
|
||||||
bundle := merchBundle{
|
bundle := merchBundle{
|
||||||
Merch{
|
&Merch{
|
||||||
CreatedAt: time.Time{},
|
CreatedAt: time.Time{},
|
||||||
UpdatedAt: sql.NullTime{Valid: false},
|
UpdatedAt: sql.NullTime{Valid: false},
|
||||||
DeletedAt: sql.NullTime{Valid: false},
|
DeletedAt: sql.NullTime{Valid: false},
|
||||||
|
|
@ -30,14 +30,14 @@ func (s *service) addMerch(payload MerchDTO, userUuid string) error {
|
||||||
Name: payload.Name,
|
Name: payload.Name,
|
||||||
},
|
},
|
||||||
|
|
||||||
Surugaya{
|
&Surugaya{
|
||||||
DeletedAt: sql.NullTime{},
|
DeletedAt: sql.NullTime{},
|
||||||
MerchUuid: merchUuid,
|
MerchUuid: merchUuid,
|
||||||
Link: payload.OriginSurugaya.Link,
|
Link: payload.OriginSurugaya.Link,
|
||||||
CookieValues: payload.OriginSurugaya.CookieValues,
|
CookieValues: payload.OriginSurugaya.CookieValues,
|
||||||
},
|
},
|
||||||
|
|
||||||
Mandarake{
|
&Mandarake{
|
||||||
DeletedAt: sql.NullTime{},
|
DeletedAt: sql.NullTime{},
|
||||||
MerchUuid: merchUuid,
|
MerchUuid: merchUuid,
|
||||||
Link: payload.OriginMandarake.Link,
|
Link: payload.OriginMandarake.Link,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue