Skip to content

Commit ac6ed76

Browse files
authored
Merge pull request #286 from CodIN-INU/develop
Develop
2 parents b7cbbd4 + 3fae328 commit ac6ed76

5 files changed

Lines changed: 74 additions & 2 deletions

File tree

src/main/java/inu/codin/codin/common/security/service/JwtService.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,15 @@ private void createBothToken(HttpServletResponse response) {
119119
// Authorization 헤더에 Access Token 추가
120120
response.setHeader(ACCESS_TOKEN, ACCESS_TOKEN_PREFIX + newToken.getAccessToken());
121121

122+
String domain = BASEURL.replaceFirst("https?://", "").split(":")[0];
123+
122124
// todo: x-access-token 쿠키에 Access Token 추가 - 추후 제거
123125
Cookie newAccessToken = new Cookie("x-access-token", newToken.getAccessToken());
124126
newAccessToken.setHttpOnly(true);
125127
newAccessToken.setSecure(true);
126128
newAccessToken.setPath("/");
127129
newAccessToken.setMaxAge(10 * 24 * 60 * 60); // 10일
128-
newAccessToken.setDomain(BASEURL.split("//")[1]);
130+
newAccessToken.setDomain(domain);
129131
newAccessToken.setAttribute("SameSite", "None");
130132
response.addCookie(newAccessToken);
131133

@@ -135,7 +137,7 @@ private void createBothToken(HttpServletResponse response) {
135137
newRefreshToken.setSecure(true);
136138
newRefreshToken.setPath("/");
137139
newRefreshToken.setMaxAge(10 * 24 * 60 * 60); // 10일
138-
newRefreshToken.setDomain(BASEURL.split("//")[1]);
140+
newRefreshToken.setDomain(domain);
139141
newRefreshToken.setAttribute("SameSite", "None");
140142
response.addCookie(newRefreshToken);
141143

src/main/java/inu/codin/codin/domain/user/controller/UserController.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import inu.codin.codin.common.response.SingleResponse;
44
import inu.codin.codin.domain.post.dto.response.PostPageResponse;
5+
import inu.codin.codin.domain.user.dto.request.UserNameUpdateRequestDto;
56
import inu.codin.codin.domain.user.dto.request.UserNicknameRequestDto;
67
import inu.codin.codin.domain.user.dto.request.UserTicketingParticipationInfoUpdateRequest;
78
import inu.codin.codin.domain.user.dto.response.UserInfoResponseDto;
@@ -104,6 +105,16 @@ public ResponseEntity<SingleResponse<?>> updateUserProfile(@RequestPart(value =
104105
.body(new SingleResponse<>(200, "유저 사진 수정 완료", null));
105106
}
106107

108+
@Operation(
109+
summary = "유저 이름 수정"
110+
)
111+
@PutMapping("/name")
112+
public ResponseEntity<SingleResponse<?>> updateUserName(@RequestBody @Valid UserNameUpdateRequestDto userUpdateRequestDto){
113+
userService.updateUserName(userUpdateRequestDto);
114+
return ResponseEntity.ok()
115+
.body(new SingleResponse<>(200, "유저 이름 수정 완료", null));
116+
}
117+
107118
@Operation(
108119
summary = "유저 티켓팅 수령자 정보 반환 (학번, 이름, 소속) - [Ticketing]"
109120
)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package inu.codin.codin.domain.user.dto.request;
2+
3+
import io.swagger.v3.oas.annotations.media.Schema;
4+
import jakarta.validation.constraints.NotBlank;
5+
import jakarta.validation.constraints.Size;
6+
import lombok.Getter;
7+
8+
import java.beans.ConstructorProperties;
9+
10+
@Getter
11+
public class UserNameUpdateRequestDto {
12+
13+
@Schema(description = "이름", example = "횃불이")
14+
@NotBlank(message = "이름은 비어 있을 수 없습니다.")
15+
@Size(min = 1, max = 10, message = "이름은 1~10자여야 합니다.")
16+
private String name;
17+
18+
@ConstructorProperties({"name"})
19+
public UserNameUpdateRequestDto(String name) {
20+
this.name = name;
21+
}
22+
}

src/main/java/inu/codin/codin/domain/user/entity/UserEntity.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ public UserEntity(String email, String password, String studentId, String name,
5959
this.status = status;
6060
}
6161

62+
public void updateName(String name) {
63+
this.name = name;
64+
}
65+
6266
public void updateNickname(String nickname) {
6367
this.nickname = nickname;
6468
}

src/main/java/inu/codin/codin/domain/user/service/UserService.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import inu.codin.codin.domain.post.service.PostDtoAssembler;
1515
import inu.codin.codin.domain.scrap.entity.ScrapEntity;
1616
import inu.codin.codin.domain.scrap.repository.ScrapRepository;
17+
import inu.codin.codin.domain.user.dto.request.UserNameUpdateRequestDto;
1718
import inu.codin.codin.domain.user.dto.request.UserNicknameRequestDto;
1819
import inu.codin.codin.domain.user.dto.request.UserTicketingParticipationInfoUpdateRequest;
1920
import inu.codin.codin.domain.user.dto.response.UserInfoResponseDto;
@@ -184,6 +185,38 @@ public void updateUserProfile(MultipartFile profileImage) {
184185
log.info("[프로필 이미지 업데이트 성공] 사용자 ID: {}, 프로필 이미지 URL: {}", userId, profileImageUrl);
185186
}
186187

188+
public void updateUserName(@Valid UserNameUpdateRequestDto request){
189+
ObjectId userId = SecurityUtils.getCurrentUserId();
190+
log.info("[유저 실명 수정] 현재 사용자 ID: {}, 요청 이름: {}", userId, request.getName());
191+
192+
UserEntity user = userRepository.findById(userId)
193+
.orElseThrow(() -> {
194+
log.info("[유저 실명 수정 실패] 유저 정보를 찾을 수 없음. 사용자 ID: {}", userId);
195+
return new NotFoundException("유저 정보를 찾을 수 없습니다.");
196+
});
197+
198+
String newName = request.getName().trim();
199+
200+
if (newName.isEmpty()) {
201+
throw new IllegalArgumentException("이름은 비어 있을 수 없습니다.");
202+
}
203+
if (newName.length() > 10) {
204+
throw new IllegalArgumentException("이름은 10자 이하여야 합니다.");
205+
}
206+
if (!newName.matches("^[가-힣a-zA-Z]+$")) {
207+
throw new IllegalArgumentException("이름은 한글 또는 영어만 입력 가능합니다.");
208+
}
209+
210+
if (newName.equals(user.getName())) {
211+
log.info("[유저 실명 수정] 변경 사항 없음. 사용자 ID: {}", userId);
212+
return;
213+
}
214+
215+
user.updateName(newName);
216+
userRepository.save(user);
217+
218+
log.info("[유저 실명 수정 성공] 사용자 ID: {}, 변경 이름: {}", userId, newName);
219+
}
187220
/**
188221
* 유저 티켓팅 수령 정보 반환
189222
* @return UserTicketingParticipationInfoResponse 유저의 학번, 이름, 소속 Dto 반환

0 commit comments

Comments
 (0)