-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eb46c7e
commit 2654b15
Showing
26 changed files
with
396 additions
and
38 deletions.
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.