Skip to content
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 @@ -13,6 +13,8 @@ public record RecordSaveRequest(
LocalDateTime endAt,
@Schema(description = "달린 거리 (미터)", example = "10000")
Long totalDistanceInMeters,
@Schema(description = "달린 시간 (초)", example = "3600000")
Long totalTimeInSeconds,
@Schema(description = "평균 페이스 (밀리초)", example = "300000")
Long averagePaceInMilliSeconds,
@Schema(description = "세그먼트 페이스 리스트")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import jakarta.persistence.Table;
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
Expand All @@ -35,6 +36,7 @@ public class RunningRecord extends BaseEntity {
private String imgUrl;
private LocalDateTime startedAt;
private LocalDateTime endAt;
private Long totalTimeInSeconds;
@Embedded
@AttributeOverride(name = "amount", column = @Column(name = "total_distance"))
private Distance totalDistance;
Expand All @@ -55,6 +57,7 @@ public RunningRecord(
LocalDateTime startedAt,
LocalDateTime endAt,
Distance totalDistance,
Long totalTimeInSeconds,
Pace averagePace,
Boolean isRewarded,
List<SegmentPace> pacePerKm) {
Expand All @@ -67,6 +70,7 @@ public RunningRecord(
this.endAt = endAt;
this.isRewarded = isRewarded;
this.totalDistance = totalDistance;
this.totalTimeInSeconds = totalTimeInSeconds;
this.averagePace = averagePace;
setTitleIfNull();
}
Expand Down Expand Up @@ -104,7 +108,7 @@ public Distance getTotalDistance() {
}

public Duration getRunningTime() {
return Duration.between(startedAt, endAt);
return Duration.of(this.totalTimeInSeconds, ChronoUnit.SECONDS);
}

@PrePersist
Expand All @@ -115,7 +119,9 @@ public void generateRecordPublicId() {
}

private void setTitleIfNull() {
if (this.title != null) return;
if (this.title != null) {
return;
}
this.title = DefaultTitle.fromTime(this.startedAt).getTitle();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ private RunningRecord mapToCreatedRunningRecord(Long id, RecordCreateCommand com
.endAt(command.endAt())
.averagePace(command.averagePace())
.totalDistance(command.totalDistance())
.totalTimeInSeconds(command.totalTimeInSeconds())
.isRewarded(false)
.pacePerKm(command.segmentPaces())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public record RecordCreateCommand(
Long userId,
LocalDateTime startedAt,
LocalDateTime endAt,
Long totalTimeInSeconds,
Pace averagePace,
Distance totalDistance,
List<SegmentPace> segmentPaces
Expand All @@ -21,6 +22,7 @@ public static RecordCreateCommand from(final RecordSaveRequest request, final Lo
userId,
request.startedAt(),
request.endAt(),
request.totalTimeInSeconds(),
new Pace(request.averagePaceInMilliSeconds()),
new Distance(request.totalDistanceInMeters()),
request.segmentPaces()
Expand Down
33 changes: 17 additions & 16 deletions src/main/resources/sql/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ CREATE TABLE `users`
`public_id` VARCHAR(255),
`nickname` VARCHAR(255),
`img_url` VARCHAR(255),
`total_distance_in_meters` BIGINT NOT NULL DEFAULT 0,
`total_time_in_seconds` BIGINT NOT NULL DEFAULT 0,
`total_distance_in_meters` BIGINT NOT NULL DEFAULT 0,
`total_time_in_seconds` BIGINT NOT NULL DEFAULT 0,
`main_runimo_id` BIGINT,
`gender` VARCHAR(24),
`role` VARCHAR(24) NOT NULL DEFAULT 'USER',
`updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
`deleted_at` TIMESTAMP NULL
`updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
`deleted_at` TIMESTAMP NULL
);

CREATE TABLE `user_token`
Expand Down Expand Up @@ -93,14 +93,15 @@ CREATE TABLE `signup_token`
CREATE TABLE `running_record`
(
`id` BIGINT PRIMARY KEY AUTO_INCREMENT,
`user_id` BIGINT NOT NULL,
`user_id` BIGINT NOT NULL,
`record_public_id` VARCHAR(255) NOT NULL,
`title` VARCHAR(255),
`description` VARCHAR(255),
`img_url` VARCHAR(255),
`started_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
`end_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
`total_distance` BIGINT,
`total_time_in_seconds` BIGINT,
`pace_in_milli_seconds` BIGINT,
`is_rewarded` BOOLEAN,
`pace_per_km` VARCHAR(10000),
Expand Down Expand Up @@ -141,8 +142,8 @@ CREATE TABLE `egg_type`
CREATE TABLE `item_activity`
(
`id` BIGINT PRIMARY KEY AUTO_INCREMENT,
`activity_user_id` BIGINT NOT NULL,
`activity_item_id` BIGINT NOT NULL,
`activity_user_id` BIGINT NOT NULL,
`activity_item_id` BIGINT NOT NULL,
`activity_event_type` VARCHAR(255) NOT NULL,
`quantity` BIGINT,
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
Expand All @@ -153,9 +154,9 @@ CREATE TABLE `item_activity`
CREATE TABLE `user_item`
(
`id` BIGINT PRIMARY KEY AUTO_INCREMENT,
`user_id` BIGINT NOT NULL,
`item_id` BIGINT NOT NULL,
`quantity` BIGINT NOT NULL,
`user_id` BIGINT NOT NULL,
`item_id` BIGINT NOT NULL,
`quantity` BIGINT NOT NULL,
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
`updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`deleted_at` TIMESTAMP NULL
Expand All @@ -164,8 +165,8 @@ CREATE TABLE `user_item`
CREATE TABLE `incubating_egg`
(
`id` BIGINT PRIMARY KEY AUTO_INCREMENT,
`user_id` BIGINT NOT NULL,
`egg_id` BIGINT NOT NULL,
`user_id` BIGINT NOT NULL,
`egg_id` BIGINT NOT NULL,
`current_love_point_amount` BIGINT,
`hatch_require_amount` BIGINT,
`egg_status` VARCHAR(255),
Expand Down Expand Up @@ -201,9 +202,9 @@ CREATE TABLE `runimo`

CREATE TABLE `user_refresh_token`
(
`id` BIGINT PRIMARY KEY AUTO_INCREMENT,
`user_id` BIGINT NOT NULL UNIQUE ,
`refresh_token` TEXT NOT NULL,
`id` BIGINT PRIMARY KEY AUTO_INCREMENT,
`user_id` BIGINT NOT NULL UNIQUE,
`refresh_token` TEXT NOT NULL,
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
`updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public static RecordSaveRequest createRecordSaveRequest() {
LocalDateTime.of(2025, 3, 30, 9, 30, 0),
LocalDateTime.of(2025, 3, 30, 10, 0, 0),
5000L,
1800L,
360000L,
List.of(new SegmentPace(1.0, 732000))
);
Expand Down
Loading
Loading