-
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: Carpool Register API #19
Changes from all commits
433dcdc
586f78b
c66eeeb
ca3f83d
9878a58
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.fullcar.carpool.application; | ||
|
||
import com.fullcar.carpool.domain.Carpool; | ||
import com.fullcar.carpool.domain.Cost; | ||
import com.fullcar.carpool.domain.Driver; | ||
import com.fullcar.carpool.domain.service.CarpoolIdService; | ||
import com.fullcar.carpool.presentation.dto.CarpoolDto; | ||
import com.fullcar.member.domain.MemberId; | ||
import lombok.AccessLevel; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@RequiredArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class CarpoolMapper { | ||
private final CarpoolIdService carpoolIdService; | ||
|
||
public CarpoolDto toDto(Carpool carpool) { | ||
return CarpoolDto.builder() | ||
.id(carpool.getCarpoolId().getId()) | ||
.pickupLocation(carpool.getPickupLocation()) | ||
.periodType(carpool.getCost().getPeriodType()) | ||
.money(carpool.getCost().getMoney()) | ||
.content(carpool.getContent()) | ||
.moodType(carpool.getMoodType()) | ||
.build(); | ||
} | ||
|
||
public Carpool toEntity(MemberId memberId, CarpoolDto carpoolDto) { | ||
return Carpool.builder() | ||
.carpoolId(carpoolIdService.nextId()) | ||
.pickupLocation(carpoolDto.getPickupLocation()) | ||
.cost( | ||
Cost.builder() | ||
.periodType(carpoolDto.getPeriodType()) | ||
.money(carpoolDto.getMoney()) | ||
.build() | ||
) | ||
.content(carpoolDto.getContent()) | ||
.moodType(carpoolDto.getMoodType()) | ||
.driver( | ||
Driver.builder() | ||
.memberId(memberId) | ||
.build() | ||
) | ||
.build(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.fullcar.carpool.application; | ||
|
||
import com.fullcar.carpool.domain.Carpool; | ||
import com.fullcar.carpool.domain.CarpoolRepository; | ||
import com.fullcar.carpool.presentation.dto.CarpoolDto; | ||
import com.fullcar.member.domain.MemberId; | ||
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 CarpoolService { | ||
private final CarpoolRepository carpoolRepository; | ||
private final CarpoolMapper carpoolMapper; | ||
|
||
@Transactional | ||
public CarpoolDto registerCarpool(MemberId memberId, CarpoolDto carpoolDto) { | ||
Carpool carpool = carpoolMapper.toEntity(memberId, carpoolDto); | ||
|
||
return carpoolMapper.toDto( | ||
carpoolRepository.saveAndFlush(carpool) | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.fullcar.carpool.domain; | ||
|
||
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; | ||
|
||
import static lombok.AccessLevel.PROTECTED; | ||
|
||
@Entity | ||
@Getter | ||
@Builder | ||
@NoArgsConstructor(access = PROTECTED) | ||
@AllArgsConstructor(access = PROTECTED) | ||
@EntityListeners(AuditingEntityListener.class) | ||
@Table(name = "carpool") | ||
public class Carpool { | ||
|
||
@EmbeddedId | ||
private CarpoolId carpoolId; | ||
|
||
private String content; | ||
|
||
@Column(name = "pickup_location") | ||
private String pickupLocation; | ||
Comment on lines
+27
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. μ’μ λΆλΆ μ§μ΄μ£Όμ μ κ°μ¬ν©λλ€! κ·Όλ° μ λ κΈμ μ ν μμ κ°μ μμΈμ²λ¦¬λ ν΄λΌμ΄μΈνΈμμ μΆ©λΆν κ²μ¦ν μ μκ³ μμ£Ό λ³λλ μ μλ λΉμ¦λμ€ μꡬμ¬νμ΄κΈ° λλ¬Έμ λλ©μΈμ λ°μμμΌμ λλΈμ²΄νΉνκΈ°λ³΄λ¨ ν΄λΌμ΄μΈνΈμμ κ²μ¦νλκ² μ’λ€κ³ μκ°ν©λλ€! |
||
|
||
@Embedded | ||
private Driver driver; | ||
|
||
@Embedded | ||
private Cost cost; | ||
|
||
@Enumerated(EnumType.STRING) | ||
@Column(name = "carpool_state") | ||
@Builder.Default | ||
private CarpoolState carpoolState = CarpoolState.OPEN; | ||
|
||
@Enumerated(EnumType.STRING) | ||
@Column(name = "mood_type") | ||
private MoodType moodType; | ||
|
||
@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; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.fullcar.carpool.domain; | ||
|
||
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 CarpoolId implements Serializable { | ||
|
||
@Column(name = "id") | ||
private Long id; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.fullcar.carpool.domain; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.Optional; | ||
|
||
@Repository | ||
public interface CarpoolRepository extends JpaRepository<Carpool, CarpoolId> { | ||
Optional<Carpool> findByCarpoolIdAndIsDeleted(CarpoolId carpoolId, boolean isDeleted); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.fullcar.carpool.domain; | ||
|
||
public enum CarpoolState { | ||
OPEN, | ||
CLOSE | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.fullcar.carpool.domain; | ||
|
||
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ν¬λ§λΉμ©μ μ΅λ 10μλ€μ! |
||
|
||
@Enumerated(EnumType.STRING) | ||
@Column(name = "period_type") | ||
private PeriodType periodType; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.fullcar.carpool.domain; | ||
|
||
import com.fullcar.member.domain.MemberId; | ||
import jakarta.persistence.*; | ||
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 Driver { | ||
@Embedded | ||
@AttributeOverrides( | ||
@AttributeOverride(name = "id", column = @Column(name = "driver_id")) | ||
) | ||
private MemberId memberId; | ||
|
||
//:TODO CarId | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.fullcar.carpool.domain; | ||
|
||
public enum MoodType { | ||
CHATTY, | ||
QUIET | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.fullcar.carpool.domain; | ||
|
||
public enum PeriodType { | ||
ONCE, | ||
ONE_WEEK, | ||
TWO_WEEK, | ||
THREE_WEEK, | ||
FOUR_WEEK | ||
} |
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.CarpoolId; | ||
import com.fullcar.core.id.SnowFlake; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class CarpoolIdService { | ||
private final SnowFlake snowFlake; | ||
|
||
public CarpoolIdService() { | ||
snowFlake = new SnowFlake(255); | ||
} | ||
public CarpoolId nextId() { | ||
return new CarpoolId(snowFlake.nextId()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.fullcar.carpool.presentation; | ||
|
||
import com.fullcar.carpool.application.CarpoolService; | ||
import com.fullcar.carpool.presentation.dto.CarpoolDto; | ||
import com.fullcar.core.annotation.CurrentMember; | ||
import com.fullcar.core.response.ApiResponse; | ||
import com.fullcar.core.response.SuccessCode; | ||
import com.fullcar.member.domain.Member; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
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; | ||
|
||
|
||
@Tag(description = "μΉ΄ν κ΄λ ¨ Endpoint", name = "μΉ΄ν") | ||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/v1/carpools") | ||
public class CarpoolController { | ||
private final CarpoolService carpoolService; | ||
|
||
@Operation(description = "μΉ΄ν λ±λ‘") | ||
@ApiResponses({ | ||
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "201", description = "λ±λ‘ μ±κ³΅") | ||
}) | ||
@PostMapping("") | ||
public ApiResponse<CarpoolDto> postCarpool( | ||
@Parameter(hidden = true) | ||
@CurrentMember Member member, | ||
@Parameter(description = "μΉ΄ν λͺ¨λΈ", required = true) | ||
@RequestBody @Valid CarpoolDto carpoolDto | ||
) { | ||
return ApiResponse.success( | ||
SuccessCode.REGISTER_SUCCESS, | ||
carpoolService.registerCarpool(member.getId(), carpoolDto) | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.fullcar.carpool.presentation.dto; | ||
|
||
import com.fullcar.carpool.domain.Carpool; | ||
import com.fullcar.carpool.domain.CarpoolId; | ||
import com.fullcar.carpool.domain.MoodType; | ||
import com.fullcar.carpool.domain.PeriodType; | ||
import com.fullcar.carpool.domain.service.CarpoolIdService; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.*; | ||
import org.springframework.stereotype.Component; | ||
|
||
|
||
@Getter | ||
@Builder | ||
@AllArgsConstructor(access = AccessLevel.PROTECTED) | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Schema(description = "μΉ΄ν λͺ¨λΈ") | ||
public class CarpoolDto { | ||
|
||
@Schema(description = "μΉ΄ν id") | ||
private Long id; | ||
|
||
@Schema(description = "ν½μ μ₯μ") | ||
private String pickupLocation; | ||
|
||
@Schema(description = "ν¬λ§λΉμ©(κΈ°κ°)") | ||
private PeriodType periodType; | ||
|
||
@Schema(description = "ν¬λ§λΉμ©(κ°κ²©)") | ||
private Long money; | ||
|
||
@Schema(description = "νμΉμμκ² μ ν λ§") | ||
private String content; | ||
|
||
@Schema(description = "μ΄ν λΆμκΈ°") | ||
private MoodType moodType; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.fullcar.core.annotation; | ||
|
||
import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
|
||
@Target({ElementType.PARAMETER, ElementType.TYPE}) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") | ||
public @interface CurrentMember { | ||
} |
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.
contentκ° νμΉμμκ² μ ν λ§μ΄κ΅°μ! (μ΅λ 150μ) μλ©μ΄ μ’ λ μ§κ΄μ μ΄λ©΄ μ’μ κ² κ°μλ°..! ν ,, messageλ μ΄λ€κ°μ?
μλ note, memo....
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.
μΉ΄ν κ²μκΈμ λ΄μ©μ΄λΌκ³ μκ°νμ¬ contentλΌκ³ λ€μ΄λ° νμ΅λλ€! λν νμΉ μμ² μλ½ λ νμΉμμκ² λ³΄λ΄λ λ©μμ§λ μμ΄μ ꡬλΆνκΈ° μν΄ μ΄λ κ² νμ΅λλ€!