Skip to content

Commit

Permalink
🔥 fix: 그룹 생성 API 생성 로직 수정 (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
loveysuby committed Jul 12, 2024
1 parent 4a27f0d commit 3b32f5b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package slvtwn.khu.toyouserver.application;

import java.util.Optional;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import slvtwn.khu.toyouserver.common.ErrorType;
Expand Down Expand Up @@ -29,15 +28,13 @@ public GroupResponse registerUser(long groupId, long userId) {
.orElseThrow(() -> new ToyouException(ErrorType.GROUP_NOT_FOUND));
User user = userRepository.findById(userId)
.orElseThrow(() -> new ToyouException(ErrorType.USER_NOT_FOUND));
// group.addMember(user);
return new GroupResponse(group.getId(), group.getName());
}

@Transactional
public GroupResponse create(String name) {
return Optional.of(new Group(name))
.map(groupRepository::save)
.map(group -> new GroupResponse(group.getId(), group.getName()))
.orElseThrow(() -> new ToyouException(ErrorType.INVALID_GROUP_DATA));
var group = new Group(name);
var savedGroup = groupRepository.save(group);
return new GroupResponse(savedGroup.getId(), savedGroup.getName());
}
}
1 change: 0 additions & 1 deletion src/main/java/slvtwn/khu/toyouserver/common/ErrorType.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ public enum ErrorType {
// 400 ~ 499 (요청 오류)
RESPONSE_FORMAT_ERROR(HttpStatus.BAD_REQUEST, "TYU-400", "응답 형식 오류"),
BAD_REQUEST(HttpStatus.BAD_REQUEST, "TYU-400", "잘못된 요청입니다."),
INVALID_GROUP_DATA(HttpStatus.BAD_REQUEST, "TYU-4001", "Invalid group data provided"),
NOT_FOUND(HttpStatus.NOT_FOUND, "TYU-404", "요청한 자원을 찾을 수 없습니다."),
GROUP_NOT_FOUND(HttpStatus.NOT_FOUND, "TYU-4041", "그룹을 찾을 수 없습니다."),
USER_NOT_FOUND(HttpStatus.NOT_FOUND, "TYU-4042", "사용자를 찾을 수 없습니다."),
Expand Down

0 comments on commit 3b32f5b

Please sign in to comment.