-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/feature/9' into feature/9
- Loading branch information
Showing
26 changed files
with
947 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/main/java/com/backend/blooming/admin/application/AdminPageService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
138 changes: 138 additions & 0 deletions
138
src/main/java/com/backend/blooming/admin/controller/AdminPageController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | ||
); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/com/backend/blooming/admin/controller/dto/CreateGoalRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) { | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/backend/blooming/admin/controller/dto/CreateUserRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = "사용자 이름을 입력되지 않았습니다.") | ||
String name, | ||
String email, | ||
String theme, | ||
String statusMessage | ||
) { | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/backend/blooming/admin/controller/dto/FriendStatus.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/backend/blooming/admin/controller/dto/RequestFriendRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = "친구 요청자가 입력되지 않았습니다.") | ||
@Positive(message = "친구 요청자의 아이디가 잘못됐습니다.") | ||
Long requestUser, | ||
|
||
@NotEmpty(message = "친구 요청 수신자가 입력되지 않았습니다.") | ||
@Positive(message = "친구 요청 수신자의 아이디가 잘못됐습니다.") | ||
Long requestedUser | ||
) { | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/com/backend/blooming/admin/controller/dto/UpdateFriendRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = "친구 요청자가 입력되지 않았습니다.") | ||
@Positive(message = "친구 요청자의 아이디가 잘못됐습니다.") | ||
Long requestUser, | ||
|
||
@NotEmpty(message = "친구 요청 수신자가 입력되지 않았습니다.") | ||
@Positive(message = "친구 요청 수신자의 아이디가 잘못됐습니다.") | ||
Long requestedUser, | ||
|
||
@NotEmpty(message = "친구 요청 상태가 입력되지 않았습니다.") | ||
String status | ||
) { | ||
} |
11 changes: 11 additions & 0 deletions
11
...in/java/com/backend/blooming/admin/controller/exception/InvalidFriendStatusException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 0 additions & 11 deletions
11
...va/com/backend/blooming/friend/application/exception/AlreadyRequestedFriendException.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.