Skip to content

Commit

Permalink
{improvement} - 테이블 수정\n #237
Browse files Browse the repository at this point in the history
  • Loading branch information
JokerTrickster committed Nov 30, 2024
1 parent c17669d commit 8445215
Show file tree
Hide file tree
Showing 17 changed files with 184 additions and 322 deletions.
12 changes: 0 additions & 12 deletions src/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1795,18 +1795,6 @@ const docTemplate = `{
},
"name": {
"type": "string"
},
"scenario": {
"type": "string"
},
"theme": {
"type": "string"
},
"time": {
"type": "string"
},
"type": {
"type": "string"
}
}
},
Expand Down
12 changes: 0 additions & 12 deletions src/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1784,18 +1784,6 @@
},
"name": {
"type": "string"
},
"scenario": {
"type": "string"
},
"theme": {
"type": "string"
},
"time": {
"type": "string"
},
"type": {
"type": "string"
}
}
},
Expand Down
46 changes: 19 additions & 27 deletions src/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ definitions:
sex:
type: string
type: object
request.ReqV02GoogleOauth:
properties:
token:
type: string
type: object
request.ReqV12RecommendFood:
properties:
previousAnswer:
Expand Down Expand Up @@ -208,11 +213,6 @@ definitions:
example: 한식
type: string
type: object
request.ReqV02GoogleOauth:
properties:
token:
type: string
type: object
request.ReqValidatePassword:
properties:
code:
Expand Down Expand Up @@ -281,14 +281,6 @@ definitions:
type: string
name:
type: string
scenario:
type: string
theme:
type: string
time:
type: string
type:
type: string
type: object
response.MetaData:
properties:
Expand Down Expand Up @@ -444,6 +436,20 @@ definitions:
image:
type: string
type: object
response.ResV12RecommendFood:
properties:
foodNames:
items:
$ref: '#/definitions/response.V12RecommendFood'
type: array
type: object
response.ResV1RecommendFood:
properties:
foodNames:
items:
$ref: '#/definitions/response.V1RecommendFood'
type: array
type: object
response.ResV02GoogleOauth:
properties:
accessToken:
Expand All @@ -462,20 +468,6 @@ definitions:
userID:
type: integer
type: object
response.ResV12RecommendFood:
properties:
foodNames:
items:
$ref: '#/definitions/response.V12RecommendFood'
type: array
type: object
response.ResV1RecommendFood:
properties:
foodNames:
items:
$ref: '#/definitions/response.V1RecommendFood'
type: array
type: object
response.V12RecommendFood:
properties:
amount:
Expand Down
4 changes: 2 additions & 2 deletions src/features/food/model/interface/IFoodRepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ type IRecommendFoodRepository interface {

type ISelectFoodRepository interface {
FindOneFood(ctx context.Context, foodDTO *mysql.Foods) (uint, error)
InsertOneFoodHistory(ctx context.Context, foodHistoryDTO *mysql.FoodHistory) error
InsertOneFoodHistory(ctx context.Context, foodHistoryDTO *mysql.FoodHistories) error
IncrementFoodRanking(ctx context.Context, foodName string, score float64) error
}
type IHistoryFoodRepository interface {
FindAllFoodHistory(ctx context.Context, userID uint) ([]mysql.FoodHistory, error)
FindAllFoodHistory(ctx context.Context, userID uint) ([]mysql.FoodHistories, error)
FindOneFood(ctx context.Context, foodID uint) (*mysql.Foods, error)
}

Expand Down
8 changes: 2 additions & 6 deletions src/features/food/model/response/historyFood.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ type ResHistoryFood struct {
}

type HistoryFood struct {
Name string `json:"name"`
Type string `json:"type"`
Time string `json:"time"`
Scenario string `json:"scenario"`
Theme string `json:"theme"`
Created string `json:"created"`
Name string `json:"name"`
Created string `json:"created"`
}
4 changes: 2 additions & 2 deletions src/features/food/repository/historyFoodRepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ func (g *HistoryFoodRepository) FindOneFood(ctx context.Context, foodID uint) (*
return &food, nil
}

func (g *HistoryFoodRepository) FindAllFoodHistory(ctx context.Context, userID uint) ([]mysql.FoodHistory, error) {
foodHistoryList := []mysql.FoodHistory{}
func (g *HistoryFoodRepository) FindAllFoodHistory(ctx context.Context, userID uint) ([]mysql.FoodHistories, error) {
foodHistoryList := []mysql.FoodHistories{}
if err := g.GormDB.WithContext(ctx).Where("user_id = ?", userID).Find(&foodHistoryList).Error; err != nil {
return nil, utils.ErrorMsg(ctx, utils.ErrInternalDB, utils.Trace(), utils.HandleError(_errors.ErrServerError.Error()+err.Error(), userID), utils.ErrFromMysqlDB)
}
Expand Down
2 changes: 1 addition & 1 deletion src/features/food/repository/recommendFoodRepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (d *RecommendFoodRepository) FindOneUser(ctx context.Context, uID uint) (*m
func (d *RecommendFoodRepository) SaveRecommendFood(ctx context.Context, foodDTO *mysql.Foods) (*mysql.Foods, error) {
foods := mysql.Foods{}
// 존재 여부 확인
err := d.GormDB.WithContext(ctx).Model(&foods).Where("name = ? AND time_id = ? AND type_id = ? AND scenario_id = ? and theme_id = ? ", foodDTO.Name, foodDTO.TimeID, foodDTO.TypeID, foodDTO.ScenarioID, foodDTO.ThemeID).First(&foods).Error
err := d.GormDB.WithContext(ctx).Model(&foods).Where("name = ? ", foodDTO.Name).First(&foods).Error

if err == nil {
// 데이터가 이미 존재함
Expand Down
2 changes: 1 addition & 1 deletion src/features/food/repository/saveFoodRepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func NewSaveFoodRepository(gormDB *gorm.DB) _interface.ISaveFoodRepository {
func (d *SaveFoodRepository) SaveFood(ctx context.Context, foodDTO *mysql.Foods) error {
foods := mysql.Foods{}
// 존재 여부 확인
err := d.GormDB.WithContext(ctx).Model(&foods).Where("name = ? AND time_id = ? AND type_id = ? AND scenario_id = ? and theme_id = ? ", foodDTO.Name, foodDTO.TimeID, foodDTO.TypeID, foodDTO.ScenarioID, foodDTO.ThemeID).First(&foods).Error
err := d.GormDB.WithContext(ctx).Model(&foods).Where("name = ? ", foodDTO.Name).First(&foods).Error

if err == nil {
// 데이터가 이미 존재함
Expand Down
2 changes: 1 addition & 1 deletion src/features/food/repository/selectFoodRepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (g *SelectFoodRepository) FindOneFood(ctx context.Context, foodDTO *mysql.F
}
return food.ID, nil
}
func (g *SelectFoodRepository) InsertOneFoodHistory(ctx context.Context, foodHistoryDTO *mysql.FoodHistory) error {
func (g *SelectFoodRepository) InsertOneFoodHistory(ctx context.Context, foodHistoryDTO *mysql.FoodHistories) error {
if err := g.GormDB.WithContext(ctx).Create(&foodHistoryDTO).Error; err != nil {
return utils.ErrorMsg(ctx, utils.ErrInternalDB, utils.Trace(), utils.HandleError(_errors.ErrServerError.Error()+err.Error(), foodHistoryDTO), utils.ErrFromMysqlDB)
}
Expand Down
2 changes: 1 addition & 1 deletion src/features/food/repository/v1RecommendFoodRepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (d *V1RecommendFoodRepository) FindOneV1RecommendFood(ctx context.Context,
func (d *V1RecommendFoodRepository) SaveRecommendFood(ctx context.Context, foodDTO *mysql.Foods) (*mysql.Foods, error) {
foods := mysql.Foods{}
// 존재 여부 확인
err := d.GormDB.WithContext(ctx).Model(&foods).Where("name = ? AND time_id = ? AND type_id = ? AND scenario_id = ? and theme_id = ? ", foodDTO.Name, foodDTO.TimeID, foodDTO.TypeID, foodDTO.ScenarioID, foodDTO.ThemeID).First(&foods).Error
err := d.GormDB.WithContext(ctx).Model(&foods).Where("name = ? ", foodDTO.Name).First(&foods).Error

if err == nil {
// 데이터가 이미 존재함
Expand Down
2 changes: 1 addition & 1 deletion src/features/food/usecase/dailyRecommendFoodUseCase.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (d *DailyRecommendFoodUseCase) DailyRecommend(c context.Context) (response.
res := response.ResDailyRecommendFood{}
for _, food := range foods {
// 음식 이미지를 가져온다.
foodImage, err := d.Repository.FindOneFoodImage(ctx, food.FoodImageID)
foodImage, err := d.Repository.FindOneFoodImage(ctx, food.ImageID)
if err != nil {
return response.ResDailyRecommendFood{}, err
}
Expand Down
29 changes: 3 additions & 26 deletions src/features/food/usecase/historyFoodUseCase.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ package usecase
import (
"context"

_errors "main/features/food/model/errors"
_interface "main/features/food/model/interface"
"main/features/food/model/response"
"main/utils"
"main/utils/db/mysql"
"time"
)

Expand All @@ -34,34 +31,14 @@ func (d *HistoryFoodUseCase) History(c context.Context, userID uint) (response.R
foods := make([]response.HistoryFood, 0)
//TODO 추후 성능 처리 개선 필요
for _, foodHistory := range foodHistoryList {
foodDTO, err := d.Repository.FindOneFood(ctx, foodHistory.FoodID)
foodDTO, err := d.Repository.FindOneFood(ctx, uint(foodHistory.FoodID))
if err != nil {
return response.ResHistoryFood{}, err
}
timeID, ok := mysql.GetTimeKey(foodDTO.TimeID)
if !ok {
return response.ResHistoryFood{}, utils.ErrorMsg(ctx, utils.ErrInternalServer, utils.Trace(), _errors.ErrServerError.Error()+" timeID is not valid", utils.ErrFromInternal)
}
typeID, ok := mysql.GetTypeKey(foodDTO.TypeID)
if !ok {
return response.ResHistoryFood{}, utils.ErrorMsg(ctx, utils.ErrInternalServer, utils.Trace(), _errors.ErrServerError.Error()+" typeID is not valid", utils.ErrFromInternal)
}
scenarioID, ok := mysql.GetScenarioKey(foodDTO.ScenarioID)
if !ok {
return response.ResHistoryFood{}, utils.ErrorMsg(ctx, utils.ErrInternalServer, utils.Trace(), _errors.ErrServerError.Error()+" scenarioID is not valid", utils.ErrFromInternal)
}
themeID, ok := mysql.GetThemeKey(foodDTO.ThemeID)
if !ok {
return response.ResHistoryFood{}, utils.ErrorMsg(ctx, utils.ErrInternalServer, utils.Trace(), _errors.ErrServerError.Error()+" themeID is not valid", utils.ErrFromInternal)
}

food := response.HistoryFood{
Name: foodDTO.Name,
Type: typeID,
Time: timeID,
Scenario: scenarioID,
Theme: themeID,
Created: foodHistory.CreatedAt.Format("2006-01-02 15:04:05"),
Name: foodDTO.Name,
Created: foodHistory.CreatedAt.Format("2006-01-02 15:04:05"),
}
foods = append(foods, food)
}
Expand Down
Loading

0 comments on commit 8445215

Please sign in to comment.