Skip to content

Commit

Permalink
[FIX] 백엔드 api 수정 및 예외 추가 (#18)
Browse files Browse the repository at this point in the history
* [FIX] /api/v1 추가

* [FEAT] cors 에러 추가

* [FIX] 예외처리 추가

* [CHORE] /api/v1 추가

* [CHORE] 사업체 리스트에 사업자등록번호 추가

* [CHORE] 사용자 리스트 -> 최신순 정렬 추가

* [CHORE] 토큰 기간 변경
  • Loading branch information
sangminee authored Feb 26, 2024
1 parent 24ab16c commit b4bc2d6
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ private CommunityResponse mapToCommunityResponses(User loginUser, List<Community
*/
public String saveCollection(String email, long communityId) {
User loginUser = userRepository.findByEmail(email);
communityRepository.findByIdWithView(communityId, loginUser.getId());
CollectionMapperRequest request = new CollectionMapperRequest(communityId, loginUser.getId());
boolean success = communityRepository.saveCollections(request);
if (success) {
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/com/oya/kr/global/config/WebCorsConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.oya.kr.global.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
* @author 이상민
* @since 2024.02.25
*/
@Configuration
public class WebCorsConfig implements WebMvcConfigurer {

@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("*")
.allowedMethods("GET", "POST", "DELETE", "PUT");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ protected void configure(HttpSecurity http) throws Exception {
http.addFilterBefore(tokenAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class);

http.authorizeRequests()
.antMatchers("/api/v1/join", "/api/v1/login", "/oauth/login").permitAll()
.antMatchers("/api/v1/join", "/api/v1/login", "/api/v1/oauth/login").permitAll()
.anyRequest().authenticated();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class TokenAuthenticationFilter extends OncePerRequestFilter {
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
FilterChain filterChain) throws ServletException, IOException {

logger.info("regquest 값 : " + String.valueOf(request));
logger.info("request 값 : " + String.valueOf(request));
String authorizationHeader = request.getHeader(HEADER_AUTHORIZATION);
logger.info("token : " + authorizationHeader);
if (!isAuthenticationRequired(request)) {
Expand Down Expand Up @@ -98,6 +98,6 @@ private String getAccessToken(String authorizationHeader) {
*/
private boolean isAuthenticationRequired(HttpServletRequest request) {
String requestURI = request.getRequestURI();
return !("/api/v1/login".equals(requestURI) || "/api/v1/join".equals(requestURI) || "/oauth/login".equals(requestURI));
return !("/api/v1/login".equals(requestURI) || "/api/v1/join".equals(requestURI) || "/api/v1/oauth/login".equals(requestURI));
}
}
4 changes: 2 additions & 2 deletions src/main/java/com/oya/kr/global/jwt/TokenProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
@Slf4j
public class TokenProvider {

public static final Duration ACCESS_TOKEN_DURATION = Duration.ofDays(1);
private static final Duration REFRESH_TOKEN_DURATION = Duration.ofDays(14);
public static final Duration ACCESS_TOKEN_DURATION = Duration.ofDays(30);
private static final Duration REFRESH_TOKEN_DURATION = Duration.ofDays(90);
private final JwtProperties jwtProperties;

/**
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/oya/kr/user/controller/KaKaoController.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

Expand All @@ -19,6 +20,7 @@
*/
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1")
public class KaKaoController {

private final KaKaoLoginService kaKaoLoginService;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/oya/kr/user/controller/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.springframework.web.bind.annotation.RestController;

import com.oya.kr.global.dto.response.ApplicationResponse;
import com.oya.kr.user.controller.dto.request.AccessTokenRequest;
import com.oya.kr.user.controller.dto.request.DuplicatedEmailRequest;
import com.oya.kr.user.controller.dto.request.DuplicatedNicknameRequest;
import com.oya.kr.user.controller.dto.request.JoinRequest;
Expand Down Expand Up @@ -107,7 +108,7 @@ public ResponseEntity<ApplicationResponse<JwtTokenResponse>> login(@RequestBody
* @since 2024.02.13
*/
@PostMapping("/users/reissue")
public ResponseEntity<ApplicationResponse<JwtTokenResponse>> reissue(Principal principal) {
public ResponseEntity<ApplicationResponse<JwtTokenResponse>> reissue(Principal principal, @RequestBody AccessTokenRequest accessToken) {
return ResponseEntity.ok(ApplicationResponse.success(userService.reissueAccessToken(principal.getName(), getAccessToken())));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
public class BusinessUserResponse extends BasicUserResponse{

private final Long businessId;
private final String businessRegistrationNumber;
private final String nameOfCompany; // 상호
private final String nameOfRepresentative; // 대표자
private final String dateOfBusinessCommencement; // 개업일
Expand All @@ -33,5 +34,6 @@ public BusinessUserResponse(BusinessMapperResponse businessMapperResponse){
this.businessAddress = businessMapperResponse.getBusinessAddress();
this.planCount = businessMapperResponse.getPlanCount();
this.popupCount = businessMapperResponse.getPopupCount();
this.businessRegistrationNumber = businessMapperResponse.getBusinessRegistrationNumber();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class BusinessMapperResponse extends BasicMapperResponse{
private final String faxNumber;
private final String zipCode;
private final String businessAddress; // 사업장 소재지
private final String businessRegistrationNumber;

private final int planCount;
private final int popupCount;
Expand All @@ -26,7 +27,7 @@ public BusinessMapperResponse(Long userId, String nickname, String email, LocalD
String registrationType, String userType, String profileUrl, LocalDateTime userCreatedDate,
LocalDateTime userModifiedDate, boolean userDeleted, int communityCount, Long businessId, String nameOfCompany,
String nameOfRepresentative, LocalDate dateOfBusinessCommencement, String businessItem, String connectedNumber,
String faxNumber, String zipCode, String businessAddress, int planCount, int popupCount) {
String faxNumber, String zipCode, String businessAddress, int planCount, int popupCount, String businessRegistrationNumber) {
super(userId, nickname, email, birthDate, gender, registrationType, userType, profileUrl, userCreatedDate,
userModifiedDate, userDeleted, communityCount);
this.businessId = businessId;
Expand All @@ -40,5 +41,6 @@ public BusinessMapperResponse(Long userId, String nickname, String email, LocalD
this.businessAddress = businessAddress;
this.planCount = planCount;
this.popupCount = popupCount;
this.businessRegistrationNumber = businessRegistrationNumber;
}
}
7 changes: 5 additions & 2 deletions src/main/resources/com/oya/kr/user/mapper/UserMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@
<result property="businessAddress" column="businessAddress"/>
<result property="planCount" column="planCount"/>
<result property="popupCount" column="popupCount"/>
<result property="businessRegistrationNumber" column="business_registration_number"/>
</resultMap>

<select id="findByBasic" resultMap="basicMapperResponse" resultType="com.oya.kr.user.mapper.dto.response.BasicMapperResponse">
Expand All @@ -141,6 +142,7 @@
GROUP BY
U.ID, U.NICKNAME, U.EMAIL, U.BIRTH_DATE, U.GENDER, U.REGISTRATION_TYPE, U.USER_TYPE,
U.PROFILE_URL, U.CREATED_DATE, U.MODIFIED_DATE, U.DELETED
ORDER BY U.CREATED_DATE DESC
</select>

<select id="findByBusiness" resultMap="businessMapperResponse">
Expand All @@ -149,7 +151,7 @@
U.PROFILE_URL, U.CREATED_DATE, U.MODIFIED_DATE, U.DELETED,
U.BUSINESS_REGISTRATION_NUMBER,
B.ID as businessId,B.NAME_OF_COMPANY,B.NAME_OF_REPRESENTATIVE,B.DATE_OF_BUSINESS_COMMENCEMENT,
B.BUSINESSITEM,B.CONNECTED_NUMBER,B.FAX_NUMBER,B.ZIP_CODE,B.BUSINESS_ADDRESS,
B.BUSINESSITEM,B.CONNECTED_NUMBER,B.FAX_NUMBER,B.ZIP_CODE,B.BUSINESS_ADDRESS, U.BUSINESS_REGISTRATION_NUMBER,
COUNT(C.ID) as communityCount,
COUNT(P.ID) as planCount,
COUNT(PP.ID) as popupCount
Expand All @@ -170,7 +172,8 @@
U.PROFILE_URL, U.CREATED_DATE, U.MODIFIED_DATE, U.DELETED,
U.BUSINESS_REGISTRATION_NUMBER,
B.ID,B.NAME_OF_COMPANY,B.NAME_OF_REPRESENTATIVE,B.DATE_OF_BUSINESS_COMMENCEMENT,
B.BUSINESSITEM,B.CONNECTED_NUMBER,B.FAX_NUMBER,B.ZIP_CODE,B.BUSINESS_ADDRESS
B.BUSINESSITEM,B.CONNECTED_NUMBER,B.FAX_NUMBER,B.ZIP_CODE,B.BUSINESS_ADDRESS, U.BUSINESS_REGISTRATION_NUMBER
ORDER BY U.CREATED_DATE DESC
</select>

</mapper>

0 comments on commit b4bc2d6

Please sign in to comment.