Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/main/java/com/hatoo/domain/groups/Group.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ public void updateInviteCode(String inviteCode, LocalDateTime expiryDate) {
this.inviteCodeExpiryDate = expiryDate;
}

// 그룹 이름 수정
public void updateName(String name) {
this.name = name;
}

// 방장 변경
public void changeAssigner(UUID newAssignerId) {
this.assignerId = newAssignerId;
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/hatoo/domain/groups/GroupController.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.hatoo.domain.groups;

import com.hatoo.domain.groups.dto.*;
import jakarta.validation.Valid;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
Expand Down Expand Up @@ -106,6 +107,16 @@ public ResponseEntity<Boolean> profileImgSelect(
return ResponseEntity.ok(groupService.profileImgSelectApi(authToken, request, groupId));
}

@Operation(summary = "그룹 이름 수정", description = "방장이 그룹 이름을 수정합니다.")
@PatchMapping("/{groupId}/name")
public ResponseEntity<Boolean> updateGroupName(
@Parameter(hidden = true) @RequestHeader("Authorization") String accessToken,
@PathVariable UUID groupId,
@Valid @RequestBody GroupUpdateNameRequest request) {
String token = accessToken.startsWith("Bearer ") ? accessToken.substring(7) : accessToken;
return ResponseEntity.ok(groupService.updateGroupName(token, groupId, request));
}

@Operation(summary = "그룹별 알림 설정 조회", description = "특정 그룹의 알림 설정을 조회합니다.")
@GetMapping("/{groupId}/alarm")
public ResponseEntity<GroupAlarmSettingResponse> getGroupAlarmSetting(
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/com/hatoo/domain/groups/GroupService.java
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,29 @@ public GroupAlarmSettingResponse updateGroupAlarmSetting(String accessToken, UUI
return GroupAlarmSettingResponse.from(setting);
}

// 그룹 이름 수정
@Transactional
public boolean updateGroupName(String accessToken, UUID groupId, GroupUpdateNameRequest request) {

jwtUtil.validateToken(accessToken);
String loginId = jwtUtil.extractLoginId(accessToken);

User user = userRepository.findByLoginId(loginId)
.orElseThrow(() -> new CustomException(ErrorMessage.USER_NOT_FOUND));

Group group = groupRepository.findById(groupId)
.orElseThrow(() -> new CustomException(ErrorMessage.GROUP_NOT_FOUND));

// 방장 여부 검증
if (!user.getId().equals(group.getAssignerId())) {
throw new CustomException(ErrorMessage.NO_DELETE_PERMISSION);
}

group.updateName(request.getName());

return true;
}

// 초대코드 생성 유틸
private String generateInviteCode() {
return String.format("%04d", new Random().nextInt(10000));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.hatoo.domain.groups.dto;

import jakarta.validation.constraints.NotBlank;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
public class GroupUpdateNameRequest {

@NotBlank(message = "그룹 이름은 필수입니다.")
private String name;
}
Loading