77import java .util .List ;
88import java .util .Set ;
99
10+ import seedu .address .commons .core .Messages ;
1011import seedu .address .logic .commands .exceptions .CommandException ;
1112import seedu .address .model .Model ;
1213import seedu .address .model .lecture .Lecture ;
2627public class TagCommand extends Command {
2728 public static final String COMMAND_WORD = "tag" ;
2829
29- //TODO: MODIFY THIS
3030 public static final String MESSAGE_USAGE = COMMAND_WORD + ": Tag a specified video, module, or lecture " ;
31- //TODO: MODIFY THIS
32- public static final String MESSAGE_SUCCESS = "Item tagged" ;
33- public static final String MESSAGE_MODULE_NOT_FOUND = "Module doesn't exist in Le Tracker" ;
34- public static final String MESSAGE_LECTURE_NOT_FOUND = "Lecture doesn't exist in this module" ;
35- public static final String MESSAGE_VIDEO_NOT_FOUND = "Video doesn't exist in this lecture" ;
3631
32+ public static final String MESSAGE_SUCCESS = "%1$s tagged" ;
3733
3834 private final Set <Tag > tags ;
3935
@@ -95,18 +91,17 @@ public CommandResult execute(Model model) throws CommandException {
9591 requireNonNull (model );
9692
9793 if (this .isTaggingMod ) {
98- tagModule (model );
94+ return tagModule (model );
9995 } else if (this .isTaggingLec ) {
100- tagLecture (model );
101- } else if ( this . isTaggingVid ) {
102- tagVideo (model );
96+ return tagLecture (model );
97+ } else {
98+ return tagVideo (model );
10399 }
104- return new CommandResult (MESSAGE_SUCCESS );
105100 }
106101
107- private void tagModule (Model model ) throws CommandException {
102+ private CommandResult tagModule (Model model ) throws CommandException {
108103 if (!model .hasModule (moduleCode )) {
109- throw new CommandException (MESSAGE_MODULE_NOT_FOUND );
104+ throw new CommandException (String . format ( Messages . MESSAGE_MODULE_DOES_NOT_EXIST , moduleCode ) );
110105 }
111106
112107 ReadOnlyModule taggingModule = model .getModule (this .moduleCode );
@@ -122,15 +117,17 @@ private void tagModule(Model model) throws CommandException {
122117 Module taggedModule = new Module (taggingModule .getCode (),
123118 taggingModule .getName (), newTags , currentLectureList );
124119 model .setModule (taggingModule , taggedModule );
120+ return new CommandResult (String .format (MESSAGE_SUCCESS , moduleCode ));
125121 }
126122
127- private void tagLecture (Model model ) throws CommandException {
123+ private CommandResult tagLecture (Model model ) throws CommandException {
128124 if (!model .hasModule (moduleCode )) {
129- throw new CommandException (MESSAGE_MODULE_NOT_FOUND );
125+ throw new CommandException (String . format ( Messages . MESSAGE_MODULE_DOES_NOT_EXIST , moduleCode ) );
130126 }
131127
132128 if (!model .hasLecture (this .moduleCode , this .lectureName )) {
133- throw new CommandException (MESSAGE_LECTURE_NOT_FOUND );
129+ throw new CommandException (String .format (Messages .MESSAGE_LECTURE_DOES_NOT_EXIST , this .lectureName ,
130+ moduleCode ));
134131 }
135132
136133 ReadOnlyModule targetModule = model .getModule (this .moduleCode );
@@ -143,22 +140,26 @@ private void tagLecture(Model model) throws CommandException {
143140
144141 Lecture taggedLecture = new Lecture (taggingLecture .getName (), newTags , taggingLecture .getVideoList ());
145142 model .setLecture (targetModule , taggingLecture , taggedLecture );
143+ return new CommandResult (String .format (MESSAGE_SUCCESS , lectureName ));
146144 }
147145
148- private void tagVideo (Model model ) throws CommandException {
146+ private CommandResult tagVideo (Model model ) throws CommandException {
149147 if (!model .hasModule (moduleCode )) {
150- throw new CommandException (MESSAGE_MODULE_NOT_FOUND );
148+ throw new CommandException (String . format ( Messages . MESSAGE_MODULE_DOES_NOT_EXIST , moduleCode ) );
151149 }
152150
153151 if (!model .hasLecture (this .moduleCode , this .lectureName )) {
154- throw new CommandException (MESSAGE_LECTURE_NOT_FOUND );
152+ throw new CommandException (String .format (Messages .MESSAGE_LECTURE_DOES_NOT_EXIST , this .lectureName ,
153+ moduleCode ));
155154 }
156155
157156 ReadOnlyModule targetModule = model .getModule (this .moduleCode );
158157 ReadOnlyLecture targetLecture = targetModule .getLecture (this .lectureName );
159158
160159 if (!model .hasVideo (targetLecture , this .videoName )) {
161- throw new CommandException (MESSAGE_VIDEO_NOT_FOUND );
160+ throw new CommandException (String .format (Messages .MESSAGE_VIDEO_DOES_NOT_EXIST , this .videoName ,
161+ this .lectureName ,
162+ this .moduleCode ));
162163 }
163164
164165 Video taggingVideo = targetLecture .getVideo (this .videoName );
@@ -170,5 +171,6 @@ private void tagVideo(Model model) throws CommandException {
170171
171172 Video taggedVideo = new Video (taggingVideo .getName (), taggingVideo .hasWatched (), newTags );
172173 model .setVideo (targetLecture , taggingVideo , taggedVideo );
174+ return new CommandResult (String .format (MESSAGE_SUCCESS , videoName ));
173175 }
174176}
0 commit comments