Skip to content

Commit

Permalink
[MERGE/#93] 선배 카드 정보 조회 구현
Browse files Browse the repository at this point in the history
[FEAT] #93 - 선배 카드 정보 조회 구현
  • Loading branch information
seokbeom00 authored Jul 15, 2024
2 parents 0617fce + 64bd890 commit d7f6ff1
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
package org.sopt.seonyakServer.domain.member.dto;

import com.fasterxml.jackson.annotation.JsonInclude;

@JsonInclude(JsonInclude.Include.NON_NULL)
public record MemberJoinResponse(
Long seniorId,
String role
) {
public static MemberJoinResponse of(final String role) {
return new MemberJoinResponse(role);
public static MemberJoinResponse of(
final Long seniorId,
final String role
) {
return new MemberJoinResponse(
seniorId,
role
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,8 @@ public void updateMember(
this.departmentList = department;
}
}

public void addSenior(Senior senior) {
this.senior = senior;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,15 @@ public MemberJoinResponse patchMemberJoin(MemberJoinRequest memberJoinRequest) {

memberRepository.save(member);

Long seniorId = null;
if (memberJoinRequest.role().equals("SENIOR")) {
return MemberJoinResponse.of(seniorService.createSenior(memberJoinRequest, member));
member.addSenior(seniorService.createSenior(memberJoinRequest, member));
seniorId = member.getSenior().getId();
}

return MemberJoinResponse.of(memberJoinRequest.role());
return MemberJoinResponse.of(
seniorId,
memberJoinRequest.role()
);
}

public void sendMessage(SendCodeRequest sendCodeRequest) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.List;
import lombok.RequiredArgsConstructor;
import org.sopt.seonyakServer.domain.senior.dto.SeniorCardProfileResponse;
import org.sopt.seonyakServer.domain.senior.dto.SeniorListResponse;
import org.sopt.seonyakServer.domain.senior.dto.SeniorProfileRequest;
import org.sopt.seonyakServer.domain.senior.dto.SeniorProfileResponse;
Expand Down Expand Up @@ -52,4 +53,11 @@ public ResponseEntity<SeniorProfileResponse> getSeniorProfile(
) {
return ResponseEntity.ok(seniorService.getSeniorProfile(seniorId));
}

@GetMapping("/card/{seniorId}")
public ResponseEntity<SeniorCardProfileResponse> getSeniorCardProfile(
@PathVariable final Long seniorId
) {
return ResponseEntity.ok(seniorService.getSeniorCardProfile(seniorId));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.sopt.seonyakServer.domain.senior.dto;

public record SeniorCardProfileResponse(
String nickname,
String company,
String field,
String position,
String detailPosition,
String level
) {
public static SeniorCardProfileResponse of(
final String nickname,
final String company,
final String field,
final String position,
final String detailPosition,
final String level
) {
return new SeniorCardProfileResponse(
nickname,
company,
field,
position,
detailPosition,
level
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import lombok.RequiredArgsConstructor;
import org.sopt.seonyakServer.domain.member.dto.MemberJoinRequest;
import org.sopt.seonyakServer.domain.member.model.Member;
import org.sopt.seonyakServer.domain.member.repository.MemberRepository;
import org.sopt.seonyakServer.domain.senior.dto.SeniorCardProfileResponse;
import org.sopt.seonyakServer.domain.senior.dto.SeniorListResponse;
import org.sopt.seonyakServer.domain.senior.dto.SeniorProfileRequest;
import org.sopt.seonyakServer.domain.senior.dto.SeniorProfileResponse;
Expand All @@ -20,11 +22,12 @@
@RequiredArgsConstructor
public class SeniorService {

private final MemberRepository memberRepository;
private final SeniorRepository seniorRepository;
private final PrincipalHandler principalHandler;

@Transactional
public String createSenior(final MemberJoinRequest memberJoinRequest, Member member) {
public Senior createSenior(final MemberJoinRequest memberJoinRequest, Member member) {

Senior senior = Senior.create(
member,
Expand All @@ -35,9 +38,7 @@ public String createSenior(final MemberJoinRequest memberJoinRequest, Member mem
memberJoinRequest.level()
);

seniorRepository.save(senior);

return memberJoinRequest.role();
return seniorRepository.save(senior);
}

@Transactional
Expand Down Expand Up @@ -78,4 +79,18 @@ public SeniorProfileResponse getSeniorProfile(final Long seniorId) {
senior.getStory()
);
}

@Transactional(readOnly = true)
public SeniorCardProfileResponse getSeniorCardProfile(final Long seniorId) {
Senior senior = seniorRepository.findSeniorByIdOrThrow(seniorId);

return SeniorCardProfileResponse.of(
senior.getMember().getNickname(),
senior.getCompany(),
senior.getMember().getField(),
senior.getPosition(),
senior.getDetailPosition(),
senior.getLevel()
);
}
}

0 comments on commit d7f6ff1

Please sign in to comment.