Skip to content

Commit

Permalink
Merge pull request #14 from giwoong01/feature/refactor
Browse files Browse the repository at this point in the history
code refactor
  • Loading branch information
giwoong01 authored Sep 15, 2023
2 parents 2847675 + 0c24628 commit 67ab3d5
Show file tree
Hide file tree
Showing 15 changed files with 115 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.itcontest.skhuming.admin.api;

import com.itcontest.skhuming.admin.api.request.NoticeSaveReqDto;
import com.itcontest.skhuming.admin.api.dto.request.NoticeSaveReqDto;
import com.itcontest.skhuming.admin.application.AdminService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
Expand All @@ -16,21 +18,42 @@ public AdminController(AdminService adminService) {
}

// 공지 등록
@PostMapping("/admin/api/notice/save")
@Operation(
summary = "공지 등록",
description = "어드민 공지 등록",
responses = {
@ApiResponse(responseCode = "200", description = "성공"),
@ApiResponse(responseCode = "400", description = "잘못된 요청")
})
@PostMapping("/api/admin/notice/save")
public ResponseEntity<String> noticeSave(@RequestBody NoticeSaveReqDto noticeSaveReqDto) {
adminService.noticeSave(noticeSaveReqDto);
return new ResponseEntity<>("SUCCESS", HttpStatus.OK);
}

@Operation(
summary = "공지 수정",
description = "어드민 공지 수정",
responses = {
@ApiResponse(responseCode = "200", description = "성공"),
@ApiResponse(responseCode = "400", description = "잘못된 요청")
})
// 공지 수정
@PutMapping("/admin/api/notice/update")
@PutMapping("/api/admin/notice/update")
public ResponseEntity<String> noticeUpdate(@RequestParam("noticeId") Long noticeId, @RequestBody NoticeSaveReqDto noticeSaveReqDto) {
adminService.noticeUpdate(noticeId, noticeSaveReqDto);
return new ResponseEntity<>("SUCCESS", HttpStatus.OK);
}

@Operation(
summary = "공지 삭제",
description = "어드민 공지 삭제",
responses = {
@ApiResponse(responseCode = "200", description = "성공"),
@ApiResponse(responseCode = "400", description = "잘못된 요청")
})
// 공지 삭제
@PostMapping("/admin/api/notice/delete")
@PostMapping("/api/admin/notice/delete")
public ResponseEntity<String> noticeDelete(@RequestParam("noticeId") Long noticeId) {
adminService.noticeDelete(noticeId);
return new ResponseEntity<>("SUCCESS", HttpStatus.OK);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.itcontest.skhuming.admin.api.request;
package com.itcontest.skhuming.admin.api.dto.request;

import lombok.AccessLevel;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.itcontest.skhuming.admin.application;

import com.itcontest.skhuming.admin.api.request.NoticeSaveReqDto;
import com.itcontest.skhuming.admin.api.dto.request.NoticeSaveReqDto;
import com.itcontest.skhuming.member.domain.MemberScrapNotice;
import com.itcontest.skhuming.member.domain.repository.MemberScrapNoticeRepository;
import com.itcontest.skhuming.notice.domain.Notice;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.itcontest.skhuming.global.error.dto.ErrorResponse;
import com.itcontest.skhuming.global.jwt.exception.NotMatchTokenException;
import com.itcontest.skhuming.member.exception.InvalidMemberException;
import com.itcontest.skhuming.member.exception.NotFoundDepartmentException;
import com.itcontest.skhuming.member.exception.NotFoundMemberException;
import com.itcontest.skhuming.mileage.exception.ExistsMemberHistoryMileageException;
import com.itcontest.skhuming.mileage.exception.NotFoundMileageException;
Expand All @@ -23,8 +24,9 @@ public class ControllerAdvice {
NotFoundNoticeException.class,
NotFoundMileageException.class,
NotScheduleFormatException.class,
NotFoundDepartmentException.class,
NotMatchTokenException.class,
ExistsMemberHistoryMileageException.class
ExistsMemberHistoryMileageException.class,
})
public ResponseEntity<ErrorResponse> handleInvalidData(RuntimeException e) {
ErrorResponse errorResponse = new ErrorResponse(e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.itcontest.skhuming.main.application.MainService;
import com.itcontest.skhuming.member.api.dto.response.DepartmentRankResDto;
import com.itcontest.skhuming.member.api.dto.response.MemberRankResDto;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -20,6 +22,11 @@ public MainController(MainService mainService) {
this.mainService = mainService;
}

@Operation(summary = "메인페이지 랭킹 조회",
description = "학부별 멤버 랭킹을 3위까지 불러옴",
responses = {
@ApiResponse(responseCode = "200", description = "랭킹 조회 성공")
})
@GetMapping("/api/main")
public ResponseEntity<List<MemberRankResDto>> mainRankingList(@RequestParam("departmentNumber") int departmentNumber) {
List<MemberRankResDto> mainPageRanking;
Expand All @@ -28,10 +35,14 @@ public ResponseEntity<List<MemberRankResDto>> mainRankingList(@RequestParam("dep
} else {
mainPageRanking = mainService.mainDepartmentRanking(departmentNumber);
}

return new ResponseEntity<>(mainPageRanking, HttpStatus.OK);
}

@Operation(summary = "메인페이지 학부별 점수 랭킹 조회",
description = "학부별 점수 랭킹을 불러옴",
responses = {
@ApiResponse(responseCode = "200", description = "학부별 랭킹 조회 성공")
})
@GetMapping("/api/main/department")
public ResponseEntity<List<DepartmentRankResDto>> departmentByRankingList() {
return new ResponseEntity<>(mainService.departmentByRanking(), HttpStatus.OK);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.itcontest.skhuming.main.application;

import com.itcontest.skhuming.global.util.ChangeDepartment;
import com.itcontest.skhuming.member.util.ChangeDepartment;
import com.itcontest.skhuming.member.api.dto.response.DepartmentRankResDto;
import com.itcontest.skhuming.member.api.dto.response.MemberRankResDto;
import com.itcontest.skhuming.member.domain.Member;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public ResponseEntity<MemberDto> memberLogin(@RequestBody MemberLoginReqDto memb
return new ResponseEntity<>(memberService.memberLogin(memberLoginReqDto), HttpStatus.OK);
}

@GetMapping("/user/api/my-profile")
@GetMapping("/api/user/my-profile")
public ResponseEntity<MemberProfileResDto> memberProfileResponse(@RequestParam("memberId") Long memberId) {
return new ResponseEntity<>(memberService.memberProfileResponse(memberId), HttpStatus.OK);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.itcontest.skhuming.global.jwt.domain.Authority;
import com.itcontest.skhuming.global.jwt.JwtProvider;
import com.itcontest.skhuming.global.util.ChangeDepartment;
import com.itcontest.skhuming.member.util.ChangeDepartment;
import com.itcontest.skhuming.global.util.SecurityUtil;
import com.itcontest.skhuming.global.jwt.domain.repository.AuthorityRepository;
import com.itcontest.skhuming.member.api.dto.request.MemberLoginReqDto;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.itcontest.skhuming.member.exception;

public class NotFoundDepartmentException extends RuntimeException {
public NotFoundDepartmentException(String message) {
super(message);
}

public NotFoundDepartmentException() {
this("해당 ID의 랭킹이 존재하지 않습니다.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.itcontest.skhuming.member.util;

import com.itcontest.skhuming.member.exception.NotFoundDepartmentException;
import org.springframework.stereotype.Component;

@Component
public class ChangeDepartment {
public static String departmentNumber(int departmentNumber) {
validateDepartmentNumber(departmentNumber);
return switch (departmentNumber) {
case 1 -> "인문융합자율학부";
case 2 -> "사회융합자율학부";
case 3 -> "미디어콘텐츠융합자율학부";
case 4 -> "IT융합자율학부";
default -> null;
};
}

private static void validateDepartmentNumber(int departmentNumber) {
if (departmentNumber >= 5) {
throw new NotFoundDepartmentException();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,25 @@ public ResponseEntity<List<MileageResDto>> mileageSelectBoxResponse() {
return new ResponseEntity<>(mileageService.mileageSelectBoxResponse(), HttpStatus.OK);
}

@PostMapping("/user/api/mileage/post")
@PostMapping("/api/user/mileage/post")
public ResponseEntity<String> memberMileageRequest(@RequestBody MemberMileageReqDto memberMileageReqDto) {
mileageService.memberMileageRequest(memberMileageReqDto);
memberMileageResponse(memberMileageReqDto.getMemberId());
return new ResponseEntity<>("SUCCESS", HttpStatus.OK);
}

@PostMapping("/user/api/mileage/history/cancel")
@PostMapping("/api/user/mileage/history/cancel")
public ResponseEntity<String> cancelMileageHistory(@RequestParam("memberId") Long memberId, @RequestParam("mileageId") Long mileageId) {
mileageService.mileageHistoryCancel(memberId, mileageId);
return new ResponseEntity<>("SUCCESS", HttpStatus.OK);
}

@GetMapping("/user/api/mileage/history/list")
@GetMapping("/api/user/mileage/history/list")
public ResponseEntity<List<MileageHistoryResDto>> myMileageHistoryList(@RequestParam("memberId") Long memberId) {
return new ResponseEntity<>(mileageService.mileageHistory(memberId), HttpStatus.OK);
}

@GetMapping("/user/api/mileage/get")
@GetMapping("/api/user/mileage/get")
public ResponseEntity<MemberMileageResDto> memberMileageResponse(@RequestParam("memberId") Long memberId) {
return new ResponseEntity<>(mileageService.memberMileageResponse(memberId), HttpStatus.OK);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,12 @@ public void memberMileageRequest(MemberMileageReqDto memberMileageReqDto) {
memberRepository.save(member);

// 추월 메시지 리스트 추가
this.messageList.add(String.valueOf(message(member, historyRanking, curRanking)));
String message = String.valueOf(message(member, historyRanking, curRanking));

if (!this.messageList.contains(message)) {
this.messageList.add(message);
}

}

/**
Expand All @@ -106,7 +111,7 @@ private StringBuilder message(Member member, int historyRanking, int curRanking)
Sort.by(Sort.Direction.DESC, "score"));
StringBuilder message = new StringBuilder();

for (int i = 0; i < memberList.size(); i++) {
for (int i = 0; i < memberList.size() - 1; i++) {
if (memberList.get(i).getNickname().equals(member.getNickname())) {
Member downMember = memberList.get(i + 1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,25 @@ public ResponseEntity<Page<NoticeListResDto>> noticeSearchList(@RequestParam(val
return new ResponseEntity<>(noticeSearchPage, HttpStatus.OK);
}

@GetMapping("/user/api/my-page/scrap/list")
@GetMapping("/api/user/my-page/scrap/list")
public ResponseEntity<List<NoticeListResDto>> myPageScrapList(@RequestParam("memberId") Long memberId) {
return new ResponseEntity<>(noticeService.myPageScrapNoticeList(memberId), HttpStatus.OK);
}

@GetMapping("/user/api/scrap/list")
@GetMapping("/api/user/scrap/list")
public ResponseEntity<Page<NoticeListResDto>> myScrapList(@RequestParam("memberId") Long memberId,
@RequestParam(value = "page", defaultValue = "0") int page,
@RequestParam(value = "size", defaultValue = "10") int size) {
return new ResponseEntity<>(noticeService.myScrapNoticeList(memberId, page, size), HttpStatus.OK);
}

@PostMapping("/user/api/notice/scrap")
@PostMapping("/api/user/notice/scrap")
public ResponseEntity<String> addMyScrap(@RequestParam("memberId") Long memberId, @RequestParam("noticeId") Long noticeId) {
noticeService.noticeScrap(memberId, noticeId);
return new ResponseEntity<>("SUCCESS", HttpStatus.OK);
}

@PostMapping("/user/api/notice/scrap/cancel")
@PostMapping("/api/user/notice/scrap/cancel")
public ResponseEntity<String> cancelMyScrap(@RequestParam("memberId") Long memberId, @RequestParam("noticeId") Long noticeId) {
noticeService.noticeScrapCancel(memberId, noticeId);
return new ResponseEntity<>("SUCCESS", HttpStatus.OK);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class NoticeService {
private static final String TILDE = "~";

private LocalDate now;
private DateTimeFormatter formatter;
private final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMdd");

private final NoticeRepository noticeRepository;
private final MemberRepository memberRepository;
Expand All @@ -40,7 +40,6 @@ public NoticeService(NoticeRepository noticeRepository, MemberRepository memberR
this.noticeRepository = noticeRepository;
this.memberRepository = memberRepository;
this.memberScrapNoticeRepository = memberScrapNoticeRepository;
formatter = DateTimeFormatter.ofPattern("MMdd");
}

/**
Expand Down Expand Up @@ -88,9 +87,17 @@ private NoticeListResDto mapToNotice(Notice notice) {

String[] splitDate = notice.getSchedule().split(TILDE);
String date = getToStringDate(splitDate[1]);
String startYear = splitDate[0].substring(0, 4);
String endYear = splitDate[1].substring(0, 4);

// 종료 : true, 진행중 : false
boolean end = Integer.parseInt(date) < Integer.parseInt(systemTime);

// 연도 구분
if (Integer.parseInt(startYear) < Integer.parseInt(endYear)) {
end = false;
}

return new NoticeListResDto(
notice.getNoticeId(),
notice.getTitle(),
Expand Down Expand Up @@ -130,9 +137,17 @@ private NoticeListResDto mapToMyScrapNotice(MemberScrapNotice MemberScrapNotice)

String[] splitDate = MemberScrapNotice.getNotice().getSchedule().split(TILDE);
String date = getToStringDate(splitDate[1]);
String startYear = splitDate[0].substring(0, 4);
String endYear = splitDate[1].substring(0, 4);

// 종료 : true, 진행중 : false
boolean end = Integer.parseInt(date) < Integer.parseInt(systemTime);

// 연도 구분
if (Integer.parseInt(startYear) < Integer.parseInt(endYear)) {
end = false;
}

return new NoticeListResDto(
MemberScrapNotice.getNotice().getNoticeId(),
MemberScrapNotice.getNotice().getTitle(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.itcontest.skhuming.ranking.application;

import com.itcontest.skhuming.global.util.ChangeDepartment;
import com.itcontest.skhuming.member.util.ChangeDepartment;
import com.itcontest.skhuming.member.api.dto.response.MemberRankResDto;
import com.itcontest.skhuming.member.domain.Member;
import com.itcontest.skhuming.member.domain.repository.MemberRepository;
Expand Down

0 comments on commit 67ab3d5

Please sign in to comment.