Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ out/

### VS Code ###
.vscode/
.DS_Store
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/com/example/profileem/config/SwaggerConfig.java
Original file line number Diff line number Diff line change
@@ -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");
}
}
60 changes: 54 additions & 6 deletions src/main/java/com/example/profileem/controller/CardController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -10,6 +12,8 @@
import java.util.List;
import java.util.Optional;


@Tag(name = "Card")
@RestController
@RequestMapping("/card")
public class CardController {
Expand All @@ -21,21 +25,22 @@ public CardController(CardRepository cardRepository) {
this.cardRepository = cardRepository;
}

@PostMapping("/") // 내 프로필 카드 등록 -- 수정해야 될 내용 : 등록할 때 카카오 로그인 userid를 Card의 userid로 넘겨줘야함
@Operation(summary = "내 프로필 카드 등록", description = "내 프로필 카드 등록")
@PostMapping("/")
public ResponseEntity<Card> createCard(@RequestBody Card card) {

// 나머지 카드 정보 설정하고 저장
Card savedCard = cardRepository.save(card);
return new ResponseEntity<>(savedCard, HttpStatus.CREATED);
}

@GetMapping("/{userId}") // 내 프로필 카드 전체 조회
@Operation(summary = "내 프로필 카드 전체 조회", description = "내 프로필 카드 전체 조회")
@GetMapping("/{userId}")
public ResponseEntity<List<Card>> getCardsByUserId(@PathVariable Long userId) {
List<Card> cards = cardRepository.findByUserUserId(userId);
return new ResponseEntity<>(cards, HttpStatus.OK);
}

@GetMapping("/card/{userId}/{cardId}") // 내 프로필 카드 특정 조회
@Operation(summary = "내 프로필 카드 특정 조회", description = "내 프로필 카드 특정 조회")
@GetMapping("/{userId}/{cardId}")
public ResponseEntity<Card> getCardByUserIdAndCardId(
@PathVariable Long userId,
@PathVariable Long cardId) {
Expand All @@ -45,7 +50,8 @@ public ResponseEntity<Card> getCardByUserIdAndCardId(
.orElseGet(() -> new ResponseEntity<>(HttpStatus.NOT_FOUND));
}

@DeleteMapping("/{userId}/{cardId}") // 내 프로필 카드 특정 삭제
@Operation(summary = "내 프로필 카드 특정 삭제", description = "내 프로필 카드 특정 삭제")
@DeleteMapping("/{userId}/{cardId}")
public ResponseEntity<String> deleteCardByUserIdAndCardId(
@PathVariable Long userId,
@PathVariable Long cardId) {
Expand All @@ -57,4 +63,46 @@ public ResponseEntity<String> deleteCardByUserIdAndCardId(
return new ResponseEntity<>("Card not found.", HttpStatus.NOT_FOUND);
}
}

@Operation(summary = "내 프로필 카드 수정", description = "내 프로필 카드 수정")
@PutMapping("/{userId}/{cardId}")
public ResponseEntity<String> updateCardByUserIdAndCardId(
@PathVariable Long userId, @PathVariable Long cardId,
@RequestBody Card updatedCard) {
Optional<Card> 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);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -22,40 +23,43 @@ public class NoticeController {
public NoticeController(NoticeService noticeService) {this.noticeService = noticeService; }

// 공지사항 등록 (관리자만 하도록 수정해야함)
@Operation(summary = "공지사항 등록", description = "공지사항 등록")
@PostMapping("/")
public ResponseEntity<Notice> createNotice(@RequestBody Notice notice) {
Notice createdNotice = noticeService.createNotice(notice);
return ResponseEntity.status(HttpStatus.CREATED).body(createdNotice);
}

// 공지사항 조회
// 공지사항 전체 조회
@Operation(summary = "공지사항 전체 조회", description = "공지사항 전체 조회")
@GetMapping("/all")
public ResponseEntity<List<Notice>> getAllNotices() {
List<Notice> notices = noticeService.getAllNotices();
return ResponseEntity.status(HttpStatus.OK).body(notices);
}
// 공지사항 하나 조회
@Operation(summary = "공지사항 하나 조회", description = "공지사항 하나 조회")
@GetMapping("/{notice_id}")
public ResponseEntity<Notice> getNoticeById(@PathVariable Long notice_id) {
Optional<Notice> notice = noticeService.getNoticeById(notice_id);
return notice.map(ResponseEntity::ok).orElseGet(() -> ResponseEntity.notFound().build());
}

// 공지사항 수정 (관리자만 하도록 수정해야함)

@Operation(summary = "공지사항 수정", description = "공지사항 수정")
@PutMapping("/{notice_id}")
public ResponseEntity<Notice> updateNotice(@PathVariable Long notice_id, @RequestBody Notice newNotice) {
Notice updatedNotice = noticeService.updateNotice(notice_id, newNotice);
return ResponseEntity.status(HttpStatus.OK).body(updatedNotice);
}

// 공지사항 삭제 (관리자만 하도록 수정해야함)
@Operation(summary = "공지사항 삭제", description = "공지사항 삭제")
@DeleteMapping("/{notice_id}")
public ResponseEntity<String> deleteNotice(@PathVariable Long notice_id) {
noticeService.deleteNotice(notice_id);
return ResponseEntity.noContent().build();
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -21,7 +24,7 @@ public PartyController(PartyService partyService) {
}

// 내가 방장인 파티 생성
// 파티 생성
@Operation(summary = "(내가 방장인 파티) 파티 생성", description = "(내가 방장인 파티) 파티 생성")
@PostMapping("/")
public ResponseEntity<Party> createParty(@RequestBody Party party) {

Expand All @@ -34,7 +37,9 @@ public ResponseEntity<Party> createParty(@RequestBody Party party) {
}

// 사용자를 파티에 초대
@PostMapping("/invitation/{party_id}")
@Operation(summary = "파티에 사용자 초대", description = "파티에 사용자 초대")
@PostMapping("/{partyId}/invitation")

public ResponseEntity<String> inviteUserToParty(
@PathVariable("party_id") Long partyId,
@RequestParam("user_id") Long userId) {
Expand All @@ -50,7 +55,9 @@ public ResponseEntity<String> inviteUserToParty(


// 파티에 카드 등록
@PostMapping("/card/{party_id}")
@Operation(summary = "파티에 카드 등록", description = "파티에 카드 등록")
@PostMapping("/{partyId}/card")

public ResponseEntity<String> addCardToParty(
@PathVariable("party_id") Long partyId,
@RequestParam("card_id") Long cardId) {
Expand All @@ -63,7 +70,8 @@ public ResponseEntity<String> addCardToParty(
}

// 파티에 등록했던 카드 교체
@PutMapping("/card/{party_id}")
@Operation(summary = "파티에 등록했던 카드 교체", description = "파티에 등록했던 카드 교체")
@PutMapping("/{partyId}/card")
public ResponseEntity<String> replacePartyCard(
@PathVariable("party_id") Long partyId,
@RequestParam("old_card_id") Long oldCardId,
Expand All @@ -80,4 +88,5 @@ public ResponseEntity<String> replacePartyCard(




}
23 changes: 17 additions & 6 deletions src/main/java/com/example/profileem/controller/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -23,7 +27,9 @@ public UserController(UserService userService) {
}

// 사용자가 받은 개인 프로필 카드 ID 추가
@PostMapping("/card/{card_id}")
@Operation(summary = "사용자가 받은 개인 프로필 카드 ID 추가", description = "사용자가 받은 개인 프로필 카드 ID 추가")
@PostMapping("/{user_id}/card")

public ResponseEntity<String> addReceivedCardId(
@RequestParam("user_id") Long userId,
@PathVariable("card_id") Long cardId) {
Expand All @@ -36,8 +42,9 @@ public ResponseEntity<String> addReceivedCardId(
}

// 사용자가 받은 개인 프로필 카드 ID 목록 조희
@GetMapping("/cards")
public ResponseEntity<List<Long>> getReceivedCardIds(@RequestParam("user_id") Long userId) {
@Operation(summary = "사용자가 받은 개인 프로필 카드 ID 목록 조희", description = "사용자가 받은 개인 프로필 카드 ID 목록 조희")
@GetMapping("/{user_id}/cards")
public ResponseEntity<List<Long>> getReceivedCardIds(@PathVariable("user_id") Long userId) {
try {
List<Long> receivedCardIds = userService.getReceivedCardIds(userId);
return ResponseEntity.ok(receivedCardIds);
Expand All @@ -47,7 +54,9 @@ public ResponseEntity<List<Long>> getReceivedCardIds(@RequestParam("user_id") Lo
}

// 사용자가 받은 개인 프로필 카드 삭제
@DeleteMapping("/card/{card_id}")
@Operation(summary = "사용자가 받은 개인 프로필 카드 삭제", description = "사용자가 받은 개인 프로필 카드 삭제")
@DeleteMapping("/{user_id}/{card_id}")

public ResponseEntity<String> deleteReceivedCard(
@RequestParam("user_id") Long userId,
@PathVariable("card_id") Long cardId) {
Expand All @@ -60,8 +69,9 @@ public ResponseEntity<String> deleteReceivedCard(
}

// 사용자가 속한 파티 목록 조회
@GetMapping("/parties")
public ResponseEntity<List<Long>> getUserPartyIds(@RequestParam("user_id") Long userId) {
@Operation(summary = "사용자가 속한 파티 목록 조회", description = "사용자가 속한 파티 목록 조회")
@GetMapping("/{userId}/parties")
public ResponseEntity<List<Long>> getUserPartyIds(@PathVariable("userId") Long userId) {
try {
List<Long> userPartyIds = userService.getUserPartyIds(userId);
return ResponseEntity.ok(userPartyIds);
Expand All @@ -71,6 +81,7 @@ public ResponseEntity<List<Long>> getUserPartyIds(@RequestParam("user_id") Long
}

// 파티에서 탈퇴
@Operation(summary = "내 그룹에서 파티 삭제", description = "내 그룹에서 파티 삭제(파티에서 탈퇴)")
@DeleteMapping("/party/{party_id}") // 내 그룹에서 파티 삭제
public ResponseEntity<String> deletePartyInUserGroup(
@RequestParam("user_id") Long userId,
Expand Down
1 change: 0 additions & 1 deletion submodule-data
Submodule submodule-data deleted from a23230