Skip to content

Commit

Permalink
Feat: Event 기능 추가 및 수정, Usercard 수정 (#46)
Browse files Browse the repository at this point in the history
Co-authored-by: yby654<yby654321@gmail.com>
Co-authored-by: hhhaeri <yhoo0020@gmail.com>
  • Loading branch information
taking and hhhaeri authored Oct 26, 2023
1 parent 34045d3 commit 9b47bc1
Show file tree
Hide file tree
Showing 30 changed files with 737 additions and 326 deletions.
3 changes: 1 addition & 2 deletions application.properties_docker
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,4 @@ spring.mail.password=${SMTP_PASS:-passWord}

#echo 'lab-cherry-nw-project-secret-key' | base64
lab.cherry.nw.jwtSecret= bGFiLWNoZXJyeS1udy1wcm9qZWN0LXNlY3JldC1rZXkK
lab.cherry.nw.jwtExpirationMs= 86400000
lab.cherry.nw.uploadPath= ${UPLOAD_PATH:/data}
lab.cherry.nw.jwtExpirationMs= 86400000
1 change: 0 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ services:
DATABASE_NAME: nw
DATABASE_USERID: nw
DATABASE_USERPASS: nw
UPLOAD_PATH: /data
MAX_UPLOAD_SIZE: 3096MB
#SPRING_PROFILES_ACTIVE: prod
JAVA_OPTS: "-Xms256m -Xmx512m -XX:+UseG1GC"
Expand Down
1 change: 0 additions & 1 deletion docker-compose/.env
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ DATABASE_NAME=nw
DATABASE_USERID=admin
DATABASE_USERPASS=admin
#SPRING_PROFILES_ACTIVE=prod
UPLOAD_PATH=/data
MAX_UPLOAD_SIZE=3096MB
REDIS_HOST=nw-redis
REDIS_PORT=8083
Expand Down
18 changes: 5 additions & 13 deletions nw/src/main/java/lab/cherry/nw/configuration/Initalizer.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package lab.cherry.nw.configuration;


import java.time.Instant;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;
import lab.cherry.nw.model.OrgEntity;
import lab.cherry.nw.model.RoleEntity;
import lab.cherry.nw.model.UserEntity;
Expand All @@ -9,24 +14,11 @@
import lab.cherry.nw.repository.UserRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.time.Instant;

@Slf4j
@RequiredArgsConstructor
@Component
public class Initalizer implements ApplicationRunner {


@Value("${lab.cherry.nw.uploadPath}")
private String uploadPath;

private final UserRepository userRepository;
private final RoleRepository roleRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ public class WebSecurityConfiguration {
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
// 토큰 사용으로 csrf 설정 Disable 처리
http
.csrf()
.disable()
.formLogin()
.disable()
.httpBasic()
.disable()
.cors()
.configurationSource(corsConfigurationSource);
.csrf(csrf -> csrf
.disable())
.formLogin(login -> login
.disable())
.httpBasic(basic -> basic
.disable())
.cors(cors -> cors
.configurationSource(corsConfigurationSource));

// 엔트리 포인트
http
Expand All @@ -69,13 +69,12 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti

http
// 권한이 없는 경우 Exception 핸들링 지정
.exceptionHandling()
.exceptionHandling(handling -> handling
.accessDeniedHandler(accessDeniedHandler)
.authenticationEntryPoint(unauthorizedHandler)
.and()
.authenticationEntryPoint(unauthorizedHandler))
.authenticationProvider(authenticationProvider)
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS); // 세션 사용하지 않음 (STATELESS 처리)
.sessionManagement(management -> management
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)); // 세션 사용하지 않음 (STATELESS 처리)

http
.addFilterBefore(jwtFilter, UsernamePasswordAuthenticationFilter.class)
Expand Down
153 changes: 153 additions & 0 deletions nw/src/main/java/lab/cherry/nw/controller/EventController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
package lab.cherry.nw.controller;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import lab.cherry.nw.error.ErrorResponse;
import lab.cherry.nw.error.ResultResponse;
import lab.cherry.nw.error.enums.SuccessCode;
import lab.cherry.nw.model.EventEntity;
import lab.cherry.nw.service.EventService;
import lab.cherry.nw.util.Common;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
* <pre>
* ClassName : EventController
* Type : class
* Description : 이벤트 목록 조회, 이벤트 상세 조회, 이벤트 생성(업데이트), 이벤트 삭제 등 이벤트와 관련된 함수를 포함하고 있는 클래스입니다.
* Related : UserRepository, UserService, UserServiceImpl
* </pre>
*/

// MEMO : 재사용성을 위해 ServiceImpl에서만 비즈니스 로직을 사용하기로 함
// Dto를 통해 알맞는 파라미터로 데이터 가공 후 사용하기로 함
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/event")
@Tag(name = "Event", description = "Event API Document")
public class EventController {

private final EventService eventService;

/**
* [EventController] 이벤트 목록 함수
*
* @return 전체 이벤트 목록을 반환합니다.
*
* Author : taking(taking@duck.com)
*/
@GetMapping("")
@Operation(summary = "이벤트 목록", description = "이벤트 목록을 조회합니다.")
public ResponseEntity<?> findAllEvents(
@RequestParam(defaultValue = "0") Integer page,
@RequestParam(defaultValue = "5") Integer size,
@RequestParam(defaultValue = "id,desc") String[] sort) {

log.info("retrieve all event controller...!");

Pageable pageable = PageRequest.of(page, size, Sort.by(Common.getOrder(sort)));

Page<EventEntity> eventEntity = eventService.getEvents(pageable);

// final ResultResponse response = ResultResponse.of(SuccessCode.OK, userService.getUsers());
return new ResponseEntity<>(eventEntity, new HttpHeaders(), HttpStatus.OK);
}

/**
* [EventController] 이벤트 생성 함수
*
* @param id usercard의 고유번호입니다.
* @param eventType 이벤트 타입입니다. (ex. "reserve", "wedding")
* @return
* <pre>
* true : 성공(200)을 반환합니다.
* false : 에러(400)를 반환합니다.
* </pre>
*
* Author : taking(taking@duck.com)
*/
@PostMapping(value = "{id}")
@Operation(summary = "이벤트 생성", description = "이벤트을 생성합니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "이벤트 생성이 완료되었습니다.", content = @Content(schema = @Schema(implementation = ResponseEntity.class))),
@ApiResponse(responseCode = "400", description = "입력 값이 잘못되었습니다.", content = @Content(schema = @Schema(implementation = ErrorResponse.class)))
})
public ResponseEntity<?> createEvent(@PathVariable("id") String id) {

log.info("[EventController] createEvent...!");

return new ResponseEntity<>(eventService.createEvent(id), new HttpHeaders(), HttpStatus.OK);
}

/**
* [EventController] 특정 이벤트 삭제 함수
*
* @param id 이벤트 고유번호를 입력합니다.
* @return
* <pre>
* true : 특정 이벤트를 삭제처리합니다.
* false : 에러(400, 404)를 반환합니다.
* </pre>
*
* Author : taking(taking@duck.com)
*/
@DeleteMapping("{id}")
@Operation(summary = "이벤트 삭제", description = "이벤트를 삭제합니다.")
public ResponseEntity<?> deleteEvent(@PathVariable("id") String id) {

log.info("[EventController] deleteEvent...!");

eventService.deleteById(id);

final ResultResponse response = ResultResponse.of(SuccessCode.OK);
return new ResponseEntity<>(response, new HttpHeaders(), HttpStatus.OK);
}


/**
* [EventController] 특정 이벤트 조회 함수
*
* @param id 이벤트 고유번호를 입력합니다.
* @return
* <pre>
* true : 특정 이벤트 정보를 반환합니다.
* false : 에러(400, 404)를 반환합니다.
* </pre>
*
* How-to:
* /api/v1/event/{id}
*
* Author : taking(taking@duck.com)
*/
@GetMapping("{id}")
@Operation(summary = "이벤트 찾기", description = "이벤트를 조회합니다.")
public ResponseEntity<?> findEvent(
@PathVariable("id") String id) {

log.info("[EventController] findEvent...!");

// final ResultResponse response = ResultResponse.of(SuccessCode.OK, userService.findById(id));
return new ResponseEntity<>(eventService.findById(id), new HttpHeaders(), HttpStatus.OK);
}

}
22 changes: 0 additions & 22 deletions nw/src/main/java/lab/cherry/nw/controller/FileController.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,28 +96,6 @@ public ResponseEntity<?> findByFileId(@PathVariable("id") String id) {
return new ResponseEntity<>(fileService.findById(id), new HttpHeaders(), HttpStatus.OK);
}

/**
* [FileController] 특정 파일 조회 함수
*
* @param path 파일 path를 입력합니다.
* @return
* <pre>
* true : 특정 파일 정보를 반환합니다.
* false : 에러(400, 404)를 반환합니다.
* </pre>
*
* Author : taking(taking@duck.com)
*/
@GetMapping("info")
@Operation(summary = "Path로 조직 찾기", description = "조직을 조회합니다.")
public ResponseEntity<?> findByFilePath(@RequestParam(required = true) String path) {

log.info("[OrgController] findByFilePath...!");

final ResultResponse response = ResultResponse.of(SuccessCode.OK, fileService.findByPath(path));
return new ResponseEntity<>(response, new HttpHeaders(), HttpStatus.OK);
}

/**
* [FileController] 특정 파일 다운로드 함수
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import lab.cherry.nw.error.ResultResponse;
import lab.cherry.nw.error.enums.SuccessCode;
import lab.cherry.nw.model.UserCardEntity;
import lab.cherry.nw.model.UserEntity;
import lab.cherry.nw.service.UserCardService;
import lab.cherry.nw.util.Common;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -156,7 +155,7 @@ public ResponseEntity<?> updateUserWeddinghalls(

log.info("[UserController] updateUserCard Weddinghall...!");

userCardService.updateWeddinghallByName(id, usercardEntity.getWeddinghall());
userCardService.updateWeddinghallByName(id, usercardEntity.getWeddinghallName());

final ResultResponse response = ResultResponse.of(SuccessCode.OK);
return new ResponseEntity<>(response, new HttpHeaders(), HttpStatus.OK);
Expand Down
26 changes: 25 additions & 1 deletion nw/src/main/java/lab/cherry/nw/controller/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import lab.cherry.nw.util.Common;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import java.util.List;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
Expand All @@ -17,6 +18,7 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
* <pre>
Expand Down Expand Up @@ -100,7 +102,7 @@ public ResponseEntity<?> updateUser(
* [UserController] 사용자 조직 업데이트 함수
*
* @param id 사용자 고유번호를 입력합니다.
* @param userEntity 사용자의 조직을 업데이트하기 위한 조직 고유아이디를 갖고 있는 객체입니다.업데이트에 필요한 사용자 정보를 담고 있는 객체입니다.
* @param userEntity 사용자의 조직을 업데이트하기 위한 조직 고유아이디를 갖고 있는 객체입니다.
* @return
* <pre>
* true : 업데이트된 사용자 정보를 반환합니다.
Expand All @@ -123,6 +125,28 @@ public ResponseEntity<?> updateUserOrgs(
return new ResponseEntity<>(response, new HttpHeaders(), HttpStatus.OK);
}

/**
* [UserController] 사용자 사진 업데이트 함수
*
* @param id 사용자 고유번호를 입력합니다.
* @param image 사용자의 사진을 업데이트하기 위한 사진을 갖고 있는 객체입니다.
*
* Author : taking(taking@duck.com)
*/
@PatchMapping("{id}/photo")
@Operation(summary = "사용자 사진 업데이트", description = "특정 사용자의 사진을 업데이트합니다.")
public ResponseEntity<?> updateUserPhoto(
@PathVariable("id") String id,
@RequestPart List<MultipartFile> image) {

log.info("[UserController] updateUserOrg...!");

userService.updateUserPhoto(id, image);

final ResultResponse response = ResultResponse.of(SuccessCode.OK);
return new ResponseEntity<>(response, new HttpHeaders(), HttpStatus.OK);
}


/**
* [UserController] 특정 사용자 조회 함수
Expand Down
Loading

0 comments on commit 9b47bc1

Please sign in to comment.