Skip to content

Commit

Permalink
refactor: File 관련 요청할 수 있도록 응답 객체 설정
Browse files Browse the repository at this point in the history
  • Loading branch information
SSung023 committed Apr 18, 2024
1 parent 05e2d8b commit 4f859a1
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.genius.gitget.admin.topic.controller;

import static com.genius.gitget.global.util.exception.SuccessCode.CREATED;
import static com.genius.gitget.global.util.exception.SuccessCode.SUCCESS;

import com.genius.gitget.admin.topic.dto.TopicCreateRequest;
import com.genius.gitget.admin.topic.dto.TopicDetailResponse;
import com.genius.gitget.admin.topic.dto.TopicIndexResponse;
import com.genius.gitget.admin.topic.dto.TopicPagingResponse;
import com.genius.gitget.admin.topic.dto.TopicUpdateRequest;
import com.genius.gitget.admin.topic.service.TopicService;
import com.genius.gitget.global.util.exception.SuccessCode;
import com.genius.gitget.global.util.response.dto.CommonResponse;
import com.genius.gitget.global.util.response.dto.PagingResponse;
import com.genius.gitget.global.util.response.dto.SingleResponse;
Expand Down Expand Up @@ -38,7 +41,7 @@ public ResponseEntity<PagingResponse<TopicPagingResponse>> getAllTopics(
Page<TopicPagingResponse> allTopics = topicService.getAllTopics(pageable);

return ResponseEntity.ok().body(
new PagingResponse<>(SuccessCode.SUCCESS.getStatus(), SuccessCode.SUCCESS.getMessage(), allTopics)
new PagingResponse<>(SUCCESS.getStatus(), SUCCESS.getMessage(), allTopics)
);
}

Expand All @@ -47,28 +50,33 @@ public ResponseEntity<PagingResponse<TopicPagingResponse>> getAllTopics(
public ResponseEntity<SingleResponse<TopicDetailResponse>> getTopicById(@PathVariable Long id) {
TopicDetailResponse topicDetail = topicService.getTopicById(id);
return ResponseEntity.ok().body(
new SingleResponse<>(SuccessCode.SUCCESS.getStatus(), SuccessCode.SUCCESS.getMessage(), topicDetail)
new SingleResponse<>(SUCCESS.getStatus(), SUCCESS.getMessage(), topicDetail)
);
}

// 토픽 생성 요청
@PostMapping
public ResponseEntity<SingleResponse<Long>> createTopic(
public ResponseEntity<SingleResponse<TopicIndexResponse>> createTopic(
@RequestBody TopicCreateRequest topicCreateRequest) {
Long topicId = topicService.createTopic(topicCreateRequest);
TopicIndexResponse topicUpdateResponse = new TopicIndexResponse(topicId);

return ResponseEntity.ok().body(
new SingleResponse<>(SuccessCode.CREATED.getStatus(), SuccessCode.CREATED.getMessage(), topicId)
new SingleResponse<>(
CREATED.getStatus(), CREATED.getMessage(), topicUpdateResponse)
);
}

// 토픽 수정 요청
@PatchMapping("/{id}")
public ResponseEntity<CommonResponse> updateTopic(@PathVariable Long id,
@RequestBody TopicUpdateRequest topicUpdateRequest) {
topicService.updateTopic(id, topicUpdateRequest);
public ResponseEntity<SingleResponse<TopicIndexResponse>> updateTopic(
@PathVariable Long id,
@RequestBody TopicUpdateRequest topicUpdateRequest) {
Long topicId = topicService.updateTopic(id, topicUpdateRequest);
TopicIndexResponse topicUpdateResponse = new TopicIndexResponse(topicId);

return ResponseEntity.ok().body(
new CommonResponse(SuccessCode.SUCCESS.getStatus(), SuccessCode.SUCCESS.getMessage())
new SingleResponse<>(SUCCESS.getStatus(), SUCCESS.getMessage(), topicUpdateResponse)
);
}

Expand All @@ -77,7 +85,7 @@ public ResponseEntity<CommonResponse> updateTopic(@PathVariable Long id,
public ResponseEntity<CommonResponse> deleteTopic(@PathVariable Long id) {
topicService.deleteTopic(id);
return ResponseEntity.ok().body(
new CommonResponse(SuccessCode.SUCCESS.getStatus(), SuccessCode.SUCCESS.getMessage())
new CommonResponse(SUCCESS.getStatus(), SUCCESS.getMessage())
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.genius.gitget.admin.topic.dto;

public record TopicIndexResponse(
Long topicId
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public Long createTopic(TopicCreateRequest topicCreateRequest) {

// 토픽 업데이트 요청
@Transactional
public void updateTopic(Long id, TopicUpdateRequest topicUpdateRequest) {
public Long updateTopic(Long id, TopicUpdateRequest topicUpdateRequest) {
Topic topic = topicRepository.findById(id)
.orElseThrow(() -> new BusinessException(ErrorCode.TOPIC_NOT_FOUND));

Expand All @@ -74,7 +74,7 @@ public void updateTopic(Long id, TopicUpdateRequest topicUpdateRequest) {
topic.updateNotExistInstance(topicUpdateRequest.title(), topicUpdateRequest.description(),
topicUpdateRequest.tags(), topicUpdateRequest.notice(), topicUpdateRequest.pointPerPerson());
}
topicRepository.save(topic);
return topicRepository.save(topic).getId();
}

// 토픽 삭제 요청
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.genius.gitget.challenge.instance.controller;

import static com.genius.gitget.global.util.exception.SuccessCode.CREATED;
import static com.genius.gitget.global.util.exception.SuccessCode.SUCCESS;

import com.genius.gitget.challenge.instance.dto.crud.InstanceCreateRequest;
import com.genius.gitget.challenge.instance.dto.crud.InstanceDetailResponse;
import com.genius.gitget.challenge.instance.dto.crud.InstanceIndexResponse;
import com.genius.gitget.challenge.instance.dto.crud.InstancePagingResponse;
import com.genius.gitget.challenge.instance.dto.crud.InstanceUpdateRequest;
import com.genius.gitget.challenge.instance.service.InstanceService;
import com.genius.gitget.global.util.exception.SuccessCode;
import com.genius.gitget.global.util.response.dto.CommonResponse;
import com.genius.gitget.global.util.response.dto.PagingResponse;
import com.genius.gitget.global.util.response.dto.SingleResponse;
Expand Down Expand Up @@ -39,7 +42,7 @@ public ResponseEntity<PagingResponse<InstancePagingResponse>> getAllInstances(
Page<InstancePagingResponse> instances = instanceService.getAllInstances(pageable);

return ResponseEntity.ok().body(
new PagingResponse<>(SuccessCode.SUCCESS.getStatus(), SuccessCode.SUCCESS.getMessage(), instances)
new PagingResponse<>(SUCCESS.getStatus(), SUCCESS.getMessage(), instances)
);
}

Expand All @@ -53,7 +56,7 @@ public ResponseEntity<PagingResponse<InstancePagingResponse>> getAllInstancesOfS
pageRequest, id);

return ResponseEntity.ok().body(
new PagingResponse<>(SuccessCode.SUCCESS.getStatus(), SuccessCode.SUCCESS.getMessage(),
new PagingResponse<>(SUCCESS.getStatus(), SUCCESS.getMessage(),
allInstancesOfSpecificTopic)
);
}
Expand All @@ -64,29 +67,32 @@ public ResponseEntity<PagingResponse<InstancePagingResponse>> getAllInstancesOfS
public ResponseEntity<SingleResponse<InstanceDetailResponse>> getInstanceById(@PathVariable Long id) {
InstanceDetailResponse instanceDetails = instanceService.getInstanceById(id);
return ResponseEntity.ok().body(
new SingleResponse<>(SuccessCode.SUCCESS.getStatus(), SuccessCode.SUCCESS.getMessage(), instanceDetails)
new SingleResponse<>(SUCCESS.getStatus(), SUCCESS.getMessage(), instanceDetails)
);
}

// 인스턴스 생성
@PostMapping("/instance")
public ResponseEntity<SingleResponse<Long>> createInstance(
public ResponseEntity<SingleResponse<InstanceIndexResponse>> createInstance(
@RequestBody InstanceCreateRequest instanceCreateRequest) {
Long instanceId = instanceService.createInstance(instanceCreateRequest, LocalDate.now());
InstanceIndexResponse instanceIndexResponse = new InstanceIndexResponse(instanceId);

return ResponseEntity.ok().body(
new SingleResponse<>(SuccessCode.CREATED.getStatus(), SuccessCode.CREATED.getMessage(), instanceId)
new SingleResponse<>(CREATED.getStatus(), CREATED.getMessage(), instanceIndexResponse)
);
}

// 인스턴스 수정
@PatchMapping("/instance/{id}")
public ResponseEntity<SingleResponse<Long>> updateInstance(@PathVariable Long id,
@RequestBody InstanceUpdateRequest instanceUpdateRequest) {
public ResponseEntity<SingleResponse<InstanceIndexResponse>> updateInstance(
@PathVariable Long id,
@RequestBody InstanceUpdateRequest instanceUpdateRequest) {

Long instanceId = instanceService.updateInstance(id, instanceUpdateRequest);
InstanceIndexResponse instanceIndexResponse = new InstanceIndexResponse(instanceId);
return ResponseEntity.ok().body(
new SingleResponse<>(SuccessCode.SUCCESS.getStatus(), SuccessCode.SUCCESS.getMessage(), instanceId)
new SingleResponse<>(SUCCESS.getStatus(), SUCCESS.getMessage(), instanceIndexResponse)
);
}

Expand All @@ -95,7 +101,7 @@ public ResponseEntity<SingleResponse<Long>> updateInstance(@PathVariable Long id
public ResponseEntity<CommonResponse> deleteInstance(@PathVariable Long id) {
instanceService.deleteInstance(id);
return ResponseEntity.ok().body(
new CommonResponse(SuccessCode.SUCCESS.getStatus(), SuccessCode.SUCCESS.getMessage())
new CommonResponse(SUCCESS.getStatus(), SUCCESS.getMessage())
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.genius.gitget.challenge.instance.dto.crud;

public record InstanceIndexResponse(
Long instanceId
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ public ResponseEntity<CommonResponse> checkNicknameDuplicate(@RequestParam(value
@PostMapping("/auth/signup")
public ResponseEntity<SingleResponse<SignupResponse>> signup(
@RequestBody SignupRequest signupRequest) {
Long signupUserId = userService.signup(signupRequest);
String identifier = userService.findUserById(signupUserId).getIdentifier();
Long userId = userService.signup(signupRequest);
String identifier = userService.findUserById(userId).getIdentifier();
SignupResponse signupResponse = new SignupResponse(userId, identifier);

return ResponseEntity.ok().body(
new SingleResponse<>(CREATED.getStatus(), CREATED.getMessage(), new SignupResponse(identifier))
new SingleResponse<>(CREATED.getStatus(), CREATED.getMessage(), signupResponse)
);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.genius.gitget.global.security.dto;

public record SignupResponse(
Long userId,
String identifier
) {
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.genius.gitget.profile.controller;

import static com.genius.gitget.global.util.exception.SuccessCode.SUCCESS;

import com.genius.gitget.global.security.domain.UserPrincipal;
import com.genius.gitget.global.util.exception.SuccessCode;
import com.genius.gitget.global.util.response.dto.CommonResponse;
import com.genius.gitget.global.util.response.dto.SingleResponse;
import com.genius.gitget.profile.dto.UserChallengeResultResponse;
import com.genius.gitget.profile.dto.UserDetailsInformationResponse;
import com.genius.gitget.profile.dto.UserIndexResponse;
import com.genius.gitget.profile.dto.UserInformationRequest;
import com.genius.gitget.profile.dto.UserInformationResponse;
import com.genius.gitget.profile.dto.UserInformationUpdateRequest;
Expand Down Expand Up @@ -37,7 +39,7 @@ public ResponseEntity<SingleResponse<UserDetailsInformationResponse>> getUserDet
UserDetailsInformationResponse userInformation = profileService.getUserDetailsInformation(
userPrincipal.getUser());
return ResponseEntity.ok()
.body(new SingleResponse<>(SuccessCode.SUCCESS.getStatus(), SuccessCode.SUCCESS.getMessage(),
.body(new SingleResponse<>(SUCCESS.getStatus(), SUCCESS.getMessage(),
userInformation)
);
}
Expand All @@ -48,21 +50,22 @@ public ResponseEntity<SingleResponse<UserInformationResponse>> getUserInformatio
@RequestBody UserInformationRequest userInformationRequest) {
UserInformationResponse userInformation = profileService.getUserInformation(userInformationRequest.getUserId());
return ResponseEntity.ok()
.body(new SingleResponse<>(SuccessCode.SUCCESS.getStatus(), SuccessCode.SUCCESS.getMessage(),
.body(new SingleResponse<>(SUCCESS.getStatus(), SUCCESS.getMessage(),
userInformation)
);
}

// 마이페이지 - 회원 정보 수정
@PostMapping("/information")
public ResponseEntity<SingleResponse<Long>> updateUserInformation(
public ResponseEntity<SingleResponse<UserIndexResponse>> updateUserInformation(
@AuthenticationPrincipal UserPrincipal userPrincipal,
@RequestBody UserInformationUpdateRequest userInformationUpdateRequest) {

Long userId = profileService.updateUserInformation(userPrincipal.getUser(), userInformationUpdateRequest);
UserIndexResponse userIndexResponse = new UserIndexResponse(userId);

return ResponseEntity.ok().body(
new SingleResponse<>(SuccessCode.SUCCESS.getStatus(), SuccessCode.SUCCESS.getMessage(), userId)
new SingleResponse<>(SUCCESS.getStatus(), SUCCESS.getMessage(), userIndexResponse)
);
}

Expand All @@ -73,7 +76,7 @@ public ResponseEntity<SingleResponse<UserInterestResponse>> getUserInterest(
UserInterestResponse userInterest = profileService.getUserInterest(userPrincipal.getUser());

return ResponseEntity.ok()
.body(new SingleResponse<>(SuccessCode.SUCCESS.getStatus(), SuccessCode.SUCCESS.getMessage(),
.body(new SingleResponse<>(SUCCESS.getStatus(), SUCCESS.getMessage(),
userInterest));
}

Expand All @@ -85,7 +88,7 @@ public ResponseEntity<CommonResponse> updateUserTags(@AuthenticationPrincipal Us
profileService.updateUserTags(userPrincipal.getUser(), userInterestUpdateRequest);

return ResponseEntity.ok()
.body(new CommonResponse(SuccessCode.SUCCESS.getStatus(), SuccessCode.SUCCESS.getMessage()));
.body(new CommonResponse(SUCCESS.getStatus(), SUCCESS.getMessage()));
}


Expand All @@ -96,7 +99,7 @@ public ResponseEntity<SingleResponse<UserChallengeResultResponse>> getUserChalle
UserChallengeResultResponse userChallengeResult = profileService.getUserChallengeResult(
userPrincipal.getUser());
return ResponseEntity.ok()
.body(new SingleResponse<>(SuccessCode.SUCCESS.getStatus(), SuccessCode.SUCCESS.getMessage(),
.body(new SingleResponse<>(SUCCESS.getStatus(), SUCCESS.getMessage(),
userChallengeResult));
}

Expand All @@ -108,7 +111,7 @@ public ResponseEntity<CommonResponse> deleteUserInformation(@AuthenticationPrinc
profileService.deleteUserInformation(userPrincipal.getUser(), userSignoutRequest.getReason());

return ResponseEntity.ok()
.body(new CommonResponse(SuccessCode.SUCCESS.getStatus(), SuccessCode.SUCCESS.getMessage()));
.body(new CommonResponse(SUCCESS.getStatus(), SUCCESS.getMessage()));
}


Expand All @@ -119,7 +122,7 @@ public ResponseEntity<SingleResponse<UserPointResponse>> getUserPoint(
UserPointResponse userPoint = profileService.getUserPoint(userPrincipal.getUser());

return ResponseEntity.ok()
.body(new SingleResponse<>(SuccessCode.SUCCESS.getStatus(), SuccessCode.SUCCESS.getMessage(),
.body(new SingleResponse<>(SUCCESS.getStatus(), SUCCESS.getMessage(),
userPoint));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.genius.gitget.profile.dto;

public record UserIndexResponse(
Long userId
) {
}

0 comments on commit 4f859a1

Please sign in to comment.