Skip to content

Commit

Permalink
[feat] #3 회원 api controller 클래스 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
SunwoongH committed Oct 26, 2023
1 parent 5ebcd43 commit 861f422
Showing 1 changed file with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package org.sopt.seminar.domain.member.api;

import lombok.RequiredArgsConstructor;
import org.sopt.seminar.domain.member.dto.request.MemberSaveRequest;
import org.sopt.seminar.domain.member.dto.request.MemberUpdateRequest;
import org.sopt.seminar.domain.member.dto.response.MemberGetResponse;
import org.sopt.seminar.domain.member.dto.response.MemberSaveResponse;
import org.sopt.seminar.domain.member.service.MemberService;
import org.sopt.seminar.global.common.ApiResponse;
import org.sopt.seminar.global.common.SuccessStatus;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequiredArgsConstructor
@RequestMapping("/api/member")
@Controller
public class MemberApiController {
private final MemberService memberService;

@PostMapping
public ResponseEntity<ApiResponse<?>> saveMember(@RequestBody final MemberSaveRequest memberSaveRequest) {
final MemberSaveResponse savedMember = memberService.saveMember(memberSaveRequest);
return ApiResponse.success(SuccessStatus.CREATED, savedMember);
}

@GetMapping("/{memberId}")
public ResponseEntity<ApiResponse<?>> getMember(@PathVariable final Long memberId) {
final MemberGetResponse findMember = memberService.getMember(memberId);
return ApiResponse.success(SuccessStatus.OK, findMember);
}

@GetMapping
public ResponseEntity<ApiResponse<?>> getMembers(final Pageable pageable) {
final List<MemberGetResponse> findMembers = memberService.getMembers(pageable);
return ApiResponse.success(SuccessStatus.OK, findMembers);
}

@PatchMapping("/{memberId}")
public ResponseEntity<ApiResponse<?>> updateMember(@PathVariable final Long memberId,
@RequestBody final MemberUpdateRequest memberUpdateRequest) {
memberService.updateMember(memberId, memberUpdateRequest);
return ApiResponse.success(SuccessStatus.OK);
}

@DeleteMapping("/{memberId}")
public ResponseEntity<ApiResponse<?>> deleteMember(@PathVariable final Long memberId) {
memberService.deleteMember(memberId);
return ApiResponse.success(SuccessStatus.OK);
}
}

0 comments on commit 861f422

Please sign in to comment.