-
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.
Merge pull request #214 from JokerTrickster/feat/213/profile_image_api
{feat} - 프로필 이미지 저장하기 api 구현 \n
- Loading branch information
Showing
19 changed files
with
359 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
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,65 @@ | ||
package handler | ||
|
||
import ( | ||
"main/features/user/model/entity" | ||
_interface "main/features/user/model/interface" | ||
|
||
mw "main/middleware" | ||
"main/utils" | ||
"net/http" | ||
|
||
"github.com/labstack/echo/v4" | ||
) | ||
|
||
type UpdateProfileUserHandler struct { | ||
UseCase _interface.IUpdateProfileUserUseCase | ||
} | ||
|
||
func NewUpdateProfileUserHandler(c *echo.Echo, useCase _interface.IUpdateProfileUserUseCase) _interface.IUpdateProfileUserHandler { | ||
handler := &UpdateProfileUserHandler{ | ||
UseCase: useCase, | ||
} | ||
c.POST("/v0.1/users/profiles/image", handler.UpdateProfile, mw.TokenChecker) | ||
return handler | ||
} | ||
|
||
// 유저 프로필 이미지 저장하기 | ||
// @Router /v0.1/users/profiles/image [post] | ||
// @Summary 유저 프로필 이미지 저장하기 | ||
// @Description | ||
// @Description ■ errCode with 400 | ||
// @Description PARAM_BAD : 파라미터 오류 | ||
// @Description USER_NOT_FOUND : 유저가 존재하지 않음 | ||
// @Description ■ errCode with 401 | ||
// @Description INVALID_AUTH_CODE : 인증 코드 검증 실패 | ||
// @Description TOKEN_BAD : 잘못된 토큰 | ||
// @Description INVALID_ACCESS_TOKEN : 잘못된 액세스 토큰 | ||
// @Description | ||
// @Description ■ errCode with 500 | ||
// @Description INTERNAL_SERVER : 내부 로직 처리 실패 | ||
// @Description INTERNAL_DB : DB 처리 실패 | ||
// @Description PLAYER_STATE_CHANGE_FAILED : 플레이어 상태 변경 실패 | ||
// @Param tkn header string true "accessToken" | ||
// @Param image formData file false "프로필 이미지 파일" | ||
// @Produce json | ||
// @Success 200 {object} response.ResUpdateProfileUser | ||
// @Failure 400 {object} error | ||
// @Failure 500 {object} error | ||
// @Tags user | ||
func (d *UpdateProfileUserHandler) UpdateProfile(c echo.Context) error { | ||
ctx, uID, _ := utils.CtxGenerate(c) | ||
file, err := c.FormFile("image") | ||
if err != nil { | ||
return err | ||
} | ||
e := &entity.UpdateProfileUserEntity{ | ||
UserID: uID, | ||
Image: file, | ||
} | ||
res, err := d.UseCase.UpdateProfile(ctx, e) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return c.JSON(http.StatusOK, res) | ||
} |
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,8 @@ | ||
package entity | ||
|
||
import "mime/multipart" | ||
|
||
type UpdateProfileUserEntity struct { | ||
Image *multipart.FileHeader `json:"image"` | ||
UserID uint `json:"userID"` | ||
} |
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
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,5 @@ | ||
package response | ||
|
||
type ResUpdateProfileUser struct { | ||
Image string `json:"image"` | ||
} |
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
27 changes: 27 additions & 0 deletions
27
src/features/user/repository/updateProfileUserRepository.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,27 @@ | ||
package repository | ||
|
||
import ( | ||
"context" | ||
_errors "main/features/user/model/errors" | ||
_interface "main/features/user/model/interface" | ||
"main/utils" | ||
"main/utils/db/mysql" | ||
|
||
"gorm.io/gorm" | ||
) | ||
|
||
func NewUpdateProfileUserRepository(gormDB *gorm.DB) _interface.IUpdateProfileUserRepository { | ||
return &UpdateProfileUserRepository{GormDB: gormDB} | ||
} | ||
|
||
func (d *UpdateProfileUserRepository) UpdateProfileImage(ctx context.Context, userID uint, filename string) error { | ||
user := &mysql.Users{} | ||
result := d.GormDB.Model(&user).Where("id = ?", userID).Update("image", filename) | ||
if result.Error != nil { | ||
return utils.ErrorMsg(ctx, utils.ErrInternalServer, utils.Trace(), utils.HandleError(result.Error.Error(), user), utils.ErrFromInternal) | ||
} | ||
if result.RowsAffected == 0 { | ||
return utils.ErrorMsg(ctx, utils.ErrUserNotFound, utils.Trace(), utils.HandleError(_errors.ErrUserNotFound.Error(), user), utils.ErrFromClient) | ||
} | ||
return nil | ||
} |
Oops, something went wrong.