diff --git a/.gitignore b/.gitignore index aeda1fe..680f006 100644 --- a/.gitignore +++ b/.gitignore @@ -37,3 +37,4 @@ out/ ### VS Code ### .vscode/ +.DS_Store diff --git a/.gitmodules b/.gitmodules index dcaf99a..eebef36 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "submodule-data"] path = submodule-data - url = git@github.com:ProfileeM/submodule-data.git + url = git@github.com:ProfileeM/submodule-data.git \ No newline at end of file diff --git a/build.gradle b/build.gradle index bc8243e..f051f67 100644 --- a/build.gradle +++ b/build.gradle @@ -22,6 +22,9 @@ repositories { } dependencies { + //swagger 의존성 추가 + implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.2' + implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'com.google.code.gson:gson:2.8.7' diff --git a/src/main/java/com/example/profileem/config/SwaggerConfig.java b/src/main/java/com/example/profileem/config/SwaggerConfig.java new file mode 100644 index 0000000..dc0f91b --- /dev/null +++ b/src/main/java/com/example/profileem/config/SwaggerConfig.java @@ -0,0 +1,23 @@ +package com.example.profileem.config;// Java +import io.swagger.v3.oas.models.Components; +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.info.Info; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class SwaggerConfig { + @Bean + public OpenAPI openAPI() { + return new OpenAPI() + .components(new Components()) + .info(apiInfo()); + } + + private Info apiInfo() { + return new Info() + .title("Springdoc 테스트") + .description("Springdoc을 사용한 Swagger UI 테스트") + .version("1.0.0"); + } +} diff --git a/src/main/java/com/example/profileem/controller/CardController.java b/src/main/java/com/example/profileem/controller/CardController.java index 1c5c588..c68dc08 100644 --- a/src/main/java/com/example/profileem/controller/CardController.java +++ b/src/main/java/com/example/profileem/controller/CardController.java @@ -2,6 +2,8 @@ import com.example.profileem.domain.Card; import com.example.profileem.repository.CardRepository; +import io.swagger.v3.oas.annotations.*; +import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -10,6 +12,8 @@ import java.util.List; import java.util.Optional; + +@Tag(name = "Card") @RestController @RequestMapping("/card") public class CardController { @@ -21,21 +25,22 @@ public CardController(CardRepository cardRepository) { this.cardRepository = cardRepository; } - @PostMapping("/") // 내 프로필 카드 등록 -- 수정해야 될 내용 : 등록할 때 카카오 로그인 userid를 Card의 userid로 넘겨줘야함 + @Operation(summary = "내 프로필 카드 등록", description = "내 프로필 카드 등록") + @PostMapping("/") public ResponseEntity createCard(@RequestBody Card card) { - - // 나머지 카드 정보 설정하고 저장 Card savedCard = cardRepository.save(card); return new ResponseEntity<>(savedCard, HttpStatus.CREATED); } - @GetMapping("/{userId}") // 내 프로필 카드 전체 조회 + @Operation(summary = "내 프로필 카드 전체 조회", description = "내 프로필 카드 전체 조회") + @GetMapping("/{userId}") public ResponseEntity> getCardsByUserId(@PathVariable Long userId) { List cards = cardRepository.findByUserUserId(userId); return new ResponseEntity<>(cards, HttpStatus.OK); } - @GetMapping("/card/{userId}/{cardId}") // 내 프로필 카드 특정 조회 + @Operation(summary = "내 프로필 카드 특정 조회", description = "내 프로필 카드 특정 조회") + @GetMapping("/{userId}/{cardId}") public ResponseEntity getCardByUserIdAndCardId( @PathVariable Long userId, @PathVariable Long cardId) { @@ -45,7 +50,8 @@ public ResponseEntity getCardByUserIdAndCardId( .orElseGet(() -> new ResponseEntity<>(HttpStatus.NOT_FOUND)); } - @DeleteMapping("/{userId}/{cardId}") // 내 프로필 카드 특정 삭제 + @Operation(summary = "내 프로필 카드 특정 삭제", description = "내 프로필 카드 특정 삭제") + @DeleteMapping("/{userId}/{cardId}") public ResponseEntity deleteCardByUserIdAndCardId( @PathVariable Long userId, @PathVariable Long cardId) { @@ -57,4 +63,46 @@ public ResponseEntity deleteCardByUserIdAndCardId( return new ResponseEntity<>("Card not found.", HttpStatus.NOT_FOUND); } } + + @Operation(summary = "내 프로필 카드 수정", description = "내 프로필 카드 수정") + @PutMapping("/{userId}/{cardId}") + public ResponseEntity updateCardByUserIdAndCardId( + @PathVariable Long userId, @PathVariable Long cardId, + @RequestBody Card updatedCard) { + Optional optionalCard = cardRepository.findByUserUserIdAndCid(userId, cardId); + if (optionalCard.isPresent()) { + Card card = optionalCard.get(); + + if (updatedCard.getNickname() != null) card.setNickname(updatedCard.getNickname()); + + if (updatedCard.getUniversity() != null) card.setUniversity(updatedCard.getUniversity()); + + if (updatedCard.getMajor() != null) card.setMajor(updatedCard.getMajor()); + + if (updatedCard.getResidence() != null) card.setResidence(updatedCard.getResidence()); + + if (updatedCard.getQr() != null) card.setQr(updatedCard.getQr()); + + if (updatedCard.getProfile() != null) card.setProfile(updatedCard.getProfile()); + + if (updatedCard.getTemplate() != null) card.setTemplate(updatedCard.getTemplate()); + + if (updatedCard.getMbti() != null) card.setMbti(updatedCard.getMbti()); + + if (updatedCard.getMusic() != null) card.setMusic(updatedCard.getMusic()); + + if (updatedCard.getDrink() != null) card.setDrink(updatedCard.getDrink()); + + if (updatedCard.getBad_food() != null) card.setBad_food(updatedCard.getBad_food()); + + if (updatedCard.getBirth() != null) card.setBirth(updatedCard.getBirth()); + + cardRepository.save(card); // 수정한 카드 정보 저장 + + return new ResponseEntity<>("Card has been updated.", HttpStatus.OK); + } else { + return new ResponseEntity<>("Card not found.", HttpStatus.NOT_FOUND); + } + + } } diff --git a/src/main/java/com/example/profileem/controller/KakaoController.java b/src/main/java/com/example/profileem/controller/KakaoController.java index 3de60f4..89de1f0 100644 --- a/src/main/java/com/example/profileem/controller/KakaoController.java +++ b/src/main/java/com/example/profileem/controller/KakaoController.java @@ -2,6 +2,8 @@ import com.example.profileem.service.KakaoService; import lombok.RequiredArgsConstructor; +import io.swagger.v3.oas.annotations.*; +import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestMapping; @@ -10,10 +12,13 @@ @RestController @RequiredArgsConstructor @RequestMapping("/oauth2") +@Tag(name = "Kakao") + public class KakaoController { public final KakaoService kakaoService; + @Operation(summary = "카카오 로그인", description = "카카오 로그인") @GetMapping("/kakao") public Long kakaoLogin(@RequestHeader(value = "AccessToken") String accessToken) { Long userId = kakaoService.createKakaoUser(accessToken); diff --git a/src/main/java/com/example/profileem/controller/NoticeController.java b/src/main/java/com/example/profileem/controller/NoticeController.java index f986b0a..457fa02 100644 --- a/src/main/java/com/example/profileem/controller/NoticeController.java +++ b/src/main/java/com/example/profileem/controller/NoticeController.java @@ -7,11 +7,12 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; +import io.swagger.v3.oas.annotations.*; +import io.swagger.v3.oas.annotations.tags.Tag; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; +import java.util.*; +@Tag(name = "Notice") @RestController @RequestMapping("/notice") public class NoticeController { @@ -22,20 +23,22 @@ public class NoticeController { public NoticeController(NoticeService noticeService) {this.noticeService = noticeService; } // 공지사항 등록 (관리자만 하도록 수정해야함) + @Operation(summary = "공지사항 등록", description = "공지사항 등록") @PostMapping("/") public ResponseEntity createNotice(@RequestBody Notice notice) { Notice createdNotice = noticeService.createNotice(notice); return ResponseEntity.status(HttpStatus.CREATED).body(createdNotice); } - // 공지사항 조회 // 공지사항 전체 조회 + @Operation(summary = "공지사항 전체 조회", description = "공지사항 전체 조회") @GetMapping("/all") public ResponseEntity> getAllNotices() { List notices = noticeService.getAllNotices(); return ResponseEntity.status(HttpStatus.OK).body(notices); } // 공지사항 하나 조회 + @Operation(summary = "공지사항 하나 조회", description = "공지사항 하나 조회") @GetMapping("/{notice_id}") public ResponseEntity getNoticeById(@PathVariable Long notice_id) { Optional notice = noticeService.getNoticeById(notice_id); @@ -43,6 +46,8 @@ public ResponseEntity getNoticeById(@PathVariable Long notice_id) { } // 공지사항 수정 (관리자만 하도록 수정해야함) + + @Operation(summary = "공지사항 수정", description = "공지사항 수정") @PutMapping("/{notice_id}") public ResponseEntity updateNotice(@PathVariable Long notice_id, @RequestBody Notice newNotice) { Notice updatedNotice = noticeService.updateNotice(notice_id, newNotice); @@ -50,12 +55,11 @@ public ResponseEntity updateNotice(@PathVariable Long notice_id, @Reques } // 공지사항 삭제 (관리자만 하도록 수정해야함) + @Operation(summary = "공지사항 삭제", description = "공지사항 삭제") @DeleteMapping("/{notice_id}") public ResponseEntity deleteNotice(@PathVariable Long notice_id) { noticeService.deleteNotice(notice_id); return ResponseEntity.noContent().build(); } - - } diff --git a/src/main/java/com/example/profileem/controller/PartyController.java b/src/main/java/com/example/profileem/controller/PartyController.java index 307a550..7d15fb3 100644 --- a/src/main/java/com/example/profileem/controller/PartyController.java +++ b/src/main/java/com/example/profileem/controller/PartyController.java @@ -6,11 +6,14 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; - +import io.swagger.v3.oas.annotations.*; +import io.swagger.v3.oas.annotations.tags.Tag; import java.util.List; +@Tag(name="Party") @RestController @RequestMapping("/party") +//@Api(tags = {"Party"}) public class PartyController { private final PartyService partyService; @@ -21,7 +24,7 @@ public PartyController(PartyService partyService) { } // 내가 방장인 파티 생성 - // 파티 생성 + @Operation(summary = "(내가 방장인 파티) 파티 생성", description = "(내가 방장인 파티) 파티 생성") @PostMapping("/") public ResponseEntity createParty(@RequestBody Party party) { @@ -34,7 +37,9 @@ public ResponseEntity createParty(@RequestBody Party party) { } // 사용자를 파티에 초대 - @PostMapping("/invitation/{party_id}") + @Operation(summary = "파티에 사용자 초대", description = "파티에 사용자 초대") + @PostMapping("/{partyId}/invitation") + public ResponseEntity inviteUserToParty( @PathVariable("party_id") Long partyId, @RequestParam("user_id") Long userId) { @@ -50,7 +55,9 @@ public ResponseEntity inviteUserToParty( // 파티에 카드 등록 - @PostMapping("/card/{party_id}") + @Operation(summary = "파티에 카드 등록", description = "파티에 카드 등록") + @PostMapping("/{partyId}/card") + public ResponseEntity addCardToParty( @PathVariable("party_id") Long partyId, @RequestParam("card_id") Long cardId) { @@ -63,7 +70,8 @@ public ResponseEntity addCardToParty( } // 파티에 등록했던 카드 교체 - @PutMapping("/card/{party_id}") + @Operation(summary = "파티에 등록했던 카드 교체", description = "파티에 등록했던 카드 교체") + @PutMapping("/{partyId}/card") public ResponseEntity replacePartyCard( @PathVariable("party_id") Long partyId, @RequestParam("old_card_id") Long oldCardId, @@ -80,4 +88,5 @@ public ResponseEntity replacePartyCard( + } diff --git a/src/main/java/com/example/profileem/controller/UserController.java b/src/main/java/com/example/profileem/controller/UserController.java index ada5eda..fe39de1 100644 --- a/src/main/java/com/example/profileem/controller/UserController.java +++ b/src/main/java/com/example/profileem/controller/UserController.java @@ -8,9 +8,13 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; +import io.swagger.v3.oas.annotations.*; +import io.swagger.v3.oas.annotations.tags.Tag; + import java.util.List; import java.util.Optional; +@Tag(name = "User") @RestController @RequestMapping("/user") public class UserController { @@ -23,7 +27,9 @@ public UserController(UserService userService) { } // 사용자가 받은 개인 프로필 카드 ID 추가 - @PostMapping("/card/{card_id}") + @Operation(summary = "사용자가 받은 개인 프로필 카드 ID 추가", description = "사용자가 받은 개인 프로필 카드 ID 추가") + @PostMapping("/{user_id}/card") + public ResponseEntity addReceivedCardId( @RequestParam("user_id") Long userId, @PathVariable("card_id") Long cardId) { @@ -36,8 +42,9 @@ public ResponseEntity addReceivedCardId( } // 사용자가 받은 개인 프로필 카드 ID 목록 조희 - @GetMapping("/cards") - public ResponseEntity> getReceivedCardIds(@RequestParam("user_id") Long userId) { + @Operation(summary = "사용자가 받은 개인 프로필 카드 ID 목록 조희", description = "사용자가 받은 개인 프로필 카드 ID 목록 조희") + @GetMapping("/{user_id}/cards") + public ResponseEntity> getReceivedCardIds(@PathVariable("user_id") Long userId) { try { List receivedCardIds = userService.getReceivedCardIds(userId); return ResponseEntity.ok(receivedCardIds); @@ -47,7 +54,9 @@ public ResponseEntity> getReceivedCardIds(@RequestParam("user_id") Lo } // 사용자가 받은 개인 프로필 카드 삭제 - @DeleteMapping("/card/{card_id}") + @Operation(summary = "사용자가 받은 개인 프로필 카드 삭제", description = "사용자가 받은 개인 프로필 카드 삭제") + @DeleteMapping("/{user_id}/{card_id}") + public ResponseEntity deleteReceivedCard( @RequestParam("user_id") Long userId, @PathVariable("card_id") Long cardId) { @@ -60,8 +69,9 @@ public ResponseEntity deleteReceivedCard( } // 사용자가 속한 파티 목록 조회 - @GetMapping("/parties") - public ResponseEntity> getUserPartyIds(@RequestParam("user_id") Long userId) { + @Operation(summary = "사용자가 속한 파티 목록 조회", description = "사용자가 속한 파티 목록 조회") + @GetMapping("/{userId}/parties") + public ResponseEntity> getUserPartyIds(@PathVariable("userId") Long userId) { try { List userPartyIds = userService.getUserPartyIds(userId); return ResponseEntity.ok(userPartyIds); @@ -71,6 +81,7 @@ public ResponseEntity> getUserPartyIds(@RequestParam("user_id") Long } // 파티에서 탈퇴 + @Operation(summary = "내 그룹에서 파티 삭제", description = "내 그룹에서 파티 삭제(파티에서 탈퇴)") @DeleteMapping("/party/{party_id}") // 내 그룹에서 파티 삭제 public ResponseEntity deletePartyInUserGroup( @RequestParam("user_id") Long userId, diff --git a/submodule-data b/submodule-data deleted file mode 160000 index a232308..0000000 --- a/submodule-data +++ /dev/null @@ -1 +0,0 @@ -Subproject commit a232308a0257c81317ac65243cda20462771ebf5