Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: company selection api #35

Merged
merged 5 commits into from
Jan 30, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public CarpoolResponseDto toDto(Carpool carpool, Member member) {
.money(carpool.getCost().getMoney())
.content(carpool.getContent())
.moodType(carpool.getMoodType())
.companyName(member.getCompany())
.companyName(member.getCompany().getCompanyName())
.gender(member.getGender())
.createdAt(carpool.getCreatedAt())
.build();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.fullcar.member.application.auth;

import com.fullcar.member.application.member.MemberService;
import com.fullcar.member.domain.member.Member;
import com.fullcar.member.domain.member.MemberId;
import com.fullcar.member.presentation.auth.dto.CustomUserDetails;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.fullcar.member.application.member;

import com.fullcar.member.domain.member.Company;
import com.fullcar.member.presentation.member.dto.request.CompanyRequestDto;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor(access = AccessLevel.PROTECTED)
public class CompanyMapper {
public Company toEntity(CompanyRequestDto companyRequestDto) {
return Company.builder()
.companyName(companyRequestDto.getCompanyName())
.latitude(companyRequestDto.getLatitude())
.longitude(companyRequestDto.getLongitude())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
package com.fullcar.member.application.auth;
package com.fullcar.member.application.member;

import com.fullcar.core.exception.NotFoundException;
import com.fullcar.core.response.ErrorCode;
import com.fullcar.member.domain.member.Member;
import com.fullcar.member.domain.member.MemberId;
import com.fullcar.member.domain.member.MemberRepository;
import com.fullcar.member.domain.member.*;
import com.fullcar.member.presentation.member.dto.request.CompanyRequestDto;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;

@Validated
@Service
@RequiredArgsConstructor
public class MemberService {
private final MemberRepository memberRepository;
private final CompanyMapper companyMapper;

/**
* νšŒμ›μ„ μ‹λ³„μžλ‘œ μ‘°νšŒν•©λ‹ˆλ‹€.
Expand All @@ -26,4 +28,9 @@ public Member findByMemberId(MemberId memberId) {
.orElseThrow(() -> new NotFoundException(ErrorCode.NOT_EXIST_USER));
}

@Transactional
public void registerCompany(Member member, CompanyRequestDto companyRequestDto) {
Company company = companyMapper.toEntity(companyRequestDto);
findByMemberId(member.getId()).updateCompany(company);
}
}
23 changes: 23 additions & 0 deletions src/main/java/com/fullcar/member/domain/member/Company.java
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Double νƒ€μž…μ€ λΆ€λ™μ†Œμˆ˜μ  ν‘œν˜„ 방식이기 λ•Œλ¬Έμ— 값에 μ˜€μ°¨κ°€ λ°œμƒν•˜κ²Œ λ˜λŠ”λ°μš”! 경도와 μœ„λ„λŠ” μžμ„Έν•œ 값을 μ €μž₯ν•˜κ³  κ³„μ‚°λ˜μ–΄μ•Ό ν•˜κΈ° λ•Œλ¬Έμ— BigDecimal νƒ€μž…μ„ μ‚¬μš©ν•˜λŠ” 것을 μΆ”μ²œλ“œλ¦½λ‹ˆλ‹€!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

λͺ¨λ‘ λ°˜μ˜μ™„λ£Œν–ˆμ–΄μš”~!!

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.fullcar.member.domain.member;

import jakarta.persistence.Column;
import jakarta.persistence.Embeddable;
import lombok.*;

import java.math.BigDecimal;

import static lombok.AccessLevel.PROTECTED;

@Embeddable
@Getter
@Builder
@NoArgsConstructor(access = PROTECTED)
@AllArgsConstructor(access = PROTECTED)
public class Company {
@Column(name = "company_name")
private String companyName;

private BigDecimal latitude;

private BigDecimal longitude;
}
8 changes: 7 additions & 1 deletion src/main/java/com/fullcar/member/domain/member/Member.java
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

엔티티와 λ°Έλ₯˜ κ°μ²΄λŠ” μ°Έμ‘° 투λͺ…μ„±κ³Ό λ©€ν‹°μŠ€λ ˆλ“œ ν™˜κ²½μ—μ„œμ˜ μ•ˆμ •μ„±μ„ μœ„ν•΄ Immutable 즉, λΆˆλ³€ 객체둜 κ΅¬ν˜„ν•˜λŠ”κ²Œ μ’‹λ‹€κ³  μƒκ°ν•©λ‹ˆλ‹€!
μžμ„Έν•œ λ‚΄μš©μ€ 도메인 주도 개발 μ‹œμž‘ν•˜κΈ° 50νŽ˜μ΄μ§€ ν•œλ²ˆ λ΄μ£Όμ„Έμš”!!

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
Expand Down Expand Up @@ -34,7 +35,8 @@ public class Member {

private SocialId socialId;

private String company;
@Embedded
private Company company;

@Length(min=2, max=10)
@Column(length = 10)
Expand Down Expand Up @@ -74,4 +76,8 @@ public void loginMember(String deviceToken, String refreshToken) {
public void updateCarInformation(CarId carId) {
this.carId = carId;
}

public void updateCompany(Company company) {
this.company = new Company(company.getCompanyName(), company.getLatitude(), company.getLongitude());
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
public class CarController {
private final CarService carService;

@Operation(description = "μ°¨λŸ‰ 등둝")
@Operation(summary = "μ°¨λŸ‰ 등둝 API")
@ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "201", description = "등둝 성곡"),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "500", description = "μ„œλ²„ λ‚΄λΆ€ 였λ₯˜", content = @Content)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.fullcar.member.presentation.member;

import com.fullcar.core.annotation.CurrentMember;
import com.fullcar.core.response.ApiResponse;
import com.fullcar.core.response.SuccessCode;
import com.fullcar.member.application.member.MemberService;
import com.fullcar.member.domain.member.Member;
import com.fullcar.member.presentation.member.dto.request.CompanyRequestDto;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/members")
@Tag(name = "[Member] 멀버 κ΄€λ ¨ API")
public class MemberController {

private final MemberService memberService;

@Operation(summary = "νšŒμ‚¬ 선택 API")
@ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "201", description = "등둝 성곡"),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "500", description = "μ„œλ²„ λ‚΄λΆ€ 였λ₯˜", content = @Content)
})
@PostMapping("/onboarding/company")
public ApiResponse<Object> postCompany(@CurrentMember Member member, @RequestBody @Valid CompanyRequestDto companyRequestDto) {
memberService.registerCompany(member, companyRequestDto);
return ApiResponse.success(SuccessCode.REGISTER_SUCCESS);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.fullcar.member.presentation.member.dto.request;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import lombok.*;

import java.math.BigDecimal;

@Getter
@Builder
@AllArgsConstructor(access = AccessLevel.PROTECTED)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class CompanyRequestDto {
@Schema(description = "νšŒμ‚¬ 이름", example = "넀이버")
@NotBlank
private String companyName;

@Schema(description = "μœ„λ„", example = "46.652719")
private BigDecimal latitude;

@Schema(description = "경도", example = "71.530045")
private BigDecimal longitude;
}
Loading