-
Notifications
You must be signed in to change notification settings - Fork 0
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: Form request API #41
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
12 changes: 6 additions & 6 deletions
12
...ar/carpool/application/CarpoolMapper.java β ...ol/application/carpool/CarpoolMapper.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
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
53 changes: 53 additions & 0 deletions
53
src/main/java/com/fullcar/carpool/application/form/FormMapper.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,53 @@ | ||
package com.fullcar.carpool.application.form; | ||
|
||
import com.fullcar.carpool.domain.carpool.CarpoolId; | ||
import com.fullcar.carpool.domain.form.Cost; | ||
import com.fullcar.carpool.domain.form.Form; | ||
import com.fullcar.carpool.domain.form.Passenger; | ||
import com.fullcar.carpool.domain.service.FormIdService; | ||
import com.fullcar.carpool.presentation.form.dto.request.FormRequestDto; | ||
import com.fullcar.carpool.presentation.form.dto.response.FormResponseDto; | ||
import com.fullcar.member.domain.member.Member; | ||
import lombok.AccessLevel; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@RequiredArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class FormMapper { | ||
private final FormIdService formIdService; | ||
|
||
public FormResponseDto toDto(Form form, Member member) { | ||
return FormResponseDto.builder() | ||
.id(form.getFormId().getId()) | ||
.pickupLocation(form.getPickupLocation()) | ||
.periodType(form.getCost().getPeriodType()) | ||
.money(form.getCost().getMoney()) | ||
.content(form.getContent()) | ||
.formState(form.getFormState()) | ||
.companyName(member.getCompany().getCompanyName()) | ||
.nickname(member.getNickname()) | ||
.createdAt(form.getCreatedAt()) | ||
.build(); | ||
} | ||
|
||
public Form toEntity(Member member, CarpoolId carpoolId, FormRequestDto formRequestDto) { | ||
return Form.builder() | ||
.formId(formIdService.nextId()) | ||
.content(formRequestDto.getContent()) | ||
.pickupLocation(formRequestDto.getPickupLocation()) | ||
.cost( | ||
Cost.builder() | ||
.periodType(formRequestDto.getPeriodType()) | ||
.money(formRequestDto.getMoney()) | ||
.build() | ||
) | ||
.passenger( | ||
Passenger.builder() | ||
.memberId(member.getId()) | ||
.build() | ||
) | ||
.carpoolId(carpoolId) | ||
.build(); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/com/fullcar/carpool/application/form/FormService.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,40 @@ | ||
package com.fullcar.carpool.application.form; | ||
|
||
import com.fullcar.carpool.domain.carpool.Carpool; | ||
import com.fullcar.carpool.domain.carpool.CarpoolId; | ||
import com.fullcar.carpool.domain.carpool.CarpoolRepository; | ||
import com.fullcar.carpool.domain.form.Form; | ||
import com.fullcar.carpool.domain.form.FormRepository; | ||
import com.fullcar.carpool.presentation.form.dto.request.FormRequestDto; | ||
import com.fullcar.carpool.presentation.form.dto.response.FormResponseDto; | ||
import com.fullcar.core.exception.CustomException; | ||
import com.fullcar.core.response.ErrorCode; | ||
import com.fullcar.member.domain.member.Member; | ||
import lombok.AccessLevel; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import org.springframework.validation.annotation.Validated; | ||
|
||
@Validated | ||
@Service | ||
@RequiredArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class FormService { | ||
private final FormRepository formRepository; | ||
private final CarpoolRepository carpoolRepository; | ||
private final FormMapper formMapper; | ||
|
||
@Transactional | ||
public FormResponseDto requestForm(Member member, CarpoolId carpoolId, FormRequestDto formRequestDto) { | ||
Carpool carpool = carpoolRepository.findByCarpoolIdAndIsDeleted(carpoolId, false) | ||
.orElseThrow(() -> new CustomException(ErrorCode.NOT_EXIST_CARPOOL)); | ||
|
||
Form form = formMapper.toEntity(member, carpoolId, formRequestDto); | ||
|
||
return formMapper.toDto( | ||
formRepository.saveAndFlush(form), | ||
member | ||
); | ||
} | ||
|
||
} |
2 changes: 1 addition & 1 deletion
2
...a/com/fullcar/carpool/domain/Carpool.java β ...llcar/carpool/domain/carpool/Carpool.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
2 changes: 1 addition & 1 deletion
2
...com/fullcar/carpool/domain/CarpoolId.java β ...car/carpool/domain/carpool/CarpoolId.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
3 changes: 1 addition & 2 deletions
3
...car/carpool/domain/CarpoolRepository.java β ...ool/domain/carpool/CarpoolRepository.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
2 changes: 1 addition & 1 deletion
2
.../fullcar/carpool/domain/CarpoolState.java β .../carpool/domain/carpool/CarpoolState.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
2 changes: 1 addition & 1 deletion
2
...java/com/fullcar/carpool/domain/Cost.java β .../fullcar/carpool/domain/carpool/Cost.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
2 changes: 1 addition & 1 deletion
2
...va/com/fullcar/carpool/domain/Driver.java β ...ullcar/carpool/domain/carpool/Driver.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
2 changes: 1 addition & 1 deletion
2
.../com/fullcar/carpool/domain/MoodType.java β ...lcar/carpool/domain/carpool/MoodType.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,4 +1,4 @@ | ||
package com.fullcar.carpool.domain; | ||
package com.fullcar.carpool.domain.carpool; | ||
|
||
public enum MoodType { | ||
CHATTY, | ||
|
2 changes: 1 addition & 1 deletion
2
...om/fullcar/carpool/domain/PeriodType.java β ...ar/carpool/domain/carpool/PeriodType.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,4 +1,4 @@ | ||
package com.fullcar.carpool.domain; | ||
package com.fullcar.carpool.domain.carpool; | ||
|
||
public enum PeriodType { | ||
ONCE, | ||
|
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,26 @@ | ||
package com.fullcar.carpool.domain.form; | ||
|
||
import com.fullcar.carpool.domain.carpool.PeriodType; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Embeddable; | ||
import jakarta.persistence.EnumType; | ||
import jakarta.persistence.Enumerated; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import static lombok.AccessLevel.PROTECTED; | ||
|
||
@Embeddable | ||
@Getter | ||
@Builder | ||
@NoArgsConstructor(access = PROTECTED) | ||
@AllArgsConstructor(access = PROTECTED) | ||
public class Cost { | ||
private Long money; | ||
|
||
@Enumerated(EnumType.STRING) | ||
@Column(name = "period_type") | ||
private PeriodType periodType; | ||
} |
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,55 @@ | ||
package com.fullcar.carpool.domain.form; | ||
|
||
import com.fullcar.carpool.domain.carpool.CarpoolId; | ||
import jakarta.persistence.*; | ||
import lombok.*; | ||
import org.springframework.data.annotation.CreatedDate; | ||
import org.springframework.data.annotation.LastModifiedDate; | ||
import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Entity | ||
@Getter | ||
@Builder | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor(access = AccessLevel.PROTECTED) | ||
@EntityListeners(AuditingEntityListener.class) | ||
@Table(name = "form") | ||
public class Form { | ||
|
||
@EmbeddedId | ||
private FormId formId; | ||
|
||
private String content; | ||
|
||
@Column(name = "pickup_location") | ||
private String pickupLocation; | ||
|
||
@Embedded | ||
private Cost cost; | ||
|
||
@Enumerated(EnumType.STRING) | ||
@Column(name = "form_state") | ||
@Builder.Default | ||
private FormState formState = FormState.REQUEST; | ||
|
||
@Embedded | ||
private Passenger passenger; | ||
|
||
@Embedded | ||
@AttributeOverride(name = "id", column = @Column(name = "carpool_id")) | ||
private CarpoolId carpoolId; | ||
|
||
@Column(name = "is_deleted", nullable = false) | ||
@Builder.Default | ||
private boolean isDeleted = false; | ||
|
||
@Column(name = "created_at") | ||
@CreatedDate | ||
private LocalDateTime createdAt; | ||
|
||
@Column(name = "updated_at") | ||
@LastModifiedDate | ||
private LocalDateTime updatedAt; | ||
} |
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,21 @@ | ||
package com.fullcar.carpool.domain.form; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Embeddable; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.io.Serializable; | ||
|
||
import static lombok.AccessLevel.PROTECTED; | ||
|
||
@Embeddable | ||
@Getter | ||
@NoArgsConstructor(access = PROTECTED) | ||
@AllArgsConstructor | ||
public class FormId implements Serializable { | ||
|
||
@Column(name = "id") | ||
private Long id; | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/fullcar/carpool/domain/form/FormRepository.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,8 @@ | ||
package com.fullcar.carpool.domain.form; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface FormRepository extends JpaRepository<Form, FormId> { | ||
} |
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,7 @@ | ||
package com.fullcar.carpool.domain.form; | ||
|
||
public enum FormState { | ||
REQUEST, | ||
ACCEPT, | ||
REJECT | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/fullcar/carpool/domain/form/Passenger.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,16 @@ | ||
package com.fullcar.carpool.domain.form; | ||
|
||
import com.fullcar.member.domain.member.MemberId; | ||
import jakarta.persistence.*; | ||
import lombok.*; | ||
|
||
@Embeddable | ||
@Getter | ||
@Builder | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class Passenger { | ||
@Embedded | ||
@AttributeOverride(name = "id", column = @Column(name = "passenger_id")) | ||
private MemberId memberId; | ||
} |
2 changes: 1 addition & 1 deletion
2
src/main/java/com/fullcar/carpool/domain/service/CarpoolIdService.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
17 changes: 17 additions & 0 deletions
17
src/main/java/com/fullcar/carpool/domain/service/FormIdService.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,17 @@ | ||
package com.fullcar.carpool.domain.service; | ||
|
||
import com.fullcar.carpool.domain.form.FormId; | ||
import com.fullcar.core.id.SnowFlake; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class FormIdService { | ||
private final SnowFlake snowFlake; | ||
|
||
public FormIdService() { | ||
snowFlake = new SnowFlake(255); | ||
} | ||
public FormId nextId() { | ||
return new FormId(snowFlake.nextId()); | ||
} | ||
} |
10 changes: 5 additions & 5 deletions
10
...rpool/presentation/CarpoolController.java β ...esentation/carpool/CarpoolController.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
9 changes: 3 additions & 6 deletions
9
...tation/dto/request/CarpoolRequestDto.java β ...arpool/dto/request/CarpoolRequestDto.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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CarpoolServiceμλ findByCarpoolIdAndIsDeleted ν¨μκ° λ°λ³΅λΌμ μ¬μ©λκ³ μλλ°, CarpoolRepositoryμμ default methodλ‘ μ’ λ κΉλνκ² μ¬μ©νλ 건 μ΄λ¨κΉμ??
ex)
default Member findByIdAndIsDeletedOrThrow(MemberId id, boolean isDeleted) {
return findByIdAndIsDeleted(id, isDeleted)
.orElseThrow(() -> new CustomException(ErrorCode.NOT_EXIST_USER));
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μ’μ 리뷰 κ°μ¬ν©λλ€! λ°μνμ΅λλ€~