Skip to content

Commit

Permalink
Merge pull request #17 from Timetris-Trendithon/mypage
Browse files Browse the repository at this point in the history
โœจFeat: ๋งˆ์ดํŽ˜์ด์ง€ ์ด๋ฆ„ ์ˆ˜์ • API
  • Loading branch information
jiinkyung authored Feb 19, 2024
2 parents 5a40c14 + 0d276e0 commit 8cd3721
Show file tree
Hide file tree
Showing 19 changed files with 105 additions and 156 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,61 +25,41 @@ public class CategoryController {
private final CategoryService categoryService;
private final TokenProvider tokenProvider;

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 {
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);
public ApiResponse<List<CategoryViewDTO>> readCategoryAll(HttpServletRequest request) {
Long userId = tokenProvider.getUserId(request);

List<CategoryViewDTO> categoryList = categoryService.readCategoryAll(userId);
return ApiResponse.success(SuccessStatus.OK, categoryList);
}

@PostMapping("")
public ApiResponse<CategoryRequestDTO> createCategory(HttpServletRequest request,
@RequestBody CategoryRequestDTO categoryRequestDTO)
{
long userId = getUserId(request);
@RequestBody CategoryRequestDTO categoryRequestDTO) {
Long userId = tokenProvider.getUserId(request);

Category category = categoryService.createCategory(userId, categoryRequestDTO);
if (category == null){
if (category == null) {
throw new CustomException(ErrorStatus.INVALID_FORMAT_ERROR);
}
return ApiResponse.success(SuccessStatus.OK, categoryRequestDTO);
}

@PutMapping("/{categoryId}")
public ApiResponse<CategoryRequestDTO> updateCategory(HttpServletRequest request,
@PathVariable long categoryId,
@RequestBody CategoryRequestDTO categoryRequestDTO)
{
long userId = getUserId(request);
@PathVariable long categoryId,
@RequestBody CategoryRequestDTO categoryRequestDTO) {
Long userId = tokenProvider.getUserId(request);

categoryService.updateCategory(userId, categoryId, categoryRequestDTO);
return ApiResponse.success(SuccessStatus.OK, categoryRequestDTO);
}

@DeleteMapping("/{categoryId}")
public ApiResponse deleteCategory(HttpServletRequest request,
@PathVariable long categoryId)
{
long userId = getUserId(request);
@PathVariable long categoryId) {
Long userId = tokenProvider.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,31 +23,14 @@ public class DoController {
private final DoService doService;
private final TokenProvider tokenProvider;

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 {
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);
@RequestBody DoRequestDTO doRequestDTO) {
Long userId = tokenProvider.getUserId(request);

Do done = doService.createDo(userId, doRequestDTO);
if (done == null){
if (done == null) {
throw new CustomException(ErrorStatus.INVALID_FORMAT_ERROR);
}
return ApiResponse.success(SuccessStatus.OK);
Expand All @@ -56,19 +39,17 @@ public ApiResponse createDo(HttpServletRequest request,
@PutMapping("/{doId}")
public ApiResponse updateDo(HttpServletRequest request,
@PathVariable long doId,
@RequestBody DoRequestDTO doRequestDTO)
{
long userId = getUserId(request);
@RequestBody DoRequestDTO doRequestDTO) {
Long userId = tokenProvider.getUserId(request);

doService.updateDo(userId, doId, doRequestDTO);
return ApiResponse.success(SuccessStatus.OK);
}

@DeleteMapping("/{doId}")
public ApiResponse deleteDo(HttpServletRequest request,
@PathVariable long doId)
{
long userId = getUserId(request);
@PathVariable long doId) {
Long userId = tokenProvider.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 @@ -27,19 +27,9 @@ public class MainPageController {

@GetMapping("")
public ApiResponse<MainPageDTO> getMainPage(HttpServletRequest request) {
String accessToken = tokenProvider.extractAccessToken(request).orElse(null);

Long userId = null;
Long userId = tokenProvider.getUserId(request);

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);
}
MainPageDTO mainPageDTO = mainPageService.getMainPage(userId);
return ApiResponse.success(SuccessStatus.OK, mainPageDTO);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,14 @@ public class PlanController {
private final PlanService planService;
private final TokenProvider tokenProvider;

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 {
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);
@RequestBody PlanRequestDTO planRequestDTO) {
Long userId = tokenProvider.getUserId(request);

Plan plan = planService.createPlan(userId, planRequestDTO);
if (plan == null){
if (plan == null) {
throw new CustomException(ErrorStatus.INVALID_FORMAT_ERROR);
}
return ApiResponse.success(SuccessStatus.OK);
Expand All @@ -58,46 +41,30 @@ public ApiResponse createPlan(HttpServletRequest request,
@PutMapping("/{planId}")
public ApiResponse updatePlan(HttpServletRequest request,
@PathVariable long planId,
@RequestBody PlanRequestDTO planRequestDTO)
{
long userId = getUserId(request);
@RequestBody PlanRequestDTO planRequestDTO) {
Long userId = tokenProvider.getUserId(request);

planService.updatePlan(userId, planId, planRequestDTO);
return ApiResponse.success(SuccessStatus.OK);
}

@DeleteMapping("/{planId}")
public ApiResponse deletePlan(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);
}
@PathVariable long planId) {
Long userId = tokenProvider.getUserId(request);

planService.deletePlan(userId, planId);
return ApiResponse.success(SuccessStatus.OK);
}

@PutMapping("/{planId}/check")
public ApiResponse donePlan(HttpServletRequest request,
@PathVariable long planId)
{
long userId = getUserId(request);
@PathVariable long planId) {
Long userId = tokenProvider.getUserId(request);

planService.donePlan(userId, planId);
return ApiResponse.success(SuccessStatus.OK);
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,13 @@ public class SeeController {
private final SeeService seeService;
private final TokenProvider tokenProvider;

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 {
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);
@RequestBody SeeRequestDTO seeRequestDTO) {
Long userId = tokenProvider.getUserId(request);

See see = seeService.createSee(userId, seeRequestDTO);
if (see == null){
if (see == null) {
throw new CustomException(ErrorStatus.SEE_NOT_FOUND_ERROR);
}
return ApiResponse.success(SuccessStatus.OK);
Expand All @@ -56,19 +38,17 @@ public ApiResponse createSee(HttpServletRequest request,
@PutMapping("/{seeId}")
public ApiResponse updateSee(HttpServletRequest request,
@PathVariable long seeId,
@RequestBody SeeRequestDTO seeRequestDTO)
{
long userId = getUserId(request);
@RequestBody SeeRequestDTO seeRequestDTO) {
Long userId = tokenProvider.getUserId(request);

seeService.updateSee(userId, seeId, seeRequestDTO);
return ApiResponse.success(SuccessStatus.OK);
}

@DeleteMapping("/{seeId}")
public ApiResponse deleteSee(HttpServletRequest request,
@PathVariable long seeId)
{
long userId = getUserId(request);
@PathVariable long seeId) {
Long userId = tokenProvider.getUserId(request);

seeService.deleteSee(userId, seeId);
return ApiResponse.success(SuccessStatus.OK);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
package com.trendithon.timetris.domain.member.controller;

import com.trendithon.timetris.domain.member.dto.MyPageResponse;
import com.trendithon.timetris.domain.member.dto.UpdateNameRequest;
import com.trendithon.timetris.domain.member.service.MyPageService;
import com.trendithon.timetris.global.auth.jwt.TokenProvider;
import com.trendithon.timetris.global.exception.ApiResponse;
import com.trendithon.timetris.global.exception.CustomException;
import com.trendithon.timetris.global.exception.enums.ErrorStatus;
import com.trendithon.timetris.global.exception.enums.SuccessStatus;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
Expand All @@ -22,26 +20,25 @@ public class MyPageController {
private final MyPageService myPageService;

@GetMapping
@Operation(summary = "๋งˆ์ดํŽ˜์ด์ง€ ์กฐํšŒ API")
public ApiResponse<MyPageResponse.getMyPageDTO> getMyPage(HttpServletRequest request) {

String accessToken = tokenProvider.extractAccessToken(request).orElse(null);
Long userId = tokenProvider.getUserId(request);

Long userId = null;

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

}
return ApiResponse.success(SuccessStatus.OK, myPage);

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

MyPageResponse.getMyPageDTO myPage = myPageService.getMyPage(userId);
@PatchMapping
@Operation(summary = "์ด๋ฆ„ ์ˆ˜์ • API")
public ApiResponse<MyPageResponse.getMyPageDTO> updateName(@RequestBody UpdateNameRequest nameRequest,
HttpServletRequest request) {
Long userId = tokenProvider.getUserId(request);

return ApiResponse.success(SuccessStatus.OK, myPage);
MyPageResponse.getMyPageDTO myPageDTO = myPageService.updateName(userId, nameRequest);
return ApiResponse.success(SuccessStatus.OK, myPageDTO);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public class User {
@NotNull
private String name;

private String nickname;

@NotNull
private String email;

Expand All @@ -29,6 +31,9 @@ public class User {

private String refreshToken;

public void changeNickname(String nickname) {
this.nickname = nickname;
}

// ๋กœ๊ทธ์ธ ํ•  ๋•Œ๋งˆ๋‹ค ํ•ด๋‹น ํ•„๋“œ ์ƒˆ๋กญ๊ฒŒ ์—…๋ฐ์ดํŠธ
public User update(String name, String email, String profile) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.trendithon.timetris.domain.member.dto;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@AllArgsConstructor
@NoArgsConstructor
public class UpdateNameRequest {
String nickname;

}
Empty file.
Loading

0 comments on commit 8cd3721

Please sign in to comment.