Skip to content
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

refactor(user): user 리팩토링 #95

Merged
merged 9 commits into from
May 1, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
public class BsmLoginHandler {
private final BsmOauth bsmOauth;

public User getUserByAuthId(String authId) {
public User getUserByAuthCode(String authCode) {
try {
String token = bsmOauth.getToken(authId);
String token = bsmOauth.getToken(authCode);
BsmResourceResponse response = bsmOauth.getResource(token);
return createUnknownUser(response);
} catch (BsmAuthCodeNotFoundException | BsmAuthTokenNotFoundException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.project.bumawiki.domain.auth.presentation.dto.LoginReqestDto;
import com.project.bumawiki.domain.auth.presentation.dto.RefreshTokenRequestDto;
import com.project.bumawiki.domain.auth.presentation.dto.TokenResponseDto;
import com.project.bumawiki.domain.auth.presentation.dto.request.LoginRequestDto;
import com.project.bumawiki.domain.auth.presentation.dto.request.RefreshTokenRequestDto;
import com.project.bumawiki.domain.auth.presentation.dto.response.TokenResponseDto;
import com.project.bumawiki.domain.auth.service.CommandAuthService;

import lombok.RequiredArgsConstructor;
Expand All @@ -24,8 +24,8 @@ public class AuthController {
private final CommandAuthService commandAuthService;

@PostMapping("/oauth/bsm")
public TokenResponseDto userSignup(@RequestBody LoginReqestDto loginReqestDto) throws IOException {
return TokenResponseDto.from(commandAuthService.login(loginReqestDto.accessToken()));
public TokenResponseDto userSignup(@RequestBody LoginRequestDto loginRequestDto) throws IOException {
return TokenResponseDto.from(commandAuthService.login(loginRequestDto.authCode()));
}

@PutMapping("/refresh/access")
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.project.bumawiki.domain.auth.presentation.dto.request;

import jakarta.validation.constraints.NotNull;

public record LoginRequestDto(
@NotNull(message = "authCode는 null일 수 없습니다.")
String authCode
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.project.bumawiki.domain.auth.presentation.dto.request;

import jakarta.validation.constraints.NotNull;

public record RefreshTokenRequestDto(
@NotNull(message = "refreshToken은 null일 수 없습니다.")
String refreshToken
) {
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.project.bumawiki.domain.auth.presentation.dto;
package com.project.bumawiki.domain.auth.presentation.dto.response;

import com.project.bumawiki.domain.auth.domain.Token;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public class CommandAuthService {
private final UserCreator userCreator;
private final UserUpdater userUpdater;

public Token login(String authId) {
User unknownUser = bsmLoginHandler.getUserByAuthId(authId);
public Token login(String authCode) {
User unknownUser = bsmLoginHandler.getUserByAuthCode(authCode);
User user = userReader.getNullableUserByEmail(unknownUser.getEmail());

if (user == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import com.project.bumawiki.domain.docs.domain.type.DocsType;
import com.project.bumawiki.domain.docs.util.DocsUtil;
import com.project.bumawiki.domain.user.domain.User;
import com.project.bumawiki.domain.user.presentation.dto.SimpleUserDto;
import com.project.bumawiki.domain.user.presentation.dto.response.SimpleUserResponseDto;

public record DocsResponseDto(
Long id,
Expand All @@ -18,7 +18,7 @@ public record DocsResponseDto(
LocalDateTime lastModifiedAt,
int enroll,
boolean isDocsDetail,
List<SimpleUserDto> contributors,
List<SimpleUserResponseDto> contributors,
int version,
String thumbnail
) {
Expand All @@ -33,7 +33,7 @@ public DocsResponseDto(Docs docs, List<User> contributors, VersionDocs versionDo
docs.getEnroll(),
true,
contributors.stream()
.map(SimpleUserDto::new)
.map(SimpleUserResponseDto::new)
.toList(),
versionDocs.getVersion(),
DocsUtil.getThumbnail(versionDocs.getContents())
Expand Down
26 changes: 3 additions & 23 deletions src/main/java/com/project/bumawiki/domain/user/domain/User.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
package com.project.bumawiki.domain.user.domain;

import java.util.ArrayList;
import java.util.List;

import com.project.bumawiki.domain.thumbsup.domain.ThumbsUp;
import com.project.bumawiki.domain.thumbsup.presentation.dto.ThumbsUpResponseDto;
import com.project.bumawiki.domain.user.domain.authority.Authority;

import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
Expand All @@ -37,13 +29,6 @@ public class User {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@OneToMany(
mappedBy = "user",
fetch = FetchType.LAZY,
cascade = CascadeType.ALL,
orphanRemoval = true)
@Builder.Default
private final List<ThumbsUp> thumbsUps = new ArrayList<>();
@Email
@Size(max = 32)
@Column(unique = true, length = 32)
Expand All @@ -59,26 +44,21 @@ public class User {
@Column(length = 16)
@Enumerated(EnumType.STRING)
private Authority authority;

@NotNull
@Size(max = 16)
@Column(length = 16)
private String name;

public List<ThumbsUpResponseDto> getList() {
return this.thumbsUps
.stream()
.map(ThumbsUp::getDto)
.toList();
}

public void update(User user) {
this.email = user.getEmail();
this.name = user.getName();
this.enroll = user.getEnroll();
this.nickName = user.getNickName();
}

public void changeUserAuthority(Authority authority) {
public void updateAuthority(Authority authority) {
this.authority = authority;
}

}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package com.project.bumawiki.domain.user.implementation;

import com.project.bumawiki.domain.user.domain.User;
import com.project.bumawiki.domain.user.domain.authority.Authority;
import com.project.bumawiki.global.annotation.Implementation;

@Implementation
public class UserUpdater {
public void update(User user, User newUserInfo) {
user.update(newUserInfo);
}

public void updateAuthority(User user, Authority authority) {
user.updateAuthority(authority);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.project.bumawiki.domain.user.presentation;

import org.springframework.http.HttpStatus;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

import com.project.bumawiki.domain.auth.annotation.AdminOnly;
import com.project.bumawiki.domain.auth.annotation.LoginRequired;
import com.project.bumawiki.domain.auth.service.QueryAuthService;
import com.project.bumawiki.domain.docs.service.QueryDocsService;
import com.project.bumawiki.domain.user.domain.User;
import com.project.bumawiki.domain.user.presentation.dto.request.UserAuthorityRequestDto;
import com.project.bumawiki.domain.user.presentation.dto.response.UserResponseDto;
import com.project.bumawiki.domain.user.service.CommandUserService;
import com.project.bumawiki.domain.user.service.QueryUserService;

import lombok.RequiredArgsConstructor;

@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/user")
public class UserController {

private final QueryUserService userInfoService;
private final QueryDocsService queryDocsService;
private final QueryAuthService queryAuthService;
private final CommandUserService commandUserService;

@GetMapping
@LoginRequired
public UserResponseDto findMyInfo() {
User user = queryAuthService.getCurrentUser();
return new UserResponseDto(user, queryDocsService.findAllVersionDocsByUser(user));
}

@GetMapping("/{id}")
public UserResponseDto findAnotherUserInFo(@PathVariable Long id) {
User foundUser = userInfoService.findUserInfo(id);
return new UserResponseDto(
foundUser,
queryDocsService.findAllVersionDocsByUser(foundUser)
);
}

@AdminOnly
@PatchMapping("/authority")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void updateUserAuthority(@RequestBody UserAuthorityRequestDto userAuthorityRequestDto) {
commandUserService.updateUserAuthority(userAuthorityRequestDto.id(), userAuthorityRequestDto.authority());
qlido marked this conversation as resolved.
Show resolved Hide resolved
}

}

This file was deleted.

This file was deleted.

Loading
Loading