77import com .muji_backend .kw_muji .common .entity .enums .ProjectRole ;
88import com .muji_backend .kw_muji .team .dto .request .RegisterRequestDTO ;
99import com .muji_backend .kw_muji .team .dto .request .ResumeRequestDTO ;
10- import com .muji_backend .kw_muji .team .dto .response .ProjectListResponseDTO ;
1110import com .muji_backend .kw_muji .team .dto .response .ProjectDetailResponseDTO ;
1211import com .muji_backend .kw_muji .team .dto .response .ResumeListResponseDTO ;
1312import com .muji_backend .kw_muji .team .service .TeamService ;
14- import jakarta .validation .Valid ;
1513import lombok .RequiredArgsConstructor ;
1614import lombok .extern .slf4j .Slf4j ;
1715import org .springframework .beans .factory .annotation .Value ;
16+ import org .springframework .http .MediaType ;
1817import org .springframework .http .ResponseEntity ;
1918import org .springframework .security .core .annotation .AuthenticationPrincipal ;
2019import org .springframework .validation .BindingResult ;
2120import org .springframework .web .bind .annotation .*;
22- import org .springframework .web .multipart .MultipartFile ;
2321
2422import java .io .IOException ;
2523import java .net .URLEncoder ;
2624import java .time .LocalDate ;
2725import java .util .ArrayList ;
28- import java .util .List ;
2926import java .util .Map ;
3027import java .util .Objects ;
3128
@@ -39,19 +36,20 @@ public class TeamController {
3936 @ Value ("${cloud.aws.s3.url}" )
4037 private String bucketURL ;
4138
42- @ PostMapping ("/register" )
43- public ResponseEntity <Map <String , Object >> writeProject (@ AuthenticationPrincipal UserEntity userInfo ,
44- @ Valid @ RequestBody RegisterRequestDTO dto ,
45- @ RequestParam ( value = "image" , required = false ) MultipartFile [] file , BindingResult bindingResult ) {
39+ @ PostMapping (value = "/register" , consumes = MediaType . MULTIPART_FORM_DATA_VALUE )
40+ public ResponseEntity <Map <String , Object >> writeProject (
41+ @ AuthenticationPrincipal UserEntity userInfo ,
42+ @ ModelAttribute RegisterRequestDTO dto , BindingResult bindingResult ) {
4643 try {
4744 // 유효성 검사
4845 teamService .validation (bindingResult , "name" );
4946 teamService .validation (bindingResult , "description" );
5047
5148 final ProjectEntity teamProject = new ProjectEntity ();
5249
53- if (file != null && file .length > 0 && !file [0 ].isEmpty ())
54- teamProject .setImage (teamService .uploadProjectImage (file , dto .getName ()));
50+ if (dto .getImage () != null && dto .getImage ().length > 0 && !dto .getImage ()[0 ].isEmpty ()) {
51+ teamProject .setImage (teamService .uploadProjectImage (dto .getImage (), dto .getName ()));
52+ }
5553
5654 teamProject .setName (dto .getName ());
5755 teamProject .setDescription (dto .getDescription ());
@@ -63,16 +61,16 @@ public ResponseEntity<Map<String, Object>> writeProject(@AuthenticationPrincipal
6361 .users (userInfo )
6462 .build ();
6563
66- if (teamProject .getParticipation () == null )
64+ if (teamProject .getParticipation () == null ) {
6765 teamProject .setParticipation (new ArrayList <>());
68-
66+ }
6967 teamProject .getParticipation ().add (participation );
7068
7169 teamService .registerProject (teamProject );
7270
73- return org . springframework . http . ResponseEntity .ok ().body (Map .of ("code" , 200 , "data" , true ));
71+ return ResponseEntity .ok ().body (Map .of ("code" , 200 , "data" , true ));
7472 } catch (IllegalArgumentException | IOException e ) {
75- return org . springframework . http . ResponseEntity .badRequest ().body (Map .of ("code" , 400 , "data" , e .getMessage ()));
73+ return ResponseEntity .badRequest ().body (Map .of ("code" , 400 , "data" , e .getMessage ()));
7674 } catch (RuntimeException e ) {
7775 return ResponseEntity .status (500 ).body (Map .of ("code" , 500 , "data" , "팀플 모집 글쓰기 오류. 잠시 후 다시 시도해주세요." ));
7876 }
0 commit comments