Skip to content

Commit

Permalink
feat/#294 : Controller에 Event publish 하는 코드 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
LJH098 committed Jun 6, 2024
1 parent 8f61886 commit 399bdf0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@ public class UpdateWeightEvent extends InfraEvent {
private Long memberId;
private String url;
private LocalDateTime localDateTime;

public static UpdateWeightEvent from(Long memberId, String url, LocalDateTime localDateTime) {
return new UpdateWeightEvent(memberId,url,localDateTime);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.gaebaljip.exceed.member.adapter.in;

import com.gaebaljip.exceed.common.event.Events;
import com.gaebaljip.exceed.common.event.UpdateWeightEvent;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -18,6 +20,9 @@
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime;

@RestController
@RequiredArgsConstructor
@RequestMapping("/v1")
Expand All @@ -28,11 +33,11 @@ public class UpdateWeightController {

@Operation(summary = "회원 몸무게 및 목표 몸무게 수정", description = "회원 몸무게 및 목표 몸무게를 수정한다.")
@PatchMapping("/members/weight")
public ApiResponse<UpdateWeightResponse> updateWeight(
public ApiResponse<UpdateWeightResponse> updateWeight(HttpServletRequest servletRequest,
UpdateWeightRequest request, @AuthenticationMemberId Long memberId) {
return ApiResponseGenerator.success(
updateWeightService.execute(
UpdateWeightCommand.of(request.weight(), request.targetWeight(), memberId)),
HttpStatus.OK);
UpdateWeightResponse response = updateWeightService.execute(
UpdateWeightCommand.of(request.weight(), request.targetWeight(), memberId));
Events.raise(UpdateWeightEvent.from(memberId,servletRequest.getRequestURI(), LocalDateTime.now()));
return ApiResponseGenerator.success(response, HttpStatus.OK);
}
}

0 comments on commit 399bdf0

Please sign in to comment.