New Bulls 프로젝트 2

chaean·2024년 6월 14일

프로젝트 - Bulls

목록 보기
9/11

2024.06.08

1. 유저 소개 수정페이지가 PostMapping에서 PutMapping으로 변경

PostMapping PutMapping

PostMapping - 일반적으로 새로운 리소스를 생성할 때 + 멱등성 X
PutMapping - 일반적으로 업데이트할 때 사용됨 + 멱등성 O

멱등성

  • 동일한 연산을 여러 번 적용해도 결과가 변하지 않는 성질을 의미
  • PostMapping는 요청 마다 새로운 리서스가 생성되고, PutMapping은 요청 마다 같은 리소스를 반환한다.

2024.06.14

1. 매칭 상태를 변경 (매칭 중, 매칭 마감)하는 함수인 matchFinished()를 가독성 좋게 변경 및 에러 처리

변경전

    public boolean matchFinished(Integer id) {
        MatchPost matchPost = matchPostRepository.findById(id).orElseThrow(() ->
                new IllegalArgumentException("존재하지않는 게시물입니다." + id));

        if (matchPost.getMatchStatus().equals("매칭중")) {
            log.info("매칭 마감으로 변경");
            matchPost.setMatchStatus("매칭 마감");
        } else if (matchPost.getMatchStatus().equals("매칭 마감")) {
            log.info("매칭중으로 변경");
            matchPost.setMatchStatus("매칭중");
        }
        matchPostRepository.save(matchPost);

        return true;
    }

변경후

    public boolean matchFinished(Integer id) {
        MatchPost matchPost = matchPostRepository.findById(id).orElseThrow(() ->
                new IllegalArgumentException("존재하지않는 게시물입니다." + id));

        String str = matchPost.getMatchStatus().equals("매칭중") ? "매칭 마감" : "매칭중";
        log.info(str);
        try {
            matchPost.setMatchStatus(str);
            matchPostRepository.save(matchPost);
            return true;
        } catch (Exception e) {
            log.info(String.valueOf(e));
            return false;
        }
    }

2. BoardListDTO -> MatchDTO로 통일

3. API파일 여러개로 분할

Api.js

  • InquiryApi.js

  • MatchApi.js

  • TeamApi.js

  • UserApi.js

    		+

@ResponseBody

  • HTTP 응답을 Body에 작성
  • JSON으로 자동 변환
  • RESTful 웹 서비스에 주로 사용되며 클라이언트에게 값을 JSON으로 반환할 때 유용하다
  • 컨트롤러에 @RestController 어노테이션을 사용하면 모든 메서드에 추가됨
profile
백엔드 개발자

0개의 댓글