Skip to content

Commit

Permalink
[FIX] #87 MembershipResponse에 OfficeId 추가
Browse files Browse the repository at this point in the history
- 엔티티에 칼럼 추가
- Response에 받도록 추가
- CompanyMembership 생성 시 url로 officeId 받도록 수정
  • Loading branch information
c0smosaur committed Jun 8, 2024
1 parent 6b0a9bc commit 0f7c30a
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
@NoArgsConstructor
public abstract class BaseMembershipEntity extends BaseEntity{

private Long officeId;
private String location;
private Long price;
private Integer duration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ public CompanyResponse toCompanyResponse(Company company) {
.build();
}

public CompanyMembership toCompanyMembership(CompanyMembershipRequest request,
public CompanyMembership toCompanyMembership(Long officeId,
CompanyMembershipRequest request,
Long companyId){
return CompanyMembership.builder()
.location(request.getLocation())
.officeId(officeId)
.type(MembershipType.COMPANY_PASS)
.price(request.getPrice())
.duration(request.getDuration())
Expand All @@ -49,6 +51,7 @@ public CompanyMembership toCompanyMembership(CompanyMembershipRequest request,
public MembershipResponse toMembershipResponse(CompanyMembership companyMembership) {
return MembershipResponse.builder()
.id(companyMembership.getId())
.officeId(companyMembership.getOfficeId())
.type(companyMembership.getType().getName())
.location(companyMembership.getLocation())
.duration(companyMembership.getDuration())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@ public class CompanyMembershipService {
// 기업 생성, 기업 멤버십 생성
@Transactional
public CompanyMembershipRegistrationResponse registerCompanyMembership(
Long officeId,
CompanyMembershipRegistrationRequest request) {
if (request.getCompany().isConsentContact()){
Company company = saveCompany(request.getCompany());
CompanyMembership companyMembership =
saveCompanyMembership(request.getCompanyMembership(), company.getId());
saveCompanyMembership(officeId, request.getCompanyMembership(), company.getId());

String authCode = authCodeUtils.createCompanyAuthCode();
sendCompanyAuthCode(company, authCode);
Expand Down Expand Up @@ -70,12 +71,13 @@ public void sendCompanyAuthCode(Company company, String authCode) {
}

// 기업 멤버십 생성
public CompanyMembership saveCompanyMembership(CompanyMembershipRequest request,
public CompanyMembership saveCompanyMembership(Long officeId,
CompanyMembershipRequest request,
Long companyId) {

return companyMembershipRepository.save(
companyMembershipConverter.toCompanyMembership(
request, companyId));
officeId, request, companyId));
}

public Company saveCompany(CompanyRequest request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@
@Converter
public class IndividualMembershipConverter {

public IndividualMembership toIndividualMembershipEntity(IndividualMembershipRequest request, Member member) {
public IndividualMembership toIndividualMembershipEntity(Long officeId,
IndividualMembershipRequest
request, Member member) {
MembershipType membershipType = MembershipType.fromKor(request.getType());
return IndividualMembership.builder()
.location(request.getLocation())
.officeId(officeId)
.type(membershipType)
.duration(request.getDuration())
.startDate(request.getStartDate().atStartOfDay())
Expand All @@ -28,6 +31,7 @@ public MembershipResponse toMembershipResponse(IndividualMembership individualMe
.type(individualMembership.getType().getName())
.id(individualMembership.getId())
.location(individualMembership.getLocation())
.officeId(individualMembership.getOfficeId())
.price(individualMembership.getPrice())
.duration(individualMembership.getDuration())
.startDate(individualMembership.getStartDate().toLocalDate())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ public class IndividualMembershipService {
private final IndividualMembershipRepository individualMembershipRepository;
private final IndividualMembershipConverter individualMembershipConverter;

public IndividualMembership saveIndividualMembership(IndividualMembershipRequest request,
public IndividualMembership saveIndividualMembership(Long officeId,
IndividualMembershipRequest request,
Member member) {
return individualMembershipRepository.save(
individualMembershipConverter.toIndividualMembershipEntity(request, member));
individualMembershipConverter.toIndividualMembershipEntity(officeId, request, member));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ public class CompanyMembershipReservationController {
private final CompanyMembershipReservationService companyMembershipReservationService;

// 기업 등록, 기업 멤버십 생성, 기업 인증번호 발송
@PostMapping
@PostMapping("/{officeId}")
public BaseResponse<CompanyMembershipRegistrationResponse> registerCompany(
@RequestBody CompanyMembershipRegistrationRequest request) {
@RequestBody CompanyMembershipRegistrationRequest request,
@PathVariable Long officeId
) {
CompanyMembershipRegistrationResponse response =
companyMembershipReservationService.registerCompanyMembership(request);
companyMembershipReservationService.registerCompanyMembership(officeId, request);
return BaseResponse.response(response);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
public class MembershipResponse {
private Long id;
private String location;
private Long officeId;
private Long price;
private String type;
private Integer duration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ public class CompanyMembershipReservationService {
private final CompanyMembershipConverter companyMembershipConverter;

// (생성, 응답 변환) 기업 문의하기 -> 기업, 기업 멤버십 생성
public CompanyMembershipRegistrationResponse registerCompanyMembership(CompanyMembershipRegistrationRequest request) {
return companyMembershipService.registerCompanyMembership(request);
public CompanyMembershipRegistrationResponse registerCompanyMembership(
Long officeId,
CompanyMembershipRegistrationRequest request) {
return companyMembershipService.registerCompanyMembership(officeId, request);
}

// 사용자의 단일 기업 멤버십
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public MembershipReservationListResponse registerIndividualMembership(
IndividualMembershipRegistrationRequest requests, Member member, Long officeId) {
reservationValidationService.validateOfficeLocation(requests, officeId);
IndividualMembership membership =
individualMembershipService.saveIndividualMembership(requests.getMembership(), member);
individualMembershipService.saveIndividualMembership(officeId, requests.getMembership(), member);
List<ReservationResponse> reservationResponses =
reservationService.createReservationResponses(requests.getReservations(), membership);
return reservationConverter.toMembershipReservationListResponse(
Expand Down

0 comments on commit 0f7c30a

Please sign in to comment.