-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
448 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
backend/emm-sale/src/main/java/com/emmsale/activity/application/ActivityCommandService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.emmsale.activity.application; | ||
|
||
import com.emmsale.activity.application.dto.ActivityAddRequest; | ||
import com.emmsale.activity.application.dto.ActivityResponse; | ||
import com.emmsale.activity.domain.Activity; | ||
import com.emmsale.activity.domain.ActivityRepository; | ||
import com.emmsale.activity.exception.ActivityException; | ||
import com.emmsale.activity.exception.ActivityExceptionType; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional | ||
public class ActivityCommandService { | ||
|
||
private final ActivityRepository activityRepository; | ||
|
||
public ActivityResponse addActivity(final ActivityAddRequest request) { | ||
final String name = request.getName(); | ||
validateAlreadyExist(name); | ||
final Activity activity = new Activity(request.getActivityType(), name); | ||
return ActivityResponse.from(activityRepository.save(activity)); | ||
} | ||
|
||
private void validateAlreadyExist(final String name) { | ||
if (activityRepository.existsActivityByName(name)) { | ||
throw new ActivityException(ActivityExceptionType.ALEADY_EXIST_ACTIVITY); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
backend/emm-sale/src/main/java/com/emmsale/activity/application/dto/ActivityAddRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.emmsale.activity.application.dto; | ||
|
||
import com.emmsale.activity.domain.ActivityType; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class ActivityAddRequest { | ||
|
||
private final ActivityType activityType; | ||
private final String name; | ||
|
||
public ActivityAddRequest(final ActivityType activityType, final String name) { | ||
this.activityType = activityType; | ||
this.name = name; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
backend/emm-sale/src/main/java/com/emmsale/activity/exception/ActivityException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.emmsale.activity.exception; | ||
|
||
import com.emmsale.base.BaseException; | ||
import com.emmsale.base.BaseExceptionType; | ||
|
||
public class ActivityException extends BaseException { | ||
|
||
private final ActivityExceptionType exceptionType; | ||
|
||
public ActivityException(final ActivityExceptionType exceptionType) { | ||
super(exceptionType.errorMessage()); | ||
this.exceptionType = exceptionType; | ||
} | ||
|
||
@Override | ||
public BaseExceptionType exceptionType() { | ||
return exceptionType; | ||
} | ||
} |
Oops, something went wrong.