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

GTB-77 [refactor] 도메인 수정 및 스타일 통일 #92

Merged
merged 11 commits into from
Oct 7, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ public class Admin {
@Column(columnDefinition = "BINARY(16)")
private UUID adminId;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "pub_id", nullable = false)
private Pub pub;

@Column(nullable = false)
private String username;

Expand All @@ -25,13 +29,9 @@ public class Admin {
@Column(columnDefinition = "char(16)", nullable = false)
private String adminTel;

@Column
@Column(nullable = false)
private String refreshToken;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "pub_id")
private Pub pub;

public static Admin create(String username, String adminPassword, String adminTel, Pub pub) {
return Admin.builder()
.username(username)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
import site.gachontable.gachontablebe.domain.admin.type.Status;
import site.gachontable.gachontablebe.domain.admin.usecase.*;
import site.gachontable.gachontablebe.domain.auth.domain.AuthDetails;
import site.gachontable.gachontablebe.domain.pub.domain.Pub;
import site.gachontable.gachontablebe.domain.pub.domain.repository.PubRepository;
import site.gachontable.gachontablebe.domain.pub.exception.PubNotFoundException;
import site.gachontable.gachontablebe.domain.admin.presentation.dto.request.PubManageRequest;
import site.gachontable.gachontablebe.domain.shared.dto.request.RefreshRequest;
import site.gachontable.gachontablebe.domain.shared.dto.response.RegisterResponse;
Expand All @@ -31,9 +28,9 @@
@RequestMapping("/admin")
@RequiredArgsConstructor
public class AdminController {

private final AdminRegister adminRegister;
private final AdminLogin adminLogin;
private final PubRepository pubRepository;
private final JwtProvider jwtProvider;
private final GetWaitings getWaitings;
private final EnterUser enterUser;
Expand All @@ -53,8 +50,7 @@ public class AdminController {
})
@PostMapping("/test-register")
public ResponseEntity<RegisterResponse> register(@RequestBody AdminRegisterRequest request) {
Pub pub = pubRepository.findByPubId(request.pubId()).orElseThrow(PubNotFoundException::new);
return ResponseEntity.ok(adminRegister.execute(request.username(), request.password(), request.tel(), pub));
return ResponseEntity.ok(adminRegister.execute(request));
}

@Operation(summary = "관리자 로그인", description = "관리자 계정으로 로그인합니다.")
Expand Down Expand Up @@ -119,7 +115,8 @@ public ResponseEntity<SeatingsResponse> getSeatings(@AuthenticationPrincipal Aut
@ApiResponse(responseCode = "500", content = @Content(schema = @Schema(implementation = ErrorResponse.class)))
})
@PatchMapping("/enter")
public ResponseEntity<String> enterUser(@AuthenticationPrincipal AuthDetails authDetails, @RequestBody EnterUserRequest request) {
public ResponseEntity<String> enterUser(@AuthenticationPrincipal AuthDetails authDetails,
@RequestBody EnterUserRequest request) {
return ResponseEntity.ok(enterUser.execute(authDetails, request, Status.ENTER.getStatusKo()));
}

Expand All @@ -132,7 +129,8 @@ public ResponseEntity<String> enterUser(@AuthenticationPrincipal AuthDetails aut
@ApiResponse(responseCode = "500", content = @Content(schema = @Schema(implementation = ErrorResponse.class)))
})
@PatchMapping("/call")
public ResponseEntity<String> callUser(@AuthenticationPrincipal AuthDetails authDetails, @RequestBody CallUserRequest request) {
public ResponseEntity<String> callUser(@AuthenticationPrincipal AuthDetails authDetails,
@RequestBody CallUserRequest request) {
return ResponseEntity.ok(callUser.execute(authDetails, request, Status.CALL.getStatusKo()));
}

Expand All @@ -145,7 +143,8 @@ public ResponseEntity<String> callUser(@AuthenticationPrincipal AuthDetails auth
@ApiResponse(responseCode = "500", content = @Content(schema = @Schema(implementation = ErrorResponse.class)))
})
@PatchMapping("/exit")
public ResponseEntity<String> exitUser(@AuthenticationPrincipal AuthDetails authDetails, @RequestBody ExitUserRequest request) {
public ResponseEntity<String> exitUser(@AuthenticationPrincipal AuthDetails authDetails,
@RequestBody ExitUserRequest request) {
return ResponseEntity.ok(exitUser.execute(authDetails, request));
}

Expand All @@ -158,7 +157,8 @@ public ResponseEntity<String> exitUser(@AuthenticationPrincipal AuthDetails auth
@ApiResponse(responseCode = "500", content = @Content(schema = @Schema(implementation = ErrorResponse.class)))
})
@PatchMapping("/status")
public ResponseEntity<RegisterResponse> updateOpenStatus(@AuthenticationPrincipal AuthDetails authDetails, @RequestBody UpdateStatusRequest request) {
public ResponseEntity<RegisterResponse> updateOpenStatus(@AuthenticationPrincipal AuthDetails authDetails,
@RequestBody UpdateStatusRequest request) {
return ResponseEntity.ok(updateStatus.executeForOpenStatus(authDetails, request));
}

Expand All @@ -171,7 +171,8 @@ public ResponseEntity<RegisterResponse> updateOpenStatus(@AuthenticationPrincipa
@ApiResponse(responseCode = "500", content = @Content(schema = @Schema(implementation = ErrorResponse.class)))
})
@PatchMapping("/status-waiting")
public ResponseEntity<RegisterResponse> updateWaitingStatus(@AuthenticationPrincipal AuthDetails authDetails, @RequestBody UpdateStatusRequest request) {
public ResponseEntity<RegisterResponse> updateWaitingStatus(@AuthenticationPrincipal AuthDetails authDetails,
@RequestBody UpdateStatusRequest request) {
return ResponseEntity.ok(updateStatus.executeForWaitingStatus(authDetails, request));
}

Expand All @@ -184,7 +185,8 @@ public ResponseEntity<RegisterResponse> updateWaitingStatus(@AuthenticationPrinc
@ApiResponse(responseCode = "500", content = @Content(schema = @Schema(implementation = ErrorResponse.class)))
})
@PatchMapping("/manage")
public ResponseEntity<String> managePub(@AuthenticationPrincipal AuthDetails authDetails, @RequestBody PubManageRequest request){
public ResponseEntity<String> managePub(@AuthenticationPrincipal AuthDetails authDetails,
@RequestBody PubManageRequest request){
return ResponseEntity.ok(managePub.execute(authDetails, request));
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package site.gachontable.gachontablebe.domain.admin.presentation.dto.request;

public record AdminLoginRequest(String id, String password) {
public record AdminLoginRequest(String id,
String password) {
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package site.gachontable.gachontablebe.domain.admin.presentation.dto.request;

public record ExitUserRequest(Integer seatingId) {
public record ExitUserRequest(Long seatingId) {
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
package site.gachontable.gachontablebe.domain.admin.presentation.dto.response;

public record AdminLoginResponse(String accessToken, String refreshToken, Integer pubId) {
public record AdminLoginResponse(String accessToken,
String refreshToken,
Integer pubId) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@
public record SeatingsResponse(List<SeatingResponse> seatings) {

@Builder
public record SeatingResponse(Integer seatingId, Integer seatingNum, Table tableType, String exitTime, UUID waitingId) {
public record SeatingResponse(Integer seatingId,
Integer seatingNum,
Table tableType,
String exitTime,
UUID waitingId) {

public static SeatingResponse from(Seating seating) {

return SeatingResponse.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@
import java.util.List;
import java.util.UUID;

public record WaitingInfosResponse(Integer count, List<WaitingInfosResponse.WaitingInfo> waitingInfos) {
public record WaitingInfosResponse(Integer count,
List<WaitingInfosResponse.WaitingInfo> waitingInfos) {

@Builder
public record WaitingInfo(String username, LocalDateTime time, Table tableType, String tel, UUID waitingId, Status waitingStatus) {
public record WaitingInfo(String username,
LocalDateTime time,
Table tableType,
String tel,
UUID waitingId,
Status waitingStatus) {
public static WaitingInfo of(String userName, Waiting waiting) {
return WaitingInfo.builder()
.username(userName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
import site.gachontable.gachontablebe.domain.admin.presentation.dto.response.AdminLoginResponse;

public interface AdminLogin {

AdminLoginResponse execute(String id, String password);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
@Service
@RequiredArgsConstructor
public class AdminLoginImpl implements AdminLogin {

private final JwtProvider tokenProvider;
private final AdminRepository adminRepository;
private final PasswordEncoder passwordEncoder;
Expand Down Expand Up @@ -60,4 +61,4 @@ private void updateAdminRefreshToken(Admin admin, String refreshToken) {
admin.updateRefreshToken(refreshToken);
adminRepository.save(admin);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package site.gachontable.gachontablebe.domain.admin.usecase;

import site.gachontable.gachontablebe.domain.pub.domain.Pub;
import site.gachontable.gachontablebe.domain.admin.presentation.dto.request.AdminRegisterRequest;
import site.gachontable.gachontablebe.domain.shared.dto.response.RegisterResponse;

public interface AdminRegister {
RegisterResponse execute(String username, String password, String tel, Pub pub);

RegisterResponse execute(AdminRegisterRequest request);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
import org.springframework.stereotype.Service;
import site.gachontable.gachontablebe.domain.admin.domain.Admin;
import site.gachontable.gachontablebe.domain.admin.domain.repository.AdminRepository;
import site.gachontable.gachontablebe.domain.admin.presentation.dto.request.AdminRegisterRequest;
import site.gachontable.gachontablebe.domain.pub.domain.Pub;
import site.gachontable.gachontablebe.domain.pub.domain.repository.PubRepository;
import site.gachontable.gachontablebe.domain.pub.exception.PubNotFoundException;
import site.gachontable.gachontablebe.domain.shared.Role;
import site.gachontable.gachontablebe.domain.shared.dto.response.RegisterResponse;
import site.gachontable.gachontablebe.global.jwt.JwtProvider;
Expand All @@ -15,14 +18,19 @@
@Service
@RequiredArgsConstructor
public class AdminRegisterImpl implements AdminRegister {

private final PasswordEncoder passwordEncoder;
private final AdminRepository adminRepository;
private final PubRepository pubRepository;
private final JwtProvider jwtProvider;

@Override
public RegisterResponse execute(String username, String password, String tel, Pub pub) {
Admin admin = Admin.create(username, passwordEncoder.encode(password), tel, pub);
public RegisterResponse execute(AdminRegisterRequest request) {
Pub pub = pubRepository.findById(request.pubId()).orElseThrow(PubNotFoundException::new);

Admin admin = Admin.create(request.username(), passwordEncoder.encode(request.password()), request.tel(), pub);
adminRepository.save(admin);

generateRefreshToken(admin);

return new RegisterResponse(true, "어드민 가입 성공");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
@Service
@RequiredArgsConstructor
public class EnterUser {

private final WaitingRepository waitingRepository;
private final AdminRepository adminRepository;
private final ReadyUser readyUser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
import site.gachontable.gachontablebe.domain.auth.domain.AuthDetails;

public interface ExitUser {

String execute(AuthDetails authDetails, ExitUserRequest request);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@
@Service
@RequiredArgsConstructor
public class ExitUserImpl implements ExitUser{

private final SeatingRepository seatingRepository;
private final AdminRepository adminRepository;

@Override
@Transactional
@Override
public String execute(AuthDetails authDetails, ExitUserRequest request) {
Seating seating = seatingRepository.findBySeatingId(request.seatingId())
Seating seating = seatingRepository.findById(request.seatingId())
.orElseThrow(SeatingNotFoundException::new);

checkPubMatches(authDetails, seating);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
import site.gachontable.gachontablebe.domain.auth.domain.AuthDetails;

public interface GetSeatings {

SeatingsResponse execute(AuthDetails authDetails);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@

import java.time.LocalDateTime;

@RequiredArgsConstructor
@Service
@RequiredArgsConstructor
public class GetSeatingsImpl implements GetSeatings {

private final AdminRepository adminRepository;
private final SeatingRepository seatingRepository;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
import site.gachontable.gachontablebe.domain.admin.presentation.dto.request.PubManageRequest;

public interface ManagePub {

String execute(AuthDetails authDetails, PubManageRequest request);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
@Service
@RequiredArgsConstructor
public class ManagePubImpl implements ManagePub {

private final AdminRepository adminRepository;
private final MenuRepository menuRepository;
private final PubRepository pubRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import site.gachontable.gachontablebe.domain.shared.dto.response.RegisterResponse;

public interface UpdateStatus {

RegisterResponse executeForOpenStatus(AuthDetails authDetails, UpdateStatusRequest request);

RegisterResponse executeForWaitingStatus(AuthDetails authDetails, UpdateStatusRequest request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
@Service
@RequiredArgsConstructor
public class UpdateStatusImpl implements UpdateStatus{

private final AdminRepository adminRepository;
private final WaitingRepository waitingRepository;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
@RestController
@RequiredArgsConstructor
public class AuthController {

private final AuthService authService;

@Operation(summary = "카카오 로그인", description = "토큰을 통해 사용자를 로그인합니다.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
@Service
@RequiredArgsConstructor
public class AdminAuthDetailsService implements UserDetailsService {

private final AdminRepository adminRepository;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
@Service
@RequiredArgsConstructor
public class AuthService {

private static final String USER_INFO_URI = "https://kapi.kakao.com/v2/user/me";
private static final String TOKEN_URI = "https://kauth.kakao.com/oauth/token";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
@Service
@RequiredArgsConstructor
public class UserAuthDetailsService implements UserDetailsService {

private final UserRepository userRepository;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
import java.util.List;

public interface MenuRepository extends JpaRepository<Menu, Integer> {

List<Menu> findAllByPub(Pub pub);
}
Loading