-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into feature/#36/TIL
- Loading branch information
Showing
27 changed files
with
806 additions
and
164 deletions.
There are no files selected for viewing
77 changes: 77 additions & 0 deletions
77
src/main/java/com/umc/networkingService/domain/friend/controller/FriendController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package com.umc.networkingService.domain.friend.controller; | ||
|
||
import com.umc.networkingService.config.security.auth.CurrentMember; | ||
import com.umc.networkingService.domain.friend.dto.response.FriendIdResponse; | ||
import com.umc.networkingService.domain.friend.dto.response.FriendInquiryByStatusResponse; | ||
import com.umc.networkingService.domain.friend.service.FriendService; | ||
import com.umc.networkingService.domain.member.entity.Member; | ||
import com.umc.networkingService.global.common.base.BaseResponse; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
import io.swagger.v3.oas.annotations.Parameters; | ||
import io.swagger.v3.oas.annotations.enums.ParameterIn; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.domain.Sort; | ||
import org.springframework.data.web.PageableDefault; | ||
import org.springframework.security.core.parameters.P; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
@Tag(name = "์น๊ตฌ API", description = "์น๊ตฌ ๊ด๋ จ API") | ||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/friends") | ||
public class FriendController { | ||
|
||
private final FriendService friendService; | ||
|
||
@Operation(summary = "์น๊ตฌ ์ถ๊ฐ API", description = "์๋ก์ด ์น๊ตฌ๋ฅผ ์ถ๊ฐํ๋ API์ ๋๋ค.") | ||
@ApiResponses(value = { | ||
@ApiResponse(responseCode = "COMMON200", description = "์ฑ๊ณต"), | ||
@ApiResponse(responseCode = "MEMBER001", description = "์กด์ฌํ์ง ์๋ ๋ฉค๋ฒ๋ฅผ ์น๊ตฌ ์ถ๊ฐํ ๊ฒฝ์ฐ ๋ฐ์"), | ||
@ApiResponse(responseCode = "FRIEND001", description = "์ด๋ฏธ ์น๊ตฌ ๊ด๊ณ์ผ ๊ฒฝ์ฐ ๋ฐ์") | ||
}) | ||
@Parameter(name = "memberId", in = ParameterIn.PATH, required = true, description = "์น๊ตฌ ์ถ๊ฐํ ๋ฉค๋ฒ id์ ๋๋ค.") | ||
@PostMapping("/{memberId}") | ||
public BaseResponse<FriendIdResponse> createNewFriend(@CurrentMember Member member, | ||
@PathVariable UUID memberId) { | ||
return BaseResponse.onSuccess(friendService.createNewFriend(member, memberId)); | ||
} | ||
|
||
@Operation(summary = "์น๊ตฌ ์ญ์ API", description = "์น๊ตฌ ๊ด๊ณ๋ฅผ ์ญ์ ํ๋ API์ ๋๋ค.") | ||
@ApiResponses(value = { | ||
@ApiResponse(responseCode = "COMMON200", description = "์ฑ๊ณต"), | ||
@ApiResponse(responseCode = "MEMBER001", description = "์กด์ฌํ์ง ์๋ ๋ฉค๋ฒ๋ฅผ ์น๊ตฌ ์ญ์ ํ ๊ฒฝ์ฐ ๋ฐ์"), | ||
@ApiResponse(responseCode = "FRIEND002", description = "์น๊ตฌ ๊ด๊ณ๊ฐ ์๋๋ฐ ์ญ์ ํ ๊ฒฝ์ฐ ๋ฐ์") | ||
}) | ||
@Parameter(name = "memberId", in = ParameterIn.PATH, required = true, description = "์น๊ตฌ ์ญ์ ํ ๋ฉค๋ฒ id์ ๋๋ค.") | ||
@DeleteMapping("/{memberId}") | ||
public BaseResponse<FriendIdResponse> deleteFriend(@CurrentMember Member member, | ||
@PathVariable UUID memberId) { | ||
return BaseResponse.onSuccess(friendService.deleteFriend(member, memberId)); | ||
} | ||
|
||
@Operation(summary = "์ ์/๋น์ ์ ์ค์ธ ์น๊ตฌ ๋ชฉ๋ก ์กฐํ API", description = "์น๊ตฌ ๊ด๊ณ์ธ ๋ฉค๋ฒ ์ค ์ ์ ๋๋ ๋น์ ์ ์ค์ธ ๋ฉค๋ฒ ์กฐํ API์ ๋๋ค.") | ||
@ApiResponses(value = { | ||
@ApiResponse(responseCode = "COMMON200", description = "์ฑ๊ณต") | ||
}) | ||
@Parameters(value = { | ||
@Parameter(name = "status", required = true, description = "์ ์ ์ํ์ ๋๋ค."), | ||
@Parameter(name = "pageable", hidden = true), | ||
@Parameter(name = "size", required = true, description = "ํ ํ์ด์ง์ ํฌํจ๋๋ ๋ชฉ๋ก ๊ฐ์์ ๋๋ค.") | ||
}) | ||
@GetMapping | ||
public BaseResponse<FriendInquiryByStatusResponse> inquiryFriendsByStatus( | ||
@CurrentMember Member member, | ||
@RequestParam boolean status, | ||
@PageableDefault(page = 1, sort = "receiver.nickname", direction = Sort.Direction.ASC) Pageable pageable) { | ||
return BaseResponse.onSuccess(friendService.inquiryFriendsByStatus(member, status, pageable)); | ||
} | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/umc/networkingService/domain/friend/dto/response/FriendIdResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.umc.networkingService.domain.friend.dto.response; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
import java.util.UUID; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public class FriendIdResponse { | ||
private UUID friendId; | ||
} |
34 changes: 34 additions & 0 deletions
34
...a/com/umc/networkingService/domain/friend/dto/response/FriendInquiryByStatusResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.umc.networkingService.domain.friend.dto.response; | ||
|
||
import com.umc.networkingService.domain.member.dto.SemesterPartInfo; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
@Getter | ||
@Builder | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class FriendInquiryByStatusResponse { | ||
private List<FriendInfo> friends; | ||
private boolean hasNext; | ||
|
||
@Getter | ||
@Builder | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public static class FriendInfo { | ||
private UUID memberId; | ||
private String nickname; | ||
private String name; | ||
private String profileImage; | ||
private String universityName; | ||
private List<String> campusPositions; | ||
private List<String> centerPositions; | ||
private List<SemesterPartInfo> semesterParts; | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/com/umc/networkingService/domain/friend/mapper/FriendMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.umc.networkingService.domain.friend.mapper; | ||
|
||
import com.umc.networkingService.domain.friend.dto.response.FriendInquiryByStatusResponse; | ||
import com.umc.networkingService.domain.friend.entity.Friend; | ||
import com.umc.networkingService.domain.member.dto.SemesterPartInfo; | ||
import com.umc.networkingService.domain.member.entity.Member; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.List; | ||
|
||
@Component | ||
public class FriendMapper { | ||
|
||
public Friend toFriend(Member sender, Member receiver) { | ||
return Friend.builder() | ||
.sender(sender) | ||
.receiver(receiver) | ||
.build(); | ||
} | ||
|
||
public FriendInquiryByStatusResponse.FriendInfo toFriendInfo(Member member, | ||
List<String> campusPositions, | ||
List<String> centerPositions, | ||
List<SemesterPartInfo> semesterParts) { | ||
return FriendInquiryByStatusResponse.FriendInfo.builder() | ||
.memberId(member.getId()) | ||
.nickname(member.getNickname()) | ||
.name(member.getName()) | ||
.profileImage(member.getProfileImage()) | ||
.universityName(member.getUniversity().getName()) | ||
.campusPositions(campusPositions) | ||
.centerPositions(centerPositions) | ||
.semesterParts(semesterParts) | ||
.build(); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
src/main/java/com/umc/networkingService/domain/friend/service/FriendService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,15 @@ | ||
package com.umc.networkingService.domain.friend.service; | ||
|
||
import com.umc.networkingService.domain.friend.dto.response.FriendIdResponse; | ||
import com.umc.networkingService.domain.friend.dto.response.FriendInquiryByStatusResponse; | ||
import com.umc.networkingService.domain.member.entity.Member; | ||
import org.springframework.data.domain.Pageable; | ||
|
||
import java.util.UUID; | ||
|
||
public interface FriendService { | ||
FriendIdResponse createNewFriend(Member member, UUID memberId); | ||
FriendIdResponse deleteFriend(Member member, UUID memberId); | ||
FriendInquiryByStatusResponse inquiryFriendsByStatus(Member member, boolean status, Pageable pageable); | ||
boolean checkFriend(Member sender, Member receiver); | ||
} |
73 changes: 73 additions & 0 deletions
73
src/main/java/com/umc/networkingService/domain/friend/service/FriendServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,91 @@ | ||
package com.umc.networkingService.domain.friend.service; | ||
|
||
import com.umc.networkingService.domain.friend.dto.response.FriendIdResponse; | ||
import com.umc.networkingService.domain.friend.dto.response.FriendInquiryByStatusResponse; | ||
import com.umc.networkingService.domain.friend.entity.Friend; | ||
import com.umc.networkingService.domain.friend.mapper.FriendMapper; | ||
import com.umc.networkingService.domain.friend.repository.FriendRepository; | ||
import com.umc.networkingService.domain.member.entity.Member; | ||
import com.umc.networkingService.domain.member.entity.PositionType; | ||
import com.umc.networkingService.domain.member.mapper.MemberMapper; | ||
import com.umc.networkingService.domain.member.service.MemberService; | ||
import com.umc.networkingService.global.common.exception.ErrorCode; | ||
import com.umc.networkingService.global.common.exception.RestApiException; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class FriendServiceImpl implements FriendService { | ||
|
||
private final FriendRepository friendRepository; | ||
private final FriendMapper friendMapper; | ||
private final MemberMapper memberMapper; | ||
|
||
private final MemberService memberService; | ||
|
||
// ์น๊ตฌ ์ถ๊ฐ ํจ์ | ||
@Override | ||
public FriendIdResponse createNewFriend(Member member, UUID memberId) { | ||
Member loginMember = memberService.loadEntity(member.getId()); | ||
|
||
Member friendMember = memberService.loadEntity(memberId); | ||
|
||
if (friendRepository.existsBySenderAndReceiver(loginMember, friendMember)) | ||
throw new RestApiException(ErrorCode.ALREADY_FRIEND_RELATION); | ||
|
||
return createAndSaveNewFriend(loginMember, friendMember); | ||
} | ||
|
||
// ์น๊ตฌ ์ญ์ ํจ์ | ||
@Override | ||
public FriendIdResponse deleteFriend(Member member, UUID memberId) { | ||
Member loginMember = memberService.loadEntity(member.getId()); | ||
|
||
Member friendMember = memberService.loadEntity(memberId); | ||
|
||
// ์กด์ฌํ์ง ์์ ๊ฒฝ์ฐ ์์ธ ์ฒ๋ฆฌ | ||
Friend friend = friendRepository.findBySenderAndReceiver(loginMember, friendMember) | ||
.orElseThrow(() -> new RestApiException(ErrorCode.NOT_FRIEND_RELATION)); | ||
|
||
friend.delete(); | ||
|
||
return new FriendIdResponse(friend.getId()); | ||
} | ||
|
||
@Override | ||
public FriendInquiryByStatusResponse inquiryFriendsByStatus(Member member, boolean status, Pageable pageable) { | ||
LocalDateTime fiveMinutesAgo = LocalDateTime.now().minusMinutes(5); | ||
Page<Member> friends = friendRepository.findFriendsByStatus(member, status, fiveMinutesAgo, pageable); | ||
|
||
List<FriendInquiryByStatusResponse.FriendInfo> friendInfos = friends.stream() | ||
.map(friend -> friendMapper.toFriendInfo( | ||
friend, | ||
memberService.getPositionNamesByType(friend, PositionType.CAMPUS), | ||
memberService.getPositionNamesByType(friend, PositionType.CENTER), | ||
memberMapper.toSemesterPartInfos(friend.getSemesterParts()) | ||
)).toList(); | ||
|
||
|
||
return new FriendInquiryByStatusResponse(friendInfos, friends.hasNext()); | ||
} | ||
|
||
// ์น๊ตฌ ์ฌ๋ถ ํ์ธ ํจ์ | ||
@Override | ||
public boolean checkFriend(Member sender, Member receiver) { | ||
return friendRepository.existsBySenderAndReceiver(sender, receiver); | ||
} | ||
|
||
private FriendIdResponse createAndSaveNewFriend(Member loginMember, Member friendMember) { | ||
Friend friend = friendMapper.toFriend(loginMember, friendMember); | ||
UUID savedFriendId = friendRepository.save(friend).getId(); | ||
|
||
return new FriendIdResponse(savedFriendId); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/umc/networkingService/domain/friend/service/FriendShipService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.umc.networkingService.domain.friend.service; | ||
|
||
|
||
import com.umc.networkingService.domain.member.dto.response.MemberInquiryProfileResponse; | ||
import com.umc.networkingService.domain.member.entity.Member; | ||
|
||
import java.util.UUID; | ||
|
||
public interface FriendShipService { | ||
MemberInquiryProfileResponse inquiryProfile(Member member, UUID memberId); | ||
} |
44 changes: 44 additions & 0 deletions
44
src/main/java/com/umc/networkingService/domain/friend/service/FriendShipServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.umc.networkingService.domain.friend.service; | ||
|
||
import com.umc.networkingService.domain.friend.repository.FriendRepository; | ||
import com.umc.networkingService.domain.member.dto.response.MemberInquiryProfileResponse; | ||
import com.umc.networkingService.domain.member.entity.Member; | ||
import com.umc.networkingService.domain.member.entity.MemberRelation; | ||
import com.umc.networkingService.domain.member.mapper.MemberMapper; | ||
import com.umc.networkingService.domain.member.repository.MemberRepository; | ||
import com.umc.networkingService.domain.member.service.MemberService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.UUID; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class FriendShipServiceImpl implements FriendShipService{ | ||
private final FriendService friendService; | ||
private final MemberService memberService; | ||
|
||
private final MemberMapper memberMapper; | ||
|
||
// ํ๋กํ ์กฐํ ํจ์ | ||
@Override | ||
public MemberInquiryProfileResponse inquiryProfile(Member member, UUID memberId) { | ||
|
||
Member loginMember = memberService.loadEntity(member.getId()); | ||
// ๋ณธ์ธ ํ๋กํ ์กฐํ์ธ ๊ฒฝ์ฐ | ||
if (memberId == null || loginMember.getId().equals(memberId)) { | ||
return memberMapper.toInquiryProfileResponse(loginMember, MemberRelation.MINE); | ||
} | ||
|
||
Member inquiryMember = memberService.loadEntity(memberId); | ||
|
||
// ์น๊ตฌ ํ๋กํ ์กฐํ์ธ ๊ฒฝ์ฐ | ||
if (friendService.checkFriend(loginMember, inquiryMember)) { | ||
return memberMapper.toInquiryProfileResponse(inquiryMember, MemberRelation.FRIEND); | ||
} | ||
|
||
// ์ด์ธ์ ํ๋กํ ์กฐํ์ธ ๊ฒฝ์ฐ | ||
return memberMapper.toInquiryProfileResponse(inquiryMember, MemberRelation.OTHERS); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.