Skip to content

Commit

Permalink
Merge pull request #21 from EWHA-THON-E-BUS/develop
Browse files Browse the repository at this point in the history
[배포] 시간표 오류 수정, 좋아요 수 계산 로직 오류 수정, member role 조회 API 추가
  • Loading branch information
xyzwv authored Mar 16, 2024
2 parents 97c63bb + a7fc9c0 commit 1a8c816
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 47 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package EBus.EBusback.domain.heart.repository;

import java.util.List;
import java.util.Optional;

import org.springframework.data.jpa.repository.JpaRepository;
Expand All @@ -12,5 +13,7 @@ public interface HeartRepository extends JpaRepository<Heart, Long> {

Optional<Heart> findByMemberAndPost(Member member, Post post);

List<Heart> findAllByPostAndIsValid(Post post, Boolean isValid);

Boolean existsByMemberAndPostAndIsValid(Member member, Post post, Boolean isValid);
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,8 @@ public String createOrRemoveHeart(Long postId) {
public Boolean existsHeart(Member member, Post post) {
return heartRepository.existsByMemberAndPostAndIsValid(member, post, true);
}

public Integer getHeartCount(Post post) {
return heartRepository.findAllByPostAndIsValid(post, true).size();
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package EBus.EBusback.domain.member.controller;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

import EBus.EBusback.domain.member.entity.Role;
import EBus.EBusback.domain.member.service.MemberService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
Expand All @@ -32,4 +34,15 @@ public String changeToAdmin() {
memberService.changeToAdmin();
return "관리자로 변경되었습니다.";
}

@Operation(summary = "사용자 role 조회")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "조회 성공"),
@ApiResponse(responseCode = "401", description = "로그인 필요")
})
@GetMapping("/role")
@ResponseStatus(HttpStatus.OK)
public Role getRole() {
return memberService.getRole();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.springframework.web.server.ResponseStatusException;

import EBus.EBusback.domain.member.entity.Member;
import EBus.EBusback.domain.member.entity.Role;
import EBus.EBusback.domain.member.repository.MemberRepository;
import EBus.EBusback.global.SecurityUtil;
import EBus.EBusback.global.exception.ErrorCode;
Expand All @@ -24,4 +25,12 @@ public void changeToAdmin() {

member.changeRole();
}

public Role getRole() {
Member member = SecurityUtil.getCurrentUser();
if (member == null)
throw new ResponseStatusException(ErrorCode.NON_LOGIN.getStatus(), ErrorCode.NON_LOGIN.getMessage());

return member.getRole();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public PostDetailResponseDto findPost(Long postId) {
.orElseThrow(() -> new ResponseStatusException(
ErrorCode.NO_POST_EXIST.getStatus(), ErrorCode.NO_POST_EXIST.getMessage()));
Member member = SecurityUtil.getCurrentUser();
return new PostDetailResponseDto(new PostCreateResponseDto(post), post.getHeartList().size(),
return new PostDetailResponseDto(new PostCreateResponseDto(post), heartService.getHeartCount(post),
findPostMemberInfo(post, member));
}

Expand All @@ -78,7 +78,7 @@ public PostMemberDto findPostMemberInfo(Post post, Member member) {
public List<PostOutlineResponseDto> findPostList(Boolean isSuggestion) {
List<Post> postList = postRepository.findAllByIsSuggestion(isSuggestion);
return postList.stream()
.map(post -> new PostOutlineResponseDto(post, post.getHeartList().size()))
.map(post -> new PostOutlineResponseDto(post, heartService.getHeartCount(post)))
.collect(Collectors.toList());
}

Expand Down
118 changes: 73 additions & 45 deletions src/main/java/EBus/EBusback/domain/stop/service/StopService.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ public StopTimetable getStopTimetable(Integer stopId){
// 주간 상행
for (TimeTableDay dayUp : dayUps) {
int plus1 = 0;
// 주간 연협 상행 (stopId: 1,2,3,4,5)
if (Objects.equals(dayUp.getRoute().toString(), "RCB")) {
if (stopId == 1) {
plus1 = 0;
Expand All @@ -172,12 +173,17 @@ else if (stopId == 4) {
else if (stopId == 5) {
plus1 = 7;
}
TimeResponseDto timeDto = TimeResponseDto.builder()
.route(dayUp.getRoute().toString())
.time(dayUp.getDepartureTime().plusMinutes(plus1))
.build();
ups.add(timeDto);

if(stopId==1|stopId==2|stopId==3|stopId==4|stopId==5){
TimeResponseDto timeDto = TimeResponseDto.builder()
.route(dayUp.getRoute().toString())
.time(dayUp.getDepartureTime().plusMinutes(plus1))
.build();
ups.add(timeDto);
}
}

// 주간 한우리 상행 (stopId: 1,2,3,6)
else if (Objects.equals(dayUp.getRoute().toString(), "HANWOORI")) {
if (stopId == 1) {
plus1 = 0;
Expand All @@ -192,17 +198,19 @@ else if (stopId == 6) {
plus1 = 7;
}

TimeResponseDto timeDto = TimeResponseDto.builder()
.route(dayUp.getRoute().toString())
.time(dayUp.getDepartureTime().plusMinutes(plus1))
.build();
ups.add(timeDto);
if(stopId==1|stopId==2|stopId==3|stopId==6){
TimeResponseDto timeDto = TimeResponseDto.builder()
.route(dayUp.getRoute().toString())
.time(dayUp.getDepartureTime().plusMinutes(plus1))
.build();
ups.add(timeDto);
}
}
}

// 주간 하행
for (TimeTableDay dayDown : dayDowns) {
int plus2 = 0;
// 주간 연협 하행 (stopId: 1,2,3,4,5)
if (Objects.equals(dayDown.getRoute().toString(), "RCB")) {
if (stopId == 1) {
plus2 = 7;
Expand All @@ -219,12 +227,17 @@ else if (stopId == 4) {
else if (stopId == 5) {
plus2 = 0;
}
TimeResponseDto timeDto = TimeResponseDto.builder()
.route("MAIN_GATE")
.time(dayDown.getDepartureTime().plusMinutes(plus2))
.build();
downs.add(timeDto);

if(stopId==1|stopId==2|stopId==3|stopId==4|stopId==5){
TimeResponseDto timeDto = TimeResponseDto.builder()
.route("MAIN_GATE")
.time(dayDown.getDepartureTime().plusMinutes(plus2))
.build();
downs.add(timeDto);
}
}

// 주간 한우리 상행 (stopId: 1,2,3,6)
else if (Objects.equals(dayDown.getRoute().toString(), "HANWOORI")){
if (stopId == 1) {
plus2 = 7;
Expand All @@ -238,15 +251,18 @@ else if (stopId == 3) {
else if (stopId == 6) {
plus2 = 0;
}
TimeResponseDto timeDto = TimeResponseDto.builder()
.route("MAIN_GATE")
.time(dayDown.getDepartureTime().plusMinutes(plus2))
.build();
downs.add(timeDto);

if(stopId==1|stopId==2|stopId==3|stopId==6){
TimeResponseDto timeDto = TimeResponseDto.builder()
.route("MAIN_GATE")
.time(dayDown.getDepartureTime().plusMinutes(plus2))
.build();
downs.add(timeDto);
}
}
}

// 평일 야간 상행
// 평일 야간 상행 (stopId: 2,6,7,8)
for (TimeTableNight weekdayNightUp : weekdayNightUps) {
int plus3 = 0;
if (stopId == 8) {
Expand All @@ -261,14 +277,17 @@ else if (stopId == 6){
else if (stopId == 7){
plus3 = 7;
}
TimeResponseDto timeDto = TimeResponseDto.builder()
.route("E_HOUSE")
.time(weekdayNightUp.getDepartureTime().plusMinutes(plus3))
.build();
ups.add(timeDto);

if(stopId==2|stopId==6|stopId==7|stopId==8){
TimeResponseDto timeDto = TimeResponseDto.builder()
.route("E_HOUSE")
.time(weekdayNightUp.getDepartureTime().plusMinutes(plus3))
.build();
ups.add(timeDto);
}
}

// 평일 야간 하행
// 평일 야간 하행 (stopId: 2,6,7,8)
for (TimeTableNight weekdayNightDown : weekdayNightDowns) {
int plus4 = 0;
if (stopId == 8) {
Expand All @@ -283,17 +302,20 @@ else if (stopId == 6){
else if (stopId == 7){
plus4 = 0;
}
TimeResponseDto timeDto = TimeResponseDto.builder()
.route("ART_DESIGN")
.time(weekdayNightDown.getDepartureTime().plusMinutes(plus4))
.build();
downs.add(timeDto);

if(stopId==2|stopId==6|stopId==7|stopId==8){
TimeResponseDto timeDto = TimeResponseDto.builder()
.route("ART_DESIGN")
.time(weekdayNightDown.getDepartureTime().plusMinutes(plus4))
.build();
downs.add(timeDto);
}
}
}

// 토 : 야간 상하행 전체
else if (dayOfWeekNumber == 6) {
// 토요일 야간 상행
// 토요일 야간 상행 (stopId: 2,6,7,8)
for (TimeTableNight satNightUp : satNightUps) {
int plus5 = 0;
if (stopId == 8) {
Expand All @@ -308,14 +330,17 @@ else if (stopId == 6){
else if (stopId == 7){
plus5 = 7;
}
TimeResponseDto timeDto = TimeResponseDto.builder()
.route("E_HOUSE")
.time(satNightUp.getDepartureTime().plusMinutes(plus5))
.build();
ups.add(timeDto);

if(stopId==2|stopId==6|stopId==7|stopId==8){
TimeResponseDto timeDto = TimeResponseDto.builder()
.route("E_HOUSE")
.time(satNightUp.getDepartureTime().plusMinutes(plus5))
.build();
ups.add(timeDto);
}
}

// 토요일 야간 하행
// 토요일 야간 하행 (stopId: 2,6,7,8)
for (TimeTableNight satNightDown : satNightDowns) {
int plus6 = 0;
if (stopId == 8) {
Expand All @@ -330,11 +355,14 @@ else if (stopId == 6){
else if (stopId == 7){
plus6 = 0;
}
TimeResponseDto timeDto = TimeResponseDto.builder()
.route("ART_DESIGN")
.time(satNightDown.getDepartureTime().plusMinutes(plus6))
.build();
downs.add(timeDto);

if(stopId==2|stopId==6|stopId==7|stopId==8){
TimeResponseDto timeDto = TimeResponseDto.builder()
.route("ART_DESIGN")
.time(satNightDown.getDepartureTime().plusMinutes(plus6))
.build();
downs.add(timeDto);
}
}
}

Expand Down

0 comments on commit 1a8c816

Please sign in to comment.