-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
{feat} - 음식 정보 없는 음식 리포트 Api 구현 \n #228
- Loading branch information
1 parent
154b493
commit c57850e
Showing
15 changed files
with
396 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package handler | ||
|
||
import ( | ||
"context" | ||
_interface "main/features/system/model/interface" | ||
"net/http" | ||
|
||
"github.com/labstack/echo/v4" | ||
) | ||
|
||
type FoodReportSystemHandler struct { | ||
UseCase _interface.IFoodReportSystemUseCase | ||
} | ||
|
||
func NewFoodReportSystemHandler(c *echo.Echo, useCase _interface.IFoodReportSystemUseCase) _interface.IFoodReportSystemHandler { | ||
handler := &FoodReportSystemHandler{ | ||
UseCase: useCase, | ||
} | ||
c.POST("/v0.1/system/foods/report", handler.FoodReport) | ||
return handler | ||
} | ||
|
||
// 음식 이미지, 영양 성분 없는 음식 리포트 | ||
// @Router /v0.1/system/foods/report [post] | ||
// @Summary 음식 이미지, 영양 성분 없는 음식 리포트 | ||
// @Description | ||
// @Description ■ errCode with 400 | ||
// @Description PARAM_BAD : 파라미터 오류 | ||
// @Description USER_NOT_EXIST : 유저가 존재하지 않음 | ||
// @Description USER_ALREADY_EXISTED : 유저가 이미 존재 | ||
// @Description | ||
// @Description ■ errCode with 500 | ||
// @Description INTERNAL_SERVER : 내부 로직 처리 실패 | ||
// @Description INTERNAL_DB : DB 처리 실패 | ||
// @Description PLAYER_STATE_CHANGE_FAILED : 플레이어 상태 변경 실패 | ||
// @Produce json | ||
// @Success 200 {object} bool | ||
// @Failure 400 {object} error | ||
// @Failure 500 {object} error | ||
// @Tags system | ||
func (d *FoodReportSystemHandler) FoodReport(c echo.Context) error { | ||
ctx := context.Background() | ||
err := d.UseCase.FoodReport(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return c.JSON(http.StatusOK, true) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/features/system/repository/foodReportSystemRepository.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package repository | ||
|
||
import ( | ||
"context" | ||
_interface "main/features/system/model/interface" | ||
"main/utils" | ||
"main/utils/db/mysql" | ||
|
||
"gorm.io/gorm" | ||
) | ||
|
||
func NewFoodReportSystemRepository(gormDB *gorm.DB) _interface.IFoodReportSystemRepository { | ||
return &FoodReportSystemRepository{GormDB: gormDB} | ||
} | ||
|
||
func (d *FoodReportSystemRepository) FindFoodWithoutImage(ctx context.Context) ([]*mysql.FoodImages, error) { | ||
var foodImages []*mysql.FoodImages | ||
result := d.GormDB.Where("image = ?", "food_default.png").Find(&foodImages) | ||
if result.Error != nil { | ||
return nil, utils.ErrorMsg(ctx, utils.ErrInternalDB, utils.Trace(), utils.HandleError(result.Error.Error(), foodImages), utils.ErrFromMysqlDB) | ||
} | ||
return foodImages, nil | ||
} | ||
|
||
func (d *FoodReportSystemRepository) FindFoodWithoutNutrient(ctx context.Context) ([]*mysql.Foods, error) { | ||
|
||
var foodsWithoutNutrients []*mysql.Foods | ||
|
||
query := ` | ||
SELECT f.* | ||
FROM foods f | ||
LEFT JOIN nutrients n ON f.name = n.food_name | ||
WHERE n.food_name IS NULL AND f.deleted_at IS NULL | ||
` | ||
|
||
if err := d.GormDB.WithContext(ctx).Raw(query).Scan(&foodsWithoutNutrients).Error; err != nil { | ||
return nil, utils.ErrorMsg(ctx, utils.ErrInternalDB, utils.Trace(), utils.HandleError(err.Error(), foodsWithoutNutrients), utils.ErrFromMysqlDB) | ||
} | ||
|
||
return foodsWithoutNutrients, nil | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package usecase | ||
|
||
import ( | ||
"context" | ||
_interface "main/features/system/model/interface" | ||
"main/utils/aws" | ||
"time" | ||
) | ||
|
||
type FoodReportSystemUseCase struct { | ||
Repository _interface.IFoodReportSystemRepository | ||
ContextTimeout time.Duration | ||
} | ||
|
||
func NewFoodReportSystemUseCase(repo _interface.IFoodReportSystemRepository, timeout time.Duration) _interface.IFoodReportSystemUseCase { | ||
return &FoodReportSystemUseCase{Repository: repo, ContextTimeout: timeout} | ||
} | ||
|
||
func (d *FoodReportSystemUseCase) FoodReport(c context.Context) error { | ||
ctx, cancel := context.WithTimeout(c, d.ContextTimeout) | ||
defer cancel() | ||
|
||
//음식 이미지가 없는 음식 리스트 조회 | ||
images, err := d.Repository.FindFoodWithoutImage(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
//음식 영양성분이 없는 음식 리스트 조회 | ||
nutrients, err := d.Repository.FindFoodWithoutNutrient(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
imageList := make([]string, 0) | ||
nutrientList := make([]string, 0) | ||
for _, image := range images { | ||
imageList = append(imageList, image.Name) | ||
} | ||
for _, nutrient := range nutrients { | ||
nutrientList = append(nutrientList, nutrient.Name) | ||
} | ||
|
||
go aws.EmailSendFoodInfoEmptyReport(imageList, nutrientList) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,7 @@ func (d *ReportSystemUseCase) Report(c context.Context, uID uint, req *request.R | |
UserID: strconv.Itoa(int(uID)), | ||
Reason: string(req.Reason), | ||
} | ||
go aws.EmailSendReport([]string{"[email protected]", "[email protected]"}, reqReport) | ||
go aws.EmailSendReport([]string{"[email protected]", "[email protected]", "[email protected]"}, reqReport) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,20 @@ type ReqReportSES struct { | |
Reason string | ||
} | ||
|
||
|
||
func EmailSendFoodInfoEmptyReport(imageEmpty, nutrientEmpty []string) { | ||
templateDataMap := map[string][]string{ | ||
"imageMissingFoods": imageEmpty, | ||
"nutrientMissingFoods": nutrientEmpty, | ||
} | ||
templateDataJson, err := json.Marshal(templateDataMap) | ||
if err != nil { | ||
fmt.Println("Error marshaling template data:", err) | ||
return | ||
} | ||
|
||
emailSend([]string{"[email protected]", "[email protected]", "[email protected]"}, emailTypeFoodNameReport, string(templateDataJson), "foodInfoEmptyReport") | ||
} | ||
func EmailSendFoodUploadReport(successFoodList, failedFoodList []string) { | ||
templateDataMap := map[string]string{ | ||
"successFoodList": strings.Join(successFoodList, ", "), | ||
|
Oops, something went wrong.