Skip to content

Commit

Permalink
Merge pull request #15 from Timetris-Trendithon/mainpage
Browse files Browse the repository at this point in the history
♻️ Refactor: 반볡적으둜 μ‚¬μš©λ˜λŠ” μœ μ € 아이디 κ°€μ Έμ˜€λŠ” λ©”μ†Œλ“œ 생성
  • Loading branch information
Zena0128 authored Feb 19, 2024
2 parents 2e4862e + 9556009 commit 510c284
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 136 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,27 @@ public class CategoryController {
private final CategoryService categoryService;
private final TokenProvider tokenProvider;

@GetMapping("")
public ApiResponse<List<CategoryViewDTO>> readCategoryAll(HttpServletRequest request)
{
public long getUserId(HttpServletRequest request){
String accessToken = tokenProvider.extractAccessToken(request).orElse(null);

Long userId = null;

if (accessToken != null) {
userId = tokenProvider.extractId(accessToken).orElse(null);
} else {
return ApiResponse.failure(ErrorStatus.NOT_LOGIN_ERROR);
throw new CustomException(ErrorStatus.NOT_LOGIN_ERROR);

}
if(userId == null) {
throw new CustomException(ErrorStatus.USER_NOT_FOUND_ERROR);
}
return userId;
}

@GetMapping("")
public ApiResponse<List<CategoryViewDTO>> readCategoryAll(HttpServletRequest request)
{
long userId = getUserId(request);

List<CategoryViewDTO> categoryList = categoryService.readCategoryAll(userId);
return ApiResponse.success(SuccessStatus.OK, categoryList);
Expand All @@ -50,19 +55,7 @@ public ApiResponse<List<CategoryViewDTO>> readCategoryAll(HttpServletRequest req
public ApiResponse<CategoryRequestDTO> createCategory(HttpServletRequest request,
@RequestBody CategoryRequestDTO categoryRequestDTO)
{
String accessToken = tokenProvider.extractAccessToken(request).orElse(null);

Long userId = null;

if (accessToken != null) {
userId = tokenProvider.extractId(accessToken).orElse(null);
} else {
return ApiResponse.failure(ErrorStatus.NOT_LOGIN_ERROR);

}
if(userId == null) {
throw new CustomException(ErrorStatus.USER_NOT_FOUND_ERROR);
}
long userId = getUserId(request);

Category category = categoryService.createCategory(userId, categoryRequestDTO);
if (category == null){
Expand All @@ -76,19 +69,7 @@ public ApiResponse<CategoryRequestDTO> updateCategory(HttpServletRequest request
@PathVariable long categoryId,
@RequestBody CategoryRequestDTO categoryRequestDTO)
{
String accessToken = tokenProvider.extractAccessToken(request).orElse(null);

Long userId = null;

if (accessToken != null) {
userId = tokenProvider.extractId(accessToken).orElse(null);
} else {
return ApiResponse.failure(ErrorStatus.NOT_LOGIN_ERROR);

}
if(userId == null) {
throw new CustomException(ErrorStatus.USER_NOT_FOUND_ERROR);
}
long userId = getUserId(request);

categoryService.updateCategory(userId, categoryId, categoryRequestDTO);
return ApiResponse.success(SuccessStatus.OK, categoryRequestDTO);
Expand All @@ -98,19 +79,7 @@ public ApiResponse<CategoryRequestDTO> updateCategory(HttpServletRequest request
public ApiResponse deleteCategory(HttpServletRequest request,
@PathVariable long categoryId)
{
String accessToken = tokenProvider.extractAccessToken(request).orElse(null);

Long userId = null;

if (accessToken != null) {
userId = tokenProvider.extractId(accessToken).orElse(null);
} else {
return ApiResponse.failure(ErrorStatus.NOT_LOGIN_ERROR);

}
if(userId == null) {
throw new CustomException(ErrorStatus.USER_NOT_FOUND_ERROR);
}
long userId = getUserId(request);

categoryService.deleteCategory(userId, categoryId);
return ApiResponse.success(SuccessStatus.OK);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,28 @@ public class DoController {
private final DoService doService;
private final TokenProvider tokenProvider;

@PostMapping("")
public ApiResponse createDo(HttpServletRequest request,
@RequestBody DoRequestDTO doRequestDTO)
{
public long getUserId(HttpServletRequest request){
String accessToken = tokenProvider.extractAccessToken(request).orElse(null);

Long userId = null;

if (accessToken != null) {
userId = tokenProvider.extractId(accessToken).orElse(null);
} else {
return ApiResponse.failure(ErrorStatus.NOT_LOGIN_ERROR);
throw new CustomException(ErrorStatus.NOT_LOGIN_ERROR);

}
if(userId == null) {
throw new CustomException(ErrorStatus.USER_NOT_FOUND_ERROR);
}
return userId;
}

@PostMapping("")
public ApiResponse createDo(HttpServletRequest request,
@RequestBody DoRequestDTO doRequestDTO)
{
long userId = getUserId(request);

Do done = doService.createDo(userId, doRequestDTO);
if (done == null){
Expand All @@ -53,19 +58,7 @@ public ApiResponse updateDo(HttpServletRequest request,
@PathVariable long doId,
@RequestBody DoRequestDTO doRequestDTO)
{
String accessToken = tokenProvider.extractAccessToken(request).orElse(null);

Long userId = null;

if (accessToken != null) {
userId = tokenProvider.extractId(accessToken).orElse(null);
} else {
return ApiResponse.failure(ErrorStatus.NOT_LOGIN_ERROR);

}
if(userId == null) {
throw new CustomException(ErrorStatus.USER_NOT_FOUND_ERROR);
}
long userId = getUserId(request);

doService.updateDo(userId, doId, doRequestDTO);
return ApiResponse.success(SuccessStatus.OK);
Expand All @@ -75,19 +68,7 @@ public ApiResponse updateDo(HttpServletRequest request,
public ApiResponse deleteDo(HttpServletRequest request,
@PathVariable long doId)
{
String accessToken = tokenProvider.extractAccessToken(request).orElse(null);

Long userId = null;

if (accessToken != null) {
userId = tokenProvider.extractId(accessToken).orElse(null);
} else {
return ApiResponse.failure(ErrorStatus.NOT_LOGIN_ERROR);

}
if(userId == null) {
throw new CustomException(ErrorStatus.USER_NOT_FOUND_ERROR);
}
long userId = getUserId(request);

doService.deleteDo(userId, doId);
return ApiResponse.success(SuccessStatus.OK);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,28 @@ public class PlanController {
private final PlanService planService;
private final TokenProvider tokenProvider;

@PostMapping("")
public ApiResponse createPlan(HttpServletRequest request,
@RequestBody PlanRequestDTO planRequestDTO)
{
public long getUserId(HttpServletRequest request){
String accessToken = tokenProvider.extractAccessToken(request).orElse(null);

Long userId = null;

if (accessToken != null) {
userId = tokenProvider.extractId(accessToken).orElse(null);
} else {
return ApiResponse.failure(ErrorStatus.NOT_LOGIN_ERROR);
throw new CustomException(ErrorStatus.NOT_LOGIN_ERROR);

}
if(userId == null) {
throw new CustomException(ErrorStatus.USER_NOT_FOUND_ERROR);
}
return userId;
}

@PostMapping("")
public ApiResponse createPlan(HttpServletRequest request,
@RequestBody PlanRequestDTO planRequestDTO)
{
long userId = getUserId(request);

Plan plan = planService.createPlan(userId, planRequestDTO);
if (plan == null){
Expand All @@ -55,19 +60,7 @@ public ApiResponse updatePlan(HttpServletRequest request,
@PathVariable long planId,
@RequestBody PlanRequestDTO planRequestDTO)
{
String accessToken = tokenProvider.extractAccessToken(request).orElse(null);

Long userId = null;

if (accessToken != null) {
userId = tokenProvider.extractId(accessToken).orElse(null);
} else {
return ApiResponse.failure(ErrorStatus.NOT_LOGIN_ERROR);

}
if(userId == null) {
throw new CustomException(ErrorStatus.USER_NOT_FOUND_ERROR);
}
long userId = getUserId(request);

planService.updatePlan(userId, planId, planRequestDTO);
return ApiResponse.success(SuccessStatus.OK);
Expand Down Expand Up @@ -99,19 +92,7 @@ public ApiResponse deletePlan(HttpServletRequest request,
public ApiResponse donePlan(HttpServletRequest request,
@PathVariable long planId)
{
String accessToken = tokenProvider.extractAccessToken(request).orElse(null);

Long userId = null;

if (accessToken != null) {
userId = tokenProvider.extractId(accessToken).orElse(null);
} else {
return ApiResponse.failure(ErrorStatus.NOT_LOGIN_ERROR);

}
if(userId == null) {
throw new CustomException(ErrorStatus.USER_NOT_FOUND_ERROR);
}
long userId = getUserId(request);

planService.donePlan(userId, planId);
return ApiResponse.success(SuccessStatus.OK);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,28 @@ public class SeeController {
private final SeeService seeService;
private final TokenProvider tokenProvider;

@PostMapping("")
public ApiResponse createSee(HttpServletRequest request,
@RequestBody SeeRequestDTO seeRequestDTO)
{
public long getUserId(HttpServletRequest request){
String accessToken = tokenProvider.extractAccessToken(request).orElse(null);

Long userId = null;

if (accessToken != null) {
userId = tokenProvider.extractId(accessToken).orElse(null);
} else {
return ApiResponse.failure(ErrorStatus.NOT_LOGIN_ERROR);
throw new CustomException(ErrorStatus.NOT_LOGIN_ERROR);

}
if(userId == null) {
throw new CustomException(ErrorStatus.USER_NOT_FOUND_ERROR);
}
return userId;
}

@PostMapping("")
public ApiResponse createSee(HttpServletRequest request,
@RequestBody SeeRequestDTO seeRequestDTO)
{
long userId = getUserId(request);

See see = seeService.createSee(userId, seeRequestDTO);
if (see == null){
Expand All @@ -53,19 +58,7 @@ public ApiResponse updateSee(HttpServletRequest request,
@PathVariable long seeId,
@RequestBody SeeRequestDTO seeRequestDTO)
{
String accessToken = tokenProvider.extractAccessToken(request).orElse(null);

Long userId = null;

if (accessToken != null) {
userId = tokenProvider.extractId(accessToken).orElse(null);
} else {
return ApiResponse.failure(ErrorStatus.NOT_LOGIN_ERROR);

}
if(userId == null) {
throw new CustomException(ErrorStatus.USER_NOT_FOUND_ERROR);
}
long userId = getUserId(request);

seeService.updateSee(userId, seeId, seeRequestDTO);
return ApiResponse.success(SuccessStatus.OK);
Expand All @@ -75,19 +68,7 @@ public ApiResponse updateSee(HttpServletRequest request,
public ApiResponse deleteSee(HttpServletRequest request,
@PathVariable long seeId)
{
String accessToken = tokenProvider.extractAccessToken(request).orElse(null);

Long userId = null;

if (accessToken != null) {
userId = tokenProvider.extractId(accessToken).orElse(null);
} else {
return ApiResponse.failure(ErrorStatus.NOT_LOGIN_ERROR);

}
if(userId == null) {
throw new CustomException(ErrorStatus.USER_NOT_FOUND_ERROR);
}
long userId = getUserId(request);

seeService.deleteSee(userId, seeId);
return ApiResponse.success(SuccessStatus.OK);
Expand Down

0 comments on commit 510c284

Please sign in to comment.