Skip to content

Commit

Permalink
Merge pull request #109 from team-Ollie/develop
Browse files Browse the repository at this point in the history
[develop] ๋กœ๊ทธ์ธ์‹œ ์„ผํ„ฐ ์ •๋ณด ๋ฐ˜ํ™˜, ํ”„๋กœ๊ทธ๋žจ ์ง„ํ–‰์žฅ์†Œ ์ถ”๊ฐ€
  • Loading branch information
Haeun-Y authored Jul 1, 2024
2 parents b3b4007 + 7b325ff commit b94f30a
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public BaseResponse<String> participateChallenge(@RequestBody PostChallengeReq p

// ์ฑŒ๋ฆฐ์ง€ ๊ฒ€์ƒ‰
@GetMapping("/search")
public BaseResponse<List<GetChallengesRes>> getChallenges(@RequestParam(value = "searchWord", defaultValue = "", required = false) String searchWord)throws BaseException {
public BaseResponse<List<SearchChallengeRes>> getChallenges(@RequestParam(value = "searchWord", defaultValue = "", required = false) String searchWord)throws BaseException {
return new BaseResponse<>(challengeService.getChallenges(searchWord));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class GetChallengesAdminRes {
private Integer participantsCount;

private String location;
private String locatedPlace;

private String schedule;

Expand All @@ -32,6 +33,7 @@ public static GetChallengesAdminRes fromChallenge(Challenge challenge) {
return GetChallengesAdminRes.builder()
.challengeIdx(challenge.getChallengeIdx())
.name(challenge.getName())
.locatedPlace(challenge.getProgram().getLocatedPlace())
.participantsCount(challenge.getParticipants().size())
.location(getLocationTag(challenge.getProgram()) != null ? getLocationTag(challenge.getProgram()).getTagName() : null)
.schedule(challenge.getProgram().getSchedule())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public class GetChallengesRes {

private String schedule;

private String locatedPlace;

private Integer myAttendanceRate;

private Integer totalAttendanceRate;
Expand All @@ -38,6 +40,7 @@ public static GetChallengesRes fromChallenge(Challenge challenge, Integer myAtte
.location(getLocationTag(challenge.getProgram()) != null ? getLocationTag(challenge.getProgram()).getTagName() : null)
.schedule(challenge.getProgram().getSchedule())
.myAttendanceRate(myAttendanceRate)
.locatedPlace(challenge.getProgram().getLocatedPlace())
.totalAttendanceRate(challenge.getAttendanceRate()).build();
}

Expand Down
31 changes: 31 additions & 0 deletions src/main/java/ollie/wecare/challenge/dto/SearchChallengeRes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package ollie.wecare.challenge.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import ollie.wecare.challenge.entity.Challenge;

@Data
@AllArgsConstructor
@Builder
@NoArgsConstructor
public class SearchChallengeRes {
private Long challengeIdx;

private String name;

private String schedule;

private String locatedPlace;

public static SearchChallengeRes fromChallenge(Challenge challenge) {

return SearchChallengeRes.builder()
.challengeIdx(challenge.getChallengeIdx())
.name(challenge.getName())
.schedule(challenge.getProgram().getSchedule())
.locatedPlace(challenge.getProgram().getLocatedPlace())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,12 @@ public void participateChallenge(PostChallengeReq postChallengeReq) throws BaseE
/*
* ์ฑŒ๋ฆฐ์ง€ ๊ฒ€์ƒ‰
* */
public List<GetChallengesRes> getChallenges(String searchWord) {
public List<SearchChallengeRes> getChallenges(String searchWord) {
User user = userService.getUserWithValidation();
List<Challenge> challenges = challengeRepository.findByNameContainingAndParticipantsNotContaining(searchWord, user);
return challenges.stream()
.distinct()
.map(challenge -> GetChallengesRes.fromChallenge(challenge, 0))
.map(challenge -> SearchChallengeRes.fromChallenge(challenge))
.toList();

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public class GetProgramDetailRes {

private String location;

private String locatedPlace;

private String category;

private String host;
Expand All @@ -42,6 +44,7 @@ public static GetProgramDetailRes fromProgram(Program program) {
.name(program.getName())
.openDate(convertToDateDto(program.getOpenDate()))
.dueDate(convertToDateDto(program.getDueDate()))
.locatedPlace(program.getLocatedPlace())
.location(getLocationTag(program) != null ? getLocationTag(program).getTagName() : null)
.category(getCategoryTag(program) != null ? getCategoryTag(program).getTagName() : null)
.host(program.getHost())
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/ollie/wecare/program/dto/PostProgramReq.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public class PostProgramReq {

private String location;

private String locatedPlace;

private String host;

private String schedule;
Expand All @@ -28,6 +30,7 @@ public static Program toProgram(PostProgramReq postProgramReq) {
.dueDate(convertToLocalDateTime(postProgramReq.getDueDate()))
.openDate(convertToLocalDateTime(postProgramReq.getOpenDate()))
.host(postProgramReq.getHost())
.locatedPlace(postProgramReq.getLocatedPlace())
.schedule(postProgramReq.getSchedule())
.description(postProgramReq.getDescription())
.build();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ollie/wecare/program/entity/Program.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class Program extends BaseEntity {

private LocalDateTime openDate;

//private String location;
private String locatedPlace;

private String host;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ollie/wecare/user/dto/LoginResponse.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ollie.wecare.user.dto;

public record LoginResponse(String accessToken, String refreshToken, boolean isAdmin) {
public record LoginResponse(String accessToken, String refreshToken, boolean isAdmin, Long centerIdx) {
}
2 changes: 1 addition & 1 deletion src/main/java/ollie/wecare/user/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public BaseResponse<LoginResponse> login(LoginRequest loginRequest) {
if(!encoder.matches(loginRequest.password(), user.getPassword())) throw new BaseException(WRONG_PASSWORD);

JwtDto jwtDto = authService.generateToken(user.getUserIdx());
LoginResponse loginResponse = new LoginResponse(jwtDto.accessToken(), jwtDto.refreshToken(), user.getRole().equals(Admin));
LoginResponse loginResponse = new LoginResponse(jwtDto.accessToken(), jwtDto.refreshToken(), user.getRole().equals(Admin), user.getCenter().getCenterIdx());

user.login();
userRepository.save(user);
Expand Down

0 comments on commit b94f30a

Please sign in to comment.