-
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 : MyPage 개발 - 마이페이구현 * Refactor : 코드 Build되도록 수정
- Loading branch information
1 parent
7ca83fe
commit 2bb163a
Showing
8 changed files
with
202 additions
and
47 deletions.
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
44 changes: 41 additions & 3 deletions
44
Api/src/main/java/picasso/server/api/user/service/MypageService.java
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 |
---|---|---|
@@ -1,17 +1,55 @@ | ||
package picasso.server.api.user.service; | ||
|
||
import jakarta.servlet.http.HttpSession; | ||
import jakarta.transaction.Transactional; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import picasso.server.domain.domains.user.repository.MypageRepository; | ||
import picasso.server.api.user.vo.request.MyPageRequestDto; | ||
import picasso.server.common.exception.NotFoundException; | ||
import picasso.server.common.util.NaverObjectStorageUsageType; | ||
import picasso.server.common.util.NaverObjectStorageUtil; | ||
import picasso.server.domain.domains.user.entity.User; | ||
import picasso.server.domain.domains.user.repository.UserRepository; | ||
|
||
@Service | ||
@Transactional | ||
@RequiredArgsConstructor | ||
public class MypageService { | ||
|
||
private final MypageRepository mypageRepository; | ||
private final UserRepository userRepository; | ||
private final NaverObjectStorageUtil naverObjectStorageUtil; | ||
|
||
public User getUserDetail(Long id) { | ||
return userRepository.findById(id).orElse(null); | ||
} | ||
|
||
} | ||
/** | ||
* | ||
* @param session 현재 존재하는 Session | ||
* @param updateRequestDto 수정해야 하는 정보 | ||
* @return | ||
*/ | ||
|
||
public User updateUserInfo(HttpSession session, MyPageRequestDto updateRequestDto) { | ||
User sessionLoginUser = (User) session.getAttribute("loginUser"); | ||
User databaseUserInfo = userRepository.findById(sessionLoginUser.getId()).orElseThrow(()-> NotFoundException.EXCEPTION); | ||
|
||
if(sessionLoginUser.getEmail().equals(databaseUserInfo.getEmail())) { | ||
if(!databaseUserInfo.getNickName().equals(updateRequestDto.getChgNickName())) { | ||
databaseUserInfo.setNickName(updateRequestDto.getChgNickName()); | ||
} | ||
|
||
|
||
if(!updateRequestDto.getProfile().isEmpty()) { | ||
databaseUserInfo.setProfile( | ||
naverObjectStorageUtil.storageFileUpload( | ||
NaverObjectStorageUsageType.PROFILE, updateRequestDto.getProfile() | ||
) | ||
); | ||
} | ||
return databaseUserInfo; | ||
} | ||
|
||
return null; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
Api/src/main/java/picasso/server/api/user/vo/request/MyPageRequestDto.java
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,20 @@ | ||
package picasso.server.api.user.vo.request; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
import lombok.ToString; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
@Getter | ||
@Setter | ||
@ToString | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class MyPageRequestDto { | ||
private String orgNickName; | ||
private String chgNickName; | ||
private String isNewProfile; | ||
private MultipartFile profile; | ||
} |
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,22 @@ | ||
div.container > div.mypage-container { | ||
border-radius: 2%; | ||
padding: 40px; | ||
margin: 100px auto; | ||
width: 80vh; | ||
min-width: 800px; | ||
background-color: rgba(220, 220, 220, 0.857); | ||
} | ||
|
||
form#mypage-form > div.mypage-title { | ||
text-align: center; | ||
margin-bottom: 30px; | ||
} | ||
|
||
.img-thumbnail { | ||
width: 100%; | ||
height: 300px; | ||
} | ||
|
||
.col > button { | ||
width: 100%; | ||
} |
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,19 @@ | ||
function validateFileExtension(fileInput) { | ||
const allowedExtensions = ['jpg', 'jpeg', 'png']; | ||
const filenameDisplayElement = document.getElementById('filename'); | ||
|
||
if (fileInput.files.length > 0) { | ||
const fileName = fileInput.files[0].name; | ||
const fileExtension = fileName.split('.').pop().toLowerCase(); | ||
|
||
if (!allowedExtensions.includes(fileExtension)) { | ||
alert("프로필 사진은 .jpg, .jpeg 또는 .png 확장자만 허용됩니다."); | ||
fileInput.value = ''; // 파일 입력을 초기화합니다. | ||
filenameDisplayElement.textContent = ''; | ||
} else { | ||
filenameDisplayElement.textContent = fileName; | ||
} | ||
} else { | ||
filenameDisplayElement.textContent = ''; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,20 +1,78 @@ | ||
<!DOCTYPE html> | ||
<html xmlns:th="http://www.thymeleaf.org"> | ||
<head> | ||
<title>My Page</title> | ||
</head> | ||
<body> | ||
<form th:action="@{/user}" method="post"> | ||
<label for="nickname">Nickname:</label> | ||
<input type="text" id="nickname" name="nickname" /><br/> | ||
<html | ||
lang="ko" | ||
xmlns="http://www.w3.org/1999/xhtml" | ||
xmlns:th="http://www.thymeleaf.org" | ||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" | ||
layout:decorate="~{layout/layout}" | ||
> | ||
<main layout:fragment="content"> | ||
<link rel="stylesheet" type="text/css" href="/static/css/member/mypage.css" /> | ||
<div class="container"> | ||
<div class="mypage-container"> | ||
<form th:action="@{/user/update}" method="post" id="mypage-form" enctype="multipart/form-data"> | ||
<div class="row mypage-title"> | ||
<h1>마이페이지</h1> | ||
</div> | ||
|
||
<label for="point">Point:</label> | ||
<input type="text" id="point" name="point" /><br/> | ||
<div class="row d-flex align-items-center"> | ||
<div class="col-md-4 mb-5"> | ||
<img id="thumbnail-preview" th:if="${user.profile != null}" th:src="|https://kr.object.ncloudstorage.com/picasso-bucket/${user.profile}|" class="img-thumbnail" alt="..." style="width: 100%; height: 300px;"> | ||
</div> | ||
|
||
<label for="profile">Profile:</label> | ||
<input type="file" id="profile" name="profile" /><br/>> | ||
<button type="submit">등록</button> | ||
<div class="col-md-8"> | ||
<div class="mb-3 row"> | ||
<label for="chgNickName" class="col-sm-2 col-form-label">NickName</label> | ||
<div class="col-sm-10"> | ||
<input type="hidden" id="orgNickName" name="orgNickName" th:value="${user.nickName}" /> | ||
<input type="text" class="form-control" id="chgNickName" name="chgNickName" th:value="${user.nickName}"> | ||
</div> | ||
</div> | ||
|
||
</form> | ||
</body> | ||
<div class="mb-3 row"> | ||
<label for="point" class="col-sm-2 col-form-label">Point</label> | ||
<div class="col-sm-10"> | ||
<input type="text" readonly class="form-control-plaintext" id="point" th:value="${user.point}"> | ||
</div> | ||
</div> | ||
|
||
<div class="mb-3 row"> | ||
<label for="profile" class="col-sm-2 col-form-label">Profile</label> | ||
<div class="col-sm-10"> | ||
<input class="form-control" type="file" id="profile" name="profile" accept=".jpg, .jpeg, .png" onchange="previewThumbnail(); validateFileExtension(this);"> | ||
<span id="filename" class="d-block mt-2"></span> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
|
||
<div class="row" style="margin-bottom:10px;"> | ||
<div class="col" > | ||
<button type="button" style="width:100%;" class="btn btn-secondary btn-lg">취소</button> | ||
</div> | ||
<div class="col" > | ||
<button type="submit" style="width:100%;" class="btn btn-primary btn-lg">수정</button> | ||
</div> | ||
</div> | ||
</form> | ||
<hr> | ||
<div class="row"> | ||
<div class="col"> | ||
<button type="button" class="btn btn-primary btn-lg" style="width:100%;">Point 충전</button> | ||
</div> | ||
<div class="col"> | ||
<button type="button" class="btn btn-primary btn-lg" style="width:100%;">낙찰횟수</button> | ||
</div> | ||
<div class="col"> | ||
<button type="button" class="btn btn-primary btn-lg" style="width:100%;">내 경매</button> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</main> | ||
|
||
<th:block layout:fragment="script"> | ||
<script src="/static/js/mypage.js"></script> | ||
</th:block> | ||
</html> |
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
7 changes: 0 additions & 7 deletions
7
Domain/src/main/java/picasso/server/domain/domains/user/repository/MypageRepository.java
This file was deleted.
Oops, something went wrong.