Skip to content

Commit

Permalink
#2 - Feat: 성공/실패 디폴트 응답(resultCode, msg 디폴트 값 설정) 메서드 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
ahah525 committed Nov 8, 2022
1 parent 976e7dc commit b2e8bfc
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
import com.example.mutbooks.app.member.dto.LoginDto;
import com.example.mutbooks.app.member.entity.Member;
import com.example.mutbooks.app.member.service.MemberService;
import com.example.mutbooks.app.security.dto.MemberContext;
import com.example.mutbooks.util.Ut;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.crypto.password.PasswordEncoder;
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.RestController;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/member")
Expand Down Expand Up @@ -47,10 +46,20 @@ public ResponseEntity<RsData> login(@RequestBody LoginDto loginDto) {
return Ut.spring.responseEntityOf(
RsData.of(
"S-1",
"로그인 성공, JWT AccessToken 을 발급합니다.",
"로그인 성공, Access Token을 발급합니다.",
Ut.mapOf("Authentication", accessToken)
),
Ut.spring.httpHeadersOf("Authentication", accessToken)
);
}

// 회원 정보
@GetMapping("/me")
public ResponseEntity<RsData> test(@AuthenticationPrincipal MemberContext memberContext) {
if(memberContext == null) {
return Ut.spring.responseEntityOf(RsData.failOf(null));
}

return Ut.spring.responseEntityOf(RsData.successOf(memberContext));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ public static <T> RsData<T> of(String resultCode, String msg) {
return of(resultCode, msg, null);
}

// 성공 응답
public static <T> RsData<T> successOf(T data) {
return of("S-1", "성공", data);
}

// 실패 응답
public static <T> RsData<T> failOf(T data) {
return of("F-1", "실패", data);
}

public boolean isSuccess() {
return resultCode.startsWith("S-1");
}
Expand Down

0 comments on commit b2e8bfc

Please sign in to comment.