Skip to content

Commit

Permalink
[ADD] #170 - Add member introduce change function
Browse files Browse the repository at this point in the history
  • Loading branch information
Jwhyee committed Sep 19, 2022
1 parent 945e0f0 commit ab9da63
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/main/java/com/matdongsan/service/MemberService.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ public MemberInfoDto createEmptyMemberInfoDto() {
return memberInfoDto;
}

public void changeMemberIntroduce(Member member, String introduce) {
member.changeBasicInfo(introduce);
memberRepository.save(member);
}

public boolean existMemberNickname(String nickname) {
return memberRepository.existsByNickname(nickname);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.matdongsan.service.FavoriteService;
import com.matdongsan.service.MemberService;
import com.matdongsan.service.ProfileService;
import com.matdongsan.web.dto.profile.ProfileIntroduceDto;
import com.matdongsan.web.dto.profile.ProfilePasswordDto;
import com.matdongsan.web.dto.profile.ProfileWithdrawalDto;
import com.matdongsan.web.vo.MemberVo;
Expand Down Expand Up @@ -55,6 +56,7 @@ public String showProfileSettingPage(@AuthUser Account account, Model model) {
model.addAttribute("member", member);
model.addAttribute("profilePasswordDto", new ProfilePasswordDto());
model.addAttribute("profileWithdrawalDto", new ProfileWithdrawalDto());
model.addAttribute("profileIntroduceDto", new ProfileIntroduceDto());

return "profile/profile-setting";
}
Expand All @@ -78,6 +80,18 @@ public String changeNickname(@ModelAttribute(value = "nickname") String nickname
return "redirect:/settings/profile";
}

@PostMapping("/settings/profile/change/introduce")
public String changeIntroduce(@Valid ProfileIntroduceDto profileIntroduceDto, BindingResult bindingResult, @AuthUser Account account, RedirectAttributes redirectAttributes, Model model) {
if (bindingResult.hasErrors()) {
redirectAttributes.addFlashAttribute("settingMessageError", "소개글은 4글자 이상 25글자 이내로 작성해주세요.");
redirectAttributes.addFlashAttribute("profileIntroduceDto", profileIntroduceDto);
return "redirect:/settings/profile";
}
memberService.changeMemberIntroduce(account.getMember(), profileIntroduceDto.getIntroduce());
redirectAttributes.addFlashAttribute("settingMessageSuccess", "소개글이 변경되었습니다.");
return "redirect:/settings/profile";
}

@PostMapping("/settings/profile/change/password")
public String changePassword(@Valid ProfilePasswordDto profilePasswordDto, BindingResult bindingResult, @AuthUser Account account, RedirectAttributes redirectAttributes) {
if (bindingResult.hasErrors() || !accountService.checkAccountPassword(profilePasswordDto.getOriginalPassword(), account)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.matdongsan.web.dto.profile;

import lombok.Getter;
import lombok.Setter;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;

@Getter @Setter
public class ProfileIntroduceDto {

@NotBlank(message = "글을 입력해주세요.")
@Size(min = 4, max = 25, message = "소개글은 4글자 이상 25글자 이내로 작성해주세요.")
String introduce;
}
13 changes: 11 additions & 2 deletions src/main/resources/templates/profile/profile-setting.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ <h4 class="font-weight-bold py-3 mb-4">

</div>
<div class="card-body media align-items-center justify-content-start bd-highlight">
<div class="ml-4">
<img src="/media/banner/user_1.jpg" alt="" class="rounded-circle">
<div class="ml-4 item-img bg-white">
<svg th:data-jdenticon-value="${member.getNickname()}" width="115" height="115" class="rounded-circle"></svg>
</div>
<div class="form-group ml-4">
<label class="form-label">닉네임</label>
Expand Down Expand Up @@ -76,6 +76,15 @@ <h5 class="modal-title" id="nicknameChangeLabel">닉네임 변경</h5>
</div>
</div>
</div>
<div class="px-5 mb-3">
<form th:action="@{/settings/profile/change/introduce}" method="post" th:object="${profileIntroduceDto}">
<label class="form-label">소개글</label>
<input class="form-control" rows="3" placeholder="소개글을 입력해주세요." name="introduce" th:value="${member.getIntroduce()}">
<small class="form-text text-danger fieldError" th:if="${#fields.hasErrors('introduce')}" th:errors="*{introduce}">Introduce Error</small>
<small class="text-dark">소개글은 4글자 ~ 25글자까지 입력할 수 있습니다.</small><br>
<button type="submit" class="btn btn-primary mt-2">변경</button>&nbsp;
</form>
</div>
</div>
<div class="tab-pane fade" id="account-change-password">
<div class="card-body pb-2">
Expand Down

0 comments on commit ab9da63

Please sign in to comment.