Skip to content

Commit

Permalink
Merge pull request #55 from TEAM-DHS/feat/program
Browse files Browse the repository at this point in the history
[FIX] 로그인 없이 행사 조회 가능하도록 수정
  • Loading branch information
xyzwv authored Nov 25, 2023
2 parents e4de18c + a31240b commit f36c3fe
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import com.efub.dhs.domain.program.repository.ProgramRepository;
import com.efub.dhs.domain.registration.entity.Registration;
import com.efub.dhs.domain.registration.service.RegistrationService;
import com.efub.dhs.global.utils.SecurityUtils;

import lombok.RequiredArgsConstructor;

Expand All @@ -62,7 +63,7 @@ public Program getProgram(Long programId) {
public ProgramDetailResponseDto findProgramById(Long programId) {
Program program = getProgram(programId);

Member currentUser = memberService.getCurrentUser();
Member currentUser = isLoggedIn(SecurityUtils.getCurrentUsername());

Integer remainingDays = calculateRemainingDays(program.getDeadline());

Expand Down Expand Up @@ -108,9 +109,18 @@ public ProgramDto findProgramInfo(Program program, Integer remainingDays, GoalDt
}

public ProgramMemberDto findProgramMemberInfo(Program program, Member member) {
Boolean hasLike = heartService.existsByMemberAndProgram(member, program);
Boolean hasRegistration = registrationService.existsByMemberAndProgram(member, program);
Boolean isHost = program.getHost().equals(member);
boolean hasLike;
boolean hasRegistration;
boolean isHost;
if (member == null) {
hasLike = false;
hasRegistration = false;
isHost = false;
} else {
hasLike = heartService.existsByMemberAndProgram(member, program);
hasRegistration = registrationService.existsByMemberAndProgram(member, program);
isHost = program.getHost().equals(member);
}
return new ProgramMemberDto(hasLike, hasRegistration, isHost);
}

Expand All @@ -122,12 +132,21 @@ public List<ProgramOutlineResponseDto> findSimilarPrograms(Program program, Memb

public List<ProgramOutlineResponseDto> convertToProgramOutlineResponseDtoList(
List<Program> programList, Member member) {
return programList.stream().map(program ->
new ProgramOutlineResponseDto(program,
calculateRemainingDays(program.getDeadline()),
findGoalByProgram(program.getTargetNumber(), program.getRegistrantNumber()),
heartService.existsByMemberAndProgram(member, program))
).collect(Collectors.toList());
if (member == null) {
return programList.stream().map(program ->
new ProgramOutlineResponseDto(program,
calculateRemainingDays(program.getDeadline()),
findGoalByProgram(program.getTargetNumber(), program.getRegistrantNumber()),
false)
).collect(Collectors.toList());
} else {
return programList.stream().map(program ->
new ProgramOutlineResponseDto(program,
calculateRemainingDays(program.getDeadline()),
findGoalByProgram(program.getTargetNumber(), program.getRegistrantNumber()),
heartService.existsByMemberAndProgram(member, program))
).collect(Collectors.toList());
}
}

public Long createProgram(ProgramCreationRequestDto requestDto) {
Expand Down Expand Up @@ -160,7 +179,8 @@ public Registration registerProgram(Long programId, ProgramRegistrationRequestDt
}

public ProgramListResponseDto findProgramList(int page, ProgramListRequestDto requestDto) {
Member currentUser = memberService.getCurrentUser();
Member currentUser = isLoggedIn(SecurityUtils.getCurrentUsername());

Page<Program> programPage = programRepository.findProgramListByFilter(requestDto,
PageRequest.of(page, PAGE_SIZE));
PageInfoDto pageInfoDto = PageInfoDto.createProgramPageInfoDto(programPage);
Expand All @@ -178,4 +198,14 @@ public List<ProgramOutlineResponseDto> findProgramPopular() {
false)
).collect(Collectors.toList());
}

public Member isLoggedIn(String username) {
Member currentUser;
if (username.equals("anonymousUser")) {
currentUser = null;
} else {
currentUser = memberService.getCurrentUser();
}
return currentUser;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity httpSecurity) throws
"/programs/registered",
"/programs/*/registrations",
"/auth/logout").authenticated()
.antMatchers("/auth/**", "/oauth/**").permitAll()
.antMatchers("/auth/**", "/oauth/**", "/programs/**").permitAll()
.antMatchers(HttpMethod.GET).permitAll()
.anyRequest().authenticated()
.and()
Expand Down

0 comments on commit f36c3fe

Please sign in to comment.