Skip to content

Commit

Permalink
Merge pull request #112 from Hanaemong/hyeonu
Browse files Browse the repository at this point in the history
Feat: get nickname #111
  • Loading branch information
khw18 authored Jul 8, 2024
2 parents bbb9fdd + b6b08b5 commit f6c0549
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.hana.hanalink.common.dto.SuccessResponse;
import com.hana.hanalink.meetingacount.service.MeetingAccountService;
import com.hana.hanalink.member.domain.MemberDetails;
import com.hana.hanalink.teammember.dto.MyTeamMemberRes;
import com.hana.hanalink.teammember.dto.TeamMemberRes;
import com.hana.hanalink.teammember.dto.TeamMemberRoleChangeReq;
import com.hana.hanalink.teammember.service.TeamMemberService;
Expand All @@ -27,10 +28,16 @@ public SuccessResponse<List<TeamMemberRes>> getTeamMemberList(@PathVariable("tea
return SuccessResponse.success(teamMemberService.getTeamMembers(teamId));
}

@GetMapping("/my/{teamId}")
public SuccessResponse<MyTeamMemberRes> getMyNickname(@AuthenticationPrincipal MemberDetails member, @PathVariable("teamId") Long teamId) {
return SuccessResponse.success(teamMemberService.getMyNickname(member, teamId));
}

/*모임원 내보내기*/
@DeleteMapping("/{teamMemberId}")
public SuccessResponse<Long> deleteTeamMember(@PathVariable("teamMemberId") Long teamMemberId, @RequestParam("type") String type, @AuthenticationPrincipal MemberDetails member) {
teamMemberService.deleteTeamMember(teamMemberId,type,member);

teamMemberService.deleteTeamMember(teamMemberId, type, member);
return SuccessResponse.successWithNoData();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.hana.hanalink.teammember.dto;

public record MyTeamMemberRes(String nickname) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
import lombok.Builder;

@Builder
public record TeamMemberRes(Long teamMemberId,String profile, String nickName, String gender, TeamMemberRole role) {
public record TeamMemberRes(Long teamMemberId, String profile, String nickName, String gender, TeamMemberRole role) {

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package com.hana.hanalink.teammember.dto;

public record TeamMemberRoleChangeReq( Long ToChairId){
public record TeamMemberRoleChangeReq(Long ToChairId) {

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,10 @@ public interface TeamMemberRepository extends JpaRepository<TeamMember,Long> {
List<TeamMember> findTeamMemberByTeam_TeamId(Long teamId);
List<TeamMember> findTeamMembersByTeam_TeamIdAndRole(Long teamId, TeamMemberRole role);
Integer countByTeamAndRoleNot(Team team, TeamMemberRole role);

TeamMember findTeamMemberByTeam_TeamIdAndRole(Long teamId, TeamMemberRole role);
List<TeamMember> findByMember(Member member);

Optional<TeamMember> findByMemberAndTeam(Member member, Team team);

Optional<TeamMember> findByMemberAndTeam_TeamId(Member member, Long teamId);

Boolean existsByNickname(String nickname);


}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@
import com.hana.hanalink.member.domain.MemberDetails;
import com.hana.hanalink.member.exception.MemberNotFoundException;
import com.hana.hanalink.member.repository.MemberRepository;
import com.hana.hanalink.team.domain.Team;
import com.hana.hanalink.team.exception.TeamNotFoundException;
import com.hana.hanalink.team.repository.TeamRepository;
import com.hana.hanalink.teammember.domain.TeamMember;
import com.hana.hanalink.teammember.domain.TeamMemberRole;
import com.hana.hanalink.teammember.dto.MyTeamMemberRes;
import com.hana.hanalink.teammember.dto.TeamMemberRes;
import com.hana.hanalink.teammember.exception.TeamMemberNotFoundException;
import com.hana.hanalink.teammember.repository.TeamMemberRepository;
Expand All @@ -16,11 +20,13 @@
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Optional;

@Service
@RequiredArgsConstructor
public class TeamMemberService {

private final TeamRepository teamRepository;
private final TeamMemberRepository teamMemberRepository;
private final FirebaseFcmService firebaseFcmService;
private final MemberRepository memberRepository;
Expand All @@ -31,6 +37,14 @@ public List<TeamMemberRes> getTeamMembers(Long teamId) {
).toList();
}

public MyTeamMemberRes getMyNickname(MemberDetails memberDetails, Long teamId) {
Member member = memberRepository.findByPhone(memberDetails.getUsername()).orElseThrow(MemberNotFoundException::new);
Team team = teamRepository.findById(teamId).orElseThrow(TeamNotFoundException::new);
TeamMember teamMember = teamMemberRepository.findByMemberAndTeam(member, team).orElseThrow(TeamMemberNotFoundException::new);

return new MyTeamMemberRes(teamMember.getNickname());
}

@Transactional
public void deleteTeamMember(Long teamMemberId, String type, MemberDetails memberDetails) {
TeamMember teamMember = teamMemberRepository.findById(teamMemberId).orElseThrow(TeamMemberNotFoundException::new);
Expand Down

0 comments on commit f6c0549

Please sign in to comment.