Skip to content
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 @@ -19,7 +19,9 @@ public class DeptController implements DeptApi {
private final DeptService deptService;

@GetMapping("/dept")
public ResponseEntity<DeptResponse> getDept(@RequestParam(value = "dept_num") String deptNumber) {
public ResponseEntity<DeptResponse> getDept(
@RequestParam(value = "dept_num") String deptNumber
) {
DeptResponse foundDepartment = deptService.getById(deptNumber);
if (foundDepartment == null) {
return ResponseEntity.ok().build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ public ResponseEntity<List<LandListItemResponse>> getLands() {
}

@GetMapping("/lands/{id}")
public ResponseEntity<LandResponse> getLand(@PathVariable Long id) {
public ResponseEntity<LandResponse> getLand(
@PathVariable Long id
) {
LandResponse response = landService.getLand(id);
return ResponseEntity.ok(response);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,18 @@ public class ShopController implements ShopApi {
private final ShopService shopService;

@GetMapping("/shops/{shopId}/menus/{menuId}")
public ResponseEntity<ShopMenuResponse> findMenu(@PathVariable Long shopId, @PathVariable Long menuId) {
public ResponseEntity<ShopMenuResponse> findMenu(
@PathVariable Long shopId,
@PathVariable Long menuId
) {
ShopMenuResponse shopMenu = shopService.findMenu(menuId);
return ResponseEntity.ok(shopMenu);
}

@GetMapping("/shops/{shopId}/menus/categories")
public ResponseEntity<MenuCategoriesResponse> findMenuCategories(@PathVariable Long shopId) {
public ResponseEntity<MenuCategoriesResponse> findMenuCategories(
@PathVariable Long shopId
) {
MenuCategoriesResponse menuCategories = shopService.getMenuCategories(shopId);
return ResponseEntity.ok(menuCategories);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ public ResponseEntity<List<TrackResponse>> getTracks() {
}

@GetMapping("/tracks/{id}")
public ResponseEntity<TrackSingleResponse> getTrack(@PathVariable Long id) {
public ResponseEntity<TrackSingleResponse> getTrack(
@PathVariable Long id
) {
TrackSingleResponse response = trackService.getTrack(id);
return ResponseEntity.ok(response);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package in.koreatech.koin.domain.user.controller;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
Expand Down Expand Up @@ -81,4 +82,19 @@ ResponseEntity<Void> logout(
ResponseEntity<UserTokenRefreshResponse> refresh(
@RequestBody @Valid UserTokenRefreshRequest request
);

@ApiResponses(
value = {
@ApiResponse(responseCode = "204"),
@ApiResponse(responseCode = "401", content = @Content(schema = @Schema(hidden = true))),
@ApiResponse(responseCode = "403", content = @Content(schema = @Schema(hidden = true))),
@ApiResponse(responseCode = "404", content = @Content(schema = @Schema(hidden = true))),
}
)
@Operation(summary = "회원 탈퇴")
@SecurityRequirement(name = "Jwt Authentication")
@DeleteMapping("/user")
ResponseEntity<UserTokenRefreshResponse> withdraw(
@Auth(permit = {STUDENT}) Long userId
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.net.URI;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
Expand All @@ -28,20 +29,25 @@ public class UserController implements UserApi {
private final StudentService studentService;

@GetMapping("/user/student/me")
public ResponseEntity<StudentResponse> getStudent(@Auth(permit = STUDENT) Long userId) {
public ResponseEntity<StudentResponse> getStudent(
@Auth(permit = STUDENT) Long userId
) {
StudentResponse studentResponse = studentService.getStudent(userId);
return ResponseEntity.ok().body(studentResponse);
}

@PostMapping("/user/login")
public ResponseEntity<UserLoginResponse> login(@RequestBody @Valid UserLoginRequest request) {
public ResponseEntity<UserLoginResponse> login(
@RequestBody @Valid UserLoginRequest request
) {
UserLoginResponse response = userService.login(request);
return ResponseEntity.created(URI.create("/"))
.body(response);
}

@PostMapping("/user/logout")
public ResponseEntity<Void> logout(@Auth(permit = {STUDENT}) Long userId) {
public ResponseEntity<Void> logout(
@Auth(permit = {STUDENT}) Long userId) {
userService.logout(userId);
return ResponseEntity.ok().build();
}
Expand All @@ -53,4 +59,12 @@ public ResponseEntity<UserTokenRefreshResponse> refresh(
UserTokenRefreshResponse tokenGroupResponse = userService.refresh(request);
return ResponseEntity.ok().body(tokenGroupResponse);
}

@DeleteMapping("/user")
public ResponseEntity<UserTokenRefreshResponse> withdraw(
@Auth(permit = {STUDENT}) Long userId
) {
userService.withdraw(userId);
return ResponseEntity.noContent().build();
}
}
5 changes: 5 additions & 0 deletions src/main/java/in/koreatech/koin/domain/user/model/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import java.time.LocalDateTime;

import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;

import in.koreatech.koin.global.common.BaseEntity;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
Expand All @@ -22,6 +25,8 @@
@Getter
@Entity
@Table(name = "users")
@Where(clause = "is_deleted=0")
@SQLDelete(sql = "UPDATE users SET is_deleted = true WHERE id = ?")
Comment on lines +28 to +29

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A

이전에 논의되었던 내용이긴한데 차후 어드민 기능 구현할 때 적용하는게 좋을까요?
(@where 대신 @filter를 활용하여 선택적 softDelete 데이터 조회 조건 구성)

넵 저는 개인적으로 어드민 기능 구현 시 적용하는 것이 좋아 보입니다.
나중에 번거로울 수는 있지만 사용하지 않는 기능에 대해 코드를 작성해두는 것은 코드를 복잡하게 만들 우려가 있다고 생각합니다.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A

저도 @filter가 필요해질 때 적용하는 게 좋다고 생각합니다.

@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class User extends BaseEntity {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ default User getById(Long userId) {
return findById(userId)
.orElseThrow(() -> UserNotFoundException.withDetail("userId: " + userId));
}

void delete(User user);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A

삭제는 보통 delete를 사용하는 편이신가요?? deleteByIddelete의 선택은 취향의 영역인지 궁금합니다. 프로젝트 내에서 하나로 통일해야 할 지도 고민해봐야 할까요?? 🤔

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

음 결국 내부적으로 처리하는 내용은 같아서 취향차이인거같습니다.
발생하는 Exception의 종류가 다르긴 할 것 같은데 큰 차이는 없어보입니다
이미 작성된 메소드 중 deleteById가 있으니 그쪽으로 따라가는게 깔끔해보이는군요

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import in.koreatech.koin.global.auth.JwtProvider;
import in.koreatech.koin.global.auth.exception.AuthException;
import in.koreatech.koin.domain.user.dto.UserLoginRequest;
import in.koreatech.koin.domain.user.dto.UserLoginResponse;
import in.koreatech.koin.domain.user.dto.UserTokenRefreshRequest;
Expand All @@ -17,6 +15,8 @@
import in.koreatech.koin.domain.user.model.UserToken;
import in.koreatech.koin.domain.user.repository.UserRepository;
import in.koreatech.koin.domain.user.repository.UserTokenRepository;
import in.koreatech.koin.global.auth.JwtProvider;
import in.koreatech.koin.global.auth.exception.AuthException;
import lombok.RequiredArgsConstructor;

@Service
Expand Down Expand Up @@ -62,11 +62,17 @@ public UserTokenRefreshResponse refresh(UserTokenRefreshRequest request) {
return UserTokenRefreshResponse.of(accessToken, userToken.getRefreshToken());
}

private static String getUserId(String refreshToken) {
private String getUserId(String refreshToken) {
String[] split = refreshToken.split("-");
if (split.length == 0) {
throw new AuthException("올바르지 않은 인증 토큰입니다. refreshToken: " + refreshToken);
}
return split[split.length - 1];
}
Comment on lines 65 to 71

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A

static을 제거한 이유가 있을까요??

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이게 어쩌다 붙었나... 모르겠지만 눈에 보여서 제거했습니다
내부에서만 사용되는 함수이기도하고 굳이 static method일 이유가 없어서 제거했습니다 😄
불필요한 heap 메모리 사용은 지양하는게 좋겠죠?


@Transactional
public void withdraw(Long userId) {
User user = userRepository.getById(userId);
userRepository.delete(user);
}
}
15 changes: 0 additions & 15 deletions src/test/java/in/koreatech/koin/acceptance/AuthApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ void userLoginSuccess() {

ExtractableResponse<Response> response = RestAssured
.given()
.log().all()
.body("""
{
"email": "test@koreatech.ac.kr",
Expand All @@ -56,10 +55,8 @@ void userLoginSuccess() {
""")
.contentType(ContentType.JSON)
.when()
.log().all()
.post("/user/login")
.then()
.log().all()
.statusCode(HttpStatus.CREATED.value())
.extract();

Expand Down Expand Up @@ -96,7 +93,6 @@ void userLogoutSuccess() {

ExtractableResponse<Response> response = RestAssured
.given()
.log().all()
.body("""
{
"email": "test@koreatech.ac.kr",
Expand All @@ -105,22 +101,17 @@ void userLogoutSuccess() {
""")
.contentType(ContentType.JSON)
.when()
.log().all()
.post("/user/login")
.then()
.log().all()
.statusCode(HttpStatus.CREATED.value())
.extract();

RestAssured
.given()
.log().all()
.header("Authorization", "Bearer " + response.jsonPath().getString("token"))
.when()
.log().all()
.post("/user/logout")
.then()
.log().all()
.statusCode(HttpStatus.OK.value())
.extract();

Comment on lines 109 to 117

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A

앞으로 올리는 PR은 .log().all()을 전부 지워야 할까요??

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

네~! 불필요하게 로그가 많이 찍히는것 같아요~
본인 로컬에서 테스트확인이 필요하다면 그때는 잠시 넣어보고 확인해보는 정도로 사용해봅시다

Expand All @@ -147,7 +138,6 @@ void userRefreshToken() {

ExtractableResponse<Response> response = RestAssured
.given()
.log().all()
.body("""
{
"email": "test@koreatech.ac.kr",
Expand All @@ -156,25 +146,20 @@ void userRefreshToken() {
""")
.contentType(ContentType.JSON)
.when()
.log().all()
.post("/user/login")
.then()
.log().all()
.statusCode(HttpStatus.CREATED.value())
.extract();

RestAssured
.given()
.log().all()
.body(
Map.of("refresh_token", response.jsonPath().getString("refresh_token"))
)
.contentType(ContentType.JSON)
.when()
.log().all()
.post("/user/refresh")
.then()
.log().all()
.statusCode(HttpStatus.OK.value())
.extract();

Expand Down
Loading