Skip to content

Commit 52e02dd

Browse files
authored
Merge pull request #87 from Run-Us/JIS-120-get-crew-home
[Feat/get crew home] 크루홈 조회 api 구현
2 parents 8e73120 + 1f2838e commit 52e02dd

33 files changed

Lines changed: 610 additions & 33 deletions

src/main/java/com/run_us/server/domains/crew/controller/CrewController.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ public class CrewController {
3535
@PostMapping
3636
public ResponseEntity<SuccessResponse<CreateCrewResponse>> createCrew(
3737
@RequestBody CreateCrewRequest requestDto,
38-
@RequestAttribute("publicUserId") String userId) {
39-
log.info("action=create_crew user_id={}", userId);
38+
@CurrentUser String currentUserPublicId) {
39+
log.info("action=create_crew user_id={}", currentUserPublicId);
4040

41-
SuccessResponse<CreateCrewResponse> response = createCrewUseCase.createCrew(requestDto, userId);
41+
SuccessResponse<CreateCrewResponse> response = createCrewUseCase.createCrew(requestDto, currentUserPublicId);
4242

4343
return ResponseEntity.status(HttpStatus.CREATED).body(response);
4444
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.run_us.server.domains.crew.controller;
2+
3+
import com.run_us.server.domains.crew.controller.model.response.GetCrewHomeResponse;
4+
import com.run_us.server.domains.crew.service.usecase.QueryCrewUseCase;
5+
import com.run_us.server.global.common.SuccessResponse;
6+
import com.run_us.server.global.security.annotation.CurrentUser;
7+
import lombok.RequiredArgsConstructor;
8+
import lombok.extern.slf4j.Slf4j;
9+
import org.springframework.http.ResponseEntity;
10+
import org.springframework.web.bind.annotation.GetMapping;
11+
import org.springframework.web.bind.annotation.PathVariable;
12+
import org.springframework.web.bind.annotation.RequestMapping;
13+
import org.springframework.web.bind.annotation.RestController;
14+
15+
@Slf4j
16+
@RestController
17+
@RequestMapping("/crews")
18+
@RequiredArgsConstructor
19+
public class QueryCrewController {
20+
private final QueryCrewUseCase queryCrewUseCase;
21+
22+
@GetMapping("/{crewPublicId}/home")
23+
public ResponseEntity<SuccessResponse<GetCrewHomeResponse>> getCrewHome(
24+
@PathVariable String crewPublicId,
25+
@CurrentUser String currentUserPublicId) {
26+
log.info("action=get_crew_home crew_public_id={}, user_id={}", crewPublicId, currentUserPublicId);
27+
28+
SuccessResponse<GetCrewHomeResponse> response = queryCrewUseCase.getCrewHome(crewPublicId, currentUserPublicId);
29+
return ResponseEntity.ok().body(response);
30+
}
31+
}

src/main/java/com/run_us/server/domains/crew/controller/model/request/CreateCrewRequest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.run_us.server.domains.crew.domain.Crew;
44
import com.run_us.server.domains.crew.domain.CrewDescription;
55
import com.run_us.server.domains.crew.domain.CrewMembership;
6+
import com.run_us.server.domains.crew.domain.CrewMonthlyRecord;
67
import com.run_us.server.domains.crew.domain.enums.CrewJoinType;
78
import com.run_us.server.domains.crew.domain.enums.CrewMembershipRole;
89
import com.run_us.server.domains.crew.domain.enums.CrewThemeType;
@@ -37,11 +38,17 @@ public Crew toEntity(User creator) {
3738
.userId(creator.getId())
3839
.role(CrewMembershipRole.OWNER)
3940
.build();
41+
CrewMonthlyRecord monthlyRecord = CrewMonthlyRecord.builder()
42+
.totalRunningCount(0)
43+
.totalDistance(0)
44+
.totalTime(0)
45+
.build();
4046
return Crew.builder()
4147
.crewDescription(description)
4248
.joinType(CrewJoinType.valueOf(this.joinType))
4349
.owner(creator)
4450
.crewMemberships(List.of(ownerMembership))
51+
.monthlyRecord(monthlyRecord)
4552
.build();
4653
}
4754
}

src/main/java/com/run_us/server/domains/crew/controller/model/request/UpdateCrewInfoRequest.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,4 @@ public class UpdateCrewInfoRequest {
1414
private String location;
1515
private String profileImageUrl;
1616
private CrewThemeType crewType;
17-
18-
public CrewDescription from(CrewDescription old) {
19-
return CrewDescription.builder()
20-
.title(this.title)
21-
.intro(this.intro)
22-
.location(this.location)
23-
.profileImageUrl(this.profileImageUrl)
24-
.themeType(this.crewType)
25-
.joinQuestion(old.getJoinQuestion())
26-
.build();
27-
}
2817
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.run_us.server.domains.crew.controller.model.response;
2+
3+
import com.run_us.server.domains.crew.domain.CrewMonthlyRecord;
4+
import lombok.Builder;
5+
import lombok.Getter;
6+
7+
@Getter
8+
public class CrewThisMonthRecord {
9+
private Integer totalRunningCount;
10+
private Integer totalDistance;
11+
private Integer totalTime;
12+
13+
@Builder
14+
CrewThisMonthRecord(Integer totalRunningCount, Integer totalDistance, Integer totalTime){
15+
this.totalRunningCount = totalRunningCount;
16+
this.totalDistance = totalDistance;
17+
this.totalTime = totalTime;
18+
}
19+
20+
public static CrewThisMonthRecord from(CrewMonthlyRecord monthlyRecord){
21+
return CrewThisMonthRecord.builder()
22+
.totalRunningCount(monthlyRecord.getTotalRunningCount())
23+
.totalDistance(monthlyRecord.getTotalDistance())
24+
.totalTime(monthlyRecord.getTotalTime())
25+
.build();
26+
}
27+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
package com.run_us.server.domains.crew.controller.model.response;
2+
3+
import com.run_us.server.domains.crew.domain.Crew;
4+
import com.run_us.server.domains.crew.domain.CrewDescription;
5+
import com.run_us.server.domains.crew.domain.enums.CrewJoinType;
6+
import com.run_us.server.domains.crew.domain.enums.CrewThemeType;
7+
import com.run_us.server.domains.crew.service.model.CrewRunCardInfo;
8+
import lombok.AccessLevel;
9+
import lombok.Builder;
10+
import lombok.Getter;
11+
import lombok.NoArgsConstructor;
12+
import java.time.ZonedDateTime;
13+
14+
@Getter
15+
@NoArgsConstructor(access = AccessLevel.PROTECTED)
16+
public class GetCrewHomeResponse {
17+
private String crewPublicId;
18+
private String title;
19+
private String profileImg;
20+
private String location;
21+
private String intro;
22+
private CrewJoinType joinType;
23+
private String joinQuestion;
24+
private CrewThemeType crewType;
25+
private Integer memberCount;
26+
private ZonedDateTime createdAt;
27+
private SimpleUserInfo crewOwner;
28+
private Boolean existNewJoinRequest;
29+
private CrewThisMonthRecord thisMonthRecord;
30+
private RunCardInfo regularRunning;
31+
private RunCardInfo irregularRunning;
32+
33+
@Builder
34+
public GetCrewHomeResponse(
35+
String crewPublicId, String title, String profileImg, String location, String intro,
36+
CrewJoinType joinType, String joinQuestion, CrewThemeType crewType,
37+
Integer memberCount, ZonedDateTime createdAt, SimpleUserInfo crewOwner,
38+
Boolean existNewJoinRequest, CrewThisMonthRecord thisMonthRecord,
39+
RunCardInfo regularRunning, RunCardInfo irregularRunning
40+
) {
41+
this.crewPublicId = crewPublicId;
42+
this.title = title;
43+
this.profileImg = profileImg;
44+
this.location = location;
45+
this.intro = intro;
46+
this.joinType = joinType;
47+
this.joinQuestion = joinQuestion;
48+
this.crewType = crewType;
49+
this.memberCount = memberCount;
50+
this.createdAt = createdAt;
51+
this.crewOwner = crewOwner;
52+
this.existNewJoinRequest = existNewJoinRequest;
53+
this.thisMonthRecord = thisMonthRecord;
54+
this.regularRunning = regularRunning;
55+
this.irregularRunning = irregularRunning;
56+
}
57+
58+
59+
public static GetCrewHomeResponse from(Crew crew, boolean existNewJoinRequest, CrewRunCardInfo cardRunInfo) {
60+
CrewDescription description = crew.getCrewDescription();
61+
62+
GetCrewHomeResponseBuilder builder = GetCrewHomeResponse.builder()
63+
.crewPublicId(crew.getPublicId())
64+
.title(description.getTitle())
65+
.profileImg(description.getProfileImageUrl())
66+
.location(description.getLocation())
67+
.intro(description.getIntro())
68+
.joinType(crew.getJoinType())
69+
.joinQuestion(description.getJoinQuestion())
70+
.crewType(description.getThemeType())
71+
.memberCount(crew.getMemberCount())
72+
.createdAt(crew.getCreatedAt())
73+
74+
.crewOwner(SimpleUserInfo.from(crew.getOwner()))
75+
.existNewJoinRequest(existNewJoinRequest)
76+
.thisMonthRecord(CrewThisMonthRecord.from(crew.getMonthlyRecord()));
77+
78+
if (cardRunInfo.getIrregularRunCard() != null) {
79+
builder.irregularRunning(cardRunInfo.getIrregularRunCard());
80+
}
81+
if (cardRunInfo.getRegularRunCard() != null) {
82+
builder.regularRunning(cardRunInfo.getRegularRunCard());
83+
}
84+
85+
return builder.build();
86+
}
87+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package com.run_us.server.domains.crew.controller.model.response;
2+
3+
import com.run_us.server.domains.running.run.domain.Run;
4+
import com.run_us.server.domains.running.run.domain.RunPace;
5+
import com.run_us.server.domains.running.run.domain.RunningPreview;
6+
import com.run_us.server.domains.user.domain.User;
7+
import com.run_us.server.global.common.GlobalConst;
8+
import lombok.Builder;
9+
import lombok.Getter;
10+
11+
import java.time.format.DateTimeFormatter;
12+
import java.util.List;
13+
14+
@Getter
15+
public class RunCardInfo {
16+
private String runningPublicId;
17+
private String topMessage;
18+
private String title;
19+
private String description;
20+
private String startAt;
21+
private List<RunPace> paceList;
22+
private Integer participantCount;
23+
private SimpleUserInfo createdBy;
24+
25+
26+
@Builder
27+
private RunCardInfo(
28+
String runningPublicId,
29+
String topMessage, String title, String description, String startAt,
30+
List<RunPace> paceList, Integer participantCount, SimpleUserInfo createdBy) {
31+
this.runningPublicId = runningPublicId;
32+
this.topMessage = topMessage;
33+
this.title = title;
34+
this.description = description;
35+
this.startAt = startAt;
36+
this.paceList = paceList;
37+
this.participantCount = participantCount;
38+
this.createdBy = createdBy;
39+
}
40+
41+
public static RunCardInfo from(Run run, String topMessage, User createdUser) {
42+
RunningPreview preview = run.getPreview();
43+
44+
return RunCardInfo.builder()
45+
.runningPublicId(run.getPublicId())
46+
.topMessage(topMessage)
47+
.title(preview.getTitle())
48+
.description(preview.getDescription())
49+
.startAt(preview.getBeginTime().format(DateTimeFormatter.ofPattern(GlobalConst.TIME_FORMAT_PATTERN)))
50+
.paceList(run.getPaceCategories())
51+
.createdBy(SimpleUserInfo.from(createdUser))
52+
.build();
53+
}
54+
55+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.run_us.server.domains.crew.controller.model.response;
2+
3+
import com.run_us.server.domains.crew.controller.model.enums.CrewErrorCode;
4+
import com.run_us.server.domains.crew.controller.model.enums.CrewException;
5+
import com.run_us.server.domains.user.domain.Profile;
6+
import com.run_us.server.domains.user.domain.User;
7+
import com.run_us.server.domains.user.exception.UserErrorCode;
8+
import lombok.Builder;
9+
import lombok.Getter;
10+
11+
@Getter
12+
public class SimpleUserInfo {
13+
private String userPublicId;
14+
private String profileImageUrl;
15+
private String nickname;
16+
17+
@Builder
18+
public SimpleUserInfo(String userPublicId, String profileImageUrl, String nickname) {
19+
this.userPublicId = userPublicId;
20+
this.profileImageUrl = profileImageUrl;
21+
this.nickname = nickname;
22+
}
23+
24+
public static SimpleUserInfo from(User user) {
25+
Profile profile = user.getProfile();
26+
if(profile == null){
27+
throw new CrewException(UserErrorCode.GET_USER_PROFILE_FAILED);
28+
}
29+
30+
return SimpleUserInfo.builder()
31+
.userPublicId(user.getPublicId())
32+
.profileImageUrl(profile.getImgUrl())
33+
.nickname(profile.getNickname())
34+
.build();
35+
}
36+
}

src/main/java/com/run_us/server/domains/crew/domain/Crew.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ public class Crew extends DateAudit {
4646
@Embedded
4747
private CrewDescription crewDescription;
4848

49+
@Embedded
50+
private CrewMonthlyRecord monthlyRecord;
51+
4952
@ElementCollection
5053
@CollectionTable(name = "crew_memberships", joinColumns = @JoinColumn(name="crew_id"))
5154
private List<CrewMembership> crewMemberships = new ArrayList<>();
@@ -95,14 +98,16 @@ public Crew(
9598
User owner,
9699
CrewJoinType joinType,
97100
CrewDescription crewDescription,
98-
List<CrewMembership> crewMemberships
101+
List<CrewMembership> crewMemberships,
102+
CrewMonthlyRecord monthlyRecord
99103
){
100104
this.owner = owner;
101105
this.joinType = joinType;
102106
this.crewDescription = crewDescription;
103107
this.memberCount = 1;
104108
this.status = CrewStatus.ACTIVE;
105109
this.crewMemberships = crewMemberships;
110+
this.monthlyRecord = monthlyRecord;
106111
}
107112

108113
public void updateJoinRule(CrewJoinType joinType, String joinQuestion) {
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.run_us.server.domains.crew.domain;
2+
3+
import lombok.*;
4+
5+
@ToString
6+
@Getter
7+
@NoArgsConstructor(access = AccessLevel.PROTECTED)
8+
public class CrewMonthlyRecord {
9+
private int totalRunningCount;
10+
private int totalDistance;
11+
private int totalTime;
12+
13+
@Builder
14+
CrewMonthlyRecord(int totalRunningCount, int totalDistance, int totalTime){
15+
this.totalRunningCount = totalRunningCount;
16+
this.totalDistance = totalDistance;
17+
this.totalTime = totalTime;
18+
}
19+
20+
public void addRecord(int addDistance, int addTime){
21+
this.totalRunningCount++;
22+
this.totalDistance += addDistance;
23+
this.totalTime += addTime;
24+
}
25+
}

0 commit comments

Comments
 (0)