-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dev 서버용 관리자 테스트 페이지 추가 #51
Changes from all commits
5ba7419
014dfa9
883c813
cd2268c
6cff0f1
b14c153
f36a655
f25a2e5
d00f387
1f07fe6
907ba8e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.backend.blooming.admin.application; | ||
|
||
import com.backend.blooming.admin.controller.dto.CreateUserRequest; | ||
import com.backend.blooming.authentication.infrastructure.oauth.OAuthType; | ||
import com.backend.blooming.themecolor.domain.ThemeColor; | ||
import com.backend.blooming.user.domain.Email; | ||
import com.backend.blooming.user.domain.Name; | ||
import com.backend.blooming.user.domain.User; | ||
import com.backend.blooming.user.infrastructure.repository.UserRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.UUID; | ||
|
||
@Service | ||
@Transactional | ||
@RequiredArgsConstructor | ||
public class AdminPageService { | ||
|
||
private static final String DEFAULT_EMAIL = "[email protected]"; | ||
private final UserRepository userRepository; | ||
|
||
public Long createUser(final CreateUserRequest request) { | ||
final User user = User.builder() | ||
.oAuthId(UUID.randomUUID().toString()) | ||
.oAuthType(OAuthType.KAKAO) | ||
.name(new Name(request.name())) | ||
.email(processEmail(request.email())) | ||
.color(ThemeColor.valueOf(request.theme())) | ||
.statusMessage(request.statusMessage()) | ||
.build(); | ||
|
||
return userRepository.save(user) | ||
.getId(); | ||
} | ||
|
||
private Email processEmail(final String email) { | ||
if (email == null || email.isEmpty()) { | ||
return new Email(DEFAULT_EMAIL); | ||
} | ||
|
||
return new Email(email); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
package com.backend.blooming.admin.controller; | ||
|
||
import com.backend.blooming.admin.application.AdminPageService; | ||
import com.backend.blooming.admin.controller.dto.CreateGoalRequest; | ||
import com.backend.blooming.admin.controller.dto.CreateUserRequest; | ||
import com.backend.blooming.admin.controller.dto.FriendStatus; | ||
import com.backend.blooming.admin.controller.dto.RequestFriendRequest; | ||
import com.backend.blooming.admin.controller.dto.UpdateFriendRequest; | ||
import com.backend.blooming.admin.controller.exception.InvalidFriendStatusException; | ||
import com.backend.blooming.friend.application.FriendService; | ||
import com.backend.blooming.friend.application.exception.NotFoundFriendRequestException; | ||
import com.backend.blooming.friend.infrastructure.repository.FriendRepository; | ||
import com.backend.blooming.goal.application.GoalService; | ||
import com.backend.blooming.goal.application.dto.CreateGoalDto; | ||
import com.backend.blooming.themecolor.domain.ThemeColor; | ||
import com.backend.blooming.user.domain.User; | ||
import com.backend.blooming.user.infrastructure.repository.UserRepository; | ||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.ui.Model; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PatchMapping; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
@Profile("test | local | dev") | ||
@Controller | ||
@RequestMapping("/admin") | ||
@RequiredArgsConstructor | ||
public class AdminPageController { | ||
|
||
private final AdminPageService adminPageService; | ||
private final UserRepository userRepository; | ||
private final FriendService friendService; | ||
private final FriendRepository friendRepository; | ||
private final GoalService goalService; | ||
|
||
@GetMapping | ||
public String adminPage(final Model model) { | ||
model.addAttribute("themes", getThemes()); | ||
model.addAttribute("users", getUsers()); | ||
|
||
return "/admin/test"; | ||
} | ||
|
||
private static List<String> getThemes() { | ||
return Arrays.stream(ThemeColor.values()) | ||
.map(ThemeColor::name) | ||
.toList(); | ||
} | ||
|
||
private List<User> getUsers() { | ||
return userRepository.findAll(); | ||
} | ||
|
||
@PostMapping("/user") | ||
public ResponseEntity<Void> createUser(@RequestBody @Valid CreateUserRequest request) { | ||
adminPageService.createUser(request); | ||
|
||
return ResponseEntity.noContent() | ||
.build(); | ||
} | ||
|
||
@PostMapping("/friend") | ||
public ResponseEntity<Void> requestFriend(@RequestBody RequestFriendRequest request) { | ||
friendService.request(request.requestUser(), request.requestedUser()); | ||
|
||
return ResponseEntity.noContent() | ||
.build(); | ||
} | ||
|
||
@PatchMapping("/friend") | ||
public ResponseEntity<Void> updateFriendStatus(@RequestBody UpdateFriendRequest request) { | ||
final Long friendId = getFriendId(request); | ||
updateByStatus(request, friendId); | ||
|
||
return ResponseEntity.noContent() | ||
.build(); | ||
} | ||
|
||
private Long getFriendId(final UpdateFriendRequest request) { | ||
final Long friendId = friendRepository.findByRequestUserIdAndRequestedUserId( | ||
request.requestUser(), | ||
request.requestedUser() | ||
); | ||
|
||
if (friendId == null) { | ||
throw new NotFoundFriendRequestException(); | ||
} | ||
|
||
return friendId; | ||
} | ||
|
||
private void updateByStatus(final UpdateFriendRequest request, final Long friendId) { | ||
final FriendStatus friendStatus = FriendStatus.valueOf(request.status()); | ||
|
||
if (FriendStatus.FRIEND.equals(friendStatus)) { | ||
friendService.accept(request.requestedUser(), friendId); | ||
return; | ||
} | ||
if (FriendStatus.DELETE_BY_REQUEST.equals(friendStatus)) { | ||
friendService.delete(request.requestUser(), friendId); | ||
return; | ||
} | ||
if (FriendStatus.DELETE_BY_REQUESTED.equals(friendStatus)) { | ||
friendService.delete(request.requestedUser(), friendId); | ||
return; | ||
} | ||
|
||
throw new InvalidFriendStatusException(); | ||
} | ||
|
||
@PostMapping("/goal") | ||
public ResponseEntity<Void> createGoal(@RequestBody @Valid CreateGoalRequest request) { | ||
goalService.createGoal(convertToDto(request)); | ||
|
||
return ResponseEntity.noContent() | ||
.build(); | ||
} | ||
|
||
private CreateGoalDto convertToDto(final CreateGoalRequest request) { | ||
return new CreateGoalDto( | ||
request.name(), | ||
request.memo(), | ||
request.startDate(), | ||
request.endDate(), | ||
request.manager(), | ||
List.of(request.manager(), request.team()) | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.backend.blooming.admin.controller.dto; | ||
|
||
import jakarta.validation.constraints.NotEmpty; | ||
import jakarta.validation.constraints.NotNull; | ||
import jakarta.validation.constraints.Positive; | ||
|
||
import java.time.LocalDate; | ||
|
||
public record CreateGoalRequest( | ||
@NotEmpty(message = "이름이 입력되지 않았습니다.") | ||
String name, | ||
|
||
String memo, | ||
|
||
@NotNull(message = "시작일이 입력되지 않았습니다.") | ||
LocalDate startDate, | ||
|
||
@NotNull(message = "종료일이 입력되지 않았습니다.") | ||
LocalDate endDate, | ||
|
||
@NotNull(message = "골 생성자가 설정되지 않았습니다.") | ||
@Positive(message = "골 생성자의 아이디가 잘못됐습니다.") | ||
Long manager, | ||
|
||
@NotNull(message = "팀원이 설정되지 않았습니다.") | ||
@Positive(message = "팀원의 아이디가 잘못됐습니다.") | ||
Long team | ||
) { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.backend.blooming.admin.controller.dto; | ||
|
||
import jakarta.validation.constraints.NotEmpty; | ||
|
||
public record CreateUserRequest( | ||
@NotEmpty(message = "사용자 이름을 입력되지 않았습니다.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 개행해주면 좋을 것 같습니다! |
||
String name, | ||
String email, | ||
String theme, | ||
String statusMessage | ||
) { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.backend.blooming.admin.controller.dto; | ||
|
||
public enum FriendStatus { | ||
|
||
FRIEND, | ||
DELETE_BY_REQUEST, | ||
DELETE_BY_REQUESTED | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.backend.blooming.admin.controller.dto; | ||
|
||
import jakarta.validation.constraints.NotEmpty; | ||
import jakarta.validation.constraints.Positive; | ||
|
||
public record RequestFriendRequest( | ||
@NotEmpty(message = "친구 요청자가 입력되지 않았습니다.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 개행해주면 좋을 것 같습니다. |
||
@Positive(message = "친구 요청자의 아이디가 잘못됐습니다.") | ||
Long requestUser, | ||
|
||
@NotEmpty(message = "친구 요청 수신자가 입력되지 않았습니다.") | ||
@Positive(message = "친구 요청 수신자의 아이디가 잘못됐습니다.") | ||
Long requestedUser | ||
) { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.backend.blooming.admin.controller.dto; | ||
|
||
import jakarta.validation.constraints.NotEmpty; | ||
import jakarta.validation.constraints.Positive; | ||
|
||
public record UpdateFriendRequest( | ||
@NotEmpty(message = "친구 요청자가 입력되지 않았습니다.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 개행해주면 좋을 것 같습니다. |
||
@Positive(message = "친구 요청자의 아이디가 잘못됐습니다.") | ||
Long requestUser, | ||
|
||
@NotEmpty(message = "친구 요청 수신자가 입력되지 않았습니다.") | ||
@Positive(message = "친구 요청 수신자의 아이디가 잘못됐습니다.") | ||
Long requestedUser, | ||
|
||
@NotEmpty(message = "친구 요청 상태가 입력되지 않았습니다.") | ||
String status | ||
) { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.backend.blooming.admin.controller.exception; | ||
|
||
import com.backend.blooming.exception.BloomingException; | ||
import com.backend.blooming.exception.ExceptionMessage; | ||
|
||
public class InvalidFriendStatusException extends BloomingException { | ||
|
||
public InvalidFriendStatusException() { | ||
super(ExceptionMessage.INVALID_FRIEND_STATUS); | ||
} | ||
} |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
개행해주면 좋을 것 같습니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
해당 부분은 record로 클래스 시작 부분이 아닌 파라미터입니다..!
해당 부분에서도 개행이 필요한 걸까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저는 개행을 해주었는데 딱히 개행이 필요하지 않을까요?