Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[♻️ refactor/#129] 공고 상세 정보 및 검색 결과 화면 response body 수정 #132

Merged
merged 13 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ dependencies {
// gson
implementation 'com.google.code.gson:gson:2.8.6'

implementation 'org.springframework.boot:spring-boot-starter-aop'

}

//QueryDSL 초기 설정
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;
import org.terning.terningserver.controller.swagger.FilterSwagger;
import org.terning.terningserver.dto.filter.request.UserFilterRequestDto;
import org.terning.terningserver.dto.filter.response.UserFilterResponseDto;
import org.terning.terningserver.dto.filter.request.UpdateUserFilterRequestDto;
import org.terning.terningserver.dto.filter.response.UserFilterDetailResponseDto;
import org.terning.terningserver.exception.dto.SuccessResponse;
import org.terning.terningserver.service.FilterService;

Expand All @@ -20,8 +20,8 @@ public class FilterController implements FilterSwagger {
private final FilterService filterService;

@GetMapping("/filters")
public ResponseEntity<SuccessResponse<UserFilterResponseDto>> getUserFilter(
@AuthenticationPrincipal Long userId
public ResponseEntity<SuccessResponse<UserFilterDetailResponseDto>> getUserFilter(
@AuthenticationPrincipal long userId
) {
return ResponseEntity.ok(SuccessResponse.of(
SUCCESS_GET_USER_FILTER,
Expand All @@ -31,8 +31,9 @@ public ResponseEntity<SuccessResponse<UserFilterResponseDto>> getUserFilter(

@PutMapping("/filters")
public ResponseEntity<SuccessResponse> updateUserFilter(
@AuthenticationPrincipal Long userId,
@RequestBody UserFilterRequestDto requestDto) {
@AuthenticationPrincipal long userId,
@RequestBody UpdateUserFilterRequestDto requestDto
) {
filterService.updateUserFilter(requestDto, userId);
return ResponseEntity.ok(SuccessResponse.of(SUCCESS_UPDATE_USER_FILTER));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.terning.terningserver.exception.dto.SuccessResponse;
import org.terning.terningserver.jwt.PrincipalHandler;
import org.terning.terningserver.service.ScrapService;
import org.terning.terningserver.util.LogExecutionTime;

import static org.terning.terningserver.exception.enums.SuccessMessage.*;

Expand All @@ -22,25 +23,25 @@ public class ScrapController implements ScrapSwagger {

@PostMapping("/scraps/{internshipAnnouncementId}")
public ResponseEntity<SuccessResponse> createScrap(
@AuthenticationPrincipal Long userId,
@PathVariable Long internshipAnnouncementId,
@AuthenticationPrincipal long userId,
@PathVariable long internshipAnnouncementId,
@RequestBody CreateScrapRequestDto request) {
scrapService.createScrap(internshipAnnouncementId, request, userId);
return ResponseEntity.ok(SuccessResponse.of(SUCCESS_CREATE_SCRAP));
}

@DeleteMapping("/scraps/{internshipAnnouncementId}")
public ResponseEntity<SuccessResponse> deleteScrap(
@AuthenticationPrincipal Long userId,
@PathVariable Long internshipAnnouncementId) {
@AuthenticationPrincipal long userId,
@PathVariable long internshipAnnouncementId) {
scrapService.deleteScrap(internshipAnnouncementId, userId);
return ResponseEntity.ok(SuccessResponse.of(SUCCESS_DELETE_SCRAP));
}

@PatchMapping("/scraps/{internshipAnnouncementId}")
public ResponseEntity<SuccessResponse> updateScrapColor(
@AuthenticationPrincipal Long userId,
@PathVariable Long internshipAnnouncementId,
@AuthenticationPrincipal long userId,
@PathVariable long internshipAnnouncementId,
@RequestBody UpdateScrapRequestDto request) {
scrapService.updateScrapColor(internshipAnnouncementId, request, userId);
return ResponseEntity.ok(SuccessResponse.of(SUCCESS_UPDATE_SCRAP));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,21 @@
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.terning.terningserver.dto.filter.request.UserFilterRequestDto;
import org.terning.terningserver.dto.filter.response.UserFilterResponseDto;
import org.terning.terningserver.dto.filter.request.UpdateUserFilterRequestDto;
import org.terning.terningserver.dto.filter.response.UserFilterDetailResponseDto;
import org.terning.terningserver.exception.dto.SuccessResponse;

@Tag(name = "Filter", description = "사용자 필터링 관련 API")
public interface FilterSwagger {

@Operation(summary = "사용자 필터링 정보 조회 API", description = "사용자가 설정한 필터링 정보를 조회하는 API")
ResponseEntity<SuccessResponse<UserFilterResponseDto>> getUserFilter(
@AuthenticationPrincipal Long userId
ResponseEntity<SuccessResponse<UserFilterDetailResponseDto>> getUserFilter(
@AuthenticationPrincipal long userId
);

@Operation(summary = "사용자 필터링 정보 수정 API", description = "사용자 필터링을 수정하는 API")
ResponseEntity<SuccessResponse> updateUserFilter(
@AuthenticationPrincipal Long userId,
@RequestBody UserFilterRequestDto requestDto
@AuthenticationPrincipal long userId,
@RequestBody UpdateUserFilterRequestDto requestDto
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,21 @@ public interface ScrapSwagger {

@Operation(summary = "스크랩 추가", description = "사용자가 스크랩을 추가하는 API")
ResponseEntity<SuccessResponse> createScrap(
@AuthenticationPrincipal Long userId,
@PathVariable Long internshipAnnouncementId, @RequestBody CreateScrapRequestDto request
@AuthenticationPrincipal long userId,
@PathVariable long internshipAnnouncementId,
@RequestBody CreateScrapRequestDto request
);

@Operation(summary = "스크랩 취소", description = "사용자가 스크랩을 취소하는 API")
ResponseEntity<SuccessResponse> deleteScrap(
@AuthenticationPrincipal Long userId,
@PathVariable Long internshipAnnouncementId
@AuthenticationPrincipal long userId,
@PathVariable long internshipAnnouncementId
);

@Operation(summary = "스크랩 수정", description = "사용자가 스크랩 색상을 수정하는 API")
public ResponseEntity<SuccessResponse> updateScrapColor(
@AuthenticationPrincipal Long userId,
@PathVariable Long scrapId,
@AuthenticationPrincipal long userId,
@PathVariable long scrapId,
@RequestBody UpdateScrapRequestDto request
);

Expand Down
21 changes: 21 additions & 0 deletions src/main/java/org/terning/terningserver/domain/enums/Color.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.terning.terningserver.exception.CustomException;
import org.terning.terningserver.exception.enums.ErrorMessage;

import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

import static org.terning.terningserver.exception.enums.ErrorMessage.INVALID_SCRAP_COLOR;

@RequiredArgsConstructor
@Getter
Expand All @@ -22,7 +30,20 @@ public enum Color {
private final String name;
private final String value;

private static final Map<String, Color> colorMap =
Arrays.stream(Color.values())
.collect(Collectors.toMap(Color::getName, color -> color));

public String getColorValue() {
return "#" + value;
}

public static Color findByName(String name) {
Color color = colorMap.get(name);
if (color == null) {
throw new CustomException(INVALID_SCRAP_COLOR);
}
return color;
}

}
14 changes: 7 additions & 7 deletions src/main/java/org/terning/terningserver/domain/enums/Grade.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
@Getter
@RequiredArgsConstructor
public enum Grade {
FRESHMAN(0, "1학년"),
SOPHOMORE(1, "2학년"),
JUNIOR(2, "3학년"),
SENIOR(3, "4학년");
FRESHMAN("freshman", "1학년"),
SOPHOMORE("sophomore", "2학년"),
JUNIOR("junior", "3학년"),
SENIOR("senior", "4학년");

private final int key;
private final String key;
private final String value;

public static Grade fromKey(int key){
public static Grade fromKey(String key){
for(Grade grade : Grade.values()){
if(grade.key == key){
if(grade.key.equals(key)){
return grade;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
@Getter
@RequiredArgsConstructor
public enum WorkingPeriod {
OPTION1(0, "1개월 ~ 3개월"),
OPTION2(1, "4개월 ~ 6개월"),
OPTION3(2, "7개월 이상");
OPTION1("short", "1개월 ~ 3개월"),
OPTION2("middle", "4개월 ~ 6개월"),
OPTION3("long", "7개월 이상");

private final int key;
private final String key;
private final String value;

public static WorkingPeriod fromKey(int key){
public static WorkingPeriod fromKey(String key){
for(WorkingPeriod period : WorkingPeriod.values()){
if(period.key == key){
if(period.key.equals(key)){
return period;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

@Builder(access = PRIVATE)
public record SignUpFilterRequestDto(
int grade,
int workingPeriod,
String grade,
String workingPeriod,
int startYear,
int startMonth

) {
public static SignUpFilterRequestDto of(int grade, int workingPeriod, int startYear, int startMonth) {
public static SignUpFilterRequestDto of(String grade, String workingPeriod, int startYear, int startMonth) {
return SignUpFilterRequestDto.builder()
.grade(grade)
.workingPeriod(workingPeriod)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.terning.terningserver.dto.filter.request;

public record UserFilterRequestDto(
int grade,
int workingPeriod,
public record UpdateUserFilterRequestDto(
String grade,
String workingPeriod,
int startYear,
int startMonth
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@
import lombok.Builder;
import org.terning.terningserver.domain.Filter;

@Builder
public record UserFilterResponseDto(
Integer grade,
Integer workingPeriod,
import static lombok.AccessLevel.PRIVATE;

@Builder(access = PRIVATE)
public record UserFilterDetailResponseDto(
String grade,
String workingPeriod,
Integer startYear,
Integer startMonth
) {
public static UserFilterResponseDto of(Filter userFilter) {
return UserFilterResponseDto.builder()
public static UserFilterDetailResponseDto of(final Filter userFilter) {
return UserFilterDetailResponseDto.builder()
.grade(userFilter == null ? null : userFilter.getGrade().getKey())
.workingPeriod(userFilter == null ? null : userFilter.getWorkingPeriod().getKey())
.startYear(userFilter == null ? null : userFilter.getStartYear())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,52 @@
import lombok.Builder;
import org.terning.terningserver.domain.Company;
import org.terning.terningserver.domain.InternshipAnnouncement;
import org.terning.terningserver.domain.Scrap;
import org.terning.terningserver.util.DateUtil;

@Builder
import static lombok.AccessLevel.PRIVATE;

@Builder(access = PRIVATE)
public record InternshipDetailResponseDto(
String companyImage,
String dDay,
String title,
String deadline,
String workingPeriod,
String startDate,
boolean isScrapped,
String color,
String deadline,
String startYearMonth,
int scrapCount,
int viewCount,
String company,
String companyCategory,
String companyImage,
String qualification,
String jobType,
String detail,
String url,
Long scrapId
String url
) {
public static InternshipDetailResponseDto of(InternshipAnnouncement announcement, Company company, Long scrapId) {
public static InternshipDetailResponseDto of(
final InternshipAnnouncement announcement,
final Company company,
final Long scrapId,
final String color
) {
return InternshipDetailResponseDto.builder()
.companyImage(company.getCompanyImage())
.dDay(DateUtil.convert(announcement.getDeadline()))
.title(announcement.getTitle())
.deadline(DateUtil.convertDeadline(announcement.getDeadline()))
.workingPeriod(announcement.getWorkingPeriod())
.startDate(announcement.getStartYear() + "년 " + announcement.getStartMonth() + "월")
.isScrapped(scrapId!=null)
.color(color)
.deadline(DateUtil.convertDeadline(announcement.getDeadline()))
.startYearMonth(announcement.getStartYear() + "년 " + announcement.getStartMonth() + "월")
.scrapCount(announcement.getScrapCount())
.viewCount(announcement.getViewCount())
.company(company.getCompanyInfo())
.companyCategory(company.getCompanyCategory().getValue())
.companyImage(company.getCompanyImage())
.qualification(announcement.getQualifications())
.jobType(announcement.getJobType())
.detail(announcement.getDetail())
.url(announcement.getUrl())
.scrapId(scrapId)
.build();
}
}
Loading
Loading