Skip to content

Commit

Permalink
Feat: /api/auth/member 관련 MemberContoller 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
Taejin1221 committed Sep 2, 2024
1 parent a025c6e commit f8e64ac
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package kaboo.kaboo_auth.controller;

import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import kaboo.kaboo_auth.domain.dto.response.ResponseDTO;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@RestControllerAdvice
public class MainControllerAdvice {

@ExceptionHandler({IllegalStateException.class, UsernameNotFoundException.class})
public ResponseDTO<?> exceptionHandler(Exception e) {
log.error("[Kaboo-Auth]: 예외가 발생하였습니다. {}", e.getMessage());
return new ResponseDTO<>(
true,
e.getMessage(),
null
);
}
}
88 changes: 88 additions & 0 deletions src/main/java/kaboo/kaboo_auth/controller/MemberController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package kaboo.kaboo_auth.controller;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import kaboo.kaboo_auth.domain.dto.request.MemberInfoUpdateRequest;
import kaboo.kaboo_auth.domain.dto.request.MemberIntroduceUpdateRequest;
import kaboo.kaboo_auth.domain.dto.response.MemberInfoResponse;
import kaboo.kaboo_auth.domain.dto.response.MemberIntroduceResponse;
import kaboo.kaboo_auth.domain.dto.response.MemberListResponse;
import kaboo.kaboo_auth.domain.dto.response.ResponseDTO;
import kaboo.kaboo_auth.service.MemberService;
import lombok.RequiredArgsConstructor;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/auth/member")
public class MemberController {

private final MemberService memberService;

@GetMapping("/all")
public ResponseEntity<ResponseDTO<MemberListResponse>> getAllMembers() {
return ResponseEntity.status(HttpStatus.OK)
.body(new ResponseDTO<>(
memberService.getAllMembers()
));
}

@GetMapping("/class/{class}")
public ResponseEntity<ResponseDTO<MemberListResponse>> getClassMembers(
@PathVariable(name = "class") int classNum) {

return ResponseEntity.status(HttpStatus.OK)
.body(new ResponseDTO<>(
memberService.getMembersByClassNum(classNum)
));
}

@GetMapping("")
public ResponseEntity<ResponseDTO<MemberInfoResponse>> getMemberInfo(
@RequestParam(name = "name", defaultValue = "") String koreaName) {

return ResponseEntity.status(HttpStatus.OK)
.body(new ResponseDTO<>(
memberService.getMemberInfoByKoreaName(koreaName)
));
}

@PostMapping("")
public ResponseEntity<ResponseDTO<MemberInfoResponse>> updateMemberInfo(
@RequestParam(name = "name", defaultValue = "") String koreaName,
@RequestBody MemberInfoUpdateRequest request) {

return ResponseEntity.status(HttpStatus.OK)
.body(new ResponseDTO<>(
memberService.updateMemberInfoByKoreaName(koreaName, request)
));
}

@GetMapping("/introduce")
public ResponseEntity<ResponseDTO<MemberIntroduceResponse>> getMemberIntroduce(
@RequestParam(name = "name", defaultValue = "") String koreaName) {

return ResponseEntity.status(HttpStatus.OK)
.body(new ResponseDTO<>(
memberService.getMemberIntroduceByKoreaName(koreaName)
));
}

@PostMapping("/introduce")
public ResponseEntity<ResponseDTO<MemberIntroduceResponse>> updateMemberIntrouce(
@RequestParam(name = "name", defaultValue = "") String koreaName,
@RequestBody MemberIntroduceUpdateRequest request) {

return ResponseEntity.status(HttpStatus.OK)
.body(new ResponseDTO<>(
memberService.updateMemberIntroduceByKoreaName(koreaName, request)
));
}
}

0 comments on commit f8e64ac

Please sign in to comment.