1
1
package com .tnt .presentation .trainee ;
2
2
3
3
import static com .tnt .common .constant .ImageConstant .DIET_S3_IMAGE_PATH ;
4
+ import static com .tnt .common .error .model .ErrorMessage .DIET_DUPLICATE_TIME ;
4
5
import static org .springframework .http .HttpStatus .CREATED ;
5
6
import static org .springframework .http .HttpStatus .OK ;
6
7
import static org .springframework .http .MediaType .MULTIPART_FORM_DATA_VALUE ;
21
22
import com .tnt .application .member .NotificationService ;
22
23
import com .tnt .application .pt .PtService ;
23
24
import com .tnt .application .s3 .S3Service ;
25
+ import com .tnt .application .trainee .DietService ;
26
+ import com .tnt .application .trainee .TraineeService ;
27
+ import com .tnt .common .error .exception .ConflictException ;
28
+ import com .tnt .domain .trainee .Trainee ;
24
29
import com .tnt .dto .trainee .request .ConnectWithTrainerRequest ;
25
30
import com .tnt .dto .trainee .request .CreateDietRequest ;
26
31
import com .tnt .dto .trainee .response .ConnectWithTrainerResponse ;
43
48
@ RequiredArgsConstructor
44
49
public class TraineeController {
45
50
51
+ private final TraineeService traineeService ;
52
+ private final S3Service s3Service ;
46
53
private final PtService ptService ;
54
+ private final DietService dietService ;
47
55
private final NotificationService notificationService ;
48
- private final S3Service s3Service ;
49
56
50
57
@ Operation (summary = "트레이너 연결 요청 API" )
51
58
@ ResponseStatus (CREATED )
@@ -65,6 +72,12 @@ public ConnectWithTrainerResponse connectWithTrainer(@AuthMember Long memberId,
65
72
public CreateDietResponse createDiet (@ AuthMember Long memberId ,
66
73
@ RequestPart ("request" ) @ Valid CreateDietRequest request ,
67
74
@ RequestPart (value = "dietImage" , required = false ) MultipartFile dietImage ) {
75
+ Trainee trainee = traineeService .getTraineeWithMemberId (memberId );
76
+
77
+ if (dietService .isDietExistWithTraineeIdAndDate (trainee .getId (), request .date ())) {
78
+ throw new ConflictException (DIET_DUPLICATE_TIME );
79
+ }
80
+
68
81
String dietImageUrl = s3Service .uploadImage (null , DIET_S3_IMAGE_PATH , dietImage );
69
82
70
83
return ptService .createDiet (memberId , request , dietImageUrl );
0 commit comments